]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.15.3-201407012153.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.3-201407012153.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/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index 30a8ad0d..2ed9efd 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1103,6 +1103,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2099,6 +2103,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2366,6 +2374,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Makefile b/Makefile
290 index 2e37d8b..3904d75 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -246,7 +246,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294 HOSTCC = gcc
295 HOSTCXX = g++
296 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
297 -HOSTCXXFLAGS = -O2
298 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
299 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
300 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
301
302 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
303 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
304 @@ -438,8 +440,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
305 # Rules shared between *config targets and build targets
306
307 # Basic helpers built in scripts/
308 -PHONY += scripts_basic
309 -scripts_basic:
310 +PHONY += scripts_basic gcc-plugins
311 +scripts_basic: gcc-plugins
312 $(Q)$(MAKE) $(build)=scripts/basic
313 $(Q)rm -f .tmp_quiet_recordmcount
314
315 @@ -600,6 +602,72 @@ else
316 KBUILD_CFLAGS += -O2
317 endif
318
319 +ifndef DISABLE_PAX_PLUGINS
320 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
321 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
322 +else
323 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
324 +endif
325 +ifneq ($(PLUGINCC),)
326 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
327 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
328 +endif
329 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
330 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
331 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
332 +endif
333 +ifdef CONFIG_KALLOCSTAT_PLUGIN
334 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
335 +endif
336 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
337 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
338 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
339 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
340 +endif
341 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
342 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
343 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
344 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
345 +endif
346 +endif
347 +ifdef CONFIG_CHECKER_PLUGIN
348 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
349 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
350 +endif
351 +endif
352 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
353 +ifdef CONFIG_PAX_SIZE_OVERFLOW
354 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
355 +endif
356 +ifdef CONFIG_PAX_LATENT_ENTROPY
357 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
358 +endif
359 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
360 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
361 +endif
362 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
363 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
367 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
368 +ifeq ($(KBUILD_EXTMOD),)
369 +gcc-plugins:
370 + $(Q)$(MAKE) $(build)=tools/gcc
371 +else
372 +gcc-plugins: ;
373 +endif
374 +else
375 +gcc-plugins:
376 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
377 + $(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.))
378 +else
379 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
380 +endif
381 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
382 +endif
383 +endif
384 +
385 include $(srctree)/arch/$(SRCARCH)/Makefile
386
387 ifdef CONFIG_READABLE_ASM
388 @@ -816,7 +884,7 @@ export mod_sign_cmd
389
390
391 ifeq ($(KBUILD_EXTMOD),)
392 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
393 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
394
395 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
396 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
397 @@ -865,6 +933,8 @@ endif
398
399 # The actual objects are generated when descending,
400 # make sure no implicit rule kicks in
401 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
403 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
404
405 # Handle descending into subdirectories listed in $(vmlinux-dirs)
406 @@ -874,7 +944,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
407 # Error messages still appears in the original language
408
409 PHONY += $(vmlinux-dirs)
410 -$(vmlinux-dirs): prepare scripts
411 +$(vmlinux-dirs): gcc-plugins prepare scripts
412 $(Q)$(MAKE) $(build)=$@
413
414 define filechk_kernel.release
415 @@ -917,10 +987,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
416
417 archprepare: archheaders archscripts prepare1 scripts_basic
418
419 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
420 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
421 prepare0: archprepare FORCE
422 $(Q)$(MAKE) $(build)=.
423
424 # All the preparing..
425 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
426 prepare: prepare0
427
428 # Generate some files
429 @@ -1028,6 +1101,8 @@ all: modules
430 # using awk while concatenating to the final file.
431
432 PHONY += modules
433 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
434 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
435 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
436 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
437 @$(kecho) ' Building modules, stage 2.';
438 @@ -1043,7 +1118,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
439
440 # Target to prepare building external modules
441 PHONY += modules_prepare
442 -modules_prepare: prepare scripts
443 +modules_prepare: gcc-plugins prepare scripts
444
445 # Target to install modules
446 PHONY += modules_install
447 @@ -1109,7 +1184,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
448 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
449 signing_key.priv signing_key.x509 x509.genkey \
450 extra_certificates signing_key.x509.keyid \
451 - signing_key.x509.signer include/linux/version.h
452 + signing_key.x509.signer include/linux/version.h \
453 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
454 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
455 + tools/gcc/randomize_layout_seed.h
456
457 # clean - Delete most, but leave enough to build external modules
458 #
459 @@ -1148,7 +1226,7 @@ distclean: mrproper
460 @find $(srctree) $(RCS_FIND_IGNORE) \
461 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
462 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
463 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
464 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
465 -type f -print | xargs rm -f
466
467
468 @@ -1309,6 +1387,8 @@ PHONY += $(module-dirs) modules
469 $(module-dirs): crmodverdir $(objtree)/Module.symvers
470 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
471
472 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
473 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
474 modules: $(module-dirs)
475 @$(kecho) ' Building modules, stage 2.';
476 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
477 @@ -1448,17 +1528,21 @@ else
478 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
479 endif
480
481 -%.s: %.c prepare scripts FORCE
482 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484 +%.s: %.c gcc-plugins prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 %.i: %.c prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488 -%.o: %.c prepare scripts FORCE
489 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
490 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
491 +%.o: %.c gcc-plugins prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 %.lst: %.c prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495 -%.s: %.S prepare scripts FORCE
496 +%.s: %.S gcc-plugins prepare scripts FORCE
497 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
498 -%.o: %.S prepare scripts FORCE
499 +%.o: %.S gcc-plugins prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 %.symtypes: %.c prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503 @@ -1468,11 +1552,15 @@ endif
504 $(cmd_crmodverdir)
505 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
506 $(build)=$(build-dir)
507 -%/: prepare scripts FORCE
508 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
509 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
510 +%/: gcc-plugins prepare scripts FORCE
511 $(cmd_crmodverdir)
512 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
513 $(build)=$(build-dir)
514 -%.ko: prepare scripts FORCE
515 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
516 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
517 +%.ko: gcc-plugins prepare scripts FORCE
518 $(cmd_crmodverdir)
519 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
520 $(build)=$(build-dir) $(@:.ko=.o)
521 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
522 index 78b03ef..da28a51 100644
523 --- a/arch/alpha/include/asm/atomic.h
524 +++ b/arch/alpha/include/asm/atomic.h
525 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
526 #define atomic_dec(v) atomic_sub(1,(v))
527 #define atomic64_dec(v) atomic64_sub(1,(v))
528
529 +#define atomic64_read_unchecked(v) atomic64_read(v)
530 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
531 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
532 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
533 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
534 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
535 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
536 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
537 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
538 +
539 #define smp_mb__before_atomic_dec() smp_mb()
540 #define smp_mb__after_atomic_dec() smp_mb()
541 #define smp_mb__before_atomic_inc() smp_mb()
542 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
543 index ad368a9..fbe0f25 100644
544 --- a/arch/alpha/include/asm/cache.h
545 +++ b/arch/alpha/include/asm/cache.h
546 @@ -4,19 +4,19 @@
547 #ifndef __ARCH_ALPHA_CACHE_H
548 #define __ARCH_ALPHA_CACHE_H
549
550 +#include <linux/const.h>
551
552 /* Bytes per L1 (data) cache line. */
553 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
554 -# define L1_CACHE_BYTES 64
555 # define L1_CACHE_SHIFT 6
556 #else
557 /* Both EV4 and EV5 are write-through, read-allocate,
558 direct-mapped, physical.
559 */
560 -# define L1_CACHE_BYTES 32
561 # define L1_CACHE_SHIFT 5
562 #endif
563
564 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
565 #define SMP_CACHE_BYTES L1_CACHE_BYTES
566
567 #endif
568 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
569 index 968d999..d36b2df 100644
570 --- a/arch/alpha/include/asm/elf.h
571 +++ b/arch/alpha/include/asm/elf.h
572 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
573
574 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
575
576 +#ifdef CONFIG_PAX_ASLR
577 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
578 +
579 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
580 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
581 +#endif
582 +
583 /* $0 is set by ld.so to a pointer to a function which might be
584 registered using atexit. This provides a mean for the dynamic
585 linker to call DT_FINI functions for shared libraries that have
586 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
587 index aab14a0..b4fa3e7 100644
588 --- a/arch/alpha/include/asm/pgalloc.h
589 +++ b/arch/alpha/include/asm/pgalloc.h
590 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
591 pgd_set(pgd, pmd);
592 }
593
594 +static inline void
595 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
596 +{
597 + pgd_populate(mm, pgd, pmd);
598 +}
599 +
600 extern pgd_t *pgd_alloc(struct mm_struct *mm);
601
602 static inline void
603 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
604 index d8f9b7e..f6222fa 100644
605 --- a/arch/alpha/include/asm/pgtable.h
606 +++ b/arch/alpha/include/asm/pgtable.h
607 @@ -102,6 +102,17 @@ struct vm_area_struct;
608 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
609 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
610 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611 +
612 +#ifdef CONFIG_PAX_PAGEEXEC
613 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
614 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
615 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616 +#else
617 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
618 +# define PAGE_COPY_NOEXEC PAGE_COPY
619 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
620 +#endif
621 +
622 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
623
624 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
625 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
626 index 2fd00b7..cfd5069 100644
627 --- a/arch/alpha/kernel/module.c
628 +++ b/arch/alpha/kernel/module.c
629 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
630
631 /* The small sections were sorted to the end of the segment.
632 The following should definitely cover them. */
633 - gp = (u64)me->module_core + me->core_size - 0x8000;
634 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
635 got = sechdrs[me->arch.gotsecindex].sh_addr;
636
637 for (i = 0; i < n; i++) {
638 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
639 index 1402fcc..0b1abd2 100644
640 --- a/arch/alpha/kernel/osf_sys.c
641 +++ b/arch/alpha/kernel/osf_sys.c
642 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
643 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
644
645 static unsigned long
646 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
647 - unsigned long limit)
648 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
649 + unsigned long limit, unsigned long flags)
650 {
651 struct vm_unmapped_area_info info;
652 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
653
654 info.flags = 0;
655 info.length = len;
656 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
657 info.high_limit = limit;
658 info.align_mask = 0;
659 info.align_offset = 0;
660 + info.threadstack_offset = offset;
661 return vm_unmapped_area(&info);
662 }
663
664 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
665 merely specific addresses, but regions of memory -- perhaps
666 this feature should be incorporated into all ports? */
667
668 +#ifdef CONFIG_PAX_RANDMMAP
669 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
670 +#endif
671 +
672 if (addr) {
673 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
674 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
675 if (addr != (unsigned long) -ENOMEM)
676 return addr;
677 }
678
679 /* Next, try allocating at TASK_UNMAPPED_BASE. */
680 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
681 - len, limit);
682 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
683 +
684 if (addr != (unsigned long) -ENOMEM)
685 return addr;
686
687 /* Finally, try allocating in low memory. */
688 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
689 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
690
691 return addr;
692 }
693 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
694 index 98838a0..b304fb4 100644
695 --- a/arch/alpha/mm/fault.c
696 +++ b/arch/alpha/mm/fault.c
697 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
698 __reload_thread(pcb);
699 }
700
701 +#ifdef CONFIG_PAX_PAGEEXEC
702 +/*
703 + * PaX: decide what to do with offenders (regs->pc = fault address)
704 + *
705 + * returns 1 when task should be killed
706 + * 2 when patched PLT trampoline was detected
707 + * 3 when unpatched PLT trampoline was detected
708 + */
709 +static int pax_handle_fetch_fault(struct pt_regs *regs)
710 +{
711 +
712 +#ifdef CONFIG_PAX_EMUPLT
713 + int err;
714 +
715 + do { /* PaX: patched PLT emulation #1 */
716 + unsigned int ldah, ldq, jmp;
717 +
718 + err = get_user(ldah, (unsigned int *)regs->pc);
719 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
720 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
721 +
722 + if (err)
723 + break;
724 +
725 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
726 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
727 + jmp == 0x6BFB0000U)
728 + {
729 + unsigned long r27, addr;
730 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
731 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
732 +
733 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
734 + err = get_user(r27, (unsigned long *)addr);
735 + if (err)
736 + break;
737 +
738 + regs->r27 = r27;
739 + regs->pc = r27;
740 + return 2;
741 + }
742 + } while (0);
743 +
744 + do { /* PaX: patched PLT emulation #2 */
745 + unsigned int ldah, lda, br;
746 +
747 + err = get_user(ldah, (unsigned int *)regs->pc);
748 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
749 + err |= get_user(br, (unsigned int *)(regs->pc+8));
750 +
751 + if (err)
752 + break;
753 +
754 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
755 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
756 + (br & 0xFFE00000U) == 0xC3E00000U)
757 + {
758 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
759 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
760 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
761 +
762 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
763 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
764 + return 2;
765 + }
766 + } while (0);
767 +
768 + do { /* PaX: unpatched PLT emulation */
769 + unsigned int br;
770 +
771 + err = get_user(br, (unsigned int *)regs->pc);
772 +
773 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
774 + unsigned int br2, ldq, nop, jmp;
775 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
776 +
777 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
778 + err = get_user(br2, (unsigned int *)addr);
779 + err |= get_user(ldq, (unsigned int *)(addr+4));
780 + err |= get_user(nop, (unsigned int *)(addr+8));
781 + err |= get_user(jmp, (unsigned int *)(addr+12));
782 + err |= get_user(resolver, (unsigned long *)(addr+16));
783 +
784 + if (err)
785 + break;
786 +
787 + if (br2 == 0xC3600000U &&
788 + ldq == 0xA77B000CU &&
789 + nop == 0x47FF041FU &&
790 + jmp == 0x6B7B0000U)
791 + {
792 + regs->r28 = regs->pc+4;
793 + regs->r27 = addr+16;
794 + regs->pc = resolver;
795 + return 3;
796 + }
797 + }
798 + } while (0);
799 +#endif
800 +
801 + return 1;
802 +}
803 +
804 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
805 +{
806 + unsigned long i;
807 +
808 + printk(KERN_ERR "PAX: bytes at PC: ");
809 + for (i = 0; i < 5; i++) {
810 + unsigned int c;
811 + if (get_user(c, (unsigned int *)pc+i))
812 + printk(KERN_CONT "???????? ");
813 + else
814 + printk(KERN_CONT "%08x ", c);
815 + }
816 + printk("\n");
817 +}
818 +#endif
819
820 /*
821 * This routine handles page faults. It determines the address,
822 @@ -133,8 +251,29 @@ retry:
823 good_area:
824 si_code = SEGV_ACCERR;
825 if (cause < 0) {
826 - if (!(vma->vm_flags & VM_EXEC))
827 + if (!(vma->vm_flags & VM_EXEC)) {
828 +
829 +#ifdef CONFIG_PAX_PAGEEXEC
830 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
831 + goto bad_area;
832 +
833 + up_read(&mm->mmap_sem);
834 + switch (pax_handle_fetch_fault(regs)) {
835 +
836 +#ifdef CONFIG_PAX_EMUPLT
837 + case 2:
838 + case 3:
839 + return;
840 +#endif
841 +
842 + }
843 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
844 + do_group_exit(SIGKILL);
845 +#else
846 goto bad_area;
847 +#endif
848 +
849 + }
850 } else if (!cause) {
851 /* Allow reads even for write-only mappings */
852 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
853 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
854 index db3c541..a1acc89 100644
855 --- a/arch/arm/Kconfig
856 +++ b/arch/arm/Kconfig
857 @@ -1877,7 +1877,7 @@ config ALIGNMENT_TRAP
858
859 config UACCESS_WITH_MEMCPY
860 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
861 - depends on MMU
862 + depends on MMU && !PAX_MEMORY_UDEREF
863 default y if CPU_FEROCEON
864 help
865 Implement faster copy_to_user and clear_user methods for CPU
866 @@ -2141,6 +2141,7 @@ config XIP_PHYS_ADDR
867 config KEXEC
868 bool "Kexec system call (EXPERIMENTAL)"
869 depends on (!SMP || PM_SLEEP_SMP)
870 + depends on !GRKERNSEC_KMEM
871 help
872 kexec is a system call that implements the ability to shutdown your
873 current kernel, and to start another kernel. It is like a reboot
874 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
875 index 9a92fd7..3502a80 100644
876 --- a/arch/arm/include/asm/atomic.h
877 +++ b/arch/arm/include/asm/atomic.h
878 @@ -18,17 +18,35 @@
879 #include <asm/barrier.h>
880 #include <asm/cmpxchg.h>
881
882 +#ifdef CONFIG_GENERIC_ATOMIC64
883 +#include <asm-generic/atomic64.h>
884 +#endif
885 +
886 #define ATOMIC_INIT(i) { (i) }
887
888 #ifdef __KERNEL__
889
890 +#define _ASM_EXTABLE(from, to) \
891 +" .pushsection __ex_table,\"a\"\n"\
892 +" .align 3\n" \
893 +" .long " #from ", " #to"\n" \
894 +" .popsection"
895 +
896 /*
897 * On ARM, ordinary assignment (str instruction) doesn't clear the local
898 * strex/ldrex monitor on some implementations. The reason we can use it for
899 * atomic_set() is the clrex or dummy strex done on every exception return.
900 */
901 #define atomic_read(v) (*(volatile int *)&(v)->counter)
902 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
903 +{
904 + return v->counter;
905 +}
906 #define atomic_set(v,i) (((v)->counter) = (i))
907 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
908 +{
909 + v->counter = i;
910 +}
911
912 #if __LINUX_ARM_ARCH__ >= 6
913
914 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
915
916 prefetchw(&v->counter);
917 __asm__ __volatile__("@ atomic_add\n"
918 +"1: ldrex %1, [%3]\n"
919 +" adds %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + prefetchw(&v->counter);
947 + __asm__ __volatile__("@ atomic_add_unchecked\n"
948 "1: ldrex %0, [%3]\n"
949 " add %0, %0, %4\n"
950 " strex %1, %0, [%3]\n"
951 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
952 prefetchw(&v->counter);
953
954 __asm__ __volatile__("@ atomic_add_return\n"
955 +"1: ldrex %1, [%3]\n"
956 +" adds %0, %1, %4\n"
957 +
958 +#ifdef CONFIG_PAX_REFCOUNT
959 +" bvc 3f\n"
960 +" mov %0, %1\n"
961 +"2: bkpt 0xf103\n"
962 +"3:\n"
963 +#endif
964 +
965 +" strex %1, %0, [%3]\n"
966 +" teq %1, #0\n"
967 +" bne 1b"
968 +
969 +#ifdef CONFIG_PAX_REFCOUNT
970 +"\n4:\n"
971 + _ASM_EXTABLE(2b, 4b)
972 +#endif
973 +
974 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
975 + : "r" (&v->counter), "Ir" (i)
976 + : "cc");
977 +
978 + smp_mb();
979 +
980 + return result;
981 +}
982 +
983 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
984 +{
985 + unsigned long tmp;
986 + int result;
987 +
988 + smp_mb();
989 + prefetchw(&v->counter);
990 +
991 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " add %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
996
997 prefetchw(&v->counter);
998 __asm__ __volatile__("@ atomic_sub\n"
999 +"1: ldrex %1, [%3]\n"
1000 +" subs %0, %1, %4\n"
1001 +
1002 +#ifdef CONFIG_PAX_REFCOUNT
1003 +" bvc 3f\n"
1004 +"2: bkpt 0xf103\n"
1005 +"3:\n"
1006 +#endif
1007 +
1008 +" strex %1, %0, [%3]\n"
1009 +" teq %1, #0\n"
1010 +" bne 1b"
1011 +
1012 +#ifdef CONFIG_PAX_REFCOUNT
1013 +"\n4:\n"
1014 + _ASM_EXTABLE(2b, 4b)
1015 +#endif
1016 +
1017 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1018 + : "r" (&v->counter), "Ir" (i)
1019 + : "cc");
1020 +}
1021 +
1022 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1023 +{
1024 + unsigned long tmp;
1025 + int result;
1026 +
1027 + prefetchw(&v->counter);
1028 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1029 "1: ldrex %0, [%3]\n"
1030 " sub %0, %0, %4\n"
1031 " strex %1, %0, [%3]\n"
1032 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1033 prefetchw(&v->counter);
1034
1035 __asm__ __volatile__("@ atomic_sub_return\n"
1036 -"1: ldrex %0, [%3]\n"
1037 -" sub %0, %0, %4\n"
1038 +"1: ldrex %1, [%3]\n"
1039 +" subs %0, %1, %4\n"
1040 +
1041 +#ifdef CONFIG_PAX_REFCOUNT
1042 +" bvc 3f\n"
1043 +" mov %0, %1\n"
1044 +"2: bkpt 0xf103\n"
1045 +"3:\n"
1046 +#endif
1047 +
1048 " strex %1, %0, [%3]\n"
1049 " teq %1, #0\n"
1050 " bne 1b"
1051 +
1052 +#ifdef CONFIG_PAX_REFCOUNT
1053 +"\n4:\n"
1054 + _ASM_EXTABLE(2b, 4b)
1055 +#endif
1056 +
1057 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1058 : "r" (&v->counter), "Ir" (i)
1059 : "cc");
1060 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1061 __asm__ __volatile__ ("@ atomic_add_unless\n"
1062 "1: ldrex %0, [%4]\n"
1063 " teq %0, %5\n"
1064 -" beq 2f\n"
1065 -" add %1, %0, %6\n"
1066 +" beq 4f\n"
1067 +" adds %1, %0, %6\n"
1068 +
1069 +#ifdef CONFIG_PAX_REFCOUNT
1070 +" bvc 3f\n"
1071 +"2: bkpt 0xf103\n"
1072 +"3:\n"
1073 +#endif
1074 +
1075 " strex %2, %1, [%4]\n"
1076 " teq %2, #0\n"
1077 " bne 1b\n"
1078 -"2:"
1079 +"4:"
1080 +
1081 +#ifdef CONFIG_PAX_REFCOUNT
1082 + _ASM_EXTABLE(2b, 4b)
1083 +#endif
1084 +
1085 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1086 : "r" (&v->counter), "r" (u), "r" (a)
1087 : "cc");
1088 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 return oldval;
1090 }
1091
1092 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1093 +{
1094 + unsigned long oldval, res;
1095 +
1096 + smp_mb();
1097 +
1098 + do {
1099 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1100 + "ldrex %1, [%3]\n"
1101 + "mov %0, #0\n"
1102 + "teq %1, %4\n"
1103 + "strexeq %0, %5, [%3]\n"
1104 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1105 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1106 + : "cc");
1107 + } while (res);
1108 +
1109 + smp_mb();
1110 +
1111 + return oldval;
1112 +}
1113 +
1114 #else /* ARM_ARCH_6 */
1115
1116 #ifdef CONFIG_SMP
1117 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1118
1119 return val;
1120 }
1121 +
1122 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + return atomic_add_return(i, v);
1125 +}
1126 +
1127 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1128 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1129 +{
1130 + (void) atomic_add_return(i, v);
1131 +}
1132
1133 static inline int atomic_sub_return(int i, atomic_t *v)
1134 {
1135 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1136 return val;
1137 }
1138 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1139 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1140 +{
1141 + (void) atomic_sub_return(i, v);
1142 +}
1143
1144 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1145 {
1146 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1147 return ret;
1148 }
1149
1150 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1151 +{
1152 + return atomic_cmpxchg(v, old, new);
1153 +}
1154 +
1155 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1156 {
1157 int c, old;
1158 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1159 #endif /* __LINUX_ARM_ARCH__ */
1160
1161 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1162 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1163 +{
1164 + return xchg(&v->counter, new);
1165 +}
1166
1167 #define atomic_inc(v) atomic_add(1, v)
1168 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_add_unchecked(1, v);
1171 +}
1172 #define atomic_dec(v) atomic_sub(1, v)
1173 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1174 +{
1175 + atomic_sub_unchecked(1, v);
1176 +}
1177
1178 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1179 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1180 +{
1181 + return atomic_add_return_unchecked(1, v) == 0;
1182 +}
1183 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1184 #define atomic_inc_return(v) (atomic_add_return(1, v))
1185 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1186 +{
1187 + return atomic_add_return_unchecked(1, v);
1188 +}
1189 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1190 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1191
1192 @@ -251,6 +453,14 @@ typedef struct {
1193 long long counter;
1194 } atomic64_t;
1195
1196 +#ifdef CONFIG_PAX_REFCOUNT
1197 +typedef struct {
1198 + long long counter;
1199 +} atomic64_unchecked_t;
1200 +#else
1201 +typedef atomic64_t atomic64_unchecked_t;
1202 +#endif
1203 +
1204 #define ATOMIC64_INIT(i) { (i) }
1205
1206 #ifdef CONFIG_ARM_LPAE
1207 @@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1208 return result;
1209 }
1210
1211 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1212 +{
1213 + long long result;
1214 +
1215 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1216 +" ldrd %0, %H0, [%1]"
1217 + : "=&r" (result)
1218 + : "r" (&v->counter), "Qo" (v->counter)
1219 + );
1220 +
1221 + return result;
1222 +}
1223 +
1224 static inline void atomic64_set(atomic64_t *v, long long i)
1225 {
1226 __asm__ __volatile__("@ atomic64_set\n"
1227 @@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1228 : "r" (&v->counter), "r" (i)
1229 );
1230 }
1231 +
1232 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1233 +{
1234 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1235 +" strd %2, %H2, [%1]"
1236 + : "=Qo" (v->counter)
1237 + : "r" (&v->counter), "r" (i)
1238 + );
1239 +}
1240 #else
1241 static inline long long atomic64_read(const atomic64_t *v)
1242 {
1243 @@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1244 return result;
1245 }
1246
1247 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1248 +{
1249 + long long result;
1250 +
1251 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1252 +" ldrexd %0, %H0, [%1]"
1253 + : "=&r" (result)
1254 + : "r" (&v->counter), "Qo" (v->counter)
1255 + );
1256 +
1257 + return result;
1258 +}
1259 +
1260 static inline void atomic64_set(atomic64_t *v, long long i)
1261 {
1262 long long tmp;
1263 @@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1264 : "r" (&v->counter), "r" (i)
1265 : "cc");
1266 }
1267 +
1268 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1269 +{
1270 + long long tmp;
1271 +
1272 + prefetchw(&v->counter);
1273 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1274 +"1: ldrexd %0, %H0, [%2]\n"
1275 +" strexd %0, %3, %H3, [%2]\n"
1276 +" teq %0, #0\n"
1277 +" bne 1b"
1278 + : "=&r" (tmp), "=Qo" (v->counter)
1279 + : "r" (&v->counter), "r" (i)
1280 + : "cc");
1281 +}
1282 #endif
1283
1284 static inline void atomic64_add(long long i, atomic64_t *v)
1285 @@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1286 __asm__ __volatile__("@ atomic64_add\n"
1287 "1: ldrexd %0, %H0, [%3]\n"
1288 " adds %Q0, %Q0, %Q4\n"
1289 +" adcs %R0, %R0, %R4\n"
1290 +
1291 +#ifdef CONFIG_PAX_REFCOUNT
1292 +" bvc 3f\n"
1293 +"2: bkpt 0xf103\n"
1294 +"3:\n"
1295 +#endif
1296 +
1297 +" strexd %1, %0, %H0, [%3]\n"
1298 +" teq %1, #0\n"
1299 +" bne 1b"
1300 +
1301 +#ifdef CONFIG_PAX_REFCOUNT
1302 +"\n4:\n"
1303 + _ASM_EXTABLE(2b, 4b)
1304 +#endif
1305 +
1306 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1307 + : "r" (&v->counter), "r" (i)
1308 + : "cc");
1309 +}
1310 +
1311 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1312 +{
1313 + long long result;
1314 + unsigned long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%3]\n"
1319 +" adds %Q0, %Q0, %Q4\n"
1320 " adc %R0, %R0, %R4\n"
1321 " strexd %1, %0, %H0, [%3]\n"
1322 " teq %1, #0\n"
1323 @@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1324 __asm__ __volatile__("@ atomic64_add_return\n"
1325 "1: ldrexd %0, %H0, [%3]\n"
1326 " adds %Q0, %Q0, %Q4\n"
1327 +" adcs %R0, %R0, %R4\n"
1328 +
1329 +#ifdef CONFIG_PAX_REFCOUNT
1330 +" bvc 3f\n"
1331 +" mov %0, %1\n"
1332 +" mov %H0, %H1\n"
1333 +"2: bkpt 0xf103\n"
1334 +"3:\n"
1335 +#endif
1336 +
1337 +" strexd %1, %0, %H0, [%3]\n"
1338 +" teq %1, #0\n"
1339 +" bne 1b"
1340 +
1341 +#ifdef CONFIG_PAX_REFCOUNT
1342 +"\n4:\n"
1343 + _ASM_EXTABLE(2b, 4b)
1344 +#endif
1345 +
1346 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1347 + : "r" (&v->counter), "r" (i)
1348 + : "cc");
1349 +
1350 + smp_mb();
1351 +
1352 + return result;
1353 +}
1354 +
1355 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1356 +{
1357 + long long result;
1358 + unsigned long tmp;
1359 +
1360 + smp_mb();
1361 +
1362 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1363 +"1: ldrexd %0, %H0, [%3]\n"
1364 +" adds %Q0, %Q0, %Q4\n"
1365 " adc %R0, %R0, %R4\n"
1366 " strexd %1, %0, %H0, [%3]\n"
1367 " teq %1, #0\n"
1368 @@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1369 __asm__ __volatile__("@ atomic64_sub\n"
1370 "1: ldrexd %0, %H0, [%3]\n"
1371 " subs %Q0, %Q0, %Q4\n"
1372 +" sbcs %R0, %R0, %R4\n"
1373 +
1374 +#ifdef CONFIG_PAX_REFCOUNT
1375 +" bvc 3f\n"
1376 +"2: bkpt 0xf103\n"
1377 +"3:\n"
1378 +#endif
1379 +
1380 +" strexd %1, %0, %H0, [%3]\n"
1381 +" teq %1, #0\n"
1382 +" bne 1b"
1383 +
1384 +#ifdef CONFIG_PAX_REFCOUNT
1385 +"\n4:\n"
1386 + _ASM_EXTABLE(2b, 4b)
1387 +#endif
1388 +
1389 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1390 + : "r" (&v->counter), "r" (i)
1391 + : "cc");
1392 +}
1393 +
1394 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1395 +{
1396 + long long result;
1397 + unsigned long tmp;
1398 +
1399 + prefetchw(&v->counter);
1400 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1401 +"1: ldrexd %0, %H0, [%3]\n"
1402 +" subs %Q0, %Q0, %Q4\n"
1403 " sbc %R0, %R0, %R4\n"
1404 " strexd %1, %0, %H0, [%3]\n"
1405 " teq %1, #0\n"
1406 @@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1407 __asm__ __volatile__("@ atomic64_sub_return\n"
1408 "1: ldrexd %0, %H0, [%3]\n"
1409 " subs %Q0, %Q0, %Q4\n"
1410 -" sbc %R0, %R0, %R4\n"
1411 +" sbcs %R0, %R0, %R4\n"
1412 +
1413 +#ifdef CONFIG_PAX_REFCOUNT
1414 +" bvc 3f\n"
1415 +" mov %0, %1\n"
1416 +" mov %H0, %H1\n"
1417 +"2: bkpt 0xf103\n"
1418 +"3:\n"
1419 +#endif
1420 +
1421 " strexd %1, %0, %H0, [%3]\n"
1422 " teq %1, #0\n"
1423 " bne 1b"
1424 +
1425 +#ifdef CONFIG_PAX_REFCOUNT
1426 +"\n4:\n"
1427 + _ASM_EXTABLE(2b, 4b)
1428 +#endif
1429 +
1430 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1431 : "r" (&v->counter), "r" (i)
1432 : "cc");
1433
1434 - smp_mb();
1435 -
1436 return result;
1437 }
1438
1439 @@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1440 return oldval;
1441 }
1442
1443 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1444 + long long new)
1445 +{
1446 + long long oldval;
1447 + unsigned long res;
1448 +
1449 + smp_mb();
1450 +
1451 + do {
1452 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1453 + "ldrexd %1, %H1, [%3]\n"
1454 + "mov %0, #0\n"
1455 + "teq %1, %4\n"
1456 + "teqeq %H1, %H4\n"
1457 + "strexdeq %0, %5, %H5, [%3]"
1458 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1459 + : "r" (&ptr->counter), "r" (old), "r" (new)
1460 + : "cc");
1461 + } while (res);
1462 +
1463 + smp_mb();
1464 +
1465 + return oldval;
1466 +}
1467 +
1468 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1469 {
1470 long long result;
1471 @@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1472 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1473 {
1474 long long result;
1475 - unsigned long tmp;
1476 + u64 tmp;
1477
1478 smp_mb();
1479 prefetchw(&v->counter);
1480
1481 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1482 -"1: ldrexd %0, %H0, [%3]\n"
1483 -" subs %Q0, %Q0, #1\n"
1484 -" sbc %R0, %R0, #0\n"
1485 +"1: ldrexd %1, %H1, [%3]\n"
1486 +" subs %Q0, %Q1, #1\n"
1487 +" sbcs %R0, %R1, #0\n"
1488 +
1489 +#ifdef CONFIG_PAX_REFCOUNT
1490 +" bvc 3f\n"
1491 +" mov %Q0, %Q1\n"
1492 +" mov %R0, %R1\n"
1493 +"2: bkpt 0xf103\n"
1494 +"3:\n"
1495 +#endif
1496 +
1497 " teq %R0, #0\n"
1498 -" bmi 2f\n"
1499 +" bmi 4f\n"
1500 " strexd %1, %0, %H0, [%3]\n"
1501 " teq %1, #0\n"
1502 " bne 1b\n"
1503 -"2:"
1504 +"4:\n"
1505 +
1506 +#ifdef CONFIG_PAX_REFCOUNT
1507 + _ASM_EXTABLE(2b, 4b)
1508 +#endif
1509 +
1510 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1511 : "r" (&v->counter)
1512 : "cc");
1513 @@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1514 " teq %0, %5\n"
1515 " teqeq %H0, %H5\n"
1516 " moveq %1, #0\n"
1517 -" beq 2f\n"
1518 +" beq 4f\n"
1519 " adds %Q0, %Q0, %Q6\n"
1520 -" adc %R0, %R0, %R6\n"
1521 +" adcs %R0, %R0, %R6\n"
1522 +
1523 +#ifdef CONFIG_PAX_REFCOUNT
1524 +" bvc 3f\n"
1525 +"2: bkpt 0xf103\n"
1526 +"3:\n"
1527 +#endif
1528 +
1529 " strexd %2, %0, %H0, [%4]\n"
1530 " teq %2, #0\n"
1531 " bne 1b\n"
1532 -"2:"
1533 +"4:\n"
1534 +
1535 +#ifdef CONFIG_PAX_REFCOUNT
1536 + _ASM_EXTABLE(2b, 4b)
1537 +#endif
1538 +
1539 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1540 : "r" (&v->counter), "r" (u), "r" (a)
1541 : "cc");
1542 @@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1543
1544 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1545 #define atomic64_inc(v) atomic64_add(1LL, (v))
1546 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1547 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1548 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1549 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1550 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1551 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1552 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1553 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1554 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1555 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1556 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1557 index 2f59f74..1594659 100644
1558 --- a/arch/arm/include/asm/barrier.h
1559 +++ b/arch/arm/include/asm/barrier.h
1560 @@ -63,7 +63,7 @@
1561 do { \
1562 compiletime_assert_atomic_type(*p); \
1563 smp_mb(); \
1564 - ACCESS_ONCE(*p) = (v); \
1565 + ACCESS_ONCE_RW(*p) = (v); \
1566 } while (0)
1567
1568 #define smp_load_acquire(p) \
1569 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1570 index 75fe66b..ba3dee4 100644
1571 --- a/arch/arm/include/asm/cache.h
1572 +++ b/arch/arm/include/asm/cache.h
1573 @@ -4,8 +4,10 @@
1574 #ifndef __ASMARM_CACHE_H
1575 #define __ASMARM_CACHE_H
1576
1577 +#include <linux/const.h>
1578 +
1579 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1580 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1581 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1582
1583 /*
1584 * Memory returned by kmalloc() may be used for DMA, so we must make
1585 @@ -24,5 +26,6 @@
1586 #endif
1587
1588 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1589 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1590
1591 #endif
1592 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1593 index 8b8b616..d973d24 100644
1594 --- a/arch/arm/include/asm/cacheflush.h
1595 +++ b/arch/arm/include/asm/cacheflush.h
1596 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1597 void (*dma_unmap_area)(const void *, size_t, int);
1598
1599 void (*dma_flush_range)(const void *, const void *);
1600 -};
1601 +} __no_const;
1602
1603 /*
1604 * Select the calling method
1605 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1606 index 5233151..87a71fa 100644
1607 --- a/arch/arm/include/asm/checksum.h
1608 +++ b/arch/arm/include/asm/checksum.h
1609 @@ -37,7 +37,19 @@ __wsum
1610 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1611
1612 __wsum
1613 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1614 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1615 +
1616 +static inline __wsum
1617 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1618 +{
1619 + __wsum ret;
1620 + pax_open_userland();
1621 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1622 + pax_close_userland();
1623 + return ret;
1624 +}
1625 +
1626 +
1627
1628 /*
1629 * Fold a partial checksum without adding pseudo headers
1630 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1631 index abb2c37..96db950 100644
1632 --- a/arch/arm/include/asm/cmpxchg.h
1633 +++ b/arch/arm/include/asm/cmpxchg.h
1634 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1635
1636 #define xchg(ptr,x) \
1637 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1638 +#define xchg_unchecked(ptr,x) \
1639 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1640
1641 #include <asm-generic/cmpxchg-local.h>
1642
1643 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1644 index 6ddbe44..b5e38b1 100644
1645 --- a/arch/arm/include/asm/domain.h
1646 +++ b/arch/arm/include/asm/domain.h
1647 @@ -48,18 +48,37 @@
1648 * Domain types
1649 */
1650 #define DOMAIN_NOACCESS 0
1651 -#define DOMAIN_CLIENT 1
1652 #ifdef CONFIG_CPU_USE_DOMAINS
1653 +#define DOMAIN_USERCLIENT 1
1654 +#define DOMAIN_KERNELCLIENT 1
1655 #define DOMAIN_MANAGER 3
1656 +#define DOMAIN_VECTORS DOMAIN_USER
1657 #else
1658 +
1659 +#ifdef CONFIG_PAX_KERNEXEC
1660 #define DOMAIN_MANAGER 1
1661 +#define DOMAIN_KERNEXEC 3
1662 +#else
1663 +#define DOMAIN_MANAGER 1
1664 +#endif
1665 +
1666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1667 +#define DOMAIN_USERCLIENT 0
1668 +#define DOMAIN_UDEREF 1
1669 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1670 +#else
1671 +#define DOMAIN_USERCLIENT 1
1672 +#define DOMAIN_VECTORS DOMAIN_USER
1673 +#endif
1674 +#define DOMAIN_KERNELCLIENT 1
1675 +
1676 #endif
1677
1678 #define domain_val(dom,type) ((type) << (2*(dom)))
1679
1680 #ifndef __ASSEMBLY__
1681
1682 -#ifdef CONFIG_CPU_USE_DOMAINS
1683 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1684 static inline void set_domain(unsigned val)
1685 {
1686 asm volatile(
1687 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1688 isb();
1689 }
1690
1691 -#define modify_domain(dom,type) \
1692 - do { \
1693 - struct thread_info *thread = current_thread_info(); \
1694 - unsigned int domain = thread->cpu_domain; \
1695 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1696 - thread->cpu_domain = domain | domain_val(dom, type); \
1697 - set_domain(thread->cpu_domain); \
1698 - } while (0)
1699 -
1700 +extern void modify_domain(unsigned int dom, unsigned int type);
1701 #else
1702 static inline void set_domain(unsigned val) { }
1703 static inline void modify_domain(unsigned dom, unsigned type) { }
1704 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1705 index f4b46d3..abc9b2b 100644
1706 --- a/arch/arm/include/asm/elf.h
1707 +++ b/arch/arm/include/asm/elf.h
1708 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1709 the loader. We need to make sure that it is out of the way of the program
1710 that it will "exec", and that there is sufficient room for the brk. */
1711
1712 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1713 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1714 +
1715 +#ifdef CONFIG_PAX_ASLR
1716 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1717 +
1718 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1719 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1720 +#endif
1721
1722 /* When the program starts, a1 contains a pointer to a function to be
1723 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1724 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1725 extern void elf_set_personality(const struct elf32_hdr *);
1726 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1727
1728 -struct mm_struct;
1729 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1730 -#define arch_randomize_brk arch_randomize_brk
1731 -
1732 #ifdef CONFIG_MMU
1733 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1734 struct linux_binprm;
1735 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1736 index de53547..52b9a28 100644
1737 --- a/arch/arm/include/asm/fncpy.h
1738 +++ b/arch/arm/include/asm/fncpy.h
1739 @@ -81,7 +81,9 @@
1740 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1741 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1742 \
1743 + pax_open_kernel(); \
1744 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1745 + pax_close_kernel(); \
1746 flush_icache_range((unsigned long)(dest_buf), \
1747 (unsigned long)(dest_buf) + (size)); \
1748 \
1749 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1750 index 53e69da..3fdc896 100644
1751 --- a/arch/arm/include/asm/futex.h
1752 +++ b/arch/arm/include/asm/futex.h
1753 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757 + pax_open_userland();
1758 +
1759 smp_mb();
1760 /* Prefetching cannot fault */
1761 prefetchw(uaddr);
1762 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "cc", "memory");
1764 smp_mb();
1765
1766 + pax_close_userland();
1767 +
1768 *uval = val;
1769 return ret;
1770 }
1771 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1772 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1773 return -EFAULT;
1774
1775 + pax_open_userland();
1776 +
1777 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1778 "1: " TUSER(ldr) " %1, [%4]\n"
1779 " teq %1, %2\n"
1780 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1781 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1782 : "cc", "memory");
1783
1784 + pax_close_userland();
1785 +
1786 *uval = val;
1787 return ret;
1788 }
1789 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1790 return -EFAULT;
1791
1792 pagefault_disable(); /* implies preempt_disable() */
1793 + pax_open_userland();
1794
1795 switch (op) {
1796 case FUTEX_OP_SET:
1797 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1798 ret = -ENOSYS;
1799 }
1800
1801 + pax_close_userland();
1802 pagefault_enable(); /* subsumes preempt_enable() */
1803
1804 if (!ret) {
1805 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1806 index 83eb2f7..ed77159 100644
1807 --- a/arch/arm/include/asm/kmap_types.h
1808 +++ b/arch/arm/include/asm/kmap_types.h
1809 @@ -4,6 +4,6 @@
1810 /*
1811 * This is the "bare minimum". AIO seems to require this.
1812 */
1813 -#define KM_TYPE_NR 16
1814 +#define KM_TYPE_NR 17
1815
1816 #endif
1817 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1818 index 9e614a1..3302cca 100644
1819 --- a/arch/arm/include/asm/mach/dma.h
1820 +++ b/arch/arm/include/asm/mach/dma.h
1821 @@ -22,7 +22,7 @@ struct dma_ops {
1822 int (*residue)(unsigned int, dma_t *); /* optional */
1823 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1824 const char *type;
1825 -};
1826 +} __do_const;
1827
1828 struct dma_struct {
1829 void *addr; /* single DMA address */
1830 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1831 index f98c7f3..e5c626d 100644
1832 --- a/arch/arm/include/asm/mach/map.h
1833 +++ b/arch/arm/include/asm/mach/map.h
1834 @@ -23,17 +23,19 @@ struct map_desc {
1835
1836 /* types 0-3 are defined in asm/io.h */
1837 enum {
1838 - MT_UNCACHED = 4,
1839 - MT_CACHECLEAN,
1840 - MT_MINICLEAN,
1841 + MT_UNCACHED_RW = 4,
1842 + MT_CACHECLEAN_RO,
1843 + MT_MINICLEAN_RO,
1844 MT_LOW_VECTORS,
1845 MT_HIGH_VECTORS,
1846 - MT_MEMORY_RWX,
1847 + __MT_MEMORY_RWX,
1848 MT_MEMORY_RW,
1849 - MT_ROM,
1850 - MT_MEMORY_RWX_NONCACHED,
1851 + MT_MEMORY_RX,
1852 + MT_ROM_RX,
1853 + MT_MEMORY_RW_NONCACHED,
1854 + MT_MEMORY_RX_NONCACHED,
1855 MT_MEMORY_RW_DTCM,
1856 - MT_MEMORY_RWX_ITCM,
1857 + MT_MEMORY_RX_ITCM,
1858 MT_MEMORY_RW_SO,
1859 MT_MEMORY_DMA_READY,
1860 };
1861 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1862 index f94784f..9a09a4a 100644
1863 --- a/arch/arm/include/asm/outercache.h
1864 +++ b/arch/arm/include/asm/outercache.h
1865 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1866 #endif
1867 void (*set_debug)(unsigned long);
1868 void (*resume)(void);
1869 -};
1870 +} __no_const;
1871
1872 extern struct outer_cache_fns outer_cache;
1873
1874 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1875 index 4355f0e..cd9168e 100644
1876 --- a/arch/arm/include/asm/page.h
1877 +++ b/arch/arm/include/asm/page.h
1878 @@ -23,6 +23,7 @@
1879
1880 #else
1881
1882 +#include <linux/compiler.h>
1883 #include <asm/glue.h>
1884
1885 /*
1886 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1887 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1888 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1889 unsigned long vaddr, struct vm_area_struct *vma);
1890 -};
1891 +} __no_const;
1892
1893 #ifdef MULTI_USER
1894 extern struct cpu_user_fns cpu_user;
1895 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1896 index 78a7793..e3dc06c 100644
1897 --- a/arch/arm/include/asm/pgalloc.h
1898 +++ b/arch/arm/include/asm/pgalloc.h
1899 @@ -17,6 +17,7 @@
1900 #include <asm/processor.h>
1901 #include <asm/cacheflush.h>
1902 #include <asm/tlbflush.h>
1903 +#include <asm/system_info.h>
1904
1905 #define check_pgt_cache() do { } while (0)
1906
1907 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1908 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1909 }
1910
1911 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1912 +{
1913 + pud_populate(mm, pud, pmd);
1914 +}
1915 +
1916 #else /* !CONFIG_ARM_LPAE */
1917
1918 /*
1919 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1920 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1921 #define pmd_free(mm, pmd) do { } while (0)
1922 #define pud_populate(mm,pmd,pte) BUG()
1923 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1924
1925 #endif /* CONFIG_ARM_LPAE */
1926
1927 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1928 __free_page(pte);
1929 }
1930
1931 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1932 +{
1933 +#ifdef CONFIG_ARM_LPAE
1934 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1935 +#else
1936 + if (addr & SECTION_SIZE)
1937 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1938 + else
1939 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1940 +#endif
1941 + flush_pmd_entry(pmdp);
1942 +}
1943 +
1944 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1945 pmdval_t prot)
1946 {
1947 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1948 static inline void
1949 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1950 {
1951 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1952 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1953 }
1954 #define pmd_pgtable(pmd) pmd_page(pmd)
1955
1956 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1957 index 5cfba15..f415e1a 100644
1958 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1959 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1960 @@ -20,12 +20,15 @@
1961 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1962 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1963 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1964 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1965 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1966 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1967 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1968 +
1969 /*
1970 * - section
1971 */
1972 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1973 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1974 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1975 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1976 @@ -37,6 +40,7 @@
1977 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1978 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1979 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1980 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1981
1982 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1983 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1984 @@ -66,6 +70,7 @@
1985 * - extended small page/tiny page
1986 */
1987 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1988 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1989 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1990 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1991 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1992 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1993 index 219ac88..73ec32a 100644
1994 --- a/arch/arm/include/asm/pgtable-2level.h
1995 +++ b/arch/arm/include/asm/pgtable-2level.h
1996 @@ -126,6 +126,9 @@
1997 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1998 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1999
2000 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2001 +#define L_PTE_PXN (_AT(pteval_t, 0))
2002 +
2003 /*
2004 * These are the memory types, defined to be compatible with
2005 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2006 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2007 index 626989f..9d67a33 100644
2008 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2009 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2010 @@ -75,6 +75,7 @@
2011 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2012 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2013 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2014 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2015 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2016
2017 /*
2018 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2019 index 85c60ad..b0bbd7e 100644
2020 --- a/arch/arm/include/asm/pgtable-3level.h
2021 +++ b/arch/arm/include/asm/pgtable-3level.h
2022 @@ -82,6 +82,7 @@
2023 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2024 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2025 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2026 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2027 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2028 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2029 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2030 @@ -95,6 +96,7 @@
2031 /*
2032 * To be used in assembly code with the upper page attributes.
2033 */
2034 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2035 #define L_PTE_XN_HIGH (1 << (54 - 32))
2036 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2037
2038 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2039 index 5478e5d..f5b5cb3 100644
2040 --- a/arch/arm/include/asm/pgtable.h
2041 +++ b/arch/arm/include/asm/pgtable.h
2042 @@ -33,6 +33,9 @@
2043 #include <asm/pgtable-2level.h>
2044 #endif
2045
2046 +#define ktla_ktva(addr) (addr)
2047 +#define ktva_ktla(addr) (addr)
2048 +
2049 /*
2050 * Just any arbitrary offset to the start of the vmalloc VM area: the
2051 * current 8MB value just means that there will be a 8MB "hole" after the
2052 @@ -48,6 +51,9 @@
2053 #define LIBRARY_TEXT_START 0x0c000000
2054
2055 #ifndef __ASSEMBLY__
2056 +extern pteval_t __supported_pte_mask;
2057 +extern pmdval_t __supported_pmd_mask;
2058 +
2059 extern void __pte_error(const char *file, int line, pte_t);
2060 extern void __pmd_error(const char *file, int line, pmd_t);
2061 extern void __pgd_error(const char *file, int line, pgd_t);
2062 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2063 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2064 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2065
2066 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2067 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2068 +
2069 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2070 +#include <asm/domain.h>
2071 +#include <linux/thread_info.h>
2072 +#include <linux/preempt.h>
2073 +
2074 +static inline int test_domain(int domain, int domaintype)
2075 +{
2076 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2077 +}
2078 +#endif
2079 +
2080 +#ifdef CONFIG_PAX_KERNEXEC
2081 +static inline unsigned long pax_open_kernel(void) {
2082 +#ifdef CONFIG_ARM_LPAE
2083 + /* TODO */
2084 +#else
2085 + preempt_disable();
2086 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2087 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2088 +#endif
2089 + return 0;
2090 +}
2091 +
2092 +static inline unsigned long pax_close_kernel(void) {
2093 +#ifdef CONFIG_ARM_LPAE
2094 + /* TODO */
2095 +#else
2096 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2097 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2098 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2099 + preempt_enable_no_resched();
2100 +#endif
2101 + return 0;
2102 +}
2103 +#else
2104 +static inline unsigned long pax_open_kernel(void) { return 0; }
2105 +static inline unsigned long pax_close_kernel(void) { return 0; }
2106 +#endif
2107 +
2108 /*
2109 * This is the lowest virtual address we can permit any user space
2110 * mapping to be mapped at. This is particularly important for
2111 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2112 /*
2113 * The pgprot_* and protection_map entries will be fixed up in runtime
2114 * to include the cachable and bufferable bits based on memory policy,
2115 - * as well as any architecture dependent bits like global/ASID and SMP
2116 - * shared mapping bits.
2117 + * as well as any architecture dependent bits like global/ASID, PXN,
2118 + * and SMP shared mapping bits.
2119 */
2120 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2121
2122 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2123 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2124 {
2125 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2126 - L_PTE_NONE | L_PTE_VALID;
2127 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2128 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2129 return pte;
2130 }
2131 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2132 index c4ae171..ea0c0c2 100644
2133 --- a/arch/arm/include/asm/psci.h
2134 +++ b/arch/arm/include/asm/psci.h
2135 @@ -29,7 +29,7 @@ struct psci_operations {
2136 int (*cpu_off)(struct psci_power_state state);
2137 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2138 int (*migrate)(unsigned long cpuid);
2139 -};
2140 +} __no_const;
2141
2142 extern struct psci_operations psci_ops;
2143 extern struct smp_operations psci_smp_ops;
2144 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2145 index 2ec765c..beb1fe16 100644
2146 --- a/arch/arm/include/asm/smp.h
2147 +++ b/arch/arm/include/asm/smp.h
2148 @@ -113,7 +113,7 @@ struct smp_operations {
2149 int (*cpu_disable)(unsigned int cpu);
2150 #endif
2151 #endif
2152 -};
2153 +} __no_const;
2154
2155 struct of_cpu_method {
2156 const char *method;
2157 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2158 index f989d7c..e8aa7f0 100644
2159 --- a/arch/arm/include/asm/thread_info.h
2160 +++ b/arch/arm/include/asm/thread_info.h
2161 @@ -88,9 +88,9 @@ struct thread_info {
2162 .flags = 0, \
2163 .preempt_count = INIT_PREEMPT_COUNT, \
2164 .addr_limit = KERNEL_DS, \
2165 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2166 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2167 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2168 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2169 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2170 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2171 .restart_block = { \
2172 .fn = do_no_restart_syscall, \
2173 }, \
2174 @@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2175 #define TIF_SYSCALL_AUDIT 9
2176 #define TIF_SYSCALL_TRACEPOINT 10
2177 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2178 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2179 +/* within 8 bits of TIF_SYSCALL_TRACE
2180 + * to meet flexible second operand requirements
2181 + */
2182 +#define TIF_GRSEC_SETXID 12
2183 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2184 #define TIF_USING_IWMMXT 17
2185 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2186 #define TIF_RESTORE_SIGMASK 20
2187 @@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2188 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2189 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2190 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2191 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2192
2193 /* Checks for any syscall work in entry-common.S */
2194 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2195 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2196 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2197
2198 /*
2199 * Change these and you break ASM code in entry-common.S
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 75d9579..b5b40e4 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -320,13 +361,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -426,11 +471,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index f7b450f..f5364c5 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 1879e8d..b2207fc 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2565 .macro usr_entry
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -416,7 +513,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -450,11 +549,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: mov pc, r9
2605 +4: pax_close_userland
2606 + mov pc, r9
2607 .popsection
2608 .pushsection __ex_table,"a"
2609 .long 1b, 4b
2610 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index a2dcafd..1048b5a 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -10,18 +10,46 @@
2633
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index efb208d..d34bd02 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -188,6 +188,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -207,6 +261,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6)
2769 ldr r0, [sp]
2770 @@ -265,6 +322,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779 clrex @ clear the exclusive monitor
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index 918875d..cd5fa27 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 591d6e4..8322a26 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 45e4781..8eac93d 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index 81ef686..f4130b8 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -212,6 +212,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -225,7 +226,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2929
2930 const char *arch_vma_name(struct vm_area_struct *vma)
2931 {
2932 - return is_gate_vma(vma) ? "[vectors]" :
2933 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2934 - "[sigpage]" : NULL;
2935 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2936 }
2937
2938 -static struct page *signal_page;
2939 -extern struct page *get_signal_page(void);
2940 -
2941 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2942 {
2943 struct mm_struct *mm = current->mm;
2944 - unsigned long addr;
2945 - int ret;
2946 -
2947 - if (!signal_page)
2948 - signal_page = get_signal_page();
2949 - if (!signal_page)
2950 - return -ENOMEM;
2951
2952 down_write(&mm->mmap_sem);
2953 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2954 - if (IS_ERR_VALUE(addr)) {
2955 - ret = addr;
2956 - goto up_fail;
2957 - }
2958 -
2959 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2960 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2961 - &signal_page);
2962 -
2963 - if (ret == 0)
2964 - mm->context.sigpage = addr;
2965 -
2966 - up_fail:
2967 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2968 up_write(&mm->mmap_sem);
2969 - return ret;
2970 + return 0;
2971 }
2972 #endif
2973 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2974 index 4693188..4596c5e 100644
2975 --- a/arch/arm/kernel/psci.c
2976 +++ b/arch/arm/kernel/psci.c
2977 @@ -24,7 +24,7 @@
2978 #include <asm/opcodes-virt.h>
2979 #include <asm/psci.h>
2980
2981 -struct psci_operations psci_ops;
2982 +struct psci_operations psci_ops __read_only;
2983
2984 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2985
2986 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2987 index 0dd3b79..b67388e 100644
2988 --- a/arch/arm/kernel/ptrace.c
2989 +++ b/arch/arm/kernel/ptrace.c
2990 @@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2991 PTRACE_SYSCALL_EXIT,
2992 };
2993
2994 -static int tracehook_report_syscall(struct pt_regs *regs,
2995 +static void tracehook_report_syscall(struct pt_regs *regs,
2996 enum ptrace_syscall_dir dir)
2997 {
2998 unsigned long ip;
2999 @@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3000 current_thread_info()->syscall = -1;
3001
3002 regs->ARM_ip = ip;
3003 - return current_thread_info()->syscall;
3004 }
3005
3006 +#ifdef CONFIG_GRKERNSEC_SETXID
3007 +extern void gr_delayed_cred_worker(void);
3008 +#endif
3009 +
3010 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3011 {
3012 current_thread_info()->syscall = scno;
3013
3014 +#ifdef CONFIG_GRKERNSEC_SETXID
3015 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016 + gr_delayed_cred_worker();
3017 +#endif
3018 +
3019 /* Do the secure computing check first; failures should be fast. */
3020 if (secure_computing(scno) == -1)
3021 return -1;
3022
3023 if (test_thread_flag(TIF_SYSCALL_TRACE))
3024 - scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3025 + tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3026 +
3027 + scno = current_thread_info()->syscall;
3028
3029 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3030 trace_sys_enter(regs, scno);
3031 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3032 index 50e198c..a8b5f49 100644
3033 --- a/arch/arm/kernel/setup.c
3034 +++ b/arch/arm/kernel/setup.c
3035 @@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3036 unsigned int elf_hwcap2 __read_mostly;
3037 EXPORT_SYMBOL(elf_hwcap2);
3038
3039 +pteval_t __supported_pte_mask __read_only;
3040 +pmdval_t __supported_pmd_mask __read_only;
3041
3042 #ifdef MULTI_CPU
3043 -struct processor processor __read_mostly;
3044 +struct processor processor __read_only;
3045 #endif
3046 #ifdef MULTI_TLB
3047 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3048 +struct cpu_tlb_fns cpu_tlb __read_only;
3049 #endif
3050 #ifdef MULTI_USER
3051 -struct cpu_user_fns cpu_user __read_mostly;
3052 +struct cpu_user_fns cpu_user __read_only;
3053 #endif
3054 #ifdef MULTI_CACHE
3055 -struct cpu_cache_fns cpu_cache __read_mostly;
3056 +struct cpu_cache_fns cpu_cache __read_only;
3057 #endif
3058 #ifdef CONFIG_OUTER_CACHE
3059 -struct outer_cache_fns outer_cache __read_mostly;
3060 +struct outer_cache_fns outer_cache __read_only;
3061 EXPORT_SYMBOL(outer_cache);
3062 #endif
3063
3064 @@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3065 asm("mrc p15, 0, %0, c0, c1, 4"
3066 : "=r" (mmfr0));
3067 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3068 - (mmfr0 & 0x000000f0) >= 0x00000030)
3069 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3070 cpu_arch = CPU_ARCH_ARMv7;
3071 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3072 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3073 + __supported_pte_mask |= L_PTE_PXN;
3074 + __supported_pmd_mask |= PMD_PXNTABLE;
3075 + }
3076 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3077 (mmfr0 & 0x000000f0) == 0x00000020)
3078 cpu_arch = CPU_ARCH_ARMv6;
3079 else
3080 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3081 index bd19834..e4d8c66 100644
3082 --- a/arch/arm/kernel/signal.c
3083 +++ b/arch/arm/kernel/signal.c
3084 @@ -24,8 +24,6 @@
3085
3086 extern const unsigned long sigreturn_codes[7];
3087
3088 -static unsigned long signal_return_offset;
3089 -
3090 #ifdef CONFIG_CRUNCH
3091 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3092 {
3093 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3094 * except when the MPU has protected the vectors
3095 * page from PL0
3096 */
3097 - retcode = mm->context.sigpage + signal_return_offset +
3098 - (idx << 2) + thumb;
3099 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3100 } else
3101 #endif
3102 {
3103 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3104 } while (thread_flags & _TIF_WORK_MASK);
3105 return 0;
3106 }
3107 -
3108 -struct page *get_signal_page(void)
3109 -{
3110 - unsigned long ptr;
3111 - unsigned offset;
3112 - struct page *page;
3113 - void *addr;
3114 -
3115 - page = alloc_pages(GFP_KERNEL, 0);
3116 -
3117 - if (!page)
3118 - return NULL;
3119 -
3120 - addr = page_address(page);
3121 -
3122 - /* Give the signal return code some randomness */
3123 - offset = 0x200 + (get_random_int() & 0x7fc);
3124 - signal_return_offset = offset;
3125 -
3126 - /*
3127 - * Copy signal return handlers into the vector page, and
3128 - * set sigreturn to be a pointer to these.
3129 - */
3130 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3131 -
3132 - ptr = (unsigned long)addr + offset;
3133 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3134 -
3135 - return page;
3136 -}
3137 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3138 index 7c4fada..8581286 100644
3139 --- a/arch/arm/kernel/smp.c
3140 +++ b/arch/arm/kernel/smp.c
3141 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3142
3143 static DECLARE_COMPLETION(cpu_running);
3144
3145 -static struct smp_operations smp_ops;
3146 +static struct smp_operations smp_ops __read_only;
3147
3148 void __init smp_set_ops(struct smp_operations *ops)
3149 {
3150 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3151 index 7a3be1d..b00c7de 100644
3152 --- a/arch/arm/kernel/tcm.c
3153 +++ b/arch/arm/kernel/tcm.c
3154 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3155 .virtual = ITCM_OFFSET,
3156 .pfn = __phys_to_pfn(ITCM_OFFSET),
3157 .length = 0,
3158 - .type = MT_MEMORY_RWX_ITCM,
3159 + .type = MT_MEMORY_RX_ITCM,
3160 }
3161 };
3162
3163 @@ -267,7 +267,9 @@ no_dtcm:
3164 start = &__sitcm_text;
3165 end = &__eitcm_text;
3166 ram = &__itcm_start;
3167 + pax_open_kernel();
3168 memcpy(start, ram, itcm_code_sz);
3169 + pax_close_kernel();
3170 pr_debug("CPU ITCM: copied code from %p - %p\n",
3171 start, end);
3172 itcm_present = true;
3173 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3174 index abd2fc0..895dbb6 100644
3175 --- a/arch/arm/kernel/traps.c
3176 +++ b/arch/arm/kernel/traps.c
3177 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3178 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3179 {
3180 #ifdef CONFIG_KALLSYMS
3181 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3182 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3183 #else
3184 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3185 #endif
3186 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3187 static int die_owner = -1;
3188 static unsigned int die_nest_count;
3189
3190 +extern void gr_handle_kernel_exploit(void);
3191 +
3192 static unsigned long oops_begin(void)
3193 {
3194 int cpu;
3195 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3196 panic("Fatal exception in interrupt");
3197 if (panic_on_oops)
3198 panic("Fatal exception");
3199 +
3200 + gr_handle_kernel_exploit();
3201 +
3202 if (signr)
3203 do_exit(signr);
3204 }
3205 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3206 * The user helper at 0xffff0fe0 must be used instead.
3207 * (see entry-armv.S for details)
3208 */
3209 + pax_open_kernel();
3210 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3211 + pax_close_kernel();
3212 }
3213 return 0;
3214
3215 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3216 kuser_init(vectors_base);
3217
3218 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3219 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3220 +
3221 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3222 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3223 +#endif
3224 +
3225 #else /* ifndef CONFIG_CPU_V7M */
3226 /*
3227 * on V7-M there is no need to copy the vector table to a dedicated
3228 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3229 index 7bcee5c..e2f3249 100644
3230 --- a/arch/arm/kernel/vmlinux.lds.S
3231 +++ b/arch/arm/kernel/vmlinux.lds.S
3232 @@ -8,7 +8,11 @@
3233 #include <asm/thread_info.h>
3234 #include <asm/memory.h>
3235 #include <asm/page.h>
3236 -
3237 +
3238 +#ifdef CONFIG_PAX_KERNEXEC
3239 +#include <asm/pgtable.h>
3240 +#endif
3241 +
3242 #define PROC_INFO \
3243 . = ALIGN(4); \
3244 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3245 @@ -34,7 +38,7 @@
3246 #endif
3247
3248 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3249 - defined(CONFIG_GENERIC_BUG)
3250 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3251 #define ARM_EXIT_KEEP(x) x
3252 #define ARM_EXIT_DISCARD(x)
3253 #else
3254 @@ -90,6 +94,11 @@ SECTIONS
3255 _text = .;
3256 HEAD_TEXT
3257 }
3258 +
3259 +#ifdef CONFIG_PAX_KERNEXEC
3260 + . = ALIGN(1<<SECTION_SHIFT);
3261 +#endif
3262 +
3263 .text : { /* Real text segment */
3264 _stext = .; /* Text and read-only data */
3265 __exception_text_start = .;
3266 @@ -112,6 +121,8 @@ SECTIONS
3267 ARM_CPU_KEEP(PROC_INFO)
3268 }
3269
3270 + _etext = .; /* End of text section */
3271 +
3272 RO_DATA(PAGE_SIZE)
3273
3274 . = ALIGN(4);
3275 @@ -142,7 +153,9 @@ SECTIONS
3276
3277 NOTES
3278
3279 - _etext = .; /* End of text and rodata section */
3280 +#ifdef CONFIG_PAX_KERNEXEC
3281 + . = ALIGN(1<<SECTION_SHIFT);
3282 +#endif
3283
3284 #ifndef CONFIG_XIP_KERNEL
3285 . = ALIGN(PAGE_SIZE);
3286 @@ -220,6 +233,11 @@ SECTIONS
3287 . = PAGE_OFFSET + TEXT_OFFSET;
3288 #else
3289 __init_end = .;
3290 +
3291 +#ifdef CONFIG_PAX_KERNEXEC
3292 + . = ALIGN(1<<SECTION_SHIFT);
3293 +#endif
3294 +
3295 . = ALIGN(THREAD_SIZE);
3296 __data_loc = .;
3297 #endif
3298 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3299 index f0e50a0..8d5d36c 100644
3300 --- a/arch/arm/kvm/arm.c
3301 +++ b/arch/arm/kvm/arm.c
3302 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3303 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3304
3305 /* The VMID used in the VTTBR */
3306 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3307 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3308 static u8 kvm_next_vmid;
3309 static DEFINE_SPINLOCK(kvm_vmid_lock);
3310
3311 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3312 */
3313 static bool need_new_vmid_gen(struct kvm *kvm)
3314 {
3315 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3316 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3317 }
3318
3319 /**
3320 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3321
3322 /* First user of a new VMID generation? */
3323 if (unlikely(kvm_next_vmid == 0)) {
3324 - atomic64_inc(&kvm_vmid_gen);
3325 + atomic64_inc_unchecked(&kvm_vmid_gen);
3326 kvm_next_vmid = 1;
3327
3328 /*
3329 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3330 kvm_call_hyp(__kvm_flush_vm_context);
3331 }
3332
3333 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3334 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3335 kvm->arch.vmid = kvm_next_vmid;
3336 kvm_next_vmid++;
3337
3338 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3339 index 14a0d98..7771a7d 100644
3340 --- a/arch/arm/lib/clear_user.S
3341 +++ b/arch/arm/lib/clear_user.S
3342 @@ -12,14 +12,14 @@
3343
3344 .text
3345
3346 -/* Prototype: int __clear_user(void *addr, size_t sz)
3347 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3348 * Purpose : clear some user memory
3349 * Params : addr - user memory address to clear
3350 * : sz - number of bytes to clear
3351 * Returns : number of bytes NOT cleared
3352 */
3353 ENTRY(__clear_user_std)
3354 -WEAK(__clear_user)
3355 +WEAK(___clear_user)
3356 stmfd sp!, {r1, lr}
3357 mov r2, #0
3358 cmp r1, #4
3359 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3360 USER( strnebt r2, [r0])
3361 mov r0, #0
3362 ldmfd sp!, {r1, pc}
3363 -ENDPROC(__clear_user)
3364 +ENDPROC(___clear_user)
3365 ENDPROC(__clear_user_std)
3366
3367 .pushsection .fixup,"ax"
3368 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3369 index 66a477a..bee61d3 100644
3370 --- a/arch/arm/lib/copy_from_user.S
3371 +++ b/arch/arm/lib/copy_from_user.S
3372 @@ -16,7 +16,7 @@
3373 /*
3374 * Prototype:
3375 *
3376 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3377 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3378 *
3379 * Purpose:
3380 *
3381 @@ -84,11 +84,11 @@
3382
3383 .text
3384
3385 -ENTRY(__copy_from_user)
3386 +ENTRY(___copy_from_user)
3387
3388 #include "copy_template.S"
3389
3390 -ENDPROC(__copy_from_user)
3391 +ENDPROC(___copy_from_user)
3392
3393 .pushsection .fixup,"ax"
3394 .align 0
3395 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3396 index 6ee2f67..d1cce76 100644
3397 --- a/arch/arm/lib/copy_page.S
3398 +++ b/arch/arm/lib/copy_page.S
3399 @@ -10,6 +10,7 @@
3400 * ASM optimised string functions
3401 */
3402 #include <linux/linkage.h>
3403 +#include <linux/const.h>
3404 #include <asm/assembler.h>
3405 #include <asm/asm-offsets.h>
3406 #include <asm/cache.h>
3407 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3408 index d066df6..df28194 100644
3409 --- a/arch/arm/lib/copy_to_user.S
3410 +++ b/arch/arm/lib/copy_to_user.S
3411 @@ -16,7 +16,7 @@
3412 /*
3413 * Prototype:
3414 *
3415 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3416 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3417 *
3418 * Purpose:
3419 *
3420 @@ -88,11 +88,11 @@
3421 .text
3422
3423 ENTRY(__copy_to_user_std)
3424 -WEAK(__copy_to_user)
3425 +WEAK(___copy_to_user)
3426
3427 #include "copy_template.S"
3428
3429 -ENDPROC(__copy_to_user)
3430 +ENDPROC(___copy_to_user)
3431 ENDPROC(__copy_to_user_std)
3432
3433 .pushsection .fixup,"ax"
3434 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3435 index 7d08b43..f7ca7ea 100644
3436 --- a/arch/arm/lib/csumpartialcopyuser.S
3437 +++ b/arch/arm/lib/csumpartialcopyuser.S
3438 @@ -57,8 +57,8 @@
3439 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3440 */
3441
3442 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3443 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3444 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3445 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3446
3447 #include "csumpartialcopygeneric.S"
3448
3449 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3450 index 5306de3..aed6d03 100644
3451 --- a/arch/arm/lib/delay.c
3452 +++ b/arch/arm/lib/delay.c
3453 @@ -28,7 +28,7 @@
3454 /*
3455 * Default to the loop-based delay implementation.
3456 */
3457 -struct arm_delay_ops arm_delay_ops = {
3458 +struct arm_delay_ops arm_delay_ops __read_only = {
3459 .delay = __loop_delay,
3460 .const_udelay = __loop_const_udelay,
3461 .udelay = __loop_udelay,
3462 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3463 index 3e58d71..029817c 100644
3464 --- a/arch/arm/lib/uaccess_with_memcpy.c
3465 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3466 @@ -136,7 +136,7 @@ out:
3467 }
3468
3469 unsigned long
3470 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3471 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3472 {
3473 /*
3474 * This test is stubbed out of the main function above to keep
3475 @@ -190,7 +190,7 @@ out:
3476 return n;
3477 }
3478
3479 -unsigned long __clear_user(void __user *addr, unsigned long n)
3480 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3481 {
3482 /* See rational for this in __copy_to_user() above. */
3483 if (n < 64)
3484 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3485 index f7a07a5..258e1f7 100644
3486 --- a/arch/arm/mach-at91/setup.c
3487 +++ b/arch/arm/mach-at91/setup.c
3488 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3489
3490 desc->pfn = __phys_to_pfn(base);
3491 desc->length = length;
3492 - desc->type = MT_MEMORY_RWX_NONCACHED;
3493 + desc->type = MT_MEMORY_RW_NONCACHED;
3494
3495 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3496 base, length, desc->virtual);
3497 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3498 index 255f33a..507b157 100644
3499 --- a/arch/arm/mach-kirkwood/common.c
3500 +++ b/arch/arm/mach-kirkwood/common.c
3501 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3502 clk_gate_ops.disable(hw);
3503 }
3504
3505 -static struct clk_ops clk_gate_fn_ops;
3506 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3507 +{
3508 + return clk_gate_ops.is_enabled(hw);
3509 +}
3510 +
3511 +static struct clk_ops clk_gate_fn_ops = {
3512 + .enable = clk_gate_fn_enable,
3513 + .disable = clk_gate_fn_disable,
3514 + .is_enabled = clk_gate_fn_is_enabled,
3515 +};
3516
3517 static struct clk __init *clk_register_gate_fn(struct device *dev,
3518 const char *name,
3519 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3520 gate_fn->fn_en = fn_en;
3521 gate_fn->fn_dis = fn_dis;
3522
3523 - /* ops is the gate ops, but with our enable/disable functions */
3524 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3525 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3526 - clk_gate_fn_ops = clk_gate_ops;
3527 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3528 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3529 - }
3530 -
3531 clk = clk_register(dev, &gate_fn->gate.hw);
3532
3533 if (IS_ERR(clk))
3534 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3535 index aead77a..a2253fa 100644
3536 --- a/arch/arm/mach-omap2/board-n8x0.c
3537 +++ b/arch/arm/mach-omap2/board-n8x0.c
3538 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3539 }
3540 #endif
3541
3542 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3543 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3544 .late_init = n8x0_menelaus_late_init,
3545 };
3546
3547 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3548 index 9fe8c94..c014a4d 100644
3549 --- a/arch/arm/mach-omap2/gpmc.c
3550 +++ b/arch/arm/mach-omap2/gpmc.c
3551 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3552 };
3553
3554 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3555 -static struct irq_chip gpmc_irq_chip;
3556 static int gpmc_irq_start;
3557
3558 static struct resource gpmc_mem_root;
3559 @@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3560
3561 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3562
3563 +static struct irq_chip gpmc_irq_chip = {
3564 + .name = "gpmc",
3565 + .irq_startup = gpmc_irq_noop_ret,
3566 + .irq_enable = gpmc_irq_enable,
3567 + .irq_disable = gpmc_irq_disable,
3568 + .irq_shutdown = gpmc_irq_noop,
3569 + .irq_ack = gpmc_irq_noop,
3570 + .irq_mask = gpmc_irq_noop,
3571 + .irq_unmask = gpmc_irq_noop,
3572 +
3573 +};
3574 +
3575 static int gpmc_setup_irq(void)
3576 {
3577 int i;
3578 @@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3579 return gpmc_irq_start;
3580 }
3581
3582 - gpmc_irq_chip.name = "gpmc";
3583 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3584 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3585 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3586 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3587 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3588 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3589 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3590 -
3591 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3592 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3593
3594 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3595 index 667915d..2ee1219 100644
3596 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3597 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3598 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3599 int (*finish_suspend)(unsigned long cpu_state);
3600 void (*resume)(void);
3601 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3602 -};
3603 +} __no_const;
3604
3605 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3606 static struct powerdomain *mpuss_pd;
3607 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3608 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3609 {}
3610
3611 -struct cpu_pm_ops omap_pm_ops = {
3612 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3613 .finish_suspend = default_finish_suspend,
3614 .resume = dummy_cpu_resume,
3615 .scu_prepare = dummy_scu_prepare,
3616 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3617 index 693fe48..c15ea73 100644
3618 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3619 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3620 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3621 return NOTIFY_OK;
3622 }
3623
3624 -static struct notifier_block __refdata irq_hotplug_notifier = {
3625 +static struct notifier_block irq_hotplug_notifier = {
3626 .notifier_call = irq_cpu_hotplug_notify,
3627 };
3628
3629 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3630 index 01ef59d..32ae28a8 100644
3631 --- a/arch/arm/mach-omap2/omap_device.c
3632 +++ b/arch/arm/mach-omap2/omap_device.c
3633 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3634 struct platform_device __init *omap_device_build(const char *pdev_name,
3635 int pdev_id,
3636 struct omap_hwmod *oh,
3637 - void *pdata, int pdata_len)
3638 + const void *pdata, int pdata_len)
3639 {
3640 struct omap_hwmod *ohs[] = { oh };
3641
3642 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3643 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3644 int pdev_id,
3645 struct omap_hwmod **ohs,
3646 - int oh_cnt, void *pdata,
3647 + int oh_cnt, const void *pdata,
3648 int pdata_len)
3649 {
3650 int ret = -ENOMEM;
3651 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3652 index 78c02b3..c94109a 100644
3653 --- a/arch/arm/mach-omap2/omap_device.h
3654 +++ b/arch/arm/mach-omap2/omap_device.h
3655 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3656 /* Core code interface */
3657
3658 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3659 - struct omap_hwmod *oh, void *pdata,
3660 + struct omap_hwmod *oh, const void *pdata,
3661 int pdata_len);
3662
3663 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3664 struct omap_hwmod **oh, int oh_cnt,
3665 - void *pdata, int pdata_len);
3666 + const void *pdata, int pdata_len);
3667
3668 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3669 struct omap_hwmod **ohs, int oh_cnt);
3670 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3671 index 66c60fe..c78950d 100644
3672 --- a/arch/arm/mach-omap2/omap_hwmod.c
3673 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3674 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3675 int (*init_clkdm)(struct omap_hwmod *oh);
3676 void (*update_context_lost)(struct omap_hwmod *oh);
3677 int (*get_context_lost)(struct omap_hwmod *oh);
3678 -};
3679 +} __no_const;
3680
3681 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3682 -static struct omap_hwmod_soc_ops soc_ops;
3683 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3684
3685 /* omap_hwmod_list contains all registered struct omap_hwmods */
3686 static LIST_HEAD(omap_hwmod_list);
3687 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3688 index 95fee54..cfa9cf1 100644
3689 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3690 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3691 @@ -10,6 +10,7 @@
3692
3693 #include <linux/kernel.h>
3694 #include <linux/init.h>
3695 +#include <asm/pgtable.h>
3696
3697 #include "powerdomain.h"
3698
3699 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3700
3701 void __init am43xx_powerdomains_init(void)
3702 {
3703 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3704 + pax_open_kernel();
3705 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3706 + pax_close_kernel();
3707 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3708 pwrdm_register_pwrdms(powerdomains_am43xx);
3709 pwrdm_complete_init();
3710 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3711 index d15c7bb..b2d1f0c 100644
3712 --- a/arch/arm/mach-omap2/wd_timer.c
3713 +++ b/arch/arm/mach-omap2/wd_timer.c
3714 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3715 struct omap_hwmod *oh;
3716 char *oh_name = "wd_timer2";
3717 char *dev_name = "omap_wdt";
3718 - struct omap_wd_timer_platform_data pdata;
3719 + static struct omap_wd_timer_platform_data pdata = {
3720 + .read_reset_sources = prm_read_reset_sources
3721 + };
3722
3723 if (!cpu_class_is_omap2() || of_have_populated_dt())
3724 return 0;
3725 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3726 return -EINVAL;
3727 }
3728
3729 - pdata.read_reset_sources = prm_read_reset_sources;
3730 -
3731 pdev = omap_device_build(dev_name, id, oh, &pdata,
3732 sizeof(struct omap_wd_timer_platform_data));
3733 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3734 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3735 index b82dcae..44ee5b6 100644
3736 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3737 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3738 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3739 bool entered_lp2 = false;
3740
3741 if (tegra_pending_sgi())
3742 - ACCESS_ONCE(abort_flag) = true;
3743 + ACCESS_ONCE_RW(abort_flag) = true;
3744
3745 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3746
3747 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3748 index 2dea8b5..6499da2 100644
3749 --- a/arch/arm/mach-ux500/setup.h
3750 +++ b/arch/arm/mach-ux500/setup.h
3751 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3752 .type = MT_DEVICE, \
3753 }
3754
3755 -#define __MEM_DEV_DESC(x, sz) { \
3756 - .virtual = IO_ADDRESS(x), \
3757 - .pfn = __phys_to_pfn(x), \
3758 - .length = sz, \
3759 - .type = MT_MEMORY_RWX, \
3760 -}
3761 -
3762 extern struct smp_operations ux500_smp_ops;
3763 extern void ux500_cpu_die(unsigned int cpu);
3764
3765 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3766 index 5bf7c3c..571e67e 100644
3767 --- a/arch/arm/mm/Kconfig
3768 +++ b/arch/arm/mm/Kconfig
3769 @@ -446,6 +446,7 @@ config CPU_32v5
3770
3771 config CPU_32v6
3772 bool
3773 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3774 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3775
3776 config CPU_32v6K
3777 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3778
3779 config CPU_USE_DOMAINS
3780 bool
3781 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3782 help
3783 This option enables or disables the use of domain switching
3784 via the set_fs() function.
3785 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3786 config KUSER_HELPERS
3787 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3788 default y
3789 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3790 help
3791 Warning: disabling this option may break user programs.
3792
3793 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3794 See Documentation/arm/kernel_user_helpers.txt for details.
3795
3796 However, the fixed address nature of these helpers can be used
3797 - by ROP (return orientated programming) authors when creating
3798 + by ROP (Return Oriented Programming) authors when creating
3799 exploits.
3800
3801 If all of the binaries and libraries which run on your platform
3802 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3803 index 9240364..a2b8cf3 100644
3804 --- a/arch/arm/mm/alignment.c
3805 +++ b/arch/arm/mm/alignment.c
3806 @@ -212,10 +212,12 @@ union offset_union {
3807 #define __get16_unaligned_check(ins,val,addr) \
3808 do { \
3809 unsigned int err = 0, v, a = addr; \
3810 + pax_open_userland(); \
3811 __get8_unaligned_check(ins,v,a,err); \
3812 val = v << ((BE) ? 8 : 0); \
3813 __get8_unaligned_check(ins,v,a,err); \
3814 val |= v << ((BE) ? 0 : 8); \
3815 + pax_close_userland(); \
3816 if (err) \
3817 goto fault; \
3818 } while (0)
3819 @@ -229,6 +231,7 @@ union offset_union {
3820 #define __get32_unaligned_check(ins,val,addr) \
3821 do { \
3822 unsigned int err = 0, v, a = addr; \
3823 + pax_open_userland(); \
3824 __get8_unaligned_check(ins,v,a,err); \
3825 val = v << ((BE) ? 24 : 0); \
3826 __get8_unaligned_check(ins,v,a,err); \
3827 @@ -237,6 +240,7 @@ union offset_union {
3828 val |= v << ((BE) ? 8 : 16); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 24); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -250,6 +254,7 @@ union offset_union {
3836 #define __put16_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v = val, a = addr; \
3839 + pax_open_userland(); \
3840 __asm__( FIRST_BYTE_16 \
3841 ARM( "1: "ins" %1, [%2], #1\n" ) \
3842 THUMB( "1: "ins" %1, [%2]\n" ) \
3843 @@ -269,6 +274,7 @@ union offset_union {
3844 " .popsection\n" \
3845 : "=r" (err), "=&r" (v), "=&r" (a) \
3846 : "0" (err), "1" (v), "2" (a)); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -282,6 +288,7 @@ union offset_union {
3852 #define __put32_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_32 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -311,6 +318,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3868 index 7abde2c..9df495f 100644
3869 --- a/arch/arm/mm/cache-l2x0.c
3870 +++ b/arch/arm/mm/cache-l2x0.c
3871 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3872 void (*setup)(const struct device_node *, u32 *, u32 *);
3873 void (*save)(void);
3874 struct outer_cache_fns outer_cache;
3875 -};
3876 +} __do_const;
3877
3878 static bool of_init = false;
3879
3880 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3881 index 6eb97b3..ac509f6 100644
3882 --- a/arch/arm/mm/context.c
3883 +++ b/arch/arm/mm/context.c
3884 @@ -43,7 +43,7 @@
3885 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3886
3887 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3888 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3889 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3890 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3891
3892 static DEFINE_PER_CPU(atomic64_t, active_asids);
3893 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3894 {
3895 static u32 cur_idx = 1;
3896 u64 asid = atomic64_read(&mm->context.id);
3897 - u64 generation = atomic64_read(&asid_generation);
3898 + u64 generation = atomic64_read_unchecked(&asid_generation);
3899
3900 if (asid != 0 && is_reserved_asid(asid)) {
3901 /*
3902 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3903 */
3904 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3905 if (asid == NUM_USER_ASIDS) {
3906 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3907 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3908 &asid_generation);
3909 flush_context(cpu);
3910 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3911 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3912 cpu_set_reserved_ttbr0();
3913
3914 asid = atomic64_read(&mm->context.id);
3915 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3916 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3917 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3918 goto switch_mm_fastpath;
3919
3920 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3921 /* Check that our ASID belongs to the current generation. */
3922 asid = atomic64_read(&mm->context.id);
3923 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3924 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3925 asid = new_context(mm, cpu);
3926 atomic64_set(&mm->context.id, asid);
3927 }
3928 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3929 index eb8830a..5360ce7 100644
3930 --- a/arch/arm/mm/fault.c
3931 +++ b/arch/arm/mm/fault.c
3932 @@ -25,6 +25,7 @@
3933 #include <asm/system_misc.h>
3934 #include <asm/system_info.h>
3935 #include <asm/tlbflush.h>
3936 +#include <asm/sections.h>
3937
3938 #include "fault.h"
3939
3940 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3941 if (fixup_exception(regs))
3942 return;
3943
3944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3945 + if (addr < TASK_SIZE) {
3946 + if (current->signal->curr_ip)
3947 + 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),
3948 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3949 + else
3950 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3951 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3952 + }
3953 +#endif
3954 +
3955 +#ifdef CONFIG_PAX_KERNEXEC
3956 + if ((fsr & FSR_WRITE) &&
3957 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3958 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3959 + {
3960 + if (current->signal->curr_ip)
3961 + 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),
3962 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3963 + else
3964 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3965 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3966 + }
3967 +#endif
3968 +
3969 /*
3970 * No handler, we'll have to terminate things with extreme prejudice.
3971 */
3972 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3973 }
3974 #endif
3975
3976 +#ifdef CONFIG_PAX_PAGEEXEC
3977 + if (fsr & FSR_LNX_PF) {
3978 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3979 + do_group_exit(SIGKILL);
3980 + }
3981 +#endif
3982 +
3983 tsk->thread.address = addr;
3984 tsk->thread.error_code = fsr;
3985 tsk->thread.trap_no = 14;
3986 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3987 }
3988 #endif /* CONFIG_MMU */
3989
3990 +#ifdef CONFIG_PAX_PAGEEXEC
3991 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3992 +{
3993 + long i;
3994 +
3995 + printk(KERN_ERR "PAX: bytes at PC: ");
3996 + for (i = 0; i < 20; i++) {
3997 + unsigned char c;
3998 + if (get_user(c, (__force unsigned char __user *)pc+i))
3999 + printk(KERN_CONT "?? ");
4000 + else
4001 + printk(KERN_CONT "%02x ", c);
4002 + }
4003 + printk("\n");
4004 +
4005 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4006 + for (i = -1; i < 20; i++) {
4007 + unsigned long c;
4008 + if (get_user(c, (__force unsigned long __user *)sp+i))
4009 + printk(KERN_CONT "???????? ");
4010 + else
4011 + printk(KERN_CONT "%08lx ", c);
4012 + }
4013 + printk("\n");
4014 +}
4015 +#endif
4016 +
4017 /*
4018 * First Level Translation Fault Handler
4019 *
4020 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4021 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4022 struct siginfo info;
4023
4024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4025 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4026 + if (current->signal->curr_ip)
4027 + 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),
4028 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4029 + else
4030 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4031 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4032 + goto die;
4033 + }
4034 +#endif
4035 +
4036 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4037 return;
4038
4039 +die:
4040 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4041 inf->name, fsr, addr);
4042
4043 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4044 ifsr_info[nr].name = name;
4045 }
4046
4047 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4048 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4049 +
4050 asmlinkage void __exception
4051 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4052 {
4053 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4054 struct siginfo info;
4055 + unsigned long pc = instruction_pointer(regs);
4056 +
4057 + if (user_mode(regs)) {
4058 + unsigned long sigpage = current->mm->context.sigpage;
4059 +
4060 + if (sigpage <= pc && pc < sigpage + 7*4) {
4061 + if (pc < sigpage + 3*4)
4062 + sys_sigreturn(regs);
4063 + else
4064 + sys_rt_sigreturn(regs);
4065 + return;
4066 + }
4067 + if (pc == 0xffff0f60UL) {
4068 + /*
4069 + * PaX: __kuser_cmpxchg64 emulation
4070 + */
4071 + // TODO
4072 + //regs->ARM_pc = regs->ARM_lr;
4073 + //return;
4074 + }
4075 + if (pc == 0xffff0fa0UL) {
4076 + /*
4077 + * PaX: __kuser_memory_barrier emulation
4078 + */
4079 + // dmb(); implied by the exception
4080 + regs->ARM_pc = regs->ARM_lr;
4081 + return;
4082 + }
4083 + if (pc == 0xffff0fc0UL) {
4084 + /*
4085 + * PaX: __kuser_cmpxchg emulation
4086 + */
4087 + // TODO
4088 + //long new;
4089 + //int op;
4090 +
4091 + //op = FUTEX_OP_SET << 28;
4092 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4093 + //regs->ARM_r0 = old != new;
4094 + //regs->ARM_pc = regs->ARM_lr;
4095 + //return;
4096 + }
4097 + if (pc == 0xffff0fe0UL) {
4098 + /*
4099 + * PaX: __kuser_get_tls emulation
4100 + */
4101 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4102 + regs->ARM_pc = regs->ARM_lr;
4103 + return;
4104 + }
4105 + }
4106 +
4107 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4108 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4109 + if (current->signal->curr_ip)
4110 + 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),
4111 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4112 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4113 + else
4114 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4115 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4116 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4117 + goto die;
4118 + }
4119 +#endif
4120 +
4121 +#ifdef CONFIG_PAX_REFCOUNT
4122 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4123 + unsigned int bkpt;
4124 +
4125 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4126 + current->thread.error_code = ifsr;
4127 + current->thread.trap_no = 0;
4128 + pax_report_refcount_overflow(regs);
4129 + fixup_exception(regs);
4130 + return;
4131 + }
4132 + }
4133 +#endif
4134
4135 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4136 return;
4137
4138 +die:
4139 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4140 inf->name, ifsr, addr);
4141
4142 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4143 index cf08bdf..772656c 100644
4144 --- a/arch/arm/mm/fault.h
4145 +++ b/arch/arm/mm/fault.h
4146 @@ -3,6 +3,7 @@
4147
4148 /*
4149 * Fault status register encodings. We steal bit 31 for our own purposes.
4150 + * Set when the FSR value is from an instruction fault.
4151 */
4152 #define FSR_LNX_PF (1 << 31)
4153 #define FSR_WRITE (1 << 11)
4154 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4155 }
4156 #endif
4157
4158 +/* valid for LPAE and !LPAE */
4159 +static inline int is_xn_fault(unsigned int fsr)
4160 +{
4161 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4162 +}
4163 +
4164 +static inline int is_domain_fault(unsigned int fsr)
4165 +{
4166 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4167 +}
4168 +
4169 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4170 unsigned long search_exception_table(unsigned long addr);
4171
4172 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4173 index 2a77ba8..68e6a7a 100644
4174 --- a/arch/arm/mm/init.c
4175 +++ b/arch/arm/mm/init.c
4176 @@ -30,6 +30,8 @@
4177 #include <asm/setup.h>
4178 #include <asm/tlb.h>
4179 #include <asm/fixmap.h>
4180 +#include <asm/system_info.h>
4181 +#include <asm/cp15.h>
4182
4183 #include <asm/mach/arch.h>
4184 #include <asm/mach/map.h>
4185 @@ -627,7 +629,46 @@ void free_initmem(void)
4186 {
4187 #ifdef CONFIG_HAVE_TCM
4188 extern char __tcm_start, __tcm_end;
4189 +#endif
4190
4191 +#ifdef CONFIG_PAX_KERNEXEC
4192 + unsigned long addr;
4193 + pgd_t *pgd;
4194 + pud_t *pud;
4195 + pmd_t *pmd;
4196 + int cpu_arch = cpu_architecture();
4197 + unsigned int cr = get_cr();
4198 +
4199 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4200 + /* make pages tables, etc before .text NX */
4201 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4202 + pgd = pgd_offset_k(addr);
4203 + pud = pud_offset(pgd, addr);
4204 + pmd = pmd_offset(pud, addr);
4205 + __section_update(pmd, addr, PMD_SECT_XN);
4206 + }
4207 + /* make init NX */
4208 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4209 + pgd = pgd_offset_k(addr);
4210 + pud = pud_offset(pgd, addr);
4211 + pmd = pmd_offset(pud, addr);
4212 + __section_update(pmd, addr, PMD_SECT_XN);
4213 + }
4214 + /* make kernel code/rodata RX */
4215 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4216 + pgd = pgd_offset_k(addr);
4217 + pud = pud_offset(pgd, addr);
4218 + pmd = pmd_offset(pud, addr);
4219 +#ifdef CONFIG_ARM_LPAE
4220 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4221 +#else
4222 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4223 +#endif
4224 + }
4225 + }
4226 +#endif
4227 +
4228 +#ifdef CONFIG_HAVE_TCM
4229 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4230 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4231 #endif
4232 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4233 index f9c32ba..8540068 100644
4234 --- a/arch/arm/mm/ioremap.c
4235 +++ b/arch/arm/mm/ioremap.c
4236 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4237 unsigned int mtype;
4238
4239 if (cached)
4240 - mtype = MT_MEMORY_RWX;
4241 + mtype = MT_MEMORY_RX;
4242 else
4243 - mtype = MT_MEMORY_RWX_NONCACHED;
4244 + mtype = MT_MEMORY_RX_NONCACHED;
4245
4246 return __arm_ioremap_caller(phys_addr, size, mtype,
4247 __builtin_return_address(0));
4248 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4249 index 5e85ed3..b10a7ed 100644
4250 --- a/arch/arm/mm/mmap.c
4251 +++ b/arch/arm/mm/mmap.c
4252 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4253 struct vm_area_struct *vma;
4254 int do_align = 0;
4255 int aliasing = cache_is_vipt_aliasing();
4256 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4257 struct vm_unmapped_area_info info;
4258
4259 /*
4260 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4261 if (len > TASK_SIZE)
4262 return -ENOMEM;
4263
4264 +#ifdef CONFIG_PAX_RANDMMAP
4265 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266 +#endif
4267 +
4268 if (addr) {
4269 if (do_align)
4270 addr = COLOUR_ALIGN(addr, pgoff);
4271 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4272 addr = PAGE_ALIGN(addr);
4273
4274 vma = find_vma(mm, addr);
4275 - if (TASK_SIZE - len >= addr &&
4276 - (!vma || addr + len <= vma->vm_start))
4277 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4278 return addr;
4279 }
4280
4281 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4282 info.high_limit = TASK_SIZE;
4283 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4284 info.align_offset = pgoff << PAGE_SHIFT;
4285 + info.threadstack_offset = offset;
4286 return vm_unmapped_area(&info);
4287 }
4288
4289 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4290 unsigned long addr = addr0;
4291 int do_align = 0;
4292 int aliasing = cache_is_vipt_aliasing();
4293 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4294 struct vm_unmapped_area_info info;
4295
4296 /*
4297 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4298 return addr;
4299 }
4300
4301 +#ifdef CONFIG_PAX_RANDMMAP
4302 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4303 +#endif
4304 +
4305 /* requesting a specific address */
4306 if (addr) {
4307 if (do_align)
4308 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4309 else
4310 addr = PAGE_ALIGN(addr);
4311 vma = find_vma(mm, addr);
4312 - if (TASK_SIZE - len >= addr &&
4313 - (!vma || addr + len <= vma->vm_start))
4314 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4315 return addr;
4316 }
4317
4318 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4319 info.high_limit = mm->mmap_base;
4320 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4321 info.align_offset = pgoff << PAGE_SHIFT;
4322 + info.threadstack_offset = offset;
4323 addr = vm_unmapped_area(&info);
4324
4325 /*
4326 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4327 {
4328 unsigned long random_factor = 0UL;
4329
4330 +#ifdef CONFIG_PAX_RANDMMAP
4331 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4332 +#endif
4333 +
4334 /* 8 bits of randomness in 20 address space bits */
4335 if ((current->flags & PF_RANDOMIZE) &&
4336 !(current->personality & ADDR_NO_RANDOMIZE))
4337 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4338
4339 if (mmap_is_legacy()) {
4340 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4341 +
4342 +#ifdef CONFIG_PAX_RANDMMAP
4343 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4344 + mm->mmap_base += mm->delta_mmap;
4345 +#endif
4346 +
4347 mm->get_unmapped_area = arch_get_unmapped_area;
4348 } else {
4349 mm->mmap_base = mmap_base(random_factor);
4350 +
4351 +#ifdef CONFIG_PAX_RANDMMAP
4352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4353 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4354 +#endif
4355 +
4356 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4357 }
4358 }
4359 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4360 index b68c6b2..f66c492 100644
4361 --- a/arch/arm/mm/mmu.c
4362 +++ b/arch/arm/mm/mmu.c
4363 @@ -39,6 +39,22 @@
4364 #include "mm.h"
4365 #include "tcm.h"
4366
4367 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4368 +void modify_domain(unsigned int dom, unsigned int type)
4369 +{
4370 + struct thread_info *thread = current_thread_info();
4371 + unsigned int domain = thread->cpu_domain;
4372 + /*
4373 + * DOMAIN_MANAGER might be defined to some other value,
4374 + * use the arch-defined constant
4375 + */
4376 + domain &= ~domain_val(dom, 3);
4377 + thread->cpu_domain = domain | domain_val(dom, type);
4378 + set_domain(thread->cpu_domain);
4379 +}
4380 +EXPORT_SYMBOL(modify_domain);
4381 +#endif
4382 +
4383 /*
4384 * empty_zero_page is a special page that is used for
4385 * zero-initialized data and COW.
4386 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4387 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4388 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4389
4390 -static struct mem_type mem_types[] = {
4391 +#ifdef CONFIG_PAX_KERNEXEC
4392 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4393 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4394 +#else
4395 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4396 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4397 +#endif
4398 +
4399 +static struct mem_type mem_types[] __read_only = {
4400 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4401 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4402 L_PTE_SHARED,
4403 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4404 .prot_sect = PROT_SECT_DEVICE,
4405 .domain = DOMAIN_IO,
4406 },
4407 - [MT_UNCACHED] = {
4408 + [MT_UNCACHED_RW] = {
4409 .prot_pte = PROT_PTE_DEVICE,
4410 .prot_l1 = PMD_TYPE_TABLE,
4411 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4412 .domain = DOMAIN_IO,
4413 },
4414 - [MT_CACHECLEAN] = {
4415 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4416 + [MT_CACHECLEAN_RO] = {
4417 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420 #ifndef CONFIG_ARM_LPAE
4421 - [MT_MINICLEAN] = {
4422 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4423 + [MT_MINICLEAN_RO] = {
4424 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4425 .domain = DOMAIN_KERNEL,
4426 },
4427 #endif
4428 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4429 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4430 L_PTE_RDONLY,
4431 .prot_l1 = PMD_TYPE_TABLE,
4432 - .domain = DOMAIN_USER,
4433 + .domain = DOMAIN_VECTORS,
4434 },
4435 [MT_HIGH_VECTORS] = {
4436 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4437 L_PTE_USER | L_PTE_RDONLY,
4438 .prot_l1 = PMD_TYPE_TABLE,
4439 - .domain = DOMAIN_USER,
4440 + .domain = DOMAIN_VECTORS,
4441 },
4442 - [MT_MEMORY_RWX] = {
4443 + [__MT_MEMORY_RWX] = {
4444 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4445 .prot_l1 = PMD_TYPE_TABLE,
4446 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4447 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4448 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4449 .domain = DOMAIN_KERNEL,
4450 },
4451 - [MT_ROM] = {
4452 - .prot_sect = PMD_TYPE_SECT,
4453 + [MT_MEMORY_RX] = {
4454 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4455 + .prot_l1 = PMD_TYPE_TABLE,
4456 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4457 + .domain = DOMAIN_KERNEL,
4458 + },
4459 + [MT_ROM_RX] = {
4460 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4461 .domain = DOMAIN_KERNEL,
4462 },
4463 - [MT_MEMORY_RWX_NONCACHED] = {
4464 + [MT_MEMORY_RW_NONCACHED] = {
4465 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4466 L_PTE_MT_BUFFERABLE,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469 .domain = DOMAIN_KERNEL,
4470 },
4471 + [MT_MEMORY_RX_NONCACHED] = {
4472 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4473 + L_PTE_MT_BUFFERABLE,
4474 + .prot_l1 = PMD_TYPE_TABLE,
4475 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4476 + .domain = DOMAIN_KERNEL,
4477 + },
4478 [MT_MEMORY_RW_DTCM] = {
4479 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4480 L_PTE_XN,
4481 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4482 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485 - [MT_MEMORY_RWX_ITCM] = {
4486 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4487 + [MT_MEMORY_RX_ITCM] = {
4488 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493 [MT_MEMORY_RW_SO] = {
4494 @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4495 * Mark cache clean areas and XIP ROM read only
4496 * from SVC mode and no access from userspace.
4497 */
4498 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4499 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4500 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4501 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4502 +#ifdef CONFIG_PAX_KERNEXEC
4503 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4504 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4505 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4506 +#endif
4507 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4508 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4509 #endif
4510
4511 if (is_smp()) {
4512 @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4513 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4514 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4515 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4516 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4517 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4518 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4519 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4520 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4521 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4522 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4523 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4524 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4525 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4526 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4527 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4528 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4529 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4530 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4531 }
4532 }
4533
4534 @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4535 if (cpu_arch >= CPU_ARCH_ARMv6) {
4536 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4537 /* Non-cacheable Normal is XCB = 001 */
4538 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4539 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4540 + PMD_SECT_BUFFERED;
4541 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4542 PMD_SECT_BUFFERED;
4543 } else {
4544 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4545 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4546 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4547 + PMD_SECT_TEX(1);
4548 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4549 PMD_SECT_TEX(1);
4550 }
4551 } else {
4552 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4553 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4554 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4555 }
4556
4557 #ifdef CONFIG_ARM_LPAE
4558 @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4559 vecs_pgprot |= PTE_EXT_AF;
4560 #endif
4561
4562 + user_pgprot |= __supported_pte_mask;
4563 +
4564 for (i = 0; i < 16; i++) {
4565 pteval_t v = pgprot_val(protection_map[i]);
4566 protection_map[i] = __pgprot(v | user_pgprot);
4567 @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4568
4569 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4570 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4571 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4572 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4573 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4574 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4575 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4576 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4577 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4578 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4579 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4580 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4581 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4582 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4583 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4584 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4585
4586 switch (cp->pmd) {
4587 case PMD_SECT_WT:
4588 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4589 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4590 break;
4591 case PMD_SECT_WB:
4592 case PMD_SECT_WBWA:
4593 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4594 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4595 break;
4596 }
4597 pr_info("Memory policy: %sData cache %s\n",
4598 @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4599 return;
4600 }
4601
4602 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4603 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4604 md->virtual >= PAGE_OFFSET &&
4605 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4606 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4607 @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4608 * called function. This means you can't use any function or debugging
4609 * method which may touch any device, otherwise the kernel _will_ crash.
4610 */
4611 +
4612 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4613 +
4614 static void __init devicemaps_init(const struct machine_desc *mdesc)
4615 {
4616 struct map_desc map;
4617 unsigned long addr;
4618 - void *vectors;
4619
4620 - /*
4621 - * Allocate the vector page early.
4622 - */
4623 - vectors = early_alloc(PAGE_SIZE * 2);
4624 -
4625 - early_trap_init(vectors);
4626 + early_trap_init(&vectors);
4627
4628 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4629 pmd_clear(pmd_off_k(addr));
4630 @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4631 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4632 map.virtual = MODULES_VADDR;
4633 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4634 - map.type = MT_ROM;
4635 + map.type = MT_ROM_RX;
4636 create_mapping(&map);
4637 #endif
4638
4639 @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4640 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4641 map.virtual = FLUSH_BASE;
4642 map.length = SZ_1M;
4643 - map.type = MT_CACHECLEAN;
4644 + map.type = MT_CACHECLEAN_RO;
4645 create_mapping(&map);
4646 #endif
4647 #ifdef FLUSH_BASE_MINICACHE
4648 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4649 map.virtual = FLUSH_BASE_MINICACHE;
4650 map.length = SZ_1M;
4651 - map.type = MT_MINICLEAN;
4652 + map.type = MT_MINICLEAN_RO;
4653 create_mapping(&map);
4654 #endif
4655
4656 @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4657 * location (0xffff0000). If we aren't using high-vectors, also
4658 * create a mapping at the low-vectors virtual address.
4659 */
4660 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4661 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4662 map.virtual = 0xffff0000;
4663 map.length = PAGE_SIZE;
4664 #ifdef CONFIG_KUSER_HELPERS
4665 @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4666 static void __init map_lowmem(void)
4667 {
4668 struct memblock_region *reg;
4669 +#ifndef CONFIG_PAX_KERNEXEC
4670 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4671 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4672 +#endif
4673
4674 /* Map all the lowmem memory banks. */
4675 for_each_memblock(memory, reg) {
4676 @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4677 if (start >= end)
4678 break;
4679
4680 +#ifdef CONFIG_PAX_KERNEXEC
4681 + map.pfn = __phys_to_pfn(start);
4682 + map.virtual = __phys_to_virt(start);
4683 + map.length = end - start;
4684 +
4685 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4686 + struct map_desc kernel;
4687 + struct map_desc initmap;
4688 +
4689 + /* when freeing initmem we will make this RW */
4690 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4691 + initmap.virtual = (unsigned long)__init_begin;
4692 + initmap.length = _sdata - __init_begin;
4693 + initmap.type = __MT_MEMORY_RWX;
4694 + create_mapping(&initmap);
4695 +
4696 + /* when freeing initmem we will make this RX */
4697 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4698 + kernel.virtual = (unsigned long)_stext;
4699 + kernel.length = __init_begin - _stext;
4700 + kernel.type = __MT_MEMORY_RWX;
4701 + create_mapping(&kernel);
4702 +
4703 + if (map.virtual < (unsigned long)_stext) {
4704 + map.length = (unsigned long)_stext - map.virtual;
4705 + map.type = __MT_MEMORY_RWX;
4706 + create_mapping(&map);
4707 + }
4708 +
4709 + map.pfn = __phys_to_pfn(__pa(_sdata));
4710 + map.virtual = (unsigned long)_sdata;
4711 + map.length = end - __pa(_sdata);
4712 + }
4713 +
4714 + map.type = MT_MEMORY_RW;
4715 + create_mapping(&map);
4716 +#else
4717 if (end < kernel_x_start || start >= kernel_x_end) {
4718 map.pfn = __phys_to_pfn(start);
4719 map.virtual = __phys_to_virt(start);
4720 map.length = end - start;
4721 - map.type = MT_MEMORY_RWX;
4722 + map.type = __MT_MEMORY_RWX;
4723
4724 create_mapping(&map);
4725 } else {
4726 @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4727 map.pfn = __phys_to_pfn(kernel_x_start);
4728 map.virtual = __phys_to_virt(kernel_x_start);
4729 map.length = kernel_x_end - kernel_x_start;
4730 - map.type = MT_MEMORY_RWX;
4731 + map.type = __MT_MEMORY_RWX;
4732
4733 create_mapping(&map);
4734
4735 @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4736 create_mapping(&map);
4737 }
4738 }
4739 +#endif
4740 }
4741 }
4742
4743 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4744 index 5b217f4..c23f40e 100644
4745 --- a/arch/arm/plat-iop/setup.c
4746 +++ b/arch/arm/plat-iop/setup.c
4747 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4748 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4749 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4750 .length = IOP3XX_PERIPHERAL_SIZE,
4751 - .type = MT_UNCACHED,
4752 + .type = MT_UNCACHED_RW,
4753 },
4754 };
4755
4756 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4757 index a5bc92d..0bb4730 100644
4758 --- a/arch/arm/plat-omap/sram.c
4759 +++ b/arch/arm/plat-omap/sram.c
4760 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4761 * Looks like we need to preserve some bootloader code at the
4762 * beginning of SRAM for jumping to flash for reboot to work...
4763 */
4764 + pax_open_kernel();
4765 memset_io(omap_sram_base + omap_sram_skip, 0,
4766 omap_sram_size - omap_sram_skip);
4767 + pax_close_kernel();
4768 }
4769 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4770 index ce6d763..cfea917 100644
4771 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4772 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4773 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4774 int (*started)(unsigned ch);
4775 int (*flush)(unsigned ch);
4776 int (*stop)(unsigned ch);
4777 -};
4778 +} __no_const;
4779
4780 extern void *samsung_dmadev_get_ops(void);
4781 extern void *s3c_dma_get_ops(void);
4782 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4783 index 66eb764..b529b84 100644
4784 --- a/arch/arm64/include/asm/barrier.h
4785 +++ b/arch/arm64/include/asm/barrier.h
4786 @@ -41,7 +41,7 @@
4787 do { \
4788 compiletime_assert_atomic_type(*p); \
4789 smp_mb(); \
4790 - ACCESS_ONCE(*p) = (v); \
4791 + ACCESS_ONCE_RW(*p) = (v); \
4792 } while (0)
4793
4794 #define smp_load_acquire(p) \
4795 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4796 index 3bf8f4e..5dd5491 100644
4797 --- a/arch/arm64/include/asm/uaccess.h
4798 +++ b/arch/arm64/include/asm/uaccess.h
4799 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4800 flag; \
4801 })
4802
4803 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4804 #define access_ok(type, addr, size) __range_ok(addr, size)
4805 #define user_addr_max get_fs
4806
4807 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4808 index c3a58a1..78fbf54 100644
4809 --- a/arch/avr32/include/asm/cache.h
4810 +++ b/arch/avr32/include/asm/cache.h
4811 @@ -1,8 +1,10 @@
4812 #ifndef __ASM_AVR32_CACHE_H
4813 #define __ASM_AVR32_CACHE_H
4814
4815 +#include <linux/const.h>
4816 +
4817 #define L1_CACHE_SHIFT 5
4818 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4819 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4820
4821 /*
4822 * Memory returned by kmalloc() may be used for DMA, so we must make
4823 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4824 index d232888..87c8df1 100644
4825 --- a/arch/avr32/include/asm/elf.h
4826 +++ b/arch/avr32/include/asm/elf.h
4827 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4828 the loader. We need to make sure that it is out of the way of the program
4829 that it will "exec", and that there is sufficient room for the brk. */
4830
4831 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4832 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4833
4834 +#ifdef CONFIG_PAX_ASLR
4835 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4836 +
4837 +#define PAX_DELTA_MMAP_LEN 15
4838 +#define PAX_DELTA_STACK_LEN 15
4839 +#endif
4840
4841 /* This yields a mask that user programs can use to figure out what
4842 instruction set this CPU supports. This could be done in user space,
4843 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4844 index 479330b..53717a8 100644
4845 --- a/arch/avr32/include/asm/kmap_types.h
4846 +++ b/arch/avr32/include/asm/kmap_types.h
4847 @@ -2,9 +2,9 @@
4848 #define __ASM_AVR32_KMAP_TYPES_H
4849
4850 #ifdef CONFIG_DEBUG_HIGHMEM
4851 -# define KM_TYPE_NR 29
4852 +# define KM_TYPE_NR 30
4853 #else
4854 -# define KM_TYPE_NR 14
4855 +# define KM_TYPE_NR 15
4856 #endif
4857
4858 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4859 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4860 index 0eca933..eb78c7b 100644
4861 --- a/arch/avr32/mm/fault.c
4862 +++ b/arch/avr32/mm/fault.c
4863 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4864
4865 int exception_trace = 1;
4866
4867 +#ifdef CONFIG_PAX_PAGEEXEC
4868 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4869 +{
4870 + unsigned long i;
4871 +
4872 + printk(KERN_ERR "PAX: bytes at PC: ");
4873 + for (i = 0; i < 20; i++) {
4874 + unsigned char c;
4875 + if (get_user(c, (unsigned char *)pc+i))
4876 + printk(KERN_CONT "???????? ");
4877 + else
4878 + printk(KERN_CONT "%02x ", c);
4879 + }
4880 + printk("\n");
4881 +}
4882 +#endif
4883 +
4884 /*
4885 * This routine handles page faults. It determines the address and the
4886 * problem, and then passes it off to one of the appropriate routines.
4887 @@ -176,6 +193,16 @@ bad_area:
4888 up_read(&mm->mmap_sem);
4889
4890 if (user_mode(regs)) {
4891 +
4892 +#ifdef CONFIG_PAX_PAGEEXEC
4893 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4894 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4895 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4896 + do_group_exit(SIGKILL);
4897 + }
4898 + }
4899 +#endif
4900 +
4901 if (exception_trace && printk_ratelimit())
4902 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4903 "sp %08lx ecr %lu\n",
4904 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4905 index 568885a..f8008df 100644
4906 --- a/arch/blackfin/include/asm/cache.h
4907 +++ b/arch/blackfin/include/asm/cache.h
4908 @@ -7,6 +7,7 @@
4909 #ifndef __ARCH_BLACKFIN_CACHE_H
4910 #define __ARCH_BLACKFIN_CACHE_H
4911
4912 +#include <linux/const.h>
4913 #include <linux/linkage.h> /* for asmlinkage */
4914
4915 /*
4916 @@ -14,7 +15,7 @@
4917 * Blackfin loads 32 bytes for cache
4918 */
4919 #define L1_CACHE_SHIFT 5
4920 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4921 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4922 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4923
4924 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4925 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4926 index aea2718..3639a60 100644
4927 --- a/arch/cris/include/arch-v10/arch/cache.h
4928 +++ b/arch/cris/include/arch-v10/arch/cache.h
4929 @@ -1,8 +1,9 @@
4930 #ifndef _ASM_ARCH_CACHE_H
4931 #define _ASM_ARCH_CACHE_H
4932
4933 +#include <linux/const.h>
4934 /* Etrax 100LX have 32-byte cache-lines. */
4935 -#define L1_CACHE_BYTES 32
4936 #define L1_CACHE_SHIFT 5
4937 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4938
4939 #endif /* _ASM_ARCH_CACHE_H */
4940 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4941 index 7caf25d..ee65ac5 100644
4942 --- a/arch/cris/include/arch-v32/arch/cache.h
4943 +++ b/arch/cris/include/arch-v32/arch/cache.h
4944 @@ -1,11 +1,12 @@
4945 #ifndef _ASM_CRIS_ARCH_CACHE_H
4946 #define _ASM_CRIS_ARCH_CACHE_H
4947
4948 +#include <linux/const.h>
4949 #include <arch/hwregs/dma.h>
4950
4951 /* A cache-line is 32 bytes. */
4952 -#define L1_CACHE_BYTES 32
4953 #define L1_CACHE_SHIFT 5
4954 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4955
4956 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4957
4958 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4959 index b86329d..6709906 100644
4960 --- a/arch/frv/include/asm/atomic.h
4961 +++ b/arch/frv/include/asm/atomic.h
4962 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4963 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4964 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4965
4966 +#define atomic64_read_unchecked(v) atomic64_read(v)
4967 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4968 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4969 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4970 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4971 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4972 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4973 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4974 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4975 +
4976 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4977 {
4978 int c, old;
4979 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4980 index 2797163..c2a401d 100644
4981 --- a/arch/frv/include/asm/cache.h
4982 +++ b/arch/frv/include/asm/cache.h
4983 @@ -12,10 +12,11 @@
4984 #ifndef __ASM_CACHE_H
4985 #define __ASM_CACHE_H
4986
4987 +#include <linux/const.h>
4988
4989 /* bytes per L1 cache line */
4990 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4991 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4992 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4993
4994 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4995 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4996 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4997 index 43901f2..0d8b865 100644
4998 --- a/arch/frv/include/asm/kmap_types.h
4999 +++ b/arch/frv/include/asm/kmap_types.h
5000 @@ -2,6 +2,6 @@
5001 #ifndef _ASM_KMAP_TYPES_H
5002 #define _ASM_KMAP_TYPES_H
5003
5004 -#define KM_TYPE_NR 17
5005 +#define KM_TYPE_NR 18
5006
5007 #endif
5008 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5009 index 836f147..4cf23f5 100644
5010 --- a/arch/frv/mm/elf-fdpic.c
5011 +++ b/arch/frv/mm/elf-fdpic.c
5012 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5013 {
5014 struct vm_area_struct *vma;
5015 struct vm_unmapped_area_info info;
5016 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5017
5018 if (len > TASK_SIZE)
5019 return -ENOMEM;
5020 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5021 if (addr) {
5022 addr = PAGE_ALIGN(addr);
5023 vma = find_vma(current->mm, addr);
5024 - if (TASK_SIZE - len >= addr &&
5025 - (!vma || addr + len <= vma->vm_start))
5026 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5027 goto success;
5028 }
5029
5030 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5031 info.high_limit = (current->mm->start_stack - 0x00200000);
5032 info.align_mask = 0;
5033 info.align_offset = 0;
5034 + info.threadstack_offset = offset;
5035 addr = vm_unmapped_area(&info);
5036 if (!(addr & ~PAGE_MASK))
5037 goto success;
5038 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5039 index f4ca594..adc72fd6 100644
5040 --- a/arch/hexagon/include/asm/cache.h
5041 +++ b/arch/hexagon/include/asm/cache.h
5042 @@ -21,9 +21,11 @@
5043 #ifndef __ASM_CACHE_H
5044 #define __ASM_CACHE_H
5045
5046 +#include <linux/const.h>
5047 +
5048 /* Bytes per L1 cache line */
5049 -#define L1_CACHE_SHIFT (5)
5050 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5051 +#define L1_CACHE_SHIFT 5
5052 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5053
5054 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5055 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5056 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5057 index 12c3afe..b1abab2 100644
5058 --- a/arch/ia64/Kconfig
5059 +++ b/arch/ia64/Kconfig
5060 @@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5061 config KEXEC
5062 bool "kexec system call"
5063 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5064 + depends on !GRKERNSEC_KMEM
5065 help
5066 kexec is a system call that implements the ability to shutdown your
5067 current kernel, and to start another kernel. It is like a reboot
5068 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5069 index 6e6fe18..a6ae668 100644
5070 --- a/arch/ia64/include/asm/atomic.h
5071 +++ b/arch/ia64/include/asm/atomic.h
5072 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5073 #define atomic64_inc(v) atomic64_add(1, (v))
5074 #define atomic64_dec(v) atomic64_sub(1, (v))
5075
5076 +#define atomic64_read_unchecked(v) atomic64_read(v)
5077 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5078 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5079 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5080 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5081 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5082 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5083 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5084 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5085 +
5086 /* Atomic operations are already serializing */
5087 #define smp_mb__before_atomic_dec() barrier()
5088 #define smp_mb__after_atomic_dec() barrier()
5089 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5090 index d0a69aa..142f878 100644
5091 --- a/arch/ia64/include/asm/barrier.h
5092 +++ b/arch/ia64/include/asm/barrier.h
5093 @@ -64,7 +64,7 @@
5094 do { \
5095 compiletime_assert_atomic_type(*p); \
5096 barrier(); \
5097 - ACCESS_ONCE(*p) = (v); \
5098 + ACCESS_ONCE_RW(*p) = (v); \
5099 } while (0)
5100
5101 #define smp_load_acquire(p) \
5102 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5103 index 988254a..e1ee885 100644
5104 --- a/arch/ia64/include/asm/cache.h
5105 +++ b/arch/ia64/include/asm/cache.h
5106 @@ -1,6 +1,7 @@
5107 #ifndef _ASM_IA64_CACHE_H
5108 #define _ASM_IA64_CACHE_H
5109
5110 +#include <linux/const.h>
5111
5112 /*
5113 * Copyright (C) 1998-2000 Hewlett-Packard Co
5114 @@ -9,7 +10,7 @@
5115
5116 /* Bytes per L1 (data) cache line. */
5117 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5118 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5119 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5120
5121 #ifdef CONFIG_SMP
5122 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5123 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5124 index 5a83c5c..4d7f553 100644
5125 --- a/arch/ia64/include/asm/elf.h
5126 +++ b/arch/ia64/include/asm/elf.h
5127 @@ -42,6 +42,13 @@
5128 */
5129 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5130
5131 +#ifdef CONFIG_PAX_ASLR
5132 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5133 +
5134 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5135 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5136 +#endif
5137 +
5138 #define PT_IA_64_UNWIND 0x70000001
5139
5140 /* IA-64 relocations: */
5141 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5142 index 5767cdf..7462574 100644
5143 --- a/arch/ia64/include/asm/pgalloc.h
5144 +++ b/arch/ia64/include/asm/pgalloc.h
5145 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5146 pgd_val(*pgd_entry) = __pa(pud);
5147 }
5148
5149 +static inline void
5150 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5151 +{
5152 + pgd_populate(mm, pgd_entry, pud);
5153 +}
5154 +
5155 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5156 {
5157 return quicklist_alloc(0, GFP_KERNEL, NULL);
5158 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5159 pud_val(*pud_entry) = __pa(pmd);
5160 }
5161
5162 +static inline void
5163 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5164 +{
5165 + pud_populate(mm, pud_entry, pmd);
5166 +}
5167 +
5168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5169 {
5170 return quicklist_alloc(0, GFP_KERNEL, NULL);
5171 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5172 index 7935115..c0eca6a 100644
5173 --- a/arch/ia64/include/asm/pgtable.h
5174 +++ b/arch/ia64/include/asm/pgtable.h
5175 @@ -12,7 +12,7 @@
5176 * David Mosberger-Tang <davidm@hpl.hp.com>
5177 */
5178
5179 -
5180 +#include <linux/const.h>
5181 #include <asm/mman.h>
5182 #include <asm/page.h>
5183 #include <asm/processor.h>
5184 @@ -142,6 +142,17 @@
5185 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5186 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5187 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5188 +
5189 +#ifdef CONFIG_PAX_PAGEEXEC
5190 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5191 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5192 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5193 +#else
5194 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5195 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5196 +# define PAGE_COPY_NOEXEC PAGE_COPY
5197 +#endif
5198 +
5199 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5200 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5201 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5202 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5203 index 45698cd..e8e2dbc 100644
5204 --- a/arch/ia64/include/asm/spinlock.h
5205 +++ b/arch/ia64/include/asm/spinlock.h
5206 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5207 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5208
5209 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5210 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5211 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5212 }
5213
5214 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5215 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5216 index 449c8c0..3d4b1e9 100644
5217 --- a/arch/ia64/include/asm/uaccess.h
5218 +++ b/arch/ia64/include/asm/uaccess.h
5219 @@ -70,6 +70,7 @@
5220 && ((segment).seg == KERNEL_DS.seg \
5221 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5222 })
5223 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5224 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5225
5226 /*
5227 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5228 static inline unsigned long
5229 __copy_to_user (void __user *to, const void *from, unsigned long count)
5230 {
5231 + if (count > INT_MAX)
5232 + return count;
5233 +
5234 + if (!__builtin_constant_p(count))
5235 + check_object_size(from, count, true);
5236 +
5237 return __copy_user(to, (__force void __user *) from, count);
5238 }
5239
5240 static inline unsigned long
5241 __copy_from_user (void *to, const void __user *from, unsigned long count)
5242 {
5243 + if (count > INT_MAX)
5244 + return count;
5245 +
5246 + if (!__builtin_constant_p(count))
5247 + check_object_size(to, count, false);
5248 +
5249 return __copy_user((__force void __user *) to, from, count);
5250 }
5251
5252 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5253 ({ \
5254 void __user *__cu_to = (to); \
5255 const void *__cu_from = (from); \
5256 - long __cu_len = (n); \
5257 + unsigned long __cu_len = (n); \
5258 \
5259 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5260 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5261 + if (!__builtin_constant_p(n)) \
5262 + check_object_size(__cu_from, __cu_len, true); \
5263 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5264 + } \
5265 __cu_len; \
5266 })
5267
5268 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5269 ({ \
5270 void *__cu_to = (to); \
5271 const void __user *__cu_from = (from); \
5272 - long __cu_len = (n); \
5273 + unsigned long __cu_len = (n); \
5274 \
5275 __chk_user_ptr(__cu_from); \
5276 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5277 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5278 + if (!__builtin_constant_p(n)) \
5279 + check_object_size(__cu_to, __cu_len, false); \
5280 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5281 + } \
5282 __cu_len; \
5283 })
5284
5285 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5286 index 24603be..948052d 100644
5287 --- a/arch/ia64/kernel/module.c
5288 +++ b/arch/ia64/kernel/module.c
5289 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5290 void
5291 module_free (struct module *mod, void *module_region)
5292 {
5293 - if (mod && mod->arch.init_unw_table &&
5294 - module_region == mod->module_init) {
5295 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5296 unw_remove_unwind_table(mod->arch.init_unw_table);
5297 mod->arch.init_unw_table = NULL;
5298 }
5299 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5300 }
5301
5302 static inline int
5303 +in_init_rx (const struct module *mod, uint64_t addr)
5304 +{
5305 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5306 +}
5307 +
5308 +static inline int
5309 +in_init_rw (const struct module *mod, uint64_t addr)
5310 +{
5311 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5312 +}
5313 +
5314 +static inline int
5315 in_init (const struct module *mod, uint64_t addr)
5316 {
5317 - return addr - (uint64_t) mod->module_init < mod->init_size;
5318 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5319 +}
5320 +
5321 +static inline int
5322 +in_core_rx (const struct module *mod, uint64_t addr)
5323 +{
5324 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5325 +}
5326 +
5327 +static inline int
5328 +in_core_rw (const struct module *mod, uint64_t addr)
5329 +{
5330 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5331 }
5332
5333 static inline int
5334 in_core (const struct module *mod, uint64_t addr)
5335 {
5336 - return addr - (uint64_t) mod->module_core < mod->core_size;
5337 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5338 }
5339
5340 static inline int
5341 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5342 break;
5343
5344 case RV_BDREL:
5345 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5346 + if (in_init_rx(mod, val))
5347 + val -= (uint64_t) mod->module_init_rx;
5348 + else if (in_init_rw(mod, val))
5349 + val -= (uint64_t) mod->module_init_rw;
5350 + else if (in_core_rx(mod, val))
5351 + val -= (uint64_t) mod->module_core_rx;
5352 + else if (in_core_rw(mod, val))
5353 + val -= (uint64_t) mod->module_core_rw;
5354 break;
5355
5356 case RV_LTV:
5357 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5358 * addresses have been selected...
5359 */
5360 uint64_t gp;
5361 - if (mod->core_size > MAX_LTOFF)
5362 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5363 /*
5364 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5365 * at the end of the module.
5366 */
5367 - gp = mod->core_size - MAX_LTOFF / 2;
5368 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5369 else
5370 - gp = mod->core_size / 2;
5371 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5372 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5373 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5374 mod->arch.gp = gp;
5375 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5376 }
5377 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5378 index c39c3cd..3c77738 100644
5379 --- a/arch/ia64/kernel/palinfo.c
5380 +++ b/arch/ia64/kernel/palinfo.c
5381 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5382 return NOTIFY_OK;
5383 }
5384
5385 -static struct notifier_block __refdata palinfo_cpu_notifier =
5386 +static struct notifier_block palinfo_cpu_notifier =
5387 {
5388 .notifier_call = palinfo_cpu_callback,
5389 .priority = 0,
5390 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5391 index 41e33f8..65180b2a 100644
5392 --- a/arch/ia64/kernel/sys_ia64.c
5393 +++ b/arch/ia64/kernel/sys_ia64.c
5394 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5395 unsigned long align_mask = 0;
5396 struct mm_struct *mm = current->mm;
5397 struct vm_unmapped_area_info info;
5398 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5399
5400 if (len > RGN_MAP_LIMIT)
5401 return -ENOMEM;
5402 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5403 if (REGION_NUMBER(addr) == RGN_HPAGE)
5404 addr = 0;
5405 #endif
5406 +
5407 +#ifdef CONFIG_PAX_RANDMMAP
5408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5409 + addr = mm->free_area_cache;
5410 + else
5411 +#endif
5412 +
5413 if (!addr)
5414 addr = TASK_UNMAPPED_BASE;
5415
5416 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5417 info.high_limit = TASK_SIZE;
5418 info.align_mask = align_mask;
5419 info.align_offset = 0;
5420 + info.threadstack_offset = offset;
5421 return vm_unmapped_area(&info);
5422 }
5423
5424 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5425 index 84f8a52..7c76178 100644
5426 --- a/arch/ia64/kernel/vmlinux.lds.S
5427 +++ b/arch/ia64/kernel/vmlinux.lds.S
5428 @@ -192,7 +192,7 @@ SECTIONS {
5429 /* Per-cpu data: */
5430 . = ALIGN(PERCPU_PAGE_SIZE);
5431 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5432 - __phys_per_cpu_start = __per_cpu_load;
5433 + __phys_per_cpu_start = per_cpu_load;
5434 /*
5435 * ensure percpu data fits
5436 * into percpu page size
5437 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5438 index 7225dad..2a7c8256 100644
5439 --- a/arch/ia64/mm/fault.c
5440 +++ b/arch/ia64/mm/fault.c
5441 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5442 return pte_present(pte);
5443 }
5444
5445 +#ifdef CONFIG_PAX_PAGEEXEC
5446 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5447 +{
5448 + unsigned long i;
5449 +
5450 + printk(KERN_ERR "PAX: bytes at PC: ");
5451 + for (i = 0; i < 8; i++) {
5452 + unsigned int c;
5453 + if (get_user(c, (unsigned int *)pc+i))
5454 + printk(KERN_CONT "???????? ");
5455 + else
5456 + printk(KERN_CONT "%08x ", c);
5457 + }
5458 + printk("\n");
5459 +}
5460 +#endif
5461 +
5462 # define VM_READ_BIT 0
5463 # define VM_WRITE_BIT 1
5464 # define VM_EXEC_BIT 2
5465 @@ -151,8 +168,21 @@ retry:
5466 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5467 goto bad_area;
5468
5469 - if ((vma->vm_flags & mask) != mask)
5470 + if ((vma->vm_flags & mask) != mask) {
5471 +
5472 +#ifdef CONFIG_PAX_PAGEEXEC
5473 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5474 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5475 + goto bad_area;
5476 +
5477 + up_read(&mm->mmap_sem);
5478 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5479 + do_group_exit(SIGKILL);
5480 + }
5481 +#endif
5482 +
5483 goto bad_area;
5484 + }
5485
5486 /*
5487 * If for any reason at all we couldn't handle the fault, make
5488 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5489 index 76069c1..c2aa816 100644
5490 --- a/arch/ia64/mm/hugetlbpage.c
5491 +++ b/arch/ia64/mm/hugetlbpage.c
5492 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5493 unsigned long pgoff, unsigned long flags)
5494 {
5495 struct vm_unmapped_area_info info;
5496 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5497
5498 if (len > RGN_MAP_LIMIT)
5499 return -ENOMEM;
5500 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5501 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5502 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5503 info.align_offset = 0;
5504 + info.threadstack_offset = offset;
5505 return vm_unmapped_area(&info);
5506 }
5507
5508 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5509 index 25c3502..560dae7 100644
5510 --- a/arch/ia64/mm/init.c
5511 +++ b/arch/ia64/mm/init.c
5512 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5513 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5514 vma->vm_end = vma->vm_start + PAGE_SIZE;
5515 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5516 +
5517 +#ifdef CONFIG_PAX_PAGEEXEC
5518 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5519 + vma->vm_flags &= ~VM_EXEC;
5520 +
5521 +#ifdef CONFIG_PAX_MPROTECT
5522 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5523 + vma->vm_flags &= ~VM_MAYEXEC;
5524 +#endif
5525 +
5526 + }
5527 +#endif
5528 +
5529 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5530 down_write(&current->mm->mmap_sem);
5531 if (insert_vm_struct(current->mm, vma)) {
5532 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5533 index 40b3ee9..8c2c112 100644
5534 --- a/arch/m32r/include/asm/cache.h
5535 +++ b/arch/m32r/include/asm/cache.h
5536 @@ -1,8 +1,10 @@
5537 #ifndef _ASM_M32R_CACHE_H
5538 #define _ASM_M32R_CACHE_H
5539
5540 +#include <linux/const.h>
5541 +
5542 /* L1 cache line size */
5543 #define L1_CACHE_SHIFT 4
5544 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5545 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5546
5547 #endif /* _ASM_M32R_CACHE_H */
5548 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5549 index 82abd15..d95ae5d 100644
5550 --- a/arch/m32r/lib/usercopy.c
5551 +++ b/arch/m32r/lib/usercopy.c
5552 @@ -14,6 +14,9 @@
5553 unsigned long
5554 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5555 {
5556 + if ((long)n < 0)
5557 + return n;
5558 +
5559 prefetch(from);
5560 if (access_ok(VERIFY_WRITE, to, n))
5561 __copy_user(to,from,n);
5562 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5563 unsigned long
5564 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5565 {
5566 + if ((long)n < 0)
5567 + return n;
5568 +
5569 prefetchw(to);
5570 if (access_ok(VERIFY_READ, from, n))
5571 __copy_user_zeroing(to,from,n);
5572 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5573 index 0395c51..5f26031 100644
5574 --- a/arch/m68k/include/asm/cache.h
5575 +++ b/arch/m68k/include/asm/cache.h
5576 @@ -4,9 +4,11 @@
5577 #ifndef __ARCH_M68K_CACHE_H
5578 #define __ARCH_M68K_CACHE_H
5579
5580 +#include <linux/const.h>
5581 +
5582 /* bytes per L1 cache line */
5583 #define L1_CACHE_SHIFT 4
5584 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5585 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5586
5587 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5588
5589 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5590 index 2d6f0de..de5f5ac 100644
5591 --- a/arch/metag/include/asm/barrier.h
5592 +++ b/arch/metag/include/asm/barrier.h
5593 @@ -89,7 +89,7 @@ static inline void fence(void)
5594 do { \
5595 compiletime_assert_atomic_type(*p); \
5596 smp_mb(); \
5597 - ACCESS_ONCE(*p) = (v); \
5598 + ACCESS_ONCE_RW(*p) = (v); \
5599 } while (0)
5600
5601 #define smp_load_acquire(p) \
5602 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5603 index 3c52fa6..11b2ad8 100644
5604 --- a/arch/metag/mm/hugetlbpage.c
5605 +++ b/arch/metag/mm/hugetlbpage.c
5606 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5607 info.high_limit = TASK_SIZE;
5608 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5609 info.align_offset = 0;
5610 + info.threadstack_offset = 0;
5611 return vm_unmapped_area(&info);
5612 }
5613
5614 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5615 index 4efe96a..60e8699 100644
5616 --- a/arch/microblaze/include/asm/cache.h
5617 +++ b/arch/microblaze/include/asm/cache.h
5618 @@ -13,11 +13,12 @@
5619 #ifndef _ASM_MICROBLAZE_CACHE_H
5620 #define _ASM_MICROBLAZE_CACHE_H
5621
5622 +#include <linux/const.h>
5623 #include <asm/registers.h>
5624
5625 #define L1_CACHE_SHIFT 5
5626 /* word-granular cache in microblaze */
5627 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5628 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5629
5630 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5631
5632 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5633 index 5cd695f..9a24ad0 100644
5634 --- a/arch/mips/Kconfig
5635 +++ b/arch/mips/Kconfig
5636 @@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5637
5638 config KEXEC
5639 bool "Kexec system call"
5640 + depends on !GRKERNSEC_KMEM
5641 help
5642 kexec is a system call that implements the ability to shutdown your
5643 current kernel, and to start another kernel. It is like a reboot
5644 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5645 index 02f2444..506969c 100644
5646 --- a/arch/mips/cavium-octeon/dma-octeon.c
5647 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5648 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5649 if (dma_release_from_coherent(dev, order, vaddr))
5650 return;
5651
5652 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5653 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5654 }
5655
5656 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5657 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5658 index e8eb3d5..2e665d1 100644
5659 --- a/arch/mips/include/asm/atomic.h
5660 +++ b/arch/mips/include/asm/atomic.h
5661 @@ -21,15 +21,39 @@
5662 #include <asm/cmpxchg.h>
5663 #include <asm/war.h>
5664
5665 +#ifdef CONFIG_GENERIC_ATOMIC64
5666 +#include <asm-generic/atomic64.h>
5667 +#endif
5668 +
5669 #define ATOMIC_INIT(i) { (i) }
5670
5671 +#ifdef CONFIG_64BIT
5672 +#define _ASM_EXTABLE(from, to) \
5673 +" .section __ex_table,\"a\"\n" \
5674 +" .dword " #from ", " #to"\n" \
5675 +" .previous\n"
5676 +#else
5677 +#define _ASM_EXTABLE(from, to) \
5678 +" .section __ex_table,\"a\"\n" \
5679 +" .word " #from ", " #to"\n" \
5680 +" .previous\n"
5681 +#endif
5682 +
5683 /*
5684 * atomic_read - read atomic variable
5685 * @v: pointer of type atomic_t
5686 *
5687 * Atomically reads the value of @v.
5688 */
5689 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5690 +static inline int atomic_read(const atomic_t *v)
5691 +{
5692 + return (*(volatile const int *) &v->counter);
5693 +}
5694 +
5695 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5696 +{
5697 + return (*(volatile const int *) &v->counter);
5698 +}
5699
5700 /*
5701 * atomic_set - set atomic variable
5702 @@ -38,7 +62,15 @@
5703 *
5704 * Atomically sets the value of @v to @i.
5705 */
5706 -#define atomic_set(v, i) ((v)->counter = (i))
5707 +static inline void atomic_set(atomic_t *v, int i)
5708 +{
5709 + v->counter = i;
5710 +}
5711 +
5712 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5713 +{
5714 + v->counter = i;
5715 +}
5716
5717 /*
5718 * atomic_add - add integer to atomic variable
5719 @@ -47,7 +79,67 @@
5720 *
5721 * Atomically adds @i to @v.
5722 */
5723 -static __inline__ void atomic_add(int i, atomic_t * v)
5724 +static __inline__ void atomic_add(int i, atomic_t *v)
5725 +{
5726 + int temp;
5727 +
5728 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5729 + __asm__ __volatile__(
5730 + " .set mips3 \n"
5731 + "1: ll %0, %1 # atomic_add \n"
5732 +#ifdef CONFIG_PAX_REFCOUNT
5733 + /* Exception on overflow. */
5734 + "2: add %0, %2 \n"
5735 +#else
5736 + " addu %0, %2 \n"
5737 +#endif
5738 + " sc %0, %1 \n"
5739 + " beqzl %0, 1b \n"
5740 +#ifdef CONFIG_PAX_REFCOUNT
5741 + "3: \n"
5742 + _ASM_EXTABLE(2b, 3b)
5743 +#endif
5744 + " .set mips0 \n"
5745 + : "=&r" (temp), "+m" (v->counter)
5746 + : "Ir" (i));
5747 + } else if (kernel_uses_llsc) {
5748 + __asm__ __volatile__(
5749 + " .set mips3 \n"
5750 + "1: ll %0, %1 # atomic_add \n"
5751 +#ifdef CONFIG_PAX_REFCOUNT
5752 + /* Exception on overflow. */
5753 + "2: add %0, %2 \n"
5754 +#else
5755 + " addu %0, %2 \n"
5756 +#endif
5757 + " sc %0, %1 \n"
5758 + " beqz %0, 1b \n"
5759 +#ifdef CONFIG_PAX_REFCOUNT
5760 + "3: \n"
5761 + _ASM_EXTABLE(2b, 3b)
5762 +#endif
5763 + " .set mips0 \n"
5764 + : "=&r" (temp), "+m" (v->counter)
5765 + : "Ir" (i));
5766 + } else {
5767 + unsigned long flags;
5768 +
5769 + raw_local_irq_save(flags);
5770 + __asm__ __volatile__(
5771 +#ifdef CONFIG_PAX_REFCOUNT
5772 + /* Exception on overflow. */
5773 + "1: add %0, %1 \n"
5774 + "2: \n"
5775 + _ASM_EXTABLE(1b, 2b)
5776 +#else
5777 + " addu %0, %1 \n"
5778 +#endif
5779 + : "+r" (v->counter) : "Ir" (i));
5780 + raw_local_irq_restore(flags);
5781 + }
5782 +}
5783 +
5784 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5785 {
5786 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5787 int temp;
5788 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5789 *
5790 * Atomically subtracts @i from @v.
5791 */
5792 -static __inline__ void atomic_sub(int i, atomic_t * v)
5793 +static __inline__ void atomic_sub(int i, atomic_t *v)
5794 +{
5795 + int temp;
5796 +
5797 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5798 + __asm__ __volatile__(
5799 + " .set mips3 \n"
5800 + "1: ll %0, %1 # atomic64_sub \n"
5801 +#ifdef CONFIG_PAX_REFCOUNT
5802 + /* Exception on overflow. */
5803 + "2: sub %0, %2 \n"
5804 +#else
5805 + " subu %0, %2 \n"
5806 +#endif
5807 + " sc %0, %1 \n"
5808 + " beqzl %0, 1b \n"
5809 +#ifdef CONFIG_PAX_REFCOUNT
5810 + "3: \n"
5811 + _ASM_EXTABLE(2b, 3b)
5812 +#endif
5813 + " .set mips0 \n"
5814 + : "=&r" (temp), "+m" (v->counter)
5815 + : "Ir" (i));
5816 + } else if (kernel_uses_llsc) {
5817 + __asm__ __volatile__(
5818 + " .set mips3 \n"
5819 + "1: ll %0, %1 # atomic64_sub \n"
5820 +#ifdef CONFIG_PAX_REFCOUNT
5821 + /* Exception on overflow. */
5822 + "2: sub %0, %2 \n"
5823 +#else
5824 + " subu %0, %2 \n"
5825 +#endif
5826 + " sc %0, %1 \n"
5827 + " beqz %0, 1b \n"
5828 +#ifdef CONFIG_PAX_REFCOUNT
5829 + "3: \n"
5830 + _ASM_EXTABLE(2b, 3b)
5831 +#endif
5832 + " .set mips0 \n"
5833 + : "=&r" (temp), "+m" (v->counter)
5834 + : "Ir" (i));
5835 + } else {
5836 + unsigned long flags;
5837 +
5838 + raw_local_irq_save(flags);
5839 + __asm__ __volatile__(
5840 +#ifdef CONFIG_PAX_REFCOUNT
5841 + /* Exception on overflow. */
5842 + "1: sub %0, %1 \n"
5843 + "2: \n"
5844 + _ASM_EXTABLE(1b, 2b)
5845 +#else
5846 + " subu %0, %1 \n"
5847 +#endif
5848 + : "+r" (v->counter) : "Ir" (i));
5849 + raw_local_irq_restore(flags);
5850 + }
5851 +}
5852 +
5853 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5854 {
5855 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5856 int temp;
5857 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5858 /*
5859 * Same as above, but return the result value
5860 */
5861 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5862 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5863 +{
5864 + int result;
5865 + int temp;
5866 +
5867 + smp_mb__before_llsc();
5868 +
5869 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5870 + __asm__ __volatile__(
5871 + " .set mips3 \n"
5872 + "1: ll %1, %2 # atomic_add_return \n"
5873 +#ifdef CONFIG_PAX_REFCOUNT
5874 + "2: add %0, %1, %3 \n"
5875 +#else
5876 + " addu %0, %1, %3 \n"
5877 +#endif
5878 + " sc %0, %2 \n"
5879 + " beqzl %0, 1b \n"
5880 +#ifdef CONFIG_PAX_REFCOUNT
5881 + " b 4f \n"
5882 + " .set noreorder \n"
5883 + "3: b 5f \n"
5884 + " move %0, %1 \n"
5885 + " .set reorder \n"
5886 + _ASM_EXTABLE(2b, 3b)
5887 +#endif
5888 + "4: addu %0, %1, %3 \n"
5889 +#ifdef CONFIG_PAX_REFCOUNT
5890 + "5: \n"
5891 +#endif
5892 + " .set mips0 \n"
5893 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5894 + : "Ir" (i));
5895 + } else if (kernel_uses_llsc) {
5896 + __asm__ __volatile__(
5897 + " .set mips3 \n"
5898 + "1: ll %1, %2 # atomic_add_return \n"
5899 +#ifdef CONFIG_PAX_REFCOUNT
5900 + "2: add %0, %1, %3 \n"
5901 +#else
5902 + " addu %0, %1, %3 \n"
5903 +#endif
5904 + " sc %0, %2 \n"
5905 + " bnez %0, 4f \n"
5906 + " b 1b \n"
5907 +#ifdef CONFIG_PAX_REFCOUNT
5908 + " .set noreorder \n"
5909 + "3: b 5f \n"
5910 + " move %0, %1 \n"
5911 + " .set reorder \n"
5912 + _ASM_EXTABLE(2b, 3b)
5913 +#endif
5914 + "4: addu %0, %1, %3 \n"
5915 +#ifdef CONFIG_PAX_REFCOUNT
5916 + "5: \n"
5917 +#endif
5918 + " .set mips0 \n"
5919 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5920 + : "Ir" (i));
5921 + } else {
5922 + unsigned long flags;
5923 +
5924 + raw_local_irq_save(flags);
5925 + __asm__ __volatile__(
5926 + " lw %0, %1 \n"
5927 +#ifdef CONFIG_PAX_REFCOUNT
5928 + /* Exception on overflow. */
5929 + "1: add %0, %2 \n"
5930 +#else
5931 + " addu %0, %2 \n"
5932 +#endif
5933 + " sw %0, %1 \n"
5934 +#ifdef CONFIG_PAX_REFCOUNT
5935 + /* Note: Dest reg is not modified on overflow */
5936 + "2: \n"
5937 + _ASM_EXTABLE(1b, 2b)
5938 +#endif
5939 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5940 + raw_local_irq_restore(flags);
5941 + }
5942 +
5943 + smp_llsc_mb();
5944 +
5945 + return result;
5946 +}
5947 +
5948 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5949 {
5950 int result;
5951
5952 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5957 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5958 +{
5959 + int result;
5960 + int temp;
5961 +
5962 + smp_mb__before_llsc();
5963 +
5964 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5965 + __asm__ __volatile__(
5966 + " .set mips3 \n"
5967 + "1: ll %1, %2 # atomic_sub_return \n"
5968 +#ifdef CONFIG_PAX_REFCOUNT
5969 + "2: sub %0, %1, %3 \n"
5970 +#else
5971 + " subu %0, %1, %3 \n"
5972 +#endif
5973 + " sc %0, %2 \n"
5974 + " beqzl %0, 1b \n"
5975 +#ifdef CONFIG_PAX_REFCOUNT
5976 + " b 4f \n"
5977 + " .set noreorder \n"
5978 + "3: b 5f \n"
5979 + " move %0, %1 \n"
5980 + " .set reorder \n"
5981 + _ASM_EXTABLE(2b, 3b)
5982 +#endif
5983 + "4: subu %0, %1, %3 \n"
5984 +#ifdef CONFIG_PAX_REFCOUNT
5985 + "5: \n"
5986 +#endif
5987 + " .set mips0 \n"
5988 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5989 + : "Ir" (i), "m" (v->counter)
5990 + : "memory");
5991 + } else if (kernel_uses_llsc) {
5992 + __asm__ __volatile__(
5993 + " .set mips3 \n"
5994 + "1: ll %1, %2 # atomic_sub_return \n"
5995 +#ifdef CONFIG_PAX_REFCOUNT
5996 + "2: sub %0, %1, %3 \n"
5997 +#else
5998 + " subu %0, %1, %3 \n"
5999 +#endif
6000 + " sc %0, %2 \n"
6001 + " bnez %0, 4f \n"
6002 + " b 1b \n"
6003 +#ifdef CONFIG_PAX_REFCOUNT
6004 + " .set noreorder \n"
6005 + "3: b 5f \n"
6006 + " move %0, %1 \n"
6007 + " .set reorder \n"
6008 + _ASM_EXTABLE(2b, 3b)
6009 +#endif
6010 + "4: subu %0, %1, %3 \n"
6011 +#ifdef CONFIG_PAX_REFCOUNT
6012 + "5: \n"
6013 +#endif
6014 + " .set mips0 \n"
6015 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6016 + : "Ir" (i));
6017 + } else {
6018 + unsigned long flags;
6019 +
6020 + raw_local_irq_save(flags);
6021 + __asm__ __volatile__(
6022 + " lw %0, %1 \n"
6023 +#ifdef CONFIG_PAX_REFCOUNT
6024 + /* Exception on overflow. */
6025 + "1: sub %0, %2 \n"
6026 +#else
6027 + " subu %0, %2 \n"
6028 +#endif
6029 + " sw %0, %1 \n"
6030 +#ifdef CONFIG_PAX_REFCOUNT
6031 + /* Note: Dest reg is not modified on overflow */
6032 + "2: \n"
6033 + _ASM_EXTABLE(1b, 2b)
6034 +#endif
6035 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6036 + raw_local_irq_restore(flags);
6037 + }
6038 +
6039 + smp_llsc_mb();
6040 +
6041 + return result;
6042 +}
6043 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6044 {
6045 int result;
6046
6047 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6048 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6049 * The function returns the old value of @v minus @i.
6050 */
6051 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6052 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6053 {
6054 int result;
6055
6056 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6057 return result;
6058 }
6059
6060 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6061 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6062 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6063 +{
6064 + return cmpxchg(&v->counter, old, new);
6065 +}
6066 +
6067 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6068 + int new)
6069 +{
6070 + return cmpxchg(&(v->counter), old, new);
6071 +}
6072 +
6073 +static inline int atomic_xchg(atomic_t *v, int new)
6074 +{
6075 + return xchg(&v->counter, new);
6076 +}
6077 +
6078 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6079 +{
6080 + return xchg(&(v->counter), new);
6081 +}
6082
6083 /**
6084 * __atomic_add_unless - add unless the number is a given value
6085 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6086
6087 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6088 #define atomic_inc_return(v) atomic_add_return(1, (v))
6089 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6090 +{
6091 + return atomic_add_return_unchecked(1, v);
6092 +}
6093
6094 /*
6095 * atomic_sub_and_test - subtract value from variable and test result
6096 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6097 * other cases.
6098 */
6099 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6100 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6101 +{
6102 + return atomic_add_return_unchecked(1, v) == 0;
6103 +}
6104
6105 /*
6106 * atomic_dec_and_test - decrement by 1 and test
6107 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6108 * Atomically increments @v by 1.
6109 */
6110 #define atomic_inc(v) atomic_add(1, (v))
6111 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6112 +{
6113 + atomic_add_unchecked(1, v);
6114 +}
6115
6116 /*
6117 * atomic_dec - decrement and test
6118 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6119 * Atomically decrements @v by 1.
6120 */
6121 #define atomic_dec(v) atomic_sub(1, (v))
6122 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6123 +{
6124 + atomic_sub_unchecked(1, v);
6125 +}
6126
6127 /*
6128 * atomic_add_negative - add and test if negative
6129 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6130 * @v: pointer of type atomic64_t
6131 *
6132 */
6133 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6134 +static inline long atomic64_read(const atomic64_t *v)
6135 +{
6136 + return (*(volatile const long *) &v->counter);
6137 +}
6138 +
6139 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6140 +{
6141 + return (*(volatile const long *) &v->counter);
6142 +}
6143
6144 /*
6145 * atomic64_set - set atomic variable
6146 * @v: pointer of type atomic64_t
6147 * @i: required value
6148 */
6149 -#define atomic64_set(v, i) ((v)->counter = (i))
6150 +static inline void atomic64_set(atomic64_t *v, long i)
6151 +{
6152 + v->counter = i;
6153 +}
6154 +
6155 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6156 +{
6157 + v->counter = i;
6158 +}
6159
6160 /*
6161 * atomic64_add - add integer to atomic variable
6162 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6163 *
6164 * Atomically adds @i to @v.
6165 */
6166 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6167 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6168 +{
6169 + long temp;
6170 +
6171 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6172 + __asm__ __volatile__(
6173 + " .set mips3 \n"
6174 + "1: lld %0, %1 # atomic64_add \n"
6175 +#ifdef CONFIG_PAX_REFCOUNT
6176 + /* Exception on overflow. */
6177 + "2: dadd %0, %2 \n"
6178 +#else
6179 + " daddu %0, %2 \n"
6180 +#endif
6181 + " scd %0, %1 \n"
6182 + " beqzl %0, 1b \n"
6183 +#ifdef CONFIG_PAX_REFCOUNT
6184 + "3: \n"
6185 + _ASM_EXTABLE(2b, 3b)
6186 +#endif
6187 + " .set mips0 \n"
6188 + : "=&r" (temp), "+m" (v->counter)
6189 + : "Ir" (i));
6190 + } else if (kernel_uses_llsc) {
6191 + __asm__ __volatile__(
6192 + " .set mips3 \n"
6193 + "1: lld %0, %1 # atomic64_add \n"
6194 +#ifdef CONFIG_PAX_REFCOUNT
6195 + /* Exception on overflow. */
6196 + "2: dadd %0, %2 \n"
6197 +#else
6198 + " daddu %0, %2 \n"
6199 +#endif
6200 + " scd %0, %1 \n"
6201 + " beqz %0, 1b \n"
6202 +#ifdef CONFIG_PAX_REFCOUNT
6203 + "3: \n"
6204 + _ASM_EXTABLE(2b, 3b)
6205 +#endif
6206 + " .set mips0 \n"
6207 + : "=&r" (temp), "+m" (v->counter)
6208 + : "Ir" (i));
6209 + } else {
6210 + unsigned long flags;
6211 +
6212 + raw_local_irq_save(flags);
6213 + __asm__ __volatile__(
6214 +#ifdef CONFIG_PAX_REFCOUNT
6215 + /* Exception on overflow. */
6216 + "1: dadd %0, %1 \n"
6217 + "2: \n"
6218 + _ASM_EXTABLE(1b, 2b)
6219 +#else
6220 + " daddu %0, %1 \n"
6221 +#endif
6222 + : "+r" (v->counter) : "Ir" (i));
6223 + raw_local_irq_restore(flags);
6224 + }
6225 +}
6226 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6227 {
6228 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6229 long temp;
6230 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6231 *
6232 * Atomically subtracts @i from @v.
6233 */
6234 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6235 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6236 +{
6237 + long temp;
6238 +
6239 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6240 + __asm__ __volatile__(
6241 + " .set mips3 \n"
6242 + "1: lld %0, %1 # atomic64_sub \n"
6243 +#ifdef CONFIG_PAX_REFCOUNT
6244 + /* Exception on overflow. */
6245 + "2: dsub %0, %2 \n"
6246 +#else
6247 + " dsubu %0, %2 \n"
6248 +#endif
6249 + " scd %0, %1 \n"
6250 + " beqzl %0, 1b \n"
6251 +#ifdef CONFIG_PAX_REFCOUNT
6252 + "3: \n"
6253 + _ASM_EXTABLE(2b, 3b)
6254 +#endif
6255 + " .set mips0 \n"
6256 + : "=&r" (temp), "+m" (v->counter)
6257 + : "Ir" (i));
6258 + } else if (kernel_uses_llsc) {
6259 + __asm__ __volatile__(
6260 + " .set mips3 \n"
6261 + "1: lld %0, %1 # atomic64_sub \n"
6262 +#ifdef CONFIG_PAX_REFCOUNT
6263 + /* Exception on overflow. */
6264 + "2: dsub %0, %2 \n"
6265 +#else
6266 + " dsubu %0, %2 \n"
6267 +#endif
6268 + " scd %0, %1 \n"
6269 + " beqz %0, 1b \n"
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + "3: \n"
6272 + _ASM_EXTABLE(2b, 3b)
6273 +#endif
6274 + " .set mips0 \n"
6275 + : "=&r" (temp), "+m" (v->counter)
6276 + : "Ir" (i));
6277 + } else {
6278 + unsigned long flags;
6279 +
6280 + raw_local_irq_save(flags);
6281 + __asm__ __volatile__(
6282 +#ifdef CONFIG_PAX_REFCOUNT
6283 + /* Exception on overflow. */
6284 + "1: dsub %0, %1 \n"
6285 + "2: \n"
6286 + _ASM_EXTABLE(1b, 2b)
6287 +#else
6288 + " dsubu %0, %1 \n"
6289 +#endif
6290 + : "+r" (v->counter) : "Ir" (i));
6291 + raw_local_irq_restore(flags);
6292 + }
6293 +}
6294 +
6295 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6296 {
6297 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6298 long temp;
6299 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6300 /*
6301 * Same as above, but return the result value
6302 */
6303 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6304 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6305 +{
6306 + long result;
6307 + long temp;
6308 +
6309 + smp_mb__before_llsc();
6310 +
6311 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6312 + __asm__ __volatile__(
6313 + " .set mips3 \n"
6314 + "1: lld %1, %2 # atomic64_add_return \n"
6315 +#ifdef CONFIG_PAX_REFCOUNT
6316 + "2: dadd %0, %1, %3 \n"
6317 +#else
6318 + " daddu %0, %1, %3 \n"
6319 +#endif
6320 + " scd %0, %2 \n"
6321 + " beqzl %0, 1b \n"
6322 +#ifdef CONFIG_PAX_REFCOUNT
6323 + " b 4f \n"
6324 + " .set noreorder \n"
6325 + "3: b 5f \n"
6326 + " move %0, %1 \n"
6327 + " .set reorder \n"
6328 + _ASM_EXTABLE(2b, 3b)
6329 +#endif
6330 + "4: daddu %0, %1, %3 \n"
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + "5: \n"
6333 +#endif
6334 + " .set mips0 \n"
6335 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6336 + : "Ir" (i));
6337 + } else if (kernel_uses_llsc) {
6338 + __asm__ __volatile__(
6339 + " .set mips3 \n"
6340 + "1: lld %1, %2 # atomic64_add_return \n"
6341 +#ifdef CONFIG_PAX_REFCOUNT
6342 + "2: dadd %0, %1, %3 \n"
6343 +#else
6344 + " daddu %0, %1, %3 \n"
6345 +#endif
6346 + " scd %0, %2 \n"
6347 + " bnez %0, 4f \n"
6348 + " b 1b \n"
6349 +#ifdef CONFIG_PAX_REFCOUNT
6350 + " .set noreorder \n"
6351 + "3: b 5f \n"
6352 + " move %0, %1 \n"
6353 + " .set reorder \n"
6354 + _ASM_EXTABLE(2b, 3b)
6355 +#endif
6356 + "4: daddu %0, %1, %3 \n"
6357 +#ifdef CONFIG_PAX_REFCOUNT
6358 + "5: \n"
6359 +#endif
6360 + " .set mips0 \n"
6361 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6362 + : "Ir" (i), "m" (v->counter)
6363 + : "memory");
6364 + } else {
6365 + unsigned long flags;
6366 +
6367 + raw_local_irq_save(flags);
6368 + __asm__ __volatile__(
6369 + " ld %0, %1 \n"
6370 +#ifdef CONFIG_PAX_REFCOUNT
6371 + /* Exception on overflow. */
6372 + "1: dadd %0, %2 \n"
6373 +#else
6374 + " daddu %0, %2 \n"
6375 +#endif
6376 + " sd %0, %1 \n"
6377 +#ifdef CONFIG_PAX_REFCOUNT
6378 + /* Note: Dest reg is not modified on overflow */
6379 + "2: \n"
6380 + _ASM_EXTABLE(1b, 2b)
6381 +#endif
6382 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6383 + raw_local_irq_restore(flags);
6384 + }
6385 +
6386 + smp_llsc_mb();
6387 +
6388 + return result;
6389 +}
6390 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6391 {
6392 long result;
6393
6394 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6395 return result;
6396 }
6397
6398 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6399 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6400 +{
6401 + long result;
6402 + long temp;
6403 +
6404 + smp_mb__before_llsc();
6405 +
6406 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6407 + long temp;
6408 +
6409 + __asm__ __volatile__(
6410 + " .set mips3 \n"
6411 + "1: lld %1, %2 # atomic64_sub_return \n"
6412 +#ifdef CONFIG_PAX_REFCOUNT
6413 + "2: dsub %0, %1, %3 \n"
6414 +#else
6415 + " dsubu %0, %1, %3 \n"
6416 +#endif
6417 + " scd %0, %2 \n"
6418 + " beqzl %0, 1b \n"
6419 +#ifdef CONFIG_PAX_REFCOUNT
6420 + " b 4f \n"
6421 + " .set noreorder \n"
6422 + "3: b 5f \n"
6423 + " move %0, %1 \n"
6424 + " .set reorder \n"
6425 + _ASM_EXTABLE(2b, 3b)
6426 +#endif
6427 + "4: dsubu %0, %1, %3 \n"
6428 +#ifdef CONFIG_PAX_REFCOUNT
6429 + "5: \n"
6430 +#endif
6431 + " .set mips0 \n"
6432 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6433 + : "Ir" (i), "m" (v->counter)
6434 + : "memory");
6435 + } else if (kernel_uses_llsc) {
6436 + __asm__ __volatile__(
6437 + " .set mips3 \n"
6438 + "1: lld %1, %2 # atomic64_sub_return \n"
6439 +#ifdef CONFIG_PAX_REFCOUNT
6440 + "2: dsub %0, %1, %3 \n"
6441 +#else
6442 + " dsubu %0, %1, %3 \n"
6443 +#endif
6444 + " scd %0, %2 \n"
6445 + " bnez %0, 4f \n"
6446 + " b 1b \n"
6447 +#ifdef CONFIG_PAX_REFCOUNT
6448 + " .set noreorder \n"
6449 + "3: b 5f \n"
6450 + " move %0, %1 \n"
6451 + " .set reorder \n"
6452 + _ASM_EXTABLE(2b, 3b)
6453 +#endif
6454 + "4: dsubu %0, %1, %3 \n"
6455 +#ifdef CONFIG_PAX_REFCOUNT
6456 + "5: \n"
6457 +#endif
6458 + " .set mips0 \n"
6459 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6460 + : "Ir" (i), "m" (v->counter)
6461 + : "memory");
6462 + } else {
6463 + unsigned long flags;
6464 +
6465 + raw_local_irq_save(flags);
6466 + __asm__ __volatile__(
6467 + " ld %0, %1 \n"
6468 +#ifdef CONFIG_PAX_REFCOUNT
6469 + /* Exception on overflow. */
6470 + "1: dsub %0, %2 \n"
6471 +#else
6472 + " dsubu %0, %2 \n"
6473 +#endif
6474 + " sd %0, %1 \n"
6475 +#ifdef CONFIG_PAX_REFCOUNT
6476 + /* Note: Dest reg is not modified on overflow */
6477 + "2: \n"
6478 + _ASM_EXTABLE(1b, 2b)
6479 +#endif
6480 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6481 + raw_local_irq_restore(flags);
6482 + }
6483 +
6484 + smp_llsc_mb();
6485 +
6486 + return result;
6487 +}
6488 +
6489 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6490 {
6491 long result;
6492
6493 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6494 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6495 * The function returns the old value of @v minus @i.
6496 */
6497 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6498 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6499 {
6500 long result;
6501
6502 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6503 return result;
6504 }
6505
6506 -#define atomic64_cmpxchg(v, o, n) \
6507 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6508 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6509 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6510 +{
6511 + return cmpxchg(&v->counter, old, new);
6512 +}
6513 +
6514 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6515 + long new)
6516 +{
6517 + return cmpxchg(&(v->counter), old, new);
6518 +}
6519 +
6520 +static inline long atomic64_xchg(atomic64_t *v, long new)
6521 +{
6522 + return xchg(&v->counter, new);
6523 +}
6524 +
6525 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6526 +{
6527 + return xchg(&(v->counter), new);
6528 +}
6529
6530 /**
6531 * atomic64_add_unless - add unless the number is a given value
6532 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6533
6534 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6535 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6536 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6537
6538 /*
6539 * atomic64_sub_and_test - subtract value from variable and test result
6540 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6541 * other cases.
6542 */
6543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6544 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6545
6546 /*
6547 * atomic64_dec_and_test - decrement by 1 and test
6548 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6549 * Atomically increments @v by 1.
6550 */
6551 #define atomic64_inc(v) atomic64_add(1, (v))
6552 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6553
6554 /*
6555 * atomic64_dec - decrement and test
6556 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6557 * Atomically decrements @v by 1.
6558 */
6559 #define atomic64_dec(v) atomic64_sub(1, (v))
6560 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6561
6562 /*
6563 * atomic64_add_negative - add and test if negative
6564 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6565 index e1aa4e4..670b68b 100644
6566 --- a/arch/mips/include/asm/barrier.h
6567 +++ b/arch/mips/include/asm/barrier.h
6568 @@ -184,7 +184,7 @@
6569 do { \
6570 compiletime_assert_atomic_type(*p); \
6571 smp_mb(); \
6572 - ACCESS_ONCE(*p) = (v); \
6573 + ACCESS_ONCE_RW(*p) = (v); \
6574 } while (0)
6575
6576 #define smp_load_acquire(p) \
6577 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6578 index b4db69f..8f3b093 100644
6579 --- a/arch/mips/include/asm/cache.h
6580 +++ b/arch/mips/include/asm/cache.h
6581 @@ -9,10 +9,11 @@
6582 #ifndef _ASM_CACHE_H
6583 #define _ASM_CACHE_H
6584
6585 +#include <linux/const.h>
6586 #include <kmalloc.h>
6587
6588 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6589 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6590 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6591
6592 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6593 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6594 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6595 index d414405..6bb4ba2 100644
6596 --- a/arch/mips/include/asm/elf.h
6597 +++ b/arch/mips/include/asm/elf.h
6598 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6599 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6600 #endif
6601
6602 +#ifdef CONFIG_PAX_ASLR
6603 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6604 +
6605 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6606 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6607 +#endif
6608 +
6609 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6610 struct linux_binprm;
6611 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6612 int uses_interp);
6613
6614 -struct mm_struct;
6615 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6616 -#define arch_randomize_brk arch_randomize_brk
6617 -
6618 #endif /* _ASM_ELF_H */
6619 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6620 index c1f6afa..38cc6e9 100644
6621 --- a/arch/mips/include/asm/exec.h
6622 +++ b/arch/mips/include/asm/exec.h
6623 @@ -12,6 +12,6 @@
6624 #ifndef _ASM_EXEC_H
6625 #define _ASM_EXEC_H
6626
6627 -extern unsigned long arch_align_stack(unsigned long sp);
6628 +#define arch_align_stack(x) ((x) & ~0xfUL)
6629
6630 #endif /* _ASM_EXEC_H */
6631 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6632 index 9e8ef59..1139d6b 100644
6633 --- a/arch/mips/include/asm/hw_irq.h
6634 +++ b/arch/mips/include/asm/hw_irq.h
6635 @@ -10,7 +10,7 @@
6636
6637 #include <linux/atomic.h>
6638
6639 -extern atomic_t irq_err_count;
6640 +extern atomic_unchecked_t irq_err_count;
6641
6642 /*
6643 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6644 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6645 index 46dfc3c..a16b13a 100644
6646 --- a/arch/mips/include/asm/local.h
6647 +++ b/arch/mips/include/asm/local.h
6648 @@ -12,15 +12,25 @@ typedef struct
6649 atomic_long_t a;
6650 } local_t;
6651
6652 +typedef struct {
6653 + atomic_long_unchecked_t a;
6654 +} local_unchecked_t;
6655 +
6656 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6657
6658 #define local_read(l) atomic_long_read(&(l)->a)
6659 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6660 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6661 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6662
6663 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6664 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6665 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6666 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6667 #define local_inc(l) atomic_long_inc(&(l)->a)
6668 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6669 #define local_dec(l) atomic_long_dec(&(l)->a)
6670 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6671
6672 /*
6673 * Same as above, but return the result value
6674 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6675 return result;
6676 }
6677
6678 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6679 +{
6680 + unsigned long result;
6681 +
6682 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6683 + unsigned long temp;
6684 +
6685 + __asm__ __volatile__(
6686 + " .set mips3 \n"
6687 + "1:" __LL "%1, %2 # local_add_return \n"
6688 + " addu %0, %1, %3 \n"
6689 + __SC "%0, %2 \n"
6690 + " beqzl %0, 1b \n"
6691 + " addu %0, %1, %3 \n"
6692 + " .set mips0 \n"
6693 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6694 + : "Ir" (i), "m" (l->a.counter)
6695 + : "memory");
6696 + } else if (kernel_uses_llsc) {
6697 + unsigned long temp;
6698 +
6699 + __asm__ __volatile__(
6700 + " .set mips3 \n"
6701 + "1:" __LL "%1, %2 # local_add_return \n"
6702 + " addu %0, %1, %3 \n"
6703 + __SC "%0, %2 \n"
6704 + " beqz %0, 1b \n"
6705 + " addu %0, %1, %3 \n"
6706 + " .set mips0 \n"
6707 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6708 + : "Ir" (i), "m" (l->a.counter)
6709 + : "memory");
6710 + } else {
6711 + unsigned long flags;
6712 +
6713 + local_irq_save(flags);
6714 + result = l->a.counter;
6715 + result += i;
6716 + l->a.counter = result;
6717 + local_irq_restore(flags);
6718 + }
6719 +
6720 + return result;
6721 +}
6722 +
6723 static __inline__ long local_sub_return(long i, local_t * l)
6724 {
6725 unsigned long result;
6726 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6727
6728 #define local_cmpxchg(l, o, n) \
6729 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6730 +#define local_cmpxchg_unchecked(l, o, n) \
6731 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6732 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6733
6734 /**
6735 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6736 index 5699ec3..95def83 100644
6737 --- a/arch/mips/include/asm/page.h
6738 +++ b/arch/mips/include/asm/page.h
6739 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6740 #ifdef CONFIG_CPU_MIPS32
6741 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6742 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6743 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6744 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6745 #else
6746 typedef struct { unsigned long long pte; } pte_t;
6747 #define pte_val(x) ((x).pte)
6748 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6749 index b336037..5b874cc 100644
6750 --- a/arch/mips/include/asm/pgalloc.h
6751 +++ b/arch/mips/include/asm/pgalloc.h
6752 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6753 {
6754 set_pud(pud, __pud((unsigned long)pmd));
6755 }
6756 +
6757 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6758 +{
6759 + pud_populate(mm, pud, pmd);
6760 +}
6761 #endif
6762
6763 /*
6764 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6765 index 008324d..f67c239 100644
6766 --- a/arch/mips/include/asm/pgtable.h
6767 +++ b/arch/mips/include/asm/pgtable.h
6768 @@ -20,6 +20,9 @@
6769 #include <asm/io.h>
6770 #include <asm/pgtable-bits.h>
6771
6772 +#define ktla_ktva(addr) (addr)
6773 +#define ktva_ktla(addr) (addr)
6774 +
6775 struct mm_struct;
6776 struct vm_area_struct;
6777
6778 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6779 index 25da651..ae2a259 100644
6780 --- a/arch/mips/include/asm/smtc_proc.h
6781 +++ b/arch/mips/include/asm/smtc_proc.h
6782 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6783
6784 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6785
6786 -extern atomic_t smtc_fpu_recoveries;
6787 +extern atomic_unchecked_t smtc_fpu_recoveries;
6788
6789 #endif /* __ASM_SMTC_PROC_H */
6790 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6791 index d2d961d..a674df0 100644
6792 --- a/arch/mips/include/asm/thread_info.h
6793 +++ b/arch/mips/include/asm/thread_info.h
6794 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6795 #define TIF_SECCOMP 4 /* secure computing */
6796 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6797 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6798 +/* li takes a 32bit immediate */
6799 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6800 +
6801 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6802 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6803 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6804 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6805 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6806 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6807 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6808 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6809
6810 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6811 _TIF_SYSCALL_AUDIT | \
6812 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6813 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6814 + _TIF_GRSEC_SETXID)
6815
6816 /* work to do in syscall_trace_leave() */
6817 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6818 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6819 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6820
6821 /* work to do on interrupt/exception return */
6822 #define _TIF_WORK_MASK \
6823 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6824 /* work to do on any return to u-space */
6825 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6826 _TIF_WORK_SYSCALL_EXIT | \
6827 - _TIF_SYSCALL_TRACEPOINT)
6828 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6829
6830 /*
6831 * We stash processor id into a COP0 register to retrieve it fast
6832 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6833 index a109510..94ee3f6 100644
6834 --- a/arch/mips/include/asm/uaccess.h
6835 +++ b/arch/mips/include/asm/uaccess.h
6836 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6837 __ok == 0; \
6838 })
6839
6840 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6841 #define access_ok(type, addr, size) \
6842 likely(__access_ok((addr), (size), __access_mask))
6843
6844 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6845 index 1188e00..41cf144 100644
6846 --- a/arch/mips/kernel/binfmt_elfn32.c
6847 +++ b/arch/mips/kernel/binfmt_elfn32.c
6848 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6849 #undef ELF_ET_DYN_BASE
6850 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6851
6852 +#ifdef CONFIG_PAX_ASLR
6853 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6854 +
6855 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6856 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6857 +#endif
6858 +
6859 #include <asm/processor.h>
6860 #include <linux/module.h>
6861 #include <linux/elfcore.h>
6862 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6863 index 7faf5f2..f3d3cf4 100644
6864 --- a/arch/mips/kernel/binfmt_elfo32.c
6865 +++ b/arch/mips/kernel/binfmt_elfo32.c
6866 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6867 #undef ELF_ET_DYN_BASE
6868 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6869
6870 +#ifdef CONFIG_PAX_ASLR
6871 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6872 +
6873 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6874 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6875 +#endif
6876 +
6877 #include <asm/processor.h>
6878
6879 /*
6880 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6881 index 2b91fe8..fe4f6b4 100644
6882 --- a/arch/mips/kernel/i8259.c
6883 +++ b/arch/mips/kernel/i8259.c
6884 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6885 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6886 spurious_irq_mask |= irqmask;
6887 }
6888 - atomic_inc(&irq_err_count);
6889 + atomic_inc_unchecked(&irq_err_count);
6890 /*
6891 * Theoretically we do not have to handle this IRQ,
6892 * but in Linux this does not cause problems and is
6893 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6894 index 44a1f79..2bd6aa3 100644
6895 --- a/arch/mips/kernel/irq-gt641xx.c
6896 +++ b/arch/mips/kernel/irq-gt641xx.c
6897 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6898 }
6899 }
6900
6901 - atomic_inc(&irq_err_count);
6902 + atomic_inc_unchecked(&irq_err_count);
6903 }
6904
6905 void __init gt641xx_irq_init(void)
6906 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6907 index d1fea7a..2e591b0 100644
6908 --- a/arch/mips/kernel/irq.c
6909 +++ b/arch/mips/kernel/irq.c
6910 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6911 printk("unexpected IRQ # %d\n", irq);
6912 }
6913
6914 -atomic_t irq_err_count;
6915 +atomic_unchecked_t irq_err_count;
6916
6917 int arch_show_interrupts(struct seq_file *p, int prec)
6918 {
6919 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6920 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6921 return 0;
6922 }
6923
6924 asmlinkage void spurious_interrupt(void)
6925 {
6926 - atomic_inc(&irq_err_count);
6927 + atomic_inc_unchecked(&irq_err_count);
6928 }
6929
6930 void __init init_IRQ(void)
6931 @@ -110,7 +110,10 @@ void __init init_IRQ(void)
6932 #endif
6933 }
6934
6935 +
6936 #ifdef DEBUG_STACKOVERFLOW
6937 +extern void gr_handle_kernel_exploit(void);
6938 +
6939 static inline void check_stack_overflow(void)
6940 {
6941 unsigned long sp;
6942 @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6943 printk("do_IRQ: stack overflow: %ld\n",
6944 sp - sizeof(struct thread_info));
6945 dump_stack();
6946 + gr_handle_kernel_exploit();
6947 }
6948 }
6949 #else
6950 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6951 index 60e39dc..b4829bf 100644
6952 --- a/arch/mips/kernel/process.c
6953 +++ b/arch/mips/kernel/process.c
6954 @@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6955 out:
6956 return pc;
6957 }
6958 -
6959 -/*
6960 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6961 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6962 - */
6963 -unsigned long arch_align_stack(unsigned long sp)
6964 -{
6965 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6966 - sp -= get_random_int() & ~PAGE_MASK;
6967 -
6968 - return sp & ALMASK;
6969 -}
6970 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6971 index f639ccd..e4b110d 100644
6972 --- a/arch/mips/kernel/ptrace.c
6973 +++ b/arch/mips/kernel/ptrace.c
6974 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6975 return ret;
6976 }
6977
6978 +#ifdef CONFIG_GRKERNSEC_SETXID
6979 +extern void gr_delayed_cred_worker(void);
6980 +#endif
6981 +
6982 /*
6983 * Notification of system call entry/exit
6984 * - triggered by current->work.syscall_trace
6985 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6986 tracehook_report_syscall_entry(regs))
6987 ret = -1;
6988
6989 +#ifdef CONFIG_GRKERNSEC_SETXID
6990 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6991 + gr_delayed_cred_worker();
6992 +#endif
6993 +
6994 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6995 trace_sys_enter(regs, regs->regs[2]);
6996
6997 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6998 index 07fc524..b9d7f28 100644
6999 --- a/arch/mips/kernel/reset.c
7000 +++ b/arch/mips/kernel/reset.c
7001 @@ -13,6 +13,7 @@
7002 #include <linux/reboot.h>
7003
7004 #include <asm/reboot.h>
7005 +#include <asm/bug.h>
7006
7007 /*
7008 * Urgs ... Too many MIPS machines to handle this in a generic way.
7009 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7010 {
7011 if (_machine_restart)
7012 _machine_restart(command);
7013 + BUG();
7014 }
7015
7016 void machine_halt(void)
7017 {
7018 if (_machine_halt)
7019 _machine_halt();
7020 + BUG();
7021 }
7022
7023 void machine_power_off(void)
7024 {
7025 if (pm_power_off)
7026 pm_power_off();
7027 + BUG();
7028 }
7029 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7030 index 38635a9..3fcd5e0 100644
7031 --- a/arch/mips/kernel/smtc-proc.c
7032 +++ b/arch/mips/kernel/smtc-proc.c
7033 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7034
7035 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7036
7037 -atomic_t smtc_fpu_recoveries;
7038 +atomic_unchecked_t smtc_fpu_recoveries;
7039
7040 static int smtc_proc_show(struct seq_file *m, void *v)
7041 {
7042 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7043 for(i = 0; i < NR_CPUS; i++)
7044 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7045 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7046 - atomic_read(&smtc_fpu_recoveries));
7047 + atomic_read_unchecked(&smtc_fpu_recoveries));
7048 return 0;
7049 }
7050
7051 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
7052 smtc_cpu_stats[i].selfipis = 0;
7053 }
7054
7055 - atomic_set(&smtc_fpu_recoveries, 0);
7056 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7057
7058 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7059 }
7060 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7061 index c1681d6..9f881d1 100644
7062 --- a/arch/mips/kernel/smtc.c
7063 +++ b/arch/mips/kernel/smtc.c
7064 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7065 }
7066 smtc_ipi_qdump();
7067 printk("%d Recoveries of \"stolen\" FPU\n",
7068 - atomic_read(&smtc_fpu_recoveries));
7069 + atomic_read_unchecked(&smtc_fpu_recoveries));
7070 }
7071
7072
7073 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7074 index c24ad5f..9983ab2 100644
7075 --- a/arch/mips/kernel/sync-r4k.c
7076 +++ b/arch/mips/kernel/sync-r4k.c
7077 @@ -20,8 +20,8 @@
7078 #include <asm/mipsregs.h>
7079
7080 static atomic_t count_start_flag = ATOMIC_INIT(0);
7081 -static atomic_t count_count_start = ATOMIC_INIT(0);
7082 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7083 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7084 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7085 static atomic_t count_reference = ATOMIC_INIT(0);
7086
7087 #define COUNTON 100
7088 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7089
7090 for (i = 0; i < NR_LOOPS; i++) {
7091 /* slaves loop on '!= 2' */
7092 - while (atomic_read(&count_count_start) != 1)
7093 + while (atomic_read_unchecked(&count_count_start) != 1)
7094 mb();
7095 - atomic_set(&count_count_stop, 0);
7096 + atomic_set_unchecked(&count_count_stop, 0);
7097 smp_wmb();
7098
7099 /* this lets the slaves write their count register */
7100 - atomic_inc(&count_count_start);
7101 + atomic_inc_unchecked(&count_count_start);
7102
7103 /*
7104 * Everyone initialises count in the last loop:
7105 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7106 /*
7107 * Wait for all slaves to leave the synchronization point:
7108 */
7109 - while (atomic_read(&count_count_stop) != 1)
7110 + while (atomic_read_unchecked(&count_count_stop) != 1)
7111 mb();
7112 - atomic_set(&count_count_start, 0);
7113 + atomic_set_unchecked(&count_count_start, 0);
7114 smp_wmb();
7115 - atomic_inc(&count_count_stop);
7116 + atomic_inc_unchecked(&count_count_stop);
7117 }
7118 /* Arrange for an interrupt in a short while */
7119 write_c0_compare(read_c0_count() + COUNTON);
7120 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7121 initcount = atomic_read(&count_reference);
7122
7123 for (i = 0; i < NR_LOOPS; i++) {
7124 - atomic_inc(&count_count_start);
7125 - while (atomic_read(&count_count_start) != 2)
7126 + atomic_inc_unchecked(&count_count_start);
7127 + while (atomic_read_unchecked(&count_count_start) != 2)
7128 mb();
7129
7130 /*
7131 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7132 if (i == NR_LOOPS-1)
7133 write_c0_count(initcount);
7134
7135 - atomic_inc(&count_count_stop);
7136 - while (atomic_read(&count_count_stop) != 2)
7137 + atomic_inc_unchecked(&count_count_stop);
7138 + while (atomic_read_unchecked(&count_count_stop) != 2)
7139 mb();
7140 }
7141 /* Arrange for an interrupt in a short while */
7142 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7143 index 8119ac2..b229939 100644
7144 --- a/arch/mips/kernel/traps.c
7145 +++ b/arch/mips/kernel/traps.c
7146 @@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7147 siginfo_t info;
7148
7149 prev_state = exception_enter();
7150 - die_if_kernel("Integer overflow", regs);
7151 + if (unlikely(!user_mode(regs))) {
7152 +
7153 +#ifdef CONFIG_PAX_REFCOUNT
7154 + if (fixup_exception(regs)) {
7155 + pax_report_refcount_overflow(regs);
7156 + exception_exit(prev_state);
7157 + return;
7158 + }
7159 +#endif
7160 +
7161 + die("Integer overflow", regs);
7162 + }
7163
7164 info.si_code = FPE_INTOVF;
7165 info.si_signo = SIGFPE;
7166 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7167 index becc42b..9e43d4b 100644
7168 --- a/arch/mips/mm/fault.c
7169 +++ b/arch/mips/mm/fault.c
7170 @@ -28,6 +28,23 @@
7171 #include <asm/highmem.h> /* For VMALLOC_END */
7172 #include <linux/kdebug.h>
7173
7174 +#ifdef CONFIG_PAX_PAGEEXEC
7175 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7176 +{
7177 + unsigned long i;
7178 +
7179 + printk(KERN_ERR "PAX: bytes at PC: ");
7180 + for (i = 0; i < 5; i++) {
7181 + unsigned int c;
7182 + if (get_user(c, (unsigned int *)pc+i))
7183 + printk(KERN_CONT "???????? ");
7184 + else
7185 + printk(KERN_CONT "%08x ", c);
7186 + }
7187 + printk("\n");
7188 +}
7189 +#endif
7190 +
7191 /*
7192 * This routine handles page faults. It determines the address,
7193 * and the problem, and then passes it off to one of the appropriate
7194 @@ -199,6 +216,14 @@ bad_area:
7195 bad_area_nosemaphore:
7196 /* User mode accesses just cause a SIGSEGV */
7197 if (user_mode(regs)) {
7198 +
7199 +#ifdef CONFIG_PAX_PAGEEXEC
7200 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7201 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7202 + do_group_exit(SIGKILL);
7203 + }
7204 +#endif
7205 +
7206 tsk->thread.cp0_badvaddr = address;
7207 tsk->thread.error_code = write;
7208 #if 0
7209 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7210 index f1baadd..5472dca 100644
7211 --- a/arch/mips/mm/mmap.c
7212 +++ b/arch/mips/mm/mmap.c
7213 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7214 struct vm_area_struct *vma;
7215 unsigned long addr = addr0;
7216 int do_color_align;
7217 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7218 struct vm_unmapped_area_info info;
7219
7220 if (unlikely(len > TASK_SIZE))
7221 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7222 do_color_align = 1;
7223
7224 /* requesting a specific address */
7225 +
7226 +#ifdef CONFIG_PAX_RANDMMAP
7227 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7228 +#endif
7229 +
7230 if (addr) {
7231 if (do_color_align)
7232 addr = COLOUR_ALIGN(addr, pgoff);
7233 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7234 addr = PAGE_ALIGN(addr);
7235
7236 vma = find_vma(mm, addr);
7237 - if (TASK_SIZE - len >= addr &&
7238 - (!vma || addr + len <= vma->vm_start))
7239 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7240 return addr;
7241 }
7242
7243 info.length = len;
7244 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7245 info.align_offset = pgoff << PAGE_SHIFT;
7246 + info.threadstack_offset = offset;
7247
7248 if (dir == DOWN) {
7249 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7250 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7251 {
7252 unsigned long random_factor = 0UL;
7253
7254 +#ifdef CONFIG_PAX_RANDMMAP
7255 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7256 +#endif
7257 +
7258 if (current->flags & PF_RANDOMIZE) {
7259 random_factor = get_random_int();
7260 random_factor = random_factor << PAGE_SHIFT;
7261 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7262
7263 if (mmap_is_legacy()) {
7264 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7265 +
7266 +#ifdef CONFIG_PAX_RANDMMAP
7267 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7268 + mm->mmap_base += mm->delta_mmap;
7269 +#endif
7270 +
7271 mm->get_unmapped_area = arch_get_unmapped_area;
7272 } else {
7273 mm->mmap_base = mmap_base(random_factor);
7274 +
7275 +#ifdef CONFIG_PAX_RANDMMAP
7276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7277 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7278 +#endif
7279 +
7280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7281 }
7282 }
7283
7284 -static inline unsigned long brk_rnd(void)
7285 -{
7286 - unsigned long rnd = get_random_int();
7287 -
7288 - rnd = rnd << PAGE_SHIFT;
7289 - /* 8MB for 32bit, 256MB for 64bit */
7290 - if (TASK_IS_32BIT_ADDR)
7291 - rnd = rnd & 0x7ffffful;
7292 - else
7293 - rnd = rnd & 0xffffffful;
7294 -
7295 - return rnd;
7296 -}
7297 -
7298 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7299 -{
7300 - unsigned long base = mm->brk;
7301 - unsigned long ret;
7302 -
7303 - ret = PAGE_ALIGN(base + brk_rnd());
7304 -
7305 - if (ret < mm->brk)
7306 - return mm->brk;
7307 -
7308 - return ret;
7309 -}
7310 -
7311 int __virt_addr_valid(const volatile void *kaddr)
7312 {
7313 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7314 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7315 index 59cccd9..f39ac2f 100644
7316 --- a/arch/mips/pci/pci-octeon.c
7317 +++ b/arch/mips/pci/pci-octeon.c
7318 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7319
7320
7321 static struct pci_ops octeon_pci_ops = {
7322 - octeon_read_config,
7323 - octeon_write_config,
7324 + .read = octeon_read_config,
7325 + .write = octeon_write_config,
7326 };
7327
7328 static struct resource octeon_pci_mem_resource = {
7329 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7330 index 5e36c33..eb4a17b 100644
7331 --- a/arch/mips/pci/pcie-octeon.c
7332 +++ b/arch/mips/pci/pcie-octeon.c
7333 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7334 }
7335
7336 static struct pci_ops octeon_pcie0_ops = {
7337 - octeon_pcie0_read_config,
7338 - octeon_pcie0_write_config,
7339 + .read = octeon_pcie0_read_config,
7340 + .write = octeon_pcie0_write_config,
7341 };
7342
7343 static struct resource octeon_pcie0_mem_resource = {
7344 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7345 };
7346
7347 static struct pci_ops octeon_pcie1_ops = {
7348 - octeon_pcie1_read_config,
7349 - octeon_pcie1_write_config,
7350 + .read = octeon_pcie1_read_config,
7351 + .write = octeon_pcie1_write_config,
7352 };
7353
7354 static struct resource octeon_pcie1_mem_resource = {
7355 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7356 };
7357
7358 static struct pci_ops octeon_dummy_ops = {
7359 - octeon_dummy_read_config,
7360 - octeon_dummy_write_config,
7361 + .read = octeon_dummy_read_config,
7362 + .write = octeon_dummy_write_config,
7363 };
7364
7365 static struct resource octeon_dummy_mem_resource = {
7366 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7367 index a2358b4..7cead4f 100644
7368 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7369 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7370 @@ -187,9 +187,9 @@ void
7371 cont_nmi_dump(void)
7372 {
7373 #ifndef REAL_NMI_SIGNAL
7374 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7375 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7376
7377 - atomic_inc(&nmied_cpus);
7378 + atomic_inc_unchecked(&nmied_cpus);
7379 #endif
7380 /*
7381 * Only allow 1 cpu to proceed
7382 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7383 udelay(10000);
7384 }
7385 #else
7386 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7387 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7388 #endif
7389
7390 /*
7391 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7392 index a046b30..6799527 100644
7393 --- a/arch/mips/sni/rm200.c
7394 +++ b/arch/mips/sni/rm200.c
7395 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7396 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7397 spurious_irq_mask |= irqmask;
7398 }
7399 - atomic_inc(&irq_err_count);
7400 + atomic_inc_unchecked(&irq_err_count);
7401 /*
7402 * Theoretically we do not have to handle this IRQ,
7403 * but in Linux this does not cause problems and is
7404 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7405 index 41e873b..34d33a7 100644
7406 --- a/arch/mips/vr41xx/common/icu.c
7407 +++ b/arch/mips/vr41xx/common/icu.c
7408 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7409
7410 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7411
7412 - atomic_inc(&irq_err_count);
7413 + atomic_inc_unchecked(&irq_err_count);
7414
7415 return -1;
7416 }
7417 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7418 index ae0e4ee..e8f0692 100644
7419 --- a/arch/mips/vr41xx/common/irq.c
7420 +++ b/arch/mips/vr41xx/common/irq.c
7421 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7422 irq_cascade_t *cascade;
7423
7424 if (irq >= NR_IRQS) {
7425 - atomic_inc(&irq_err_count);
7426 + atomic_inc_unchecked(&irq_err_count);
7427 return;
7428 }
7429
7430 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7431 ret = cascade->get_irq(irq);
7432 irq = ret;
7433 if (ret < 0)
7434 - atomic_inc(&irq_err_count);
7435 + atomic_inc_unchecked(&irq_err_count);
7436 else
7437 irq_dispatch(irq);
7438 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7439 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7440 index 967d144..db12197 100644
7441 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7442 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7443 @@ -11,12 +11,14 @@
7444 #ifndef _ASM_PROC_CACHE_H
7445 #define _ASM_PROC_CACHE_H
7446
7447 +#include <linux/const.h>
7448 +
7449 /* L1 cache */
7450
7451 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7452 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7453 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7454 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7455 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7456 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7457
7458 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7459 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7460 index bcb5df2..84fabd2 100644
7461 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7462 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7463 @@ -16,13 +16,15 @@
7464 #ifndef _ASM_PROC_CACHE_H
7465 #define _ASM_PROC_CACHE_H
7466
7467 +#include <linux/const.h>
7468 +
7469 /*
7470 * L1 cache
7471 */
7472 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7473 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7474 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7475 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7476 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7477 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7478
7479 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7480 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7481 index 4ce7a01..449202a 100644
7482 --- a/arch/openrisc/include/asm/cache.h
7483 +++ b/arch/openrisc/include/asm/cache.h
7484 @@ -19,11 +19,13 @@
7485 #ifndef __ASM_OPENRISC_CACHE_H
7486 #define __ASM_OPENRISC_CACHE_H
7487
7488 +#include <linux/const.h>
7489 +
7490 /* FIXME: How can we replace these with values from the CPU...
7491 * they shouldn't be hard-coded!
7492 */
7493
7494 -#define L1_CACHE_BYTES 16
7495 #define L1_CACHE_SHIFT 4
7496 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7497
7498 #endif /* __ASM_OPENRISC_CACHE_H */
7499 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7500 index 472886c..00e7df9 100644
7501 --- a/arch/parisc/include/asm/atomic.h
7502 +++ b/arch/parisc/include/asm/atomic.h
7503 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7504 return dec;
7505 }
7506
7507 +#define atomic64_read_unchecked(v) atomic64_read(v)
7508 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7509 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7510 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7511 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7512 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7513 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7514 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7515 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7516 +
7517 #endif /* !CONFIG_64BIT */
7518
7519
7520 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7521 index 47f11c7..3420df2 100644
7522 --- a/arch/parisc/include/asm/cache.h
7523 +++ b/arch/parisc/include/asm/cache.h
7524 @@ -5,6 +5,7 @@
7525 #ifndef __ARCH_PARISC_CACHE_H
7526 #define __ARCH_PARISC_CACHE_H
7527
7528 +#include <linux/const.h>
7529
7530 /*
7531 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7532 @@ -15,13 +16,13 @@
7533 * just ruin performance.
7534 */
7535 #ifdef CONFIG_PA20
7536 -#define L1_CACHE_BYTES 64
7537 #define L1_CACHE_SHIFT 6
7538 #else
7539 -#define L1_CACHE_BYTES 32
7540 #define L1_CACHE_SHIFT 5
7541 #endif
7542
7543 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544 +
7545 #ifndef __ASSEMBLY__
7546
7547 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7548 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7549 index 3391d06..c23a2cc 100644
7550 --- a/arch/parisc/include/asm/elf.h
7551 +++ b/arch/parisc/include/asm/elf.h
7552 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7553
7554 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7555
7556 +#ifdef CONFIG_PAX_ASLR
7557 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7558 +
7559 +#define PAX_DELTA_MMAP_LEN 16
7560 +#define PAX_DELTA_STACK_LEN 16
7561 +#endif
7562 +
7563 /* This yields a mask that user programs can use to figure out what
7564 instruction set this CPU supports. This could be done in user space,
7565 but it's not easy, and we've already done it here. */
7566 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7567 index f213f5b..0af3e8e 100644
7568 --- a/arch/parisc/include/asm/pgalloc.h
7569 +++ b/arch/parisc/include/asm/pgalloc.h
7570 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7571 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7572 }
7573
7574 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7575 +{
7576 + pgd_populate(mm, pgd, pmd);
7577 +}
7578 +
7579 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7580 {
7581 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7582 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7583 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7584 #define pmd_free(mm, x) do { } while (0)
7585 #define pgd_populate(mm, pmd, pte) BUG()
7586 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7587
7588 #endif
7589
7590 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7591 index 22b89d1..ce34230 100644
7592 --- a/arch/parisc/include/asm/pgtable.h
7593 +++ b/arch/parisc/include/asm/pgtable.h
7594 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7595 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7596 #define PAGE_COPY PAGE_EXECREAD
7597 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7598 +
7599 +#ifdef CONFIG_PAX_PAGEEXEC
7600 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7601 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7602 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7603 +#else
7604 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7605 +# define PAGE_COPY_NOEXEC PAGE_COPY
7606 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7607 +#endif
7608 +
7609 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7610 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7611 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7612 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7613 index 4006964..fcb3cc2 100644
7614 --- a/arch/parisc/include/asm/uaccess.h
7615 +++ b/arch/parisc/include/asm/uaccess.h
7616 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7617 const void __user *from,
7618 unsigned long n)
7619 {
7620 - int sz = __compiletime_object_size(to);
7621 + size_t sz = __compiletime_object_size(to);
7622 int ret = -EFAULT;
7623
7624 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7625 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7626 ret = __copy_from_user(to, from, n);
7627 else
7628 copy_from_user_overflow();
7629 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7630 index 50dfafc..b9fc230 100644
7631 --- a/arch/parisc/kernel/module.c
7632 +++ b/arch/parisc/kernel/module.c
7633 @@ -98,16 +98,38 @@
7634
7635 /* three functions to determine where in the module core
7636 * or init pieces the location is */
7637 +static inline int in_init_rx(struct module *me, void *loc)
7638 +{
7639 + return (loc >= me->module_init_rx &&
7640 + loc < (me->module_init_rx + me->init_size_rx));
7641 +}
7642 +
7643 +static inline int in_init_rw(struct module *me, void *loc)
7644 +{
7645 + return (loc >= me->module_init_rw &&
7646 + loc < (me->module_init_rw + me->init_size_rw));
7647 +}
7648 +
7649 static inline int in_init(struct module *me, void *loc)
7650 {
7651 - return (loc >= me->module_init &&
7652 - loc <= (me->module_init + me->init_size));
7653 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7654 +}
7655 +
7656 +static inline int in_core_rx(struct module *me, void *loc)
7657 +{
7658 + return (loc >= me->module_core_rx &&
7659 + loc < (me->module_core_rx + me->core_size_rx));
7660 +}
7661 +
7662 +static inline int in_core_rw(struct module *me, void *loc)
7663 +{
7664 + return (loc >= me->module_core_rw &&
7665 + loc < (me->module_core_rw + me->core_size_rw));
7666 }
7667
7668 static inline int in_core(struct module *me, void *loc)
7669 {
7670 - return (loc >= me->module_core &&
7671 - loc <= (me->module_core + me->core_size));
7672 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7673 }
7674
7675 static inline int in_local(struct module *me, void *loc)
7676 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7677 }
7678
7679 /* align things a bit */
7680 - me->core_size = ALIGN(me->core_size, 16);
7681 - me->arch.got_offset = me->core_size;
7682 - me->core_size += gots * sizeof(struct got_entry);
7683 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7684 + me->arch.got_offset = me->core_size_rw;
7685 + me->core_size_rw += gots * sizeof(struct got_entry);
7686
7687 - me->core_size = ALIGN(me->core_size, 16);
7688 - me->arch.fdesc_offset = me->core_size;
7689 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7690 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7691 + me->arch.fdesc_offset = me->core_size_rw;
7692 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7693
7694 me->arch.got_max = gots;
7695 me->arch.fdesc_max = fdescs;
7696 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7697
7698 BUG_ON(value == 0);
7699
7700 - got = me->module_core + me->arch.got_offset;
7701 + got = me->module_core_rw + me->arch.got_offset;
7702 for (i = 0; got[i].addr; i++)
7703 if (got[i].addr == value)
7704 goto out;
7705 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7706 #ifdef CONFIG_64BIT
7707 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7708 {
7709 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7710 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7711
7712 if (!value) {
7713 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7714 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7715
7716 /* Create new one */
7717 fdesc->addr = value;
7718 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7719 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7720 return (Elf_Addr)fdesc;
7721 }
7722 #endif /* CONFIG_64BIT */
7723 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7724
7725 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7726 end = table + sechdrs[me->arch.unwind_section].sh_size;
7727 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7728 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7729
7730 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7731 me->arch.unwind_section, table, end, gp);
7732 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7733 index e1ffea2..46ed66e 100644
7734 --- a/arch/parisc/kernel/sys_parisc.c
7735 +++ b/arch/parisc/kernel/sys_parisc.c
7736 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7737 unsigned long task_size = TASK_SIZE;
7738 int do_color_align, last_mmap;
7739 struct vm_unmapped_area_info info;
7740 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7741
7742 if (len > task_size)
7743 return -ENOMEM;
7744 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7745 goto found_addr;
7746 }
7747
7748 +#ifdef CONFIG_PAX_RANDMMAP
7749 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7750 +#endif
7751 +
7752 if (addr) {
7753 if (do_color_align && last_mmap)
7754 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7755 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7756 info.high_limit = mmap_upper_limit();
7757 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7758 info.align_offset = shared_align_offset(last_mmap, pgoff);
7759 + info.threadstack_offset = offset;
7760 addr = vm_unmapped_area(&info);
7761
7762 found_addr:
7763 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7764 unsigned long addr = addr0;
7765 int do_color_align, last_mmap;
7766 struct vm_unmapped_area_info info;
7767 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7768
7769 #ifdef CONFIG_64BIT
7770 /* This should only ever run for 32-bit processes. */
7771 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7772 }
7773
7774 /* requesting a specific address */
7775 +#ifdef CONFIG_PAX_RANDMMAP
7776 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7777 +#endif
7778 +
7779 if (addr) {
7780 if (do_color_align && last_mmap)
7781 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7782 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7783 info.high_limit = mm->mmap_base;
7784 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7785 info.align_offset = shared_align_offset(last_mmap, pgoff);
7786 + info.threadstack_offset = offset;
7787 addr = vm_unmapped_area(&info);
7788 if (!(addr & ~PAGE_MASK))
7789 goto found_addr;
7790 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7791 mm->mmap_legacy_base = mmap_legacy_base();
7792 mm->mmap_base = mmap_upper_limit();
7793
7794 +#ifdef CONFIG_PAX_RANDMMAP
7795 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7796 + mm->mmap_legacy_base += mm->delta_mmap;
7797 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7798 + }
7799 +#endif
7800 +
7801 if (mmap_is_legacy()) {
7802 mm->mmap_base = mm->mmap_legacy_base;
7803 mm->get_unmapped_area = arch_get_unmapped_area;
7804 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7805 index 47ee620..1107387 100644
7806 --- a/arch/parisc/kernel/traps.c
7807 +++ b/arch/parisc/kernel/traps.c
7808 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7809
7810 down_read(&current->mm->mmap_sem);
7811 vma = find_vma(current->mm,regs->iaoq[0]);
7812 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7813 - && (vma->vm_flags & VM_EXEC)) {
7814 -
7815 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7816 fault_address = regs->iaoq[0];
7817 fault_space = regs->iasq[0];
7818
7819 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7820 index 3ca9c11..d163ef7 100644
7821 --- a/arch/parisc/mm/fault.c
7822 +++ b/arch/parisc/mm/fault.c
7823 @@ -15,6 +15,7 @@
7824 #include <linux/sched.h>
7825 #include <linux/interrupt.h>
7826 #include <linux/module.h>
7827 +#include <linux/unistd.h>
7828
7829 #include <asm/uaccess.h>
7830 #include <asm/traps.h>
7831 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7832 static unsigned long
7833 parisc_acctyp(unsigned long code, unsigned int inst)
7834 {
7835 - if (code == 6 || code == 16)
7836 + if (code == 6 || code == 7 || code == 16)
7837 return VM_EXEC;
7838
7839 switch (inst & 0xf0000000) {
7840 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7841 }
7842 #endif
7843
7844 +#ifdef CONFIG_PAX_PAGEEXEC
7845 +/*
7846 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7847 + *
7848 + * returns 1 when task should be killed
7849 + * 2 when rt_sigreturn trampoline was detected
7850 + * 3 when unpatched PLT trampoline was detected
7851 + */
7852 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7853 +{
7854 +
7855 +#ifdef CONFIG_PAX_EMUPLT
7856 + int err;
7857 +
7858 + do { /* PaX: unpatched PLT emulation */
7859 + unsigned int bl, depwi;
7860 +
7861 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7862 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7863 +
7864 + if (err)
7865 + break;
7866 +
7867 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7868 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7869 +
7870 + err = get_user(ldw, (unsigned int *)addr);
7871 + err |= get_user(bv, (unsigned int *)(addr+4));
7872 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7873 +
7874 + if (err)
7875 + break;
7876 +
7877 + if (ldw == 0x0E801096U &&
7878 + bv == 0xEAC0C000U &&
7879 + ldw2 == 0x0E881095U)
7880 + {
7881 + unsigned int resolver, map;
7882 +
7883 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7884 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7885 + if (err)
7886 + break;
7887 +
7888 + regs->gr[20] = instruction_pointer(regs)+8;
7889 + regs->gr[21] = map;
7890 + regs->gr[22] = resolver;
7891 + regs->iaoq[0] = resolver | 3UL;
7892 + regs->iaoq[1] = regs->iaoq[0] + 4;
7893 + return 3;
7894 + }
7895 + }
7896 + } while (0);
7897 +#endif
7898 +
7899 +#ifdef CONFIG_PAX_EMUTRAMP
7900 +
7901 +#ifndef CONFIG_PAX_EMUSIGRT
7902 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7903 + return 1;
7904 +#endif
7905 +
7906 + do { /* PaX: rt_sigreturn emulation */
7907 + unsigned int ldi1, ldi2, bel, nop;
7908 +
7909 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7910 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7911 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7912 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7913 +
7914 + if (err)
7915 + break;
7916 +
7917 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7918 + ldi2 == 0x3414015AU &&
7919 + bel == 0xE4008200U &&
7920 + nop == 0x08000240U)
7921 + {
7922 + regs->gr[25] = (ldi1 & 2) >> 1;
7923 + regs->gr[20] = __NR_rt_sigreturn;
7924 + regs->gr[31] = regs->iaoq[1] + 16;
7925 + regs->sr[0] = regs->iasq[1];
7926 + regs->iaoq[0] = 0x100UL;
7927 + regs->iaoq[1] = regs->iaoq[0] + 4;
7928 + regs->iasq[0] = regs->sr[2];
7929 + regs->iasq[1] = regs->sr[2];
7930 + return 2;
7931 + }
7932 + } while (0);
7933 +#endif
7934 +
7935 + return 1;
7936 +}
7937 +
7938 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7939 +{
7940 + unsigned long i;
7941 +
7942 + printk(KERN_ERR "PAX: bytes at PC: ");
7943 + for (i = 0; i < 5; i++) {
7944 + unsigned int c;
7945 + if (get_user(c, (unsigned int *)pc+i))
7946 + printk(KERN_CONT "???????? ");
7947 + else
7948 + printk(KERN_CONT "%08x ", c);
7949 + }
7950 + printk("\n");
7951 +}
7952 +#endif
7953 +
7954 int fixup_exception(struct pt_regs *regs)
7955 {
7956 const struct exception_table_entry *fix;
7957 @@ -234,8 +345,33 @@ retry:
7958
7959 good_area:
7960
7961 - if ((vma->vm_flags & acc_type) != acc_type)
7962 + if ((vma->vm_flags & acc_type) != acc_type) {
7963 +
7964 +#ifdef CONFIG_PAX_PAGEEXEC
7965 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7966 + (address & ~3UL) == instruction_pointer(regs))
7967 + {
7968 + up_read(&mm->mmap_sem);
7969 + switch (pax_handle_fetch_fault(regs)) {
7970 +
7971 +#ifdef CONFIG_PAX_EMUPLT
7972 + case 3:
7973 + return;
7974 +#endif
7975 +
7976 +#ifdef CONFIG_PAX_EMUTRAMP
7977 + case 2:
7978 + return;
7979 +#endif
7980 +
7981 + }
7982 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7983 + do_group_exit(SIGKILL);
7984 + }
7985 +#endif
7986 +
7987 goto bad_area;
7988 + }
7989
7990 /*
7991 * If for any reason at all we couldn't handle the fault, make
7992 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7993 index e099899..457d6a8 100644
7994 --- a/arch/powerpc/Kconfig
7995 +++ b/arch/powerpc/Kconfig
7996 @@ -397,6 +397,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7997 config KEXEC
7998 bool "kexec system call"
7999 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8000 + depends on !GRKERNSEC_KMEM
8001 help
8002 kexec is a system call that implements the ability to shutdown your
8003 current kernel, and to start another kernel. It is like a reboot
8004 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8005 index e3b1d41..8e81edf 100644
8006 --- a/arch/powerpc/include/asm/atomic.h
8007 +++ b/arch/powerpc/include/asm/atomic.h
8008 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8009 return t1;
8010 }
8011
8012 +#define atomic64_read_unchecked(v) atomic64_read(v)
8013 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8014 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8015 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8016 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8017 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8018 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8019 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8020 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8021 +
8022 #endif /* __powerpc64__ */
8023
8024 #endif /* __KERNEL__ */
8025 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8026 index f89da80..7f5b05a 100644
8027 --- a/arch/powerpc/include/asm/barrier.h
8028 +++ b/arch/powerpc/include/asm/barrier.h
8029 @@ -73,7 +73,7 @@
8030 do { \
8031 compiletime_assert_atomic_type(*p); \
8032 __lwsync(); \
8033 - ACCESS_ONCE(*p) = (v); \
8034 + ACCESS_ONCE_RW(*p) = (v); \
8035 } while (0)
8036
8037 #define smp_load_acquire(p) \
8038 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8039 index ed0afc1..0332825 100644
8040 --- a/arch/powerpc/include/asm/cache.h
8041 +++ b/arch/powerpc/include/asm/cache.h
8042 @@ -3,6 +3,7 @@
8043
8044 #ifdef __KERNEL__
8045
8046 +#include <linux/const.h>
8047
8048 /* bytes per L1 cache line */
8049 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8050 @@ -22,7 +23,7 @@
8051 #define L1_CACHE_SHIFT 7
8052 #endif
8053
8054 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8055 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8056
8057 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8058
8059 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8060 index 935b5e7..7001d2d 100644
8061 --- a/arch/powerpc/include/asm/elf.h
8062 +++ b/arch/powerpc/include/asm/elf.h
8063 @@ -28,8 +28,19 @@
8064 the loader. We need to make sure that it is out of the way of the program
8065 that it will "exec", and that there is sufficient room for the brk. */
8066
8067 -extern unsigned long randomize_et_dyn(unsigned long base);
8068 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8069 +#define ELF_ET_DYN_BASE (0x20000000)
8070 +
8071 +#ifdef CONFIG_PAX_ASLR
8072 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8073 +
8074 +#ifdef __powerpc64__
8075 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8076 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8077 +#else
8078 +#define PAX_DELTA_MMAP_LEN 15
8079 +#define PAX_DELTA_STACK_LEN 15
8080 +#endif
8081 +#endif
8082
8083 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8084
8085 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8086 (0x7ff >> (PAGE_SHIFT - 12)) : \
8087 (0x3ffff >> (PAGE_SHIFT - 12)))
8088
8089 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8090 -#define arch_randomize_brk arch_randomize_brk
8091 -
8092 -
8093 #ifdef CONFIG_SPU_BASE
8094 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8095 #define NT_SPU 1
8096 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8097 index 8196e9c..d83a9f3 100644
8098 --- a/arch/powerpc/include/asm/exec.h
8099 +++ b/arch/powerpc/include/asm/exec.h
8100 @@ -4,6 +4,6 @@
8101 #ifndef _ASM_POWERPC_EXEC_H
8102 #define _ASM_POWERPC_EXEC_H
8103
8104 -extern unsigned long arch_align_stack(unsigned long sp);
8105 +#define arch_align_stack(x) ((x) & ~0xfUL)
8106
8107 #endif /* _ASM_POWERPC_EXEC_H */
8108 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8109 index 5acabbd..7ea14fa 100644
8110 --- a/arch/powerpc/include/asm/kmap_types.h
8111 +++ b/arch/powerpc/include/asm/kmap_types.h
8112 @@ -10,7 +10,7 @@
8113 * 2 of the License, or (at your option) any later version.
8114 */
8115
8116 -#define KM_TYPE_NR 16
8117 +#define KM_TYPE_NR 17
8118
8119 #endif /* __KERNEL__ */
8120 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8121 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8122 index b8da913..60b608a 100644
8123 --- a/arch/powerpc/include/asm/local.h
8124 +++ b/arch/powerpc/include/asm/local.h
8125 @@ -9,15 +9,26 @@ typedef struct
8126 atomic_long_t a;
8127 } local_t;
8128
8129 +typedef struct
8130 +{
8131 + atomic_long_unchecked_t a;
8132 +} local_unchecked_t;
8133 +
8134 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8135
8136 #define local_read(l) atomic_long_read(&(l)->a)
8137 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8138 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8139 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8140
8141 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8142 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8143 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8144 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8145 #define local_inc(l) atomic_long_inc(&(l)->a)
8146 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8147 #define local_dec(l) atomic_long_dec(&(l)->a)
8148 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8149
8150 static __inline__ long local_add_return(long a, local_t *l)
8151 {
8152 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8153
8154 return t;
8155 }
8156 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8157
8158 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8159
8160 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8161
8162 return t;
8163 }
8164 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8165
8166 static __inline__ long local_inc_return(local_t *l)
8167 {
8168 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8169
8170 #define local_cmpxchg(l, o, n) \
8171 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8172 +#define local_cmpxchg_unchecked(l, o, n) \
8173 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8174 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8175
8176 /**
8177 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8178 index 8565c25..2865190 100644
8179 --- a/arch/powerpc/include/asm/mman.h
8180 +++ b/arch/powerpc/include/asm/mman.h
8181 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8182 }
8183 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8184
8185 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8186 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8187 {
8188 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8189 }
8190 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8191 index 32e4e21..62afb12 100644
8192 --- a/arch/powerpc/include/asm/page.h
8193 +++ b/arch/powerpc/include/asm/page.h
8194 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8195 * and needs to be executable. This means the whole heap ends
8196 * up being executable.
8197 */
8198 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8199 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8200 +#define VM_DATA_DEFAULT_FLAGS32 \
8201 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8202 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8203
8204 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8205 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8206 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8207 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8208 #endif
8209
8210 +#define ktla_ktva(addr) (addr)
8211 +#define ktva_ktla(addr) (addr)
8212 +
8213 #ifndef CONFIG_PPC_BOOK3S_64
8214 /*
8215 * Use the top bit of the higher-level page table entries to indicate whether
8216 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8217 index 88693ce..ac6f9ab 100644
8218 --- a/arch/powerpc/include/asm/page_64.h
8219 +++ b/arch/powerpc/include/asm/page_64.h
8220 @@ -153,15 +153,18 @@ do { \
8221 * stack by default, so in the absence of a PT_GNU_STACK program header
8222 * we turn execute permission off.
8223 */
8224 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8225 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8226 +#define VM_STACK_DEFAULT_FLAGS32 \
8227 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8228 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8229
8230 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8231 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8232
8233 +#ifndef CONFIG_PAX_PAGEEXEC
8234 #define VM_STACK_DEFAULT_FLAGS \
8235 (is_32bit_task() ? \
8236 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8237 +#endif
8238
8239 #include <asm-generic/getorder.h>
8240
8241 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8242 index 4b0be20..c15a27d 100644
8243 --- a/arch/powerpc/include/asm/pgalloc-64.h
8244 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8245 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8246 #ifndef CONFIG_PPC_64K_PAGES
8247
8248 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8249 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8250
8251 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8252 {
8253 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8254 pud_set(pud, (unsigned long)pmd);
8255 }
8256
8257 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8258 +{
8259 + pud_populate(mm, pud, pmd);
8260 +}
8261 +
8262 #define pmd_populate(mm, pmd, pte_page) \
8263 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8264 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8265 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8266 #endif
8267
8268 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8269 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8270
8271 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8272 pte_t *pte)
8273 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8274 index 3ebb188..e17dddf 100644
8275 --- a/arch/powerpc/include/asm/pgtable.h
8276 +++ b/arch/powerpc/include/asm/pgtable.h
8277 @@ -2,6 +2,7 @@
8278 #define _ASM_POWERPC_PGTABLE_H
8279 #ifdef __KERNEL__
8280
8281 +#include <linux/const.h>
8282 #ifndef __ASSEMBLY__
8283 #include <linux/mmdebug.h>
8284 #include <asm/processor.h> /* For TASK_SIZE */
8285 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8286 index 4aad413..85d86bf 100644
8287 --- a/arch/powerpc/include/asm/pte-hash32.h
8288 +++ b/arch/powerpc/include/asm/pte-hash32.h
8289 @@ -21,6 +21,7 @@
8290 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8291 #define _PAGE_USER 0x004 /* usermode access allowed */
8292 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8293 +#define _PAGE_EXEC _PAGE_GUARDED
8294 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8295 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8296 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8297 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8298 index e5d2e0b..9ac74b1 100644
8299 --- a/arch/powerpc/include/asm/reg.h
8300 +++ b/arch/powerpc/include/asm/reg.h
8301 @@ -249,6 +249,7 @@
8302 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8303 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8304 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8305 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8306 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8307 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8308 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8309 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8310 index ff51046..b982dd4 100644
8311 --- a/arch/powerpc/include/asm/smp.h
8312 +++ b/arch/powerpc/include/asm/smp.h
8313 @@ -51,7 +51,7 @@ struct smp_ops_t {
8314 int (*cpu_disable)(void);
8315 void (*cpu_die)(unsigned int nr);
8316 int (*cpu_bootable)(unsigned int nr);
8317 -};
8318 +} __no_const;
8319
8320 extern void smp_send_debugger_break(void);
8321 extern void start_secondary_resume(void);
8322 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8323 index b034ecd..af7e31f 100644
8324 --- a/arch/powerpc/include/asm/thread_info.h
8325 +++ b/arch/powerpc/include/asm/thread_info.h
8326 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8327 #if defined(CONFIG_PPC64)
8328 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8329 #endif
8330 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8331 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8332
8333 /* as above, but as bit values */
8334 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8335 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8336 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8337 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8338 #define _TIF_NOHZ (1<<TIF_NOHZ)
8339 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8340 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8341 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8342 - _TIF_NOHZ)
8343 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8344
8345 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8346 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8347 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8348 index 9485b43..3bd3c16 100644
8349 --- a/arch/powerpc/include/asm/uaccess.h
8350 +++ b/arch/powerpc/include/asm/uaccess.h
8351 @@ -58,6 +58,7 @@
8352
8353 #endif
8354
8355 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8356 #define access_ok(type, addr, size) \
8357 (__chk_user_ptr(addr), \
8358 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8359 @@ -318,52 +319,6 @@ do { \
8360 extern unsigned long __copy_tofrom_user(void __user *to,
8361 const void __user *from, unsigned long size);
8362
8363 -#ifndef __powerpc64__
8364 -
8365 -static inline unsigned long copy_from_user(void *to,
8366 - const void __user *from, unsigned long n)
8367 -{
8368 - unsigned long over;
8369 -
8370 - if (access_ok(VERIFY_READ, from, n))
8371 - return __copy_tofrom_user((__force void __user *)to, from, n);
8372 - if ((unsigned long)from < TASK_SIZE) {
8373 - over = (unsigned long)from + n - TASK_SIZE;
8374 - return __copy_tofrom_user((__force void __user *)to, from,
8375 - n - over) + over;
8376 - }
8377 - return n;
8378 -}
8379 -
8380 -static inline unsigned long copy_to_user(void __user *to,
8381 - const void *from, unsigned long n)
8382 -{
8383 - unsigned long over;
8384 -
8385 - if (access_ok(VERIFY_WRITE, to, n))
8386 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8387 - if ((unsigned long)to < TASK_SIZE) {
8388 - over = (unsigned long)to + n - TASK_SIZE;
8389 - return __copy_tofrom_user(to, (__force void __user *)from,
8390 - n - over) + over;
8391 - }
8392 - return n;
8393 -}
8394 -
8395 -#else /* __powerpc64__ */
8396 -
8397 -#define __copy_in_user(to, from, size) \
8398 - __copy_tofrom_user((to), (from), (size))
8399 -
8400 -extern unsigned long copy_from_user(void *to, const void __user *from,
8401 - unsigned long n);
8402 -extern unsigned long copy_to_user(void __user *to, const void *from,
8403 - unsigned long n);
8404 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8405 - unsigned long n);
8406 -
8407 -#endif /* __powerpc64__ */
8408 -
8409 static inline unsigned long __copy_from_user_inatomic(void *to,
8410 const void __user *from, unsigned long n)
8411 {
8412 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8413 if (ret == 0)
8414 return 0;
8415 }
8416 +
8417 + if (!__builtin_constant_p(n))
8418 + check_object_size(to, n, false);
8419 +
8420 return __copy_tofrom_user((__force void __user *)to, from, n);
8421 }
8422
8423 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8424 if (ret == 0)
8425 return 0;
8426 }
8427 +
8428 + if (!__builtin_constant_p(n))
8429 + check_object_size(from, n, true);
8430 +
8431 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8432 }
8433
8434 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8435 return __copy_to_user_inatomic(to, from, size);
8436 }
8437
8438 +#ifndef __powerpc64__
8439 +
8440 +static inline unsigned long __must_check copy_from_user(void *to,
8441 + const void __user *from, unsigned long n)
8442 +{
8443 + unsigned long over;
8444 +
8445 + if ((long)n < 0)
8446 + return n;
8447 +
8448 + if (access_ok(VERIFY_READ, from, n)) {
8449 + if (!__builtin_constant_p(n))
8450 + check_object_size(to, n, false);
8451 + return __copy_tofrom_user((__force void __user *)to, from, n);
8452 + }
8453 + if ((unsigned long)from < TASK_SIZE) {
8454 + over = (unsigned long)from + n - TASK_SIZE;
8455 + if (!__builtin_constant_p(n - over))
8456 + check_object_size(to, n - over, false);
8457 + return __copy_tofrom_user((__force void __user *)to, from,
8458 + n - over) + over;
8459 + }
8460 + return n;
8461 +}
8462 +
8463 +static inline unsigned long __must_check copy_to_user(void __user *to,
8464 + const void *from, unsigned long n)
8465 +{
8466 + unsigned long over;
8467 +
8468 + if ((long)n < 0)
8469 + return n;
8470 +
8471 + if (access_ok(VERIFY_WRITE, to, n)) {
8472 + if (!__builtin_constant_p(n))
8473 + check_object_size(from, n, true);
8474 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8475 + }
8476 + if ((unsigned long)to < TASK_SIZE) {
8477 + over = (unsigned long)to + n - TASK_SIZE;
8478 + if (!__builtin_constant_p(n))
8479 + check_object_size(from, n - over, true);
8480 + return __copy_tofrom_user(to, (__force void __user *)from,
8481 + n - over) + over;
8482 + }
8483 + return n;
8484 +}
8485 +
8486 +#else /* __powerpc64__ */
8487 +
8488 +#define __copy_in_user(to, from, size) \
8489 + __copy_tofrom_user((to), (from), (size))
8490 +
8491 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8492 +{
8493 + if ((long)n < 0 || n > INT_MAX)
8494 + return n;
8495 +
8496 + if (!__builtin_constant_p(n))
8497 + check_object_size(to, n, false);
8498 +
8499 + if (likely(access_ok(VERIFY_READ, from, n)))
8500 + n = __copy_from_user(to, from, n);
8501 + else
8502 + memset(to, 0, n);
8503 + return n;
8504 +}
8505 +
8506 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8507 +{
8508 + if ((long)n < 0 || n > INT_MAX)
8509 + return n;
8510 +
8511 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8512 + if (!__builtin_constant_p(n))
8513 + check_object_size(from, n, true);
8514 + n = __copy_to_user(to, from, n);
8515 + }
8516 + return n;
8517 +}
8518 +
8519 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8520 + unsigned long n);
8521 +
8522 +#endif /* __powerpc64__ */
8523 +
8524 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8525
8526 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8527 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8528 index fcc9a89..07be2bb 100644
8529 --- a/arch/powerpc/kernel/Makefile
8530 +++ b/arch/powerpc/kernel/Makefile
8531 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8532 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8533 endif
8534
8535 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8536 +
8537 obj-y := cputable.o ptrace.o syscalls.o \
8538 irq.o align.o signal_32.o pmc.o vdso.o \
8539 process.o systbl.o idle.o \
8540 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8541 index c1bee3c..5b42583 100644
8542 --- a/arch/powerpc/kernel/exceptions-64e.S
8543 +++ b/arch/powerpc/kernel/exceptions-64e.S
8544 @@ -1010,6 +1010,7 @@ storage_fault_common:
8545 std r14,_DAR(r1)
8546 std r15,_DSISR(r1)
8547 addi r3,r1,STACK_FRAME_OVERHEAD
8548 + bl .save_nvgprs
8549 mr r4,r14
8550 mr r5,r15
8551 ld r14,PACA_EXGEN+EX_R14(r13)
8552 @@ -1018,8 +1019,7 @@ storage_fault_common:
8553 cmpdi r3,0
8554 bne- 1f
8555 b .ret_from_except_lite
8556 -1: bl .save_nvgprs
8557 - mr r5,r3
8558 +1: mr r5,r3
8559 addi r3,r1,STACK_FRAME_OVERHEAD
8560 ld r4,_DAR(r1)
8561 bl .bad_page_fault
8562 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8563 index 3afd391..18f9e36 100644
8564 --- a/arch/powerpc/kernel/exceptions-64s.S
8565 +++ b/arch/powerpc/kernel/exceptions-64s.S
8566 @@ -1587,10 +1587,10 @@ handle_page_fault:
8567 11: ld r4,_DAR(r1)
8568 ld r5,_DSISR(r1)
8569 addi r3,r1,STACK_FRAME_OVERHEAD
8570 + bl .save_nvgprs
8571 bl .do_page_fault
8572 cmpdi r3,0
8573 beq+ 12f
8574 - bl .save_nvgprs
8575 mr r5,r3
8576 addi r3,r1,STACK_FRAME_OVERHEAD
8577 lwz r4,_DAR(r1)
8578 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8579 index ca1cd74..6f0241a 100644
8580 --- a/arch/powerpc/kernel/irq.c
8581 +++ b/arch/powerpc/kernel/irq.c
8582 @@ -447,6 +447,8 @@ void migrate_irqs(void)
8583 }
8584 #endif
8585
8586 +extern void gr_handle_kernel_exploit(void);
8587 +
8588 static inline void check_stack_overflow(void)
8589 {
8590 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8591 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8592 printk("do_IRQ: stack overflow: %ld\n",
8593 sp - sizeof(struct thread_info));
8594 dump_stack();
8595 + gr_handle_kernel_exploit();
8596 }
8597 #endif
8598 }
8599 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8600 index 6cff040..74ac5d1 100644
8601 --- a/arch/powerpc/kernel/module_32.c
8602 +++ b/arch/powerpc/kernel/module_32.c
8603 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8604 me->arch.core_plt_section = i;
8605 }
8606 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8607 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8608 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8609 return -ENOEXEC;
8610 }
8611
8612 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8613
8614 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8615 /* Init, or core PLT? */
8616 - if (location >= mod->module_core
8617 - && location < mod->module_core + mod->core_size)
8618 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8619 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8620 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8621 - else
8622 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8623 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8624 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8625 + else {
8626 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8627 + return ~0UL;
8628 + }
8629
8630 /* Find this entry, or if that fails, the next avail. entry */
8631 while (entry->jump[0]) {
8632 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8633 }
8634 #ifdef CONFIG_DYNAMIC_FTRACE
8635 module->arch.tramp =
8636 - do_plt_call(module->module_core,
8637 + do_plt_call(module->module_core_rx,
8638 (unsigned long)ftrace_caller,
8639 sechdrs, module);
8640 #endif
8641 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8642 index 31d0215..206af70 100644
8643 --- a/arch/powerpc/kernel/process.c
8644 +++ b/arch/powerpc/kernel/process.c
8645 @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8646 * Lookup NIP late so we have the best change of getting the
8647 * above info out without failing
8648 */
8649 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8650 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8651 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8652 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8653 #endif
8654 show_stack(current, (unsigned long *) regs->gpr[1]);
8655 if (!user_mode(regs))
8656 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8657 newsp = stack[0];
8658 ip = stack[STACK_FRAME_LR_SAVE];
8659 if (!firstframe || ip != lr) {
8660 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8661 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8663 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8664 - printk(" (%pS)",
8665 + printk(" (%pA)",
8666 (void *)current->ret_stack[curr_frame].ret);
8667 curr_frame--;
8668 }
8669 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8670 struct pt_regs *regs = (struct pt_regs *)
8671 (sp + STACK_FRAME_OVERHEAD);
8672 lr = regs->link;
8673 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8674 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8675 regs->trap, (void *)regs->nip, (void *)lr);
8676 firstframe = 1;
8677 }
8678 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8679 mtspr(SPRN_CTRLT, ctrl);
8680 }
8681 #endif /* CONFIG_PPC64 */
8682 -
8683 -unsigned long arch_align_stack(unsigned long sp)
8684 -{
8685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8686 - sp -= get_random_int() & ~PAGE_MASK;
8687 - return sp & ~0xf;
8688 -}
8689 -
8690 -static inline unsigned long brk_rnd(void)
8691 -{
8692 - unsigned long rnd = 0;
8693 -
8694 - /* 8MB for 32bit, 1GB for 64bit */
8695 - if (is_32bit_task())
8696 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8697 - else
8698 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8699 -
8700 - return rnd << PAGE_SHIFT;
8701 -}
8702 -
8703 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8704 -{
8705 - unsigned long base = mm->brk;
8706 - unsigned long ret;
8707 -
8708 -#ifdef CONFIG_PPC_STD_MMU_64
8709 - /*
8710 - * If we are using 1TB segments and we are allowed to randomise
8711 - * the heap, we can put it above 1TB so it is backed by a 1TB
8712 - * segment. Otherwise the heap will be in the bottom 1TB
8713 - * which always uses 256MB segments and this may result in a
8714 - * performance penalty.
8715 - */
8716 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8717 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8718 -#endif
8719 -
8720 - ret = PAGE_ALIGN(base + brk_rnd());
8721 -
8722 - if (ret < mm->brk)
8723 - return mm->brk;
8724 -
8725 - return ret;
8726 -}
8727 -
8728 -unsigned long randomize_et_dyn(unsigned long base)
8729 -{
8730 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8731 -
8732 - if (ret < base)
8733 - return base;
8734 -
8735 - return ret;
8736 -}
8737 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8738 index 2e3d2bf..35df241 100644
8739 --- a/arch/powerpc/kernel/ptrace.c
8740 +++ b/arch/powerpc/kernel/ptrace.c
8741 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8742 return ret;
8743 }
8744
8745 +#ifdef CONFIG_GRKERNSEC_SETXID
8746 +extern void gr_delayed_cred_worker(void);
8747 +#endif
8748 +
8749 /*
8750 * We must return the syscall number to actually look up in the table.
8751 * This can be -1L to skip running any syscall at all.
8752 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8753
8754 secure_computing_strict(regs->gpr[0]);
8755
8756 +#ifdef CONFIG_GRKERNSEC_SETXID
8757 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8758 + gr_delayed_cred_worker();
8759 +#endif
8760 +
8761 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8762 tracehook_report_syscall_entry(regs))
8763 /*
8764 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8765 {
8766 int step;
8767
8768 +#ifdef CONFIG_GRKERNSEC_SETXID
8769 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8770 + gr_delayed_cred_worker();
8771 +#endif
8772 +
8773 audit_syscall_exit(regs);
8774
8775 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8776 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8777 index 4e47db6..6dcc96e 100644
8778 --- a/arch/powerpc/kernel/signal_32.c
8779 +++ b/arch/powerpc/kernel/signal_32.c
8780 @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8781 /* Save user registers on the stack */
8782 frame = &rt_sf->uc.uc_mcontext;
8783 addr = frame;
8784 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8785 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8786 sigret = 0;
8787 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8788 } else {
8789 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8790 index d501dc4..e5a0de0 100644
8791 --- a/arch/powerpc/kernel/signal_64.c
8792 +++ b/arch/powerpc/kernel/signal_64.c
8793 @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8794 current->thread.fp_state.fpscr = 0;
8795
8796 /* Set up to return from userspace. */
8797 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8798 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8799 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8800 } else {
8801 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8802 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8803 index 1bd7ca2..9b78c2f 100644
8804 --- a/arch/powerpc/kernel/traps.c
8805 +++ b/arch/powerpc/kernel/traps.c
8806 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8807 return flags;
8808 }
8809
8810 +extern void gr_handle_kernel_exploit(void);
8811 +
8812 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8813 int signr)
8814 {
8815 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8816 panic("Fatal exception in interrupt");
8817 if (panic_on_oops)
8818 panic("Fatal exception");
8819 +
8820 + gr_handle_kernel_exploit();
8821 +
8822 do_exit(signr);
8823 }
8824
8825 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8826 index ce74c33..0803371 100644
8827 --- a/arch/powerpc/kernel/vdso.c
8828 +++ b/arch/powerpc/kernel/vdso.c
8829 @@ -35,6 +35,7 @@
8830 #include <asm/vdso.h>
8831 #include <asm/vdso_datapage.h>
8832 #include <asm/setup.h>
8833 +#include <asm/mman.h>
8834
8835 #undef DEBUG
8836
8837 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8838 vdso_base = VDSO32_MBASE;
8839 #endif
8840
8841 - current->mm->context.vdso_base = 0;
8842 + current->mm->context.vdso_base = ~0UL;
8843
8844 /* vDSO has a problem and was disabled, just don't "enable" it for the
8845 * process
8846 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8847 vdso_base = get_unmapped_area(NULL, vdso_base,
8848 (vdso_pages << PAGE_SHIFT) +
8849 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8850 - 0, 0);
8851 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8852 if (IS_ERR_VALUE(vdso_base)) {
8853 rc = vdso_base;
8854 goto fail_mmapsem;
8855 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8856 index 3cf541a..ab2d825 100644
8857 --- a/arch/powerpc/kvm/powerpc.c
8858 +++ b/arch/powerpc/kvm/powerpc.c
8859 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8860 }
8861 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8862
8863 -int kvm_arch_init(void *opaque)
8864 +int kvm_arch_init(const void *opaque)
8865 {
8866 return 0;
8867 }
8868 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8869 index 5eea6f3..5d10396 100644
8870 --- a/arch/powerpc/lib/usercopy_64.c
8871 +++ b/arch/powerpc/lib/usercopy_64.c
8872 @@ -9,22 +9,6 @@
8873 #include <linux/module.h>
8874 #include <asm/uaccess.h>
8875
8876 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8877 -{
8878 - if (likely(access_ok(VERIFY_READ, from, n)))
8879 - n = __copy_from_user(to, from, n);
8880 - else
8881 - memset(to, 0, n);
8882 - return n;
8883 -}
8884 -
8885 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8886 -{
8887 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8888 - n = __copy_to_user(to, from, n);
8889 - return n;
8890 -}
8891 -
8892 unsigned long copy_in_user(void __user *to, const void __user *from,
8893 unsigned long n)
8894 {
8895 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8896 return n;
8897 }
8898
8899 -EXPORT_SYMBOL(copy_from_user);
8900 -EXPORT_SYMBOL(copy_to_user);
8901 EXPORT_SYMBOL(copy_in_user);
8902
8903 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8904 index 51ab9e7..7d3c78b 100644
8905 --- a/arch/powerpc/mm/fault.c
8906 +++ b/arch/powerpc/mm/fault.c
8907 @@ -33,6 +33,10 @@
8908 #include <linux/magic.h>
8909 #include <linux/ratelimit.h>
8910 #include <linux/context_tracking.h>
8911 +#include <linux/slab.h>
8912 +#include <linux/pagemap.h>
8913 +#include <linux/compiler.h>
8914 +#include <linux/unistd.h>
8915
8916 #include <asm/firmware.h>
8917 #include <asm/page.h>
8918 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8919 }
8920 #endif
8921
8922 +#ifdef CONFIG_PAX_PAGEEXEC
8923 +/*
8924 + * PaX: decide what to do with offenders (regs->nip = fault address)
8925 + *
8926 + * returns 1 when task should be killed
8927 + */
8928 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8929 +{
8930 + return 1;
8931 +}
8932 +
8933 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8934 +{
8935 + unsigned long i;
8936 +
8937 + printk(KERN_ERR "PAX: bytes at PC: ");
8938 + for (i = 0; i < 5; i++) {
8939 + unsigned int c;
8940 + if (get_user(c, (unsigned int __user *)pc+i))
8941 + printk(KERN_CONT "???????? ");
8942 + else
8943 + printk(KERN_CONT "%08x ", c);
8944 + }
8945 + printk("\n");
8946 +}
8947 +#endif
8948 +
8949 /*
8950 * Check whether the instruction at regs->nip is a store using
8951 * an update addressing form which will update r1.
8952 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8953 * indicate errors in DSISR but can validly be set in SRR1.
8954 */
8955 if (trap == 0x400)
8956 - error_code &= 0x48200000;
8957 + error_code &= 0x58200000;
8958 else
8959 is_write = error_code & DSISR_ISSTORE;
8960 #else
8961 @@ -378,7 +409,7 @@ good_area:
8962 * "undefined". Of those that can be set, this is the only
8963 * one which seems bad.
8964 */
8965 - if (error_code & 0x10000000)
8966 + if (error_code & DSISR_GUARDED)
8967 /* Guarded storage error. */
8968 goto bad_area;
8969 #endif /* CONFIG_8xx */
8970 @@ -393,7 +424,7 @@ good_area:
8971 * processors use the same I/D cache coherency mechanism
8972 * as embedded.
8973 */
8974 - if (error_code & DSISR_PROTFAULT)
8975 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8976 goto bad_area;
8977 #endif /* CONFIG_PPC_STD_MMU */
8978
8979 @@ -483,6 +514,23 @@ bad_area:
8980 bad_area_nosemaphore:
8981 /* User mode accesses cause a SIGSEGV */
8982 if (user_mode(regs)) {
8983 +
8984 +#ifdef CONFIG_PAX_PAGEEXEC
8985 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8986 +#ifdef CONFIG_PPC_STD_MMU
8987 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8988 +#else
8989 + if (is_exec && regs->nip == address) {
8990 +#endif
8991 + switch (pax_handle_fetch_fault(regs)) {
8992 + }
8993 +
8994 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8995 + do_group_exit(SIGKILL);
8996 + }
8997 + }
8998 +#endif
8999 +
9000 _exception(SIGSEGV, regs, code, address);
9001 goto bail;
9002 }
9003 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9004 index cb8bdbe..cde4bc7 100644
9005 --- a/arch/powerpc/mm/mmap.c
9006 +++ b/arch/powerpc/mm/mmap.c
9007 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9008 return sysctl_legacy_va_layout;
9009 }
9010
9011 -static unsigned long mmap_rnd(void)
9012 +static unsigned long mmap_rnd(struct mm_struct *mm)
9013 {
9014 unsigned long rnd = 0;
9015
9016 +#ifdef CONFIG_PAX_RANDMMAP
9017 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9018 +#endif
9019 +
9020 if (current->flags & PF_RANDOMIZE) {
9021 /* 8MB for 32bit, 1GB for 64bit */
9022 if (is_32bit_task())
9023 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9024 return rnd << PAGE_SHIFT;
9025 }
9026
9027 -static inline unsigned long mmap_base(void)
9028 +static inline unsigned long mmap_base(struct mm_struct *mm)
9029 {
9030 unsigned long gap = rlimit(RLIMIT_STACK);
9031
9032 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9033 else if (gap > MAX_GAP)
9034 gap = MAX_GAP;
9035
9036 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9037 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9038 }
9039
9040 /*
9041 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9042 */
9043 if (mmap_is_legacy()) {
9044 mm->mmap_base = TASK_UNMAPPED_BASE;
9045 +
9046 +#ifdef CONFIG_PAX_RANDMMAP
9047 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9048 + mm->mmap_base += mm->delta_mmap;
9049 +#endif
9050 +
9051 mm->get_unmapped_area = arch_get_unmapped_area;
9052 } else {
9053 - mm->mmap_base = mmap_base();
9054 + mm->mmap_base = mmap_base(mm);
9055 +
9056 +#ifdef CONFIG_PAX_RANDMMAP
9057 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9058 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9059 +#endif
9060 +
9061 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9062 }
9063 }
9064 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9065 index b0c75cc..ef7fb93 100644
9066 --- a/arch/powerpc/mm/slice.c
9067 +++ b/arch/powerpc/mm/slice.c
9068 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9069 if ((mm->task_size - len) < addr)
9070 return 0;
9071 vma = find_vma(mm, addr);
9072 - return (!vma || (addr + len) <= vma->vm_start);
9073 + return check_heap_stack_gap(vma, addr, len, 0);
9074 }
9075
9076 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9077 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9078 info.align_offset = 0;
9079
9080 addr = TASK_UNMAPPED_BASE;
9081 +
9082 +#ifdef CONFIG_PAX_RANDMMAP
9083 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9084 + addr += mm->delta_mmap;
9085 +#endif
9086 +
9087 while (addr < TASK_SIZE) {
9088 info.low_limit = addr;
9089 if (!slice_scan_available(addr, available, 1, &addr))
9090 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9091 if (fixed && addr > (mm->task_size - len))
9092 return -ENOMEM;
9093
9094 +#ifdef CONFIG_PAX_RANDMMAP
9095 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9096 + addr = 0;
9097 +#endif
9098 +
9099 /* If hint, make sure it matches our alignment restrictions */
9100 if (!fixed && addr) {
9101 addr = _ALIGN_UP(addr, 1ul << pshift);
9102 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9103 index 4278acf..67fd0e6 100644
9104 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9105 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9106 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9107 }
9108
9109 static struct pci_ops scc_pciex_pci_ops = {
9110 - scc_pciex_read_config,
9111 - scc_pciex_write_config,
9112 + .read = scc_pciex_read_config,
9113 + .write = scc_pciex_write_config,
9114 };
9115
9116 static void pciex_clear_intr_all(unsigned int __iomem *base)
9117 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9118 index 9098692..3d54cd1 100644
9119 --- a/arch/powerpc/platforms/cell/spufs/file.c
9120 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9121 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9122 return VM_FAULT_NOPAGE;
9123 }
9124
9125 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9126 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9127 unsigned long address,
9128 - void *buf, int len, int write)
9129 + void *buf, size_t len, int write)
9130 {
9131 struct spu_context *ctx = vma->vm_file->private_data;
9132 unsigned long offset = address - vma->vm_start;
9133 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9134 index 1d47061..0714963 100644
9135 --- a/arch/s390/include/asm/atomic.h
9136 +++ b/arch/s390/include/asm/atomic.h
9137 @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9138 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9139 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9140
9141 +#define atomic64_read_unchecked(v) atomic64_read(v)
9142 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9143 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9144 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9145 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9146 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9147 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9148 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9149 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9150 +
9151 #define smp_mb__before_atomic_dec() smp_mb()
9152 #define smp_mb__after_atomic_dec() smp_mb()
9153 #define smp_mb__before_atomic_inc() smp_mb()
9154 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9155 index 578680f..0eb3b11 100644
9156 --- a/arch/s390/include/asm/barrier.h
9157 +++ b/arch/s390/include/asm/barrier.h
9158 @@ -36,7 +36,7 @@
9159 do { \
9160 compiletime_assert_atomic_type(*p); \
9161 barrier(); \
9162 - ACCESS_ONCE(*p) = (v); \
9163 + ACCESS_ONCE_RW(*p) = (v); \
9164 } while (0)
9165
9166 #define smp_load_acquire(p) \
9167 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9168 index 4d7ccac..d03d0ad 100644
9169 --- a/arch/s390/include/asm/cache.h
9170 +++ b/arch/s390/include/asm/cache.h
9171 @@ -9,8 +9,10 @@
9172 #ifndef __ARCH_S390_CACHE_H
9173 #define __ARCH_S390_CACHE_H
9174
9175 -#define L1_CACHE_BYTES 256
9176 +#include <linux/const.h>
9177 +
9178 #define L1_CACHE_SHIFT 8
9179 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9180 #define NET_SKB_PAD 32
9181
9182 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9183 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9184 index 78f4f87..598ce39 100644
9185 --- a/arch/s390/include/asm/elf.h
9186 +++ b/arch/s390/include/asm/elf.h
9187 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9188 the loader. We need to make sure that it is out of the way of the program
9189 that it will "exec", and that there is sufficient room for the brk. */
9190
9191 -extern unsigned long randomize_et_dyn(unsigned long base);
9192 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9193 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9194 +
9195 +#ifdef CONFIG_PAX_ASLR
9196 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9197 +
9198 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9199 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9200 +#endif
9201
9202 /* This yields a mask that user programs can use to figure out what
9203 instruction set this CPU supports. */
9204 @@ -222,9 +228,6 @@ struct linux_binprm;
9205 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9206 int arch_setup_additional_pages(struct linux_binprm *, int);
9207
9208 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9209 -#define arch_randomize_brk arch_randomize_brk
9210 -
9211 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9212
9213 #endif
9214 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9215 index c4a93d6..4d2a9b4 100644
9216 --- a/arch/s390/include/asm/exec.h
9217 +++ b/arch/s390/include/asm/exec.h
9218 @@ -7,6 +7,6 @@
9219 #ifndef __ASM_EXEC_H
9220 #define __ASM_EXEC_H
9221
9222 -extern unsigned long arch_align_stack(unsigned long sp);
9223 +#define arch_align_stack(x) ((x) & ~0xfUL)
9224
9225 #endif /* __ASM_EXEC_H */
9226 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9227 index 1be64a1..086839d1 100644
9228 --- a/arch/s390/include/asm/uaccess.h
9229 +++ b/arch/s390/include/asm/uaccess.h
9230 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9231 __range_ok((unsigned long)(addr), (size)); \
9232 })
9233
9234 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9235 #define access_ok(type, addr, size) __access_ok(addr, size)
9236
9237 /*
9238 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9239 copy_to_user(void __user *to, const void *from, unsigned long n)
9240 {
9241 might_fault();
9242 +
9243 + if ((long)n < 0)
9244 + return n;
9245 +
9246 return __copy_to_user(to, from, n);
9247 }
9248
9249 @@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9250 static inline unsigned long __must_check
9251 copy_from_user(void *to, const void __user *from, unsigned long n)
9252 {
9253 - unsigned int sz = __compiletime_object_size(to);
9254 + size_t sz = __compiletime_object_size(to);
9255
9256 might_fault();
9257 - if (unlikely(sz != -1 && sz < n)) {
9258 +
9259 + if ((long)n < 0)
9260 + return n;
9261 +
9262 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9263 copy_from_user_overflow();
9264 return n;
9265 }
9266 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9267 index b89b591..fd9609d 100644
9268 --- a/arch/s390/kernel/module.c
9269 +++ b/arch/s390/kernel/module.c
9270 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9271
9272 /* Increase core size by size of got & plt and set start
9273 offsets for got and plt. */
9274 - me->core_size = ALIGN(me->core_size, 4);
9275 - me->arch.got_offset = me->core_size;
9276 - me->core_size += me->arch.got_size;
9277 - me->arch.plt_offset = me->core_size;
9278 - me->core_size += me->arch.plt_size;
9279 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9280 + me->arch.got_offset = me->core_size_rw;
9281 + me->core_size_rw += me->arch.got_size;
9282 + me->arch.plt_offset = me->core_size_rx;
9283 + me->core_size_rx += me->arch.plt_size;
9284 return 0;
9285 }
9286
9287 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9288 if (info->got_initialized == 0) {
9289 Elf_Addr *gotent;
9290
9291 - gotent = me->module_core + me->arch.got_offset +
9292 + gotent = me->module_core_rw + me->arch.got_offset +
9293 info->got_offset;
9294 *gotent = val;
9295 info->got_initialized = 1;
9296 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9297 rc = apply_rela_bits(loc, val, 0, 64, 0);
9298 else if (r_type == R_390_GOTENT ||
9299 r_type == R_390_GOTPLTENT) {
9300 - val += (Elf_Addr) me->module_core - loc;
9301 + val += (Elf_Addr) me->module_core_rw - loc;
9302 rc = apply_rela_bits(loc, val, 1, 32, 1);
9303 }
9304 break;
9305 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9306 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9307 if (info->plt_initialized == 0) {
9308 unsigned int *ip;
9309 - ip = me->module_core + me->arch.plt_offset +
9310 + ip = me->module_core_rx + me->arch.plt_offset +
9311 info->plt_offset;
9312 #ifndef CONFIG_64BIT
9313 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9314 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9315 val - loc + 0xffffUL < 0x1ffffeUL) ||
9316 (r_type == R_390_PLT32DBL &&
9317 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9318 - val = (Elf_Addr) me->module_core +
9319 + val = (Elf_Addr) me->module_core_rx +
9320 me->arch.plt_offset +
9321 info->plt_offset;
9322 val += rela->r_addend - loc;
9323 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9324 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9325 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9326 val = val + rela->r_addend -
9327 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9328 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9329 if (r_type == R_390_GOTOFF16)
9330 rc = apply_rela_bits(loc, val, 0, 16, 0);
9331 else if (r_type == R_390_GOTOFF32)
9332 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9333 break;
9334 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9335 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9336 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9337 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9338 rela->r_addend - loc;
9339 if (r_type == R_390_GOTPC)
9340 rc = apply_rela_bits(loc, val, 1, 32, 0);
9341 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9342 index dd14532..1dfc145 100644
9343 --- a/arch/s390/kernel/process.c
9344 +++ b/arch/s390/kernel/process.c
9345 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9346 }
9347 return 0;
9348 }
9349 -
9350 -unsigned long arch_align_stack(unsigned long sp)
9351 -{
9352 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9353 - sp -= get_random_int() & ~PAGE_MASK;
9354 - return sp & ~0xf;
9355 -}
9356 -
9357 -static inline unsigned long brk_rnd(void)
9358 -{
9359 - /* 8MB for 32bit, 1GB for 64bit */
9360 - if (is_32bit_task())
9361 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9362 - else
9363 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9364 -}
9365 -
9366 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9367 -{
9368 - unsigned long ret;
9369 -
9370 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9371 - return (ret > mm->brk) ? ret : mm->brk;
9372 -}
9373 -
9374 -unsigned long randomize_et_dyn(unsigned long base)
9375 -{
9376 - unsigned long ret;
9377 -
9378 - if (!(current->flags & PF_RANDOMIZE))
9379 - return base;
9380 - ret = PAGE_ALIGN(base + brk_rnd());
9381 - return (ret > base) ? ret : base;
9382 -}
9383 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9384 index 9b436c2..54fbf0a 100644
9385 --- a/arch/s390/mm/mmap.c
9386 +++ b/arch/s390/mm/mmap.c
9387 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9388 */
9389 if (mmap_is_legacy()) {
9390 mm->mmap_base = mmap_base_legacy();
9391 +
9392 +#ifdef CONFIG_PAX_RANDMMAP
9393 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9394 + mm->mmap_base += mm->delta_mmap;
9395 +#endif
9396 +
9397 mm->get_unmapped_area = arch_get_unmapped_area;
9398 } else {
9399 mm->mmap_base = mmap_base();
9400 +
9401 +#ifdef CONFIG_PAX_RANDMMAP
9402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9403 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9404 +#endif
9405 +
9406 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9407 }
9408 }
9409 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9410 */
9411 if (mmap_is_legacy()) {
9412 mm->mmap_base = mmap_base_legacy();
9413 +
9414 +#ifdef CONFIG_PAX_RANDMMAP
9415 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9416 + mm->mmap_base += mm->delta_mmap;
9417 +#endif
9418 +
9419 mm->get_unmapped_area = s390_get_unmapped_area;
9420 } else {
9421 mm->mmap_base = mmap_base();
9422 +
9423 +#ifdef CONFIG_PAX_RANDMMAP
9424 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9425 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9426 +#endif
9427 +
9428 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9429 }
9430 }
9431 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9432 index ae3d59f..f65f075 100644
9433 --- a/arch/score/include/asm/cache.h
9434 +++ b/arch/score/include/asm/cache.h
9435 @@ -1,7 +1,9 @@
9436 #ifndef _ASM_SCORE_CACHE_H
9437 #define _ASM_SCORE_CACHE_H
9438
9439 +#include <linux/const.h>
9440 +
9441 #define L1_CACHE_SHIFT 4
9442 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9443 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9444
9445 #endif /* _ASM_SCORE_CACHE_H */
9446 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9447 index f9f3cd5..58ff438 100644
9448 --- a/arch/score/include/asm/exec.h
9449 +++ b/arch/score/include/asm/exec.h
9450 @@ -1,6 +1,6 @@
9451 #ifndef _ASM_SCORE_EXEC_H
9452 #define _ASM_SCORE_EXEC_H
9453
9454 -extern unsigned long arch_align_stack(unsigned long sp);
9455 +#define arch_align_stack(x) (x)
9456
9457 #endif /* _ASM_SCORE_EXEC_H */
9458 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9459 index a1519ad3..e8ac1ff 100644
9460 --- a/arch/score/kernel/process.c
9461 +++ b/arch/score/kernel/process.c
9462 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9463
9464 return task_pt_regs(task)->cp0_epc;
9465 }
9466 -
9467 -unsigned long arch_align_stack(unsigned long sp)
9468 -{
9469 - return sp;
9470 -}
9471 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9472 index ef9e555..331bd29 100644
9473 --- a/arch/sh/include/asm/cache.h
9474 +++ b/arch/sh/include/asm/cache.h
9475 @@ -9,10 +9,11 @@
9476 #define __ASM_SH_CACHE_H
9477 #ifdef __KERNEL__
9478
9479 +#include <linux/const.h>
9480 #include <linux/init.h>
9481 #include <cpu/cache.h>
9482
9483 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9484 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9485
9486 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9487
9488 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9489 index 6777177..cb5e44f 100644
9490 --- a/arch/sh/mm/mmap.c
9491 +++ b/arch/sh/mm/mmap.c
9492 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9493 struct mm_struct *mm = current->mm;
9494 struct vm_area_struct *vma;
9495 int do_colour_align;
9496 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9497 struct vm_unmapped_area_info info;
9498
9499 if (flags & MAP_FIXED) {
9500 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9501 if (filp || (flags & MAP_SHARED))
9502 do_colour_align = 1;
9503
9504 +#ifdef CONFIG_PAX_RANDMMAP
9505 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9506 +#endif
9507 +
9508 if (addr) {
9509 if (do_colour_align)
9510 addr = COLOUR_ALIGN(addr, pgoff);
9511 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9512 addr = PAGE_ALIGN(addr);
9513
9514 vma = find_vma(mm, addr);
9515 - if (TASK_SIZE - len >= addr &&
9516 - (!vma || addr + len <= vma->vm_start))
9517 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9518 return addr;
9519 }
9520
9521 info.flags = 0;
9522 info.length = len;
9523 - info.low_limit = TASK_UNMAPPED_BASE;
9524 + info.low_limit = mm->mmap_base;
9525 info.high_limit = TASK_SIZE;
9526 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9527 info.align_offset = pgoff << PAGE_SHIFT;
9528 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9529 struct mm_struct *mm = current->mm;
9530 unsigned long addr = addr0;
9531 int do_colour_align;
9532 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9533 struct vm_unmapped_area_info info;
9534
9535 if (flags & MAP_FIXED) {
9536 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9537 if (filp || (flags & MAP_SHARED))
9538 do_colour_align = 1;
9539
9540 +#ifdef CONFIG_PAX_RANDMMAP
9541 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9542 +#endif
9543 +
9544 /* requesting a specific address */
9545 if (addr) {
9546 if (do_colour_align)
9547 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9548 addr = PAGE_ALIGN(addr);
9549
9550 vma = find_vma(mm, addr);
9551 - if (TASK_SIZE - len >= addr &&
9552 - (!vma || addr + len <= vma->vm_start))
9553 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9554 return addr;
9555 }
9556
9557 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9558 VM_BUG_ON(addr != -ENOMEM);
9559 info.flags = 0;
9560 info.low_limit = TASK_UNMAPPED_BASE;
9561 +
9562 +#ifdef CONFIG_PAX_RANDMMAP
9563 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9564 + info.low_limit += mm->delta_mmap;
9565 +#endif
9566 +
9567 info.high_limit = TASK_SIZE;
9568 addr = vm_unmapped_area(&info);
9569 }
9570 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9571 index be56a24..443328f 100644
9572 --- a/arch/sparc/include/asm/atomic_64.h
9573 +++ b/arch/sparc/include/asm/atomic_64.h
9574 @@ -14,18 +14,40 @@
9575 #define ATOMIC64_INIT(i) { (i) }
9576
9577 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9578 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9579 +{
9580 + return v->counter;
9581 +}
9582 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9583 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9584 +{
9585 + return v->counter;
9586 +}
9587
9588 #define atomic_set(v, i) (((v)->counter) = i)
9589 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9590 +{
9591 + v->counter = i;
9592 +}
9593 #define atomic64_set(v, i) (((v)->counter) = i)
9594 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9595 +{
9596 + v->counter = i;
9597 +}
9598
9599 extern void atomic_add(int, atomic_t *);
9600 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9601 extern void atomic64_add(long, atomic64_t *);
9602 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9603 extern void atomic_sub(int, atomic_t *);
9604 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9605 extern void atomic64_sub(long, atomic64_t *);
9606 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9607
9608 extern int atomic_add_ret(int, atomic_t *);
9609 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9610 extern long atomic64_add_ret(long, atomic64_t *);
9611 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9612 extern int atomic_sub_ret(int, atomic_t *);
9613 extern long atomic64_sub_ret(long, atomic64_t *);
9614
9615 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9616 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9617
9618 #define atomic_inc_return(v) atomic_add_ret(1, v)
9619 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9620 +{
9621 + return atomic_add_ret_unchecked(1, v);
9622 +}
9623 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9624 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9625 +{
9626 + return atomic64_add_ret_unchecked(1, v);
9627 +}
9628
9629 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9630 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9631
9632 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9633 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9634 +{
9635 + return atomic_add_ret_unchecked(i, v);
9636 +}
9637 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9638 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9639 +{
9640 + return atomic64_add_ret_unchecked(i, v);
9641 +}
9642
9643 /*
9644 * atomic_inc_and_test - increment and test
9645 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9646 * other cases.
9647 */
9648 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9649 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9650 +{
9651 + return atomic_inc_return_unchecked(v) == 0;
9652 +}
9653 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9654
9655 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9656 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9657 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9658
9659 #define atomic_inc(v) atomic_add(1, v)
9660 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9661 +{
9662 + atomic_add_unchecked(1, v);
9663 +}
9664 #define atomic64_inc(v) atomic64_add(1, v)
9665 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9666 +{
9667 + atomic64_add_unchecked(1, v);
9668 +}
9669
9670 #define atomic_dec(v) atomic_sub(1, v)
9671 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9672 +{
9673 + atomic_sub_unchecked(1, v);
9674 +}
9675 #define atomic64_dec(v) atomic64_sub(1, v)
9676 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9677 +{
9678 + atomic64_sub_unchecked(1, v);
9679 +}
9680
9681 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9682 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9683
9684 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9685 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9686 +{
9687 + return cmpxchg(&v->counter, old, new);
9688 +}
9689 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9690 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9691 +{
9692 + return xchg(&v->counter, new);
9693 +}
9694
9695 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9696 {
9697 - int c, old;
9698 + int c, old, new;
9699 c = atomic_read(v);
9700 for (;;) {
9701 - if (unlikely(c == (u)))
9702 + if (unlikely(c == u))
9703 break;
9704 - old = atomic_cmpxchg((v), c, c + (a));
9705 +
9706 + asm volatile("addcc %2, %0, %0\n"
9707 +
9708 +#ifdef CONFIG_PAX_REFCOUNT
9709 + "tvs %%icc, 6\n"
9710 +#endif
9711 +
9712 + : "=r" (new)
9713 + : "0" (c), "ir" (a)
9714 + : "cc");
9715 +
9716 + old = atomic_cmpxchg(v, c, new);
9717 if (likely(old == c))
9718 break;
9719 c = old;
9720 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9721 #define atomic64_cmpxchg(v, o, n) \
9722 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9723 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9724 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9725 +{
9726 + return xchg(&v->counter, new);
9727 +}
9728
9729 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9730 {
9731 - long c, old;
9732 + long c, old, new;
9733 c = atomic64_read(v);
9734 for (;;) {
9735 - if (unlikely(c == (u)))
9736 + if (unlikely(c == u))
9737 break;
9738 - old = atomic64_cmpxchg((v), c, c + (a));
9739 +
9740 + asm volatile("addcc %2, %0, %0\n"
9741 +
9742 +#ifdef CONFIG_PAX_REFCOUNT
9743 + "tvs %%xcc, 6\n"
9744 +#endif
9745 +
9746 + : "=r" (new)
9747 + : "0" (c), "ir" (a)
9748 + : "cc");
9749 +
9750 + old = atomic64_cmpxchg(v, c, new);
9751 if (likely(old == c))
9752 break;
9753 c = old;
9754 }
9755 - return c != (u);
9756 + return c != u;
9757 }
9758
9759 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9760 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9761 index b5aad96..99d7465 100644
9762 --- a/arch/sparc/include/asm/barrier_64.h
9763 +++ b/arch/sparc/include/asm/barrier_64.h
9764 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9765 do { \
9766 compiletime_assert_atomic_type(*p); \
9767 barrier(); \
9768 - ACCESS_ONCE(*p) = (v); \
9769 + ACCESS_ONCE_RW(*p) = (v); \
9770 } while (0)
9771
9772 #define smp_load_acquire(p) \
9773 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9774 index 5bb6991..5c2132e 100644
9775 --- a/arch/sparc/include/asm/cache.h
9776 +++ b/arch/sparc/include/asm/cache.h
9777 @@ -7,10 +7,12 @@
9778 #ifndef _SPARC_CACHE_H
9779 #define _SPARC_CACHE_H
9780
9781 +#include <linux/const.h>
9782 +
9783 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9784
9785 #define L1_CACHE_SHIFT 5
9786 -#define L1_CACHE_BYTES 32
9787 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9788
9789 #ifdef CONFIG_SPARC32
9790 #define SMP_CACHE_BYTES_SHIFT 5
9791 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9792 index a24e41f..47677ff 100644
9793 --- a/arch/sparc/include/asm/elf_32.h
9794 +++ b/arch/sparc/include/asm/elf_32.h
9795 @@ -114,6 +114,13 @@ typedef struct {
9796
9797 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9798
9799 +#ifdef CONFIG_PAX_ASLR
9800 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9801 +
9802 +#define PAX_DELTA_MMAP_LEN 16
9803 +#define PAX_DELTA_STACK_LEN 16
9804 +#endif
9805 +
9806 /* This yields a mask that user programs can use to figure out what
9807 instruction set this cpu supports. This can NOT be done in userspace
9808 on Sparc. */
9809 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9810 index 370ca1e..d4f4a98 100644
9811 --- a/arch/sparc/include/asm/elf_64.h
9812 +++ b/arch/sparc/include/asm/elf_64.h
9813 @@ -189,6 +189,13 @@ typedef struct {
9814 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9815 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9816
9817 +#ifdef CONFIG_PAX_ASLR
9818 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9819 +
9820 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9821 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9822 +#endif
9823 +
9824 extern unsigned long sparc64_elf_hwcap;
9825 #define ELF_HWCAP sparc64_elf_hwcap
9826
9827 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9828 index 9b1c36d..209298b 100644
9829 --- a/arch/sparc/include/asm/pgalloc_32.h
9830 +++ b/arch/sparc/include/asm/pgalloc_32.h
9831 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9832 }
9833
9834 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9835 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9836
9837 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9838 unsigned long address)
9839 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9840 index bcfe063..b333142 100644
9841 --- a/arch/sparc/include/asm/pgalloc_64.h
9842 +++ b/arch/sparc/include/asm/pgalloc_64.h
9843 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9844 }
9845
9846 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9847 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9848
9849 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9850 {
9851 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9852 index 59ba6f6..4518128 100644
9853 --- a/arch/sparc/include/asm/pgtable.h
9854 +++ b/arch/sparc/include/asm/pgtable.h
9855 @@ -5,4 +5,8 @@
9856 #else
9857 #include <asm/pgtable_32.h>
9858 #endif
9859 +
9860 +#define ktla_ktva(addr) (addr)
9861 +#define ktva_ktla(addr) (addr)
9862 +
9863 #endif
9864 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9865 index 502f632..da1917f 100644
9866 --- a/arch/sparc/include/asm/pgtable_32.h
9867 +++ b/arch/sparc/include/asm/pgtable_32.h
9868 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9869 #define PAGE_SHARED SRMMU_PAGE_SHARED
9870 #define PAGE_COPY SRMMU_PAGE_COPY
9871 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9872 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9873 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9874 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9875 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9876
9877 /* Top-level page directory - dummy used by init-mm.
9878 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9879
9880 /* xwr */
9881 #define __P000 PAGE_NONE
9882 -#define __P001 PAGE_READONLY
9883 -#define __P010 PAGE_COPY
9884 -#define __P011 PAGE_COPY
9885 +#define __P001 PAGE_READONLY_NOEXEC
9886 +#define __P010 PAGE_COPY_NOEXEC
9887 +#define __P011 PAGE_COPY_NOEXEC
9888 #define __P100 PAGE_READONLY
9889 #define __P101 PAGE_READONLY
9890 #define __P110 PAGE_COPY
9891 #define __P111 PAGE_COPY
9892
9893 #define __S000 PAGE_NONE
9894 -#define __S001 PAGE_READONLY
9895 -#define __S010 PAGE_SHARED
9896 -#define __S011 PAGE_SHARED
9897 +#define __S001 PAGE_READONLY_NOEXEC
9898 +#define __S010 PAGE_SHARED_NOEXEC
9899 +#define __S011 PAGE_SHARED_NOEXEC
9900 #define __S100 PAGE_READONLY
9901 #define __S101 PAGE_READONLY
9902 #define __S110 PAGE_SHARED
9903 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9904 index 79da178..c2eede8 100644
9905 --- a/arch/sparc/include/asm/pgtsrmmu.h
9906 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9907 @@ -115,6 +115,11 @@
9908 SRMMU_EXEC | SRMMU_REF)
9909 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9910 SRMMU_EXEC | SRMMU_REF)
9911 +
9912 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9913 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9914 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915 +
9916 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9917 SRMMU_DIRTY | SRMMU_REF)
9918
9919 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9920 index 9689176..63c18ea 100644
9921 --- a/arch/sparc/include/asm/spinlock_64.h
9922 +++ b/arch/sparc/include/asm/spinlock_64.h
9923 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9924
9925 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9926
9927 -static void inline arch_read_lock(arch_rwlock_t *lock)
9928 +static inline void arch_read_lock(arch_rwlock_t *lock)
9929 {
9930 unsigned long tmp1, tmp2;
9931
9932 __asm__ __volatile__ (
9933 "1: ldsw [%2], %0\n"
9934 " brlz,pn %0, 2f\n"
9935 -"4: add %0, 1, %1\n"
9936 +"4: addcc %0, 1, %1\n"
9937 +
9938 +#ifdef CONFIG_PAX_REFCOUNT
9939 +" tvs %%icc, 6\n"
9940 +#endif
9941 +
9942 " cas [%2], %0, %1\n"
9943 " cmp %0, %1\n"
9944 " bne,pn %%icc, 1b\n"
9945 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9946 " .previous"
9947 : "=&r" (tmp1), "=&r" (tmp2)
9948 : "r" (lock)
9949 - : "memory");
9950 + : "memory", "cc");
9951 }
9952
9953 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9954 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9955 {
9956 int tmp1, tmp2;
9957
9958 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9959 "1: ldsw [%2], %0\n"
9960 " brlz,a,pn %0, 2f\n"
9961 " mov 0, %0\n"
9962 -" add %0, 1, %1\n"
9963 +" addcc %0, 1, %1\n"
9964 +
9965 +#ifdef CONFIG_PAX_REFCOUNT
9966 +" tvs %%icc, 6\n"
9967 +#endif
9968 +
9969 " cas [%2], %0, %1\n"
9970 " cmp %0, %1\n"
9971 " bne,pn %%icc, 1b\n"
9972 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9973 return tmp1;
9974 }
9975
9976 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9977 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9978 {
9979 unsigned long tmp1, tmp2;
9980
9981 __asm__ __volatile__(
9982 "1: lduw [%2], %0\n"
9983 -" sub %0, 1, %1\n"
9984 +" subcc %0, 1, %1\n"
9985 +
9986 +#ifdef CONFIG_PAX_REFCOUNT
9987 +" tvs %%icc, 6\n"
9988 +#endif
9989 +
9990 " cas [%2], %0, %1\n"
9991 " cmp %0, %1\n"
9992 " bne,pn %%xcc, 1b\n"
9993 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9994 : "memory");
9995 }
9996
9997 -static void inline arch_write_lock(arch_rwlock_t *lock)
9998 +static inline void arch_write_lock(arch_rwlock_t *lock)
9999 {
10000 unsigned long mask, tmp1, tmp2;
10001
10002 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10003 : "memory");
10004 }
10005
10006 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10007 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10008 {
10009 __asm__ __volatile__(
10010 " stw %%g0, [%0]"
10011 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10012 : "memory");
10013 }
10014
10015 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10016 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10017 {
10018 unsigned long mask, tmp1, tmp2, result;
10019
10020 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10021 index 96efa7a..16858bf 100644
10022 --- a/arch/sparc/include/asm/thread_info_32.h
10023 +++ b/arch/sparc/include/asm/thread_info_32.h
10024 @@ -49,6 +49,8 @@ struct thread_info {
10025 unsigned long w_saved;
10026
10027 struct restart_block restart_block;
10028 +
10029 + unsigned long lowest_stack;
10030 };
10031
10032 /*
10033 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10034 index a5f01ac..703b554 100644
10035 --- a/arch/sparc/include/asm/thread_info_64.h
10036 +++ b/arch/sparc/include/asm/thread_info_64.h
10037 @@ -63,6 +63,8 @@ struct thread_info {
10038 struct pt_regs *kern_una_regs;
10039 unsigned int kern_una_insn;
10040
10041 + unsigned long lowest_stack;
10042 +
10043 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10044 };
10045
10046 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10047 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10048 /* flag bit 4 is available */
10049 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10050 -/* flag bit 6 is available */
10051 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10052 #define TIF_32BIT 7 /* 32-bit binary */
10053 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10054 #define TIF_SECCOMP 9 /* secure computing */
10055 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10056 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10057 +
10058 /* NOTE: Thread flags >= 12 should be ones we have no interest
10059 * in using in assembly, else we can't use the mask as
10060 * an immediate value in instructions such as andcc.
10061 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10062 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10063 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10064 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10065 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10066
10067 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10068 _TIF_DO_NOTIFY_RESUME_MASK | \
10069 _TIF_NEED_RESCHED)
10070 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10071
10072 +#define _TIF_WORK_SYSCALL \
10073 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10074 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10075 +
10076 +
10077 /*
10078 * Thread-synchronous status.
10079 *
10080 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10081 index 0167d26..767bb0c 100644
10082 --- a/arch/sparc/include/asm/uaccess.h
10083 +++ b/arch/sparc/include/asm/uaccess.h
10084 @@ -1,5 +1,6 @@
10085 #ifndef ___ASM_SPARC_UACCESS_H
10086 #define ___ASM_SPARC_UACCESS_H
10087 +
10088 #if defined(__sparc__) && defined(__arch64__)
10089 #include <asm/uaccess_64.h>
10090 #else
10091 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10092 index 53a28dd..50c38c3 100644
10093 --- a/arch/sparc/include/asm/uaccess_32.h
10094 +++ b/arch/sparc/include/asm/uaccess_32.h
10095 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10096
10097 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10098 {
10099 - if (n && __access_ok((unsigned long) to, n))
10100 + if ((long)n < 0)
10101 + return n;
10102 +
10103 + if (n && __access_ok((unsigned long) to, n)) {
10104 + if (!__builtin_constant_p(n))
10105 + check_object_size(from, n, true);
10106 return __copy_user(to, (__force void __user *) from, n);
10107 - else
10108 + } else
10109 return n;
10110 }
10111
10112 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10113 {
10114 + if ((long)n < 0)
10115 + return n;
10116 +
10117 + if (!__builtin_constant_p(n))
10118 + check_object_size(from, n, true);
10119 +
10120 return __copy_user(to, (__force void __user *) from, n);
10121 }
10122
10123 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10124 {
10125 - if (n && __access_ok((unsigned long) from, n))
10126 + if ((long)n < 0)
10127 + return n;
10128 +
10129 + if (n && __access_ok((unsigned long) from, n)) {
10130 + if (!__builtin_constant_p(n))
10131 + check_object_size(to, n, false);
10132 return __copy_user((__force void __user *) to, from, n);
10133 - else
10134 + } else
10135 return n;
10136 }
10137
10138 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10139 {
10140 + if ((long)n < 0)
10141 + return n;
10142 +
10143 return __copy_user((__force void __user *) to, from, n);
10144 }
10145
10146 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10147 index ad7e178..c9e7423 100644
10148 --- a/arch/sparc/include/asm/uaccess_64.h
10149 +++ b/arch/sparc/include/asm/uaccess_64.h
10150 @@ -10,6 +10,7 @@
10151 #include <linux/compiler.h>
10152 #include <linux/string.h>
10153 #include <linux/thread_info.h>
10154 +#include <linux/kernel.h>
10155 #include <asm/asi.h>
10156 #include <asm/spitfire.h>
10157 #include <asm-generic/uaccess-unaligned.h>
10158 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10159 static inline unsigned long __must_check
10160 copy_from_user(void *to, const void __user *from, unsigned long size)
10161 {
10162 - unsigned long ret = ___copy_from_user(to, from, size);
10163 + unsigned long ret;
10164
10165 + if ((long)size < 0 || size > INT_MAX)
10166 + return size;
10167 +
10168 + if (!__builtin_constant_p(size))
10169 + check_object_size(to, size, false);
10170 +
10171 + ret = ___copy_from_user(to, from, size);
10172 if (unlikely(ret))
10173 ret = copy_from_user_fixup(to, from, size);
10174
10175 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10176 static inline unsigned long __must_check
10177 copy_to_user(void __user *to, const void *from, unsigned long size)
10178 {
10179 - unsigned long ret = ___copy_to_user(to, from, size);
10180 + unsigned long ret;
10181
10182 + if ((long)size < 0 || size > INT_MAX)
10183 + return size;
10184 +
10185 + if (!__builtin_constant_p(size))
10186 + check_object_size(from, size, true);
10187 +
10188 + ret = ___copy_to_user(to, from, size);
10189 if (unlikely(ret))
10190 ret = copy_to_user_fixup(to, from, size);
10191 return ret;
10192 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10193 index d15cc17..d0ae796 100644
10194 --- a/arch/sparc/kernel/Makefile
10195 +++ b/arch/sparc/kernel/Makefile
10196 @@ -4,7 +4,7 @@
10197 #
10198
10199 asflags-y := -ansi
10200 -ccflags-y := -Werror
10201 +#ccflags-y := -Werror
10202
10203 extra-y := head_$(BITS).o
10204
10205 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10206 index 510baec..9ff2607 100644
10207 --- a/arch/sparc/kernel/process_32.c
10208 +++ b/arch/sparc/kernel/process_32.c
10209 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10210
10211 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10212 r->psr, r->pc, r->npc, r->y, print_tainted());
10213 - printk("PC: <%pS>\n", (void *) r->pc);
10214 + printk("PC: <%pA>\n", (void *) r->pc);
10215 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10216 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10217 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10218 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10219 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10220 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10221 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10222 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10223
10224 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10225 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10226 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10227 rw = (struct reg_window32 *) fp;
10228 pc = rw->ins[7];
10229 printk("[%08lx : ", pc);
10230 - printk("%pS ] ", (void *) pc);
10231 + printk("%pA ] ", (void *) pc);
10232 fp = rw->ins[6];
10233 } while (++count < 16);
10234 printk("\n");
10235 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10236 index d7b4967..2edf827 100644
10237 --- a/arch/sparc/kernel/process_64.c
10238 +++ b/arch/sparc/kernel/process_64.c
10239 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10240 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10241 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10242 if (regs->tstate & TSTATE_PRIV)
10243 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10244 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10245 }
10246
10247 void show_regs(struct pt_regs *regs)
10248 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10249
10250 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10251 regs->tpc, regs->tnpc, regs->y, print_tainted());
10252 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10253 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10254 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10255 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10256 regs->u_regs[3]);
10257 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10258 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10259 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10260 regs->u_regs[15]);
10261 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10262 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10263 show_regwindow(regs);
10264 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10265 }
10266 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10267 ((tp && tp->task) ? tp->task->pid : -1));
10268
10269 if (gp->tstate & TSTATE_PRIV) {
10270 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10271 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10272 (void *) gp->tpc,
10273 (void *) gp->o7,
10274 (void *) gp->i7,
10275 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10276 index 79cc0d1..ec62734 100644
10277 --- a/arch/sparc/kernel/prom_common.c
10278 +++ b/arch/sparc/kernel/prom_common.c
10279 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10280
10281 unsigned int prom_early_allocated __initdata;
10282
10283 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10284 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10285 .nextprop = prom_common_nextprop,
10286 .getproplen = prom_getproplen,
10287 .getproperty = prom_getproperty,
10288 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10289 index c13c9f2..d572c34 100644
10290 --- a/arch/sparc/kernel/ptrace_64.c
10291 +++ b/arch/sparc/kernel/ptrace_64.c
10292 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10293 return ret;
10294 }
10295
10296 +#ifdef CONFIG_GRKERNSEC_SETXID
10297 +extern void gr_delayed_cred_worker(void);
10298 +#endif
10299 +
10300 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10301 {
10302 int ret = 0;
10303 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10304 if (test_thread_flag(TIF_NOHZ))
10305 user_exit();
10306
10307 +#ifdef CONFIG_GRKERNSEC_SETXID
10308 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10309 + gr_delayed_cred_worker();
10310 +#endif
10311 +
10312 if (test_thread_flag(TIF_SYSCALL_TRACE))
10313 ret = tracehook_report_syscall_entry(regs);
10314
10315 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10316 if (test_thread_flag(TIF_NOHZ))
10317 user_exit();
10318
10319 +#ifdef CONFIG_GRKERNSEC_SETXID
10320 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10321 + gr_delayed_cred_worker();
10322 +#endif
10323 +
10324 audit_syscall_exit(regs);
10325
10326 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10327 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10328 index 745a363..b5566b1 100644
10329 --- a/arch/sparc/kernel/smp_64.c
10330 +++ b/arch/sparc/kernel/smp_64.c
10331 @@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10332 extern unsigned long xcall_flush_dcache_page_spitfire;
10333
10334 #ifdef CONFIG_DEBUG_DCFLUSH
10335 -extern atomic_t dcpage_flushes;
10336 -extern atomic_t dcpage_flushes_xcall;
10337 +extern atomic_unchecked_t dcpage_flushes;
10338 +extern atomic_unchecked_t dcpage_flushes_xcall;
10339 #endif
10340
10341 static inline void __local_flush_dcache_page(struct page *page)
10342 @@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10343 return;
10344
10345 #ifdef CONFIG_DEBUG_DCFLUSH
10346 - atomic_inc(&dcpage_flushes);
10347 + atomic_inc_unchecked(&dcpage_flushes);
10348 #endif
10349
10350 this_cpu = get_cpu();
10351 @@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10352 xcall_deliver(data0, __pa(pg_addr),
10353 (u64) pg_addr, cpumask_of(cpu));
10354 #ifdef CONFIG_DEBUG_DCFLUSH
10355 - atomic_inc(&dcpage_flushes_xcall);
10356 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10357 #endif
10358 }
10359 }
10360 @@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10361 preempt_disable();
10362
10363 #ifdef CONFIG_DEBUG_DCFLUSH
10364 - atomic_inc(&dcpage_flushes);
10365 + atomic_inc_unchecked(&dcpage_flushes);
10366 #endif
10367 data0 = 0;
10368 pg_addr = page_address(page);
10369 @@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10370 xcall_deliver(data0, __pa(pg_addr),
10371 (u64) pg_addr, cpu_online_mask);
10372 #ifdef CONFIG_DEBUG_DCFLUSH
10373 - atomic_inc(&dcpage_flushes_xcall);
10374 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10375 #endif
10376 }
10377 __local_flush_dcache_page(page);
10378 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10379 index 3a8d184..49498a8 100644
10380 --- a/arch/sparc/kernel/sys_sparc_32.c
10381 +++ b/arch/sparc/kernel/sys_sparc_32.c
10382 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10383 if (len > TASK_SIZE - PAGE_SIZE)
10384 return -ENOMEM;
10385 if (!addr)
10386 - addr = TASK_UNMAPPED_BASE;
10387 + addr = current->mm->mmap_base;
10388
10389 info.flags = 0;
10390 info.length = len;
10391 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10392 index beb0b5a..5a153f7 100644
10393 --- a/arch/sparc/kernel/sys_sparc_64.c
10394 +++ b/arch/sparc/kernel/sys_sparc_64.c
10395 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10396 struct vm_area_struct * vma;
10397 unsigned long task_size = TASK_SIZE;
10398 int do_color_align;
10399 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10400 struct vm_unmapped_area_info info;
10401
10402 if (flags & MAP_FIXED) {
10403 /* We do not accept a shared mapping if it would violate
10404 * cache aliasing constraints.
10405 */
10406 - if ((flags & MAP_SHARED) &&
10407 + if ((filp || (flags & MAP_SHARED)) &&
10408 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10409 return -EINVAL;
10410 return addr;
10411 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10412 if (filp || (flags & MAP_SHARED))
10413 do_color_align = 1;
10414
10415 +#ifdef CONFIG_PAX_RANDMMAP
10416 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10417 +#endif
10418 +
10419 if (addr) {
10420 if (do_color_align)
10421 addr = COLOR_ALIGN(addr, pgoff);
10422 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10423 addr = PAGE_ALIGN(addr);
10424
10425 vma = find_vma(mm, addr);
10426 - if (task_size - len >= addr &&
10427 - (!vma || addr + len <= vma->vm_start))
10428 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10429 return addr;
10430 }
10431
10432 info.flags = 0;
10433 info.length = len;
10434 - info.low_limit = TASK_UNMAPPED_BASE;
10435 + info.low_limit = mm->mmap_base;
10436 info.high_limit = min(task_size, VA_EXCLUDE_START);
10437 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10438 info.align_offset = pgoff << PAGE_SHIFT;
10439 + info.threadstack_offset = offset;
10440 addr = vm_unmapped_area(&info);
10441
10442 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10443 VM_BUG_ON(addr != -ENOMEM);
10444 info.low_limit = VA_EXCLUDE_END;
10445 +
10446 +#ifdef CONFIG_PAX_RANDMMAP
10447 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10448 + info.low_limit += mm->delta_mmap;
10449 +#endif
10450 +
10451 info.high_limit = task_size;
10452 addr = vm_unmapped_area(&info);
10453 }
10454 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10455 unsigned long task_size = STACK_TOP32;
10456 unsigned long addr = addr0;
10457 int do_color_align;
10458 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10459 struct vm_unmapped_area_info info;
10460
10461 /* This should only ever run for 32-bit processes. */
10462 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10463 /* We do not accept a shared mapping if it would violate
10464 * cache aliasing constraints.
10465 */
10466 - if ((flags & MAP_SHARED) &&
10467 + if ((filp || (flags & MAP_SHARED)) &&
10468 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10469 return -EINVAL;
10470 return addr;
10471 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 if (filp || (flags & MAP_SHARED))
10473 do_color_align = 1;
10474
10475 +#ifdef CONFIG_PAX_RANDMMAP
10476 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10477 +#endif
10478 +
10479 /* requesting a specific address */
10480 if (addr) {
10481 if (do_color_align)
10482 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 addr = PAGE_ALIGN(addr);
10484
10485 vma = find_vma(mm, addr);
10486 - if (task_size - len >= addr &&
10487 - (!vma || addr + len <= vma->vm_start))
10488 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10489 return addr;
10490 }
10491
10492 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10493 info.high_limit = mm->mmap_base;
10494 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10495 info.align_offset = pgoff << PAGE_SHIFT;
10496 + info.threadstack_offset = offset;
10497 addr = vm_unmapped_area(&info);
10498
10499 /*
10500 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10501 VM_BUG_ON(addr != -ENOMEM);
10502 info.flags = 0;
10503 info.low_limit = TASK_UNMAPPED_BASE;
10504 +
10505 +#ifdef CONFIG_PAX_RANDMMAP
10506 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10507 + info.low_limit += mm->delta_mmap;
10508 +#endif
10509 +
10510 info.high_limit = STACK_TOP32;
10511 addr = vm_unmapped_area(&info);
10512 }
10513 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10514 EXPORT_SYMBOL(get_fb_unmapped_area);
10515
10516 /* Essentially the same as PowerPC. */
10517 -static unsigned long mmap_rnd(void)
10518 +static unsigned long mmap_rnd(struct mm_struct *mm)
10519 {
10520 unsigned long rnd = 0UL;
10521
10522 +#ifdef CONFIG_PAX_RANDMMAP
10523 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10524 +#endif
10525 +
10526 if (current->flags & PF_RANDOMIZE) {
10527 unsigned long val = get_random_int();
10528 if (test_thread_flag(TIF_32BIT))
10529 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10530
10531 void arch_pick_mmap_layout(struct mm_struct *mm)
10532 {
10533 - unsigned long random_factor = mmap_rnd();
10534 + unsigned long random_factor = mmap_rnd(mm);
10535 unsigned long gap;
10536
10537 /*
10538 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10539 gap == RLIM_INFINITY ||
10540 sysctl_legacy_va_layout) {
10541 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10542 +
10543 +#ifdef CONFIG_PAX_RANDMMAP
10544 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10545 + mm->mmap_base += mm->delta_mmap;
10546 +#endif
10547 +
10548 mm->get_unmapped_area = arch_get_unmapped_area;
10549 } else {
10550 /* We know it's 32-bit */
10551 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10552 gap = (task_size / 6 * 5);
10553
10554 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10555 +
10556 +#ifdef CONFIG_PAX_RANDMMAP
10557 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10558 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10559 +#endif
10560 +
10561 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10562 }
10563 }
10564 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10565 index 33a17e7..d87fb1f 100644
10566 --- a/arch/sparc/kernel/syscalls.S
10567 +++ b/arch/sparc/kernel/syscalls.S
10568 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10569 #endif
10570 .align 32
10571 1: ldx [%g6 + TI_FLAGS], %l5
10572 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10573 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10574 be,pt %icc, rtrap
10575 nop
10576 call syscall_trace_leave
10577 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10578
10579 srl %i3, 0, %o3 ! IEU0
10580 srl %i2, 0, %o2 ! IEU0 Group
10581 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10582 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10583 bne,pn %icc, linux_syscall_trace32 ! CTI
10584 mov %i0, %l5 ! IEU1
10585 5: call %l7 ! CTI Group brk forced
10586 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10587
10588 mov %i3, %o3 ! IEU1
10589 mov %i4, %o4 ! IEU0 Group
10590 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10591 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10592 bne,pn %icc, linux_syscall_trace ! CTI Group
10593 mov %i0, %l5 ! IEU0
10594 2: call %l7 ! CTI Group brk forced
10595 @@ -223,7 +223,7 @@ ret_sys_call:
10596
10597 cmp %o0, -ERESTART_RESTARTBLOCK
10598 bgeu,pn %xcc, 1f
10599 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10600 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10601 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10602
10603 2:
10604 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10605 index 6629829..036032d 100644
10606 --- a/arch/sparc/kernel/traps_32.c
10607 +++ b/arch/sparc/kernel/traps_32.c
10608 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10609 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10610 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10611
10612 +extern void gr_handle_kernel_exploit(void);
10613 +
10614 void die_if_kernel(char *str, struct pt_regs *regs)
10615 {
10616 static int die_counter;
10617 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10618 count++ < 30 &&
10619 (((unsigned long) rw) >= PAGE_OFFSET) &&
10620 !(((unsigned long) rw) & 0x7)) {
10621 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10622 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10623 (void *) rw->ins[7]);
10624 rw = (struct reg_window32 *)rw->ins[6];
10625 }
10626 }
10627 printk("Instruction DUMP:");
10628 instruction_dump ((unsigned long *) regs->pc);
10629 - if(regs->psr & PSR_PS)
10630 + if(regs->psr & PSR_PS) {
10631 + gr_handle_kernel_exploit();
10632 do_exit(SIGKILL);
10633 + }
10634 do_exit(SIGSEGV);
10635 }
10636
10637 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10638 index 4ced92f..965eeed 100644
10639 --- a/arch/sparc/kernel/traps_64.c
10640 +++ b/arch/sparc/kernel/traps_64.c
10641 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10642 i + 1,
10643 p->trapstack[i].tstate, p->trapstack[i].tpc,
10644 p->trapstack[i].tnpc, p->trapstack[i].tt);
10645 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10646 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10647 }
10648 }
10649
10650 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10651
10652 lvl -= 0x100;
10653 if (regs->tstate & TSTATE_PRIV) {
10654 +
10655 +#ifdef CONFIG_PAX_REFCOUNT
10656 + if (lvl == 6)
10657 + pax_report_refcount_overflow(regs);
10658 +#endif
10659 +
10660 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10661 die_if_kernel(buffer, regs);
10662 }
10663 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10664 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10665 {
10666 char buffer[32];
10667 -
10668 +
10669 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10670 0, lvl, SIGTRAP) == NOTIFY_STOP)
10671 return;
10672
10673 +#ifdef CONFIG_PAX_REFCOUNT
10674 + if (lvl == 6)
10675 + pax_report_refcount_overflow(regs);
10676 +#endif
10677 +
10678 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10679
10680 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10681 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10682 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10683 printk("%s" "ERROR(%d): ",
10684 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10685 - printk("TPC<%pS>\n", (void *) regs->tpc);
10686 + printk("TPC<%pA>\n", (void *) regs->tpc);
10687 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10688 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10689 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10690 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10691 smp_processor_id(),
10692 (type & 0x1) ? 'I' : 'D',
10693 regs->tpc);
10694 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10695 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10696 panic("Irrecoverable Cheetah+ parity error.");
10697 }
10698
10699 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10700 smp_processor_id(),
10701 (type & 0x1) ? 'I' : 'D',
10702 regs->tpc);
10703 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10704 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10705 }
10706
10707 struct sun4v_error_entry {
10708 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10709 /*0x38*/u64 reserved_5;
10710 };
10711
10712 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10713 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10714 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10715 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10716
10717 static const char *sun4v_err_type_to_str(u8 type)
10718 {
10719 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10720 }
10721
10722 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10723 - int cpu, const char *pfx, atomic_t *ocnt)
10724 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10725 {
10726 u64 *raw_ptr = (u64 *) ent;
10727 u32 attrs;
10728 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10729
10730 show_regs(regs);
10731
10732 - if ((cnt = atomic_read(ocnt)) != 0) {
10733 - atomic_set(ocnt, 0);
10734 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10735 + atomic_set_unchecked(ocnt, 0);
10736 wmb();
10737 printk("%s: Queue overflowed %d times.\n",
10738 pfx, cnt);
10739 @@ -2046,7 +2057,7 @@ out:
10740 */
10741 void sun4v_resum_overflow(struct pt_regs *regs)
10742 {
10743 - atomic_inc(&sun4v_resum_oflow_cnt);
10744 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10745 }
10746
10747 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10748 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10749 /* XXX Actually even this can make not that much sense. Perhaps
10750 * XXX we should just pull the plug and panic directly from here?
10751 */
10752 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10753 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10754 }
10755
10756 unsigned long sun4v_err_itlb_vaddr;
10757 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10758
10759 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10760 regs->tpc, tl);
10761 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10762 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10763 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10764 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10765 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10766 (void *) regs->u_regs[UREG_I7]);
10767 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10768 "pte[%lx] error[%lx]\n",
10769 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10770
10771 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10772 regs->tpc, tl);
10773 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10774 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10775 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10776 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10777 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10778 (void *) regs->u_regs[UREG_I7]);
10779 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10780 "pte[%lx] error[%lx]\n",
10781 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10782 fp = (unsigned long)sf->fp + STACK_BIAS;
10783 }
10784
10785 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10786 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10787 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10788 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10789 int index = tsk->curr_ret_stack;
10790 if (tsk->ret_stack && index >= graph) {
10791 pc = tsk->ret_stack[index - graph].ret;
10792 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10793 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10794 graph++;
10795 }
10796 }
10797 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10798 return (struct reg_window *) (fp + STACK_BIAS);
10799 }
10800
10801 +extern void gr_handle_kernel_exploit(void);
10802 +
10803 void die_if_kernel(char *str, struct pt_regs *regs)
10804 {
10805 static int die_counter;
10806 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10807 while (rw &&
10808 count++ < 30 &&
10809 kstack_valid(tp, (unsigned long) rw)) {
10810 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10811 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10812 (void *) rw->ins[7]);
10813
10814 rw = kernel_stack_up(rw);
10815 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10816 }
10817 user_instruction_dump ((unsigned int __user *) regs->tpc);
10818 }
10819 - if (regs->tstate & TSTATE_PRIV)
10820 + if (regs->tstate & TSTATE_PRIV) {
10821 + gr_handle_kernel_exploit();
10822 do_exit(SIGKILL);
10823 + }
10824 do_exit(SIGSEGV);
10825 }
10826 EXPORT_SYMBOL(die_if_kernel);
10827 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10828 index 35ab8b6..9046547 100644
10829 --- a/arch/sparc/kernel/unaligned_64.c
10830 +++ b/arch/sparc/kernel/unaligned_64.c
10831 @@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10832 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10833
10834 if (__ratelimit(&ratelimit)) {
10835 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10836 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10837 regs->tpc, (void *) regs->tpc);
10838 }
10839 }
10840 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10841 index dbe119b..089c7c1 100644
10842 --- a/arch/sparc/lib/Makefile
10843 +++ b/arch/sparc/lib/Makefile
10844 @@ -2,7 +2,7 @@
10845 #
10846
10847 asflags-y := -ansi -DST_DIV0=0x02
10848 -ccflags-y := -Werror
10849 +#ccflags-y := -Werror
10850
10851 lib-$(CONFIG_SPARC32) += ashrdi3.o
10852 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10853 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10854 index 85c233d..68500e0 100644
10855 --- a/arch/sparc/lib/atomic_64.S
10856 +++ b/arch/sparc/lib/atomic_64.S
10857 @@ -17,7 +17,12 @@
10858 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10859 BACKOFF_SETUP(%o2)
10860 1: lduw [%o1], %g1
10861 - add %g1, %o0, %g7
10862 + addcc %g1, %o0, %g7
10863 +
10864 +#ifdef CONFIG_PAX_REFCOUNT
10865 + tvs %icc, 6
10866 +#endif
10867 +
10868 cas [%o1], %g1, %g7
10869 cmp %g1, %g7
10870 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10871 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10872 2: BACKOFF_SPIN(%o2, %o3, 1b)
10873 ENDPROC(atomic_add)
10874
10875 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10876 + BACKOFF_SETUP(%o2)
10877 +1: lduw [%o1], %g1
10878 + add %g1, %o0, %g7
10879 + cas [%o1], %g1, %g7
10880 + cmp %g1, %g7
10881 + bne,pn %icc, 2f
10882 + nop
10883 + retl
10884 + nop
10885 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10886 +ENDPROC(atomic_add_unchecked)
10887 +
10888 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10889 BACKOFF_SETUP(%o2)
10890 1: lduw [%o1], %g1
10891 - sub %g1, %o0, %g7
10892 + subcc %g1, %o0, %g7
10893 +
10894 +#ifdef CONFIG_PAX_REFCOUNT
10895 + tvs %icc, 6
10896 +#endif
10897 +
10898 cas [%o1], %g1, %g7
10899 cmp %g1, %g7
10900 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10901 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10902 2: BACKOFF_SPIN(%o2, %o3, 1b)
10903 ENDPROC(atomic_sub)
10904
10905 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10906 + BACKOFF_SETUP(%o2)
10907 +1: lduw [%o1], %g1
10908 + sub %g1, %o0, %g7
10909 + cas [%o1], %g1, %g7
10910 + cmp %g1, %g7
10911 + bne,pn %icc, 2f
10912 + nop
10913 + retl
10914 + nop
10915 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10916 +ENDPROC(atomic_sub_unchecked)
10917 +
10918 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10919 BACKOFF_SETUP(%o2)
10920 1: lduw [%o1], %g1
10921 - add %g1, %o0, %g7
10922 + addcc %g1, %o0, %g7
10923 +
10924 +#ifdef CONFIG_PAX_REFCOUNT
10925 + tvs %icc, 6
10926 +#endif
10927 +
10928 cas [%o1], %g1, %g7
10929 cmp %g1, %g7
10930 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10931 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10932 2: BACKOFF_SPIN(%o2, %o3, 1b)
10933 ENDPROC(atomic_add_ret)
10934
10935 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10936 + BACKOFF_SETUP(%o2)
10937 +1: lduw [%o1], %g1
10938 + addcc %g1, %o0, %g7
10939 + cas [%o1], %g1, %g7
10940 + cmp %g1, %g7
10941 + bne,pn %icc, 2f
10942 + add %g7, %o0, %g7
10943 + sra %g7, 0, %o0
10944 + retl
10945 + nop
10946 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10947 +ENDPROC(atomic_add_ret_unchecked)
10948 +
10949 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10950 BACKOFF_SETUP(%o2)
10951 1: lduw [%o1], %g1
10952 - sub %g1, %o0, %g7
10953 + subcc %g1, %o0, %g7
10954 +
10955 +#ifdef CONFIG_PAX_REFCOUNT
10956 + tvs %icc, 6
10957 +#endif
10958 +
10959 cas [%o1], %g1, %g7
10960 cmp %g1, %g7
10961 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10962 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10963 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10964 BACKOFF_SETUP(%o2)
10965 1: ldx [%o1], %g1
10966 - add %g1, %o0, %g7
10967 + addcc %g1, %o0, %g7
10968 +
10969 +#ifdef CONFIG_PAX_REFCOUNT
10970 + tvs %xcc, 6
10971 +#endif
10972 +
10973 casx [%o1], %g1, %g7
10974 cmp %g1, %g7
10975 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10976 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10977 2: BACKOFF_SPIN(%o2, %o3, 1b)
10978 ENDPROC(atomic64_add)
10979
10980 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10981 + BACKOFF_SETUP(%o2)
10982 +1: ldx [%o1], %g1
10983 + addcc %g1, %o0, %g7
10984 + casx [%o1], %g1, %g7
10985 + cmp %g1, %g7
10986 + bne,pn %xcc, 2f
10987 + nop
10988 + retl
10989 + nop
10990 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10991 +ENDPROC(atomic64_add_unchecked)
10992 +
10993 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10994 BACKOFF_SETUP(%o2)
10995 1: ldx [%o1], %g1
10996 - sub %g1, %o0, %g7
10997 + subcc %g1, %o0, %g7
10998 +
10999 +#ifdef CONFIG_PAX_REFCOUNT
11000 + tvs %xcc, 6
11001 +#endif
11002 +
11003 casx [%o1], %g1, %g7
11004 cmp %g1, %g7
11005 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11006 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11007 2: BACKOFF_SPIN(%o2, %o3, 1b)
11008 ENDPROC(atomic64_sub)
11009
11010 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11011 + BACKOFF_SETUP(%o2)
11012 +1: ldx [%o1], %g1
11013 + subcc %g1, %o0, %g7
11014 + casx [%o1], %g1, %g7
11015 + cmp %g1, %g7
11016 + bne,pn %xcc, 2f
11017 + nop
11018 + retl
11019 + nop
11020 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11021 +ENDPROC(atomic64_sub_unchecked)
11022 +
11023 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11024 BACKOFF_SETUP(%o2)
11025 1: ldx [%o1], %g1
11026 - add %g1, %o0, %g7
11027 + addcc %g1, %o0, %g7
11028 +
11029 +#ifdef CONFIG_PAX_REFCOUNT
11030 + tvs %xcc, 6
11031 +#endif
11032 +
11033 casx [%o1], %g1, %g7
11034 cmp %g1, %g7
11035 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11036 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11037 2: BACKOFF_SPIN(%o2, %o3, 1b)
11038 ENDPROC(atomic64_add_ret)
11039
11040 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11041 + BACKOFF_SETUP(%o2)
11042 +1: ldx [%o1], %g1
11043 + addcc %g1, %o0, %g7
11044 + casx [%o1], %g1, %g7
11045 + cmp %g1, %g7
11046 + bne,pn %xcc, 2f
11047 + add %g7, %o0, %g7
11048 + mov %g7, %o0
11049 + retl
11050 + nop
11051 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11052 +ENDPROC(atomic64_add_ret_unchecked)
11053 +
11054 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11055 BACKOFF_SETUP(%o2)
11056 1: ldx [%o1], %g1
11057 - sub %g1, %o0, %g7
11058 + subcc %g1, %o0, %g7
11059 +
11060 +#ifdef CONFIG_PAX_REFCOUNT
11061 + tvs %xcc, 6
11062 +#endif
11063 +
11064 casx [%o1], %g1, %g7
11065 cmp %g1, %g7
11066 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11067 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11068 index 323335b..ed85ea2 100644
11069 --- a/arch/sparc/lib/ksyms.c
11070 +++ b/arch/sparc/lib/ksyms.c
11071 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11072
11073 /* Atomic counter implementation. */
11074 EXPORT_SYMBOL(atomic_add);
11075 +EXPORT_SYMBOL(atomic_add_unchecked);
11076 EXPORT_SYMBOL(atomic_add_ret);
11077 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11078 EXPORT_SYMBOL(atomic_sub);
11079 +EXPORT_SYMBOL(atomic_sub_unchecked);
11080 EXPORT_SYMBOL(atomic_sub_ret);
11081 EXPORT_SYMBOL(atomic64_add);
11082 +EXPORT_SYMBOL(atomic64_add_unchecked);
11083 EXPORT_SYMBOL(atomic64_add_ret);
11084 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11085 EXPORT_SYMBOL(atomic64_sub);
11086 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11087 EXPORT_SYMBOL(atomic64_sub_ret);
11088 EXPORT_SYMBOL(atomic64_dec_if_positive);
11089
11090 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11091 index 30c3ecc..736f015 100644
11092 --- a/arch/sparc/mm/Makefile
11093 +++ b/arch/sparc/mm/Makefile
11094 @@ -2,7 +2,7 @@
11095 #
11096
11097 asflags-y := -ansi
11098 -ccflags-y := -Werror
11099 +#ccflags-y := -Werror
11100
11101 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11102 obj-y += fault_$(BITS).o
11103 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11104 index 59dbd46..1dd7f5e 100644
11105 --- a/arch/sparc/mm/fault_32.c
11106 +++ b/arch/sparc/mm/fault_32.c
11107 @@ -21,6 +21,9 @@
11108 #include <linux/perf_event.h>
11109 #include <linux/interrupt.h>
11110 #include <linux/kdebug.h>
11111 +#include <linux/slab.h>
11112 +#include <linux/pagemap.h>
11113 +#include <linux/compiler.h>
11114
11115 #include <asm/page.h>
11116 #include <asm/pgtable.h>
11117 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11118 return safe_compute_effective_address(regs, insn);
11119 }
11120
11121 +#ifdef CONFIG_PAX_PAGEEXEC
11122 +#ifdef CONFIG_PAX_DLRESOLVE
11123 +static void pax_emuplt_close(struct vm_area_struct *vma)
11124 +{
11125 + vma->vm_mm->call_dl_resolve = 0UL;
11126 +}
11127 +
11128 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11129 +{
11130 + unsigned int *kaddr;
11131 +
11132 + vmf->page = alloc_page(GFP_HIGHUSER);
11133 + if (!vmf->page)
11134 + return VM_FAULT_OOM;
11135 +
11136 + kaddr = kmap(vmf->page);
11137 + memset(kaddr, 0, PAGE_SIZE);
11138 + kaddr[0] = 0x9DE3BFA8U; /* save */
11139 + flush_dcache_page(vmf->page);
11140 + kunmap(vmf->page);
11141 + return VM_FAULT_MAJOR;
11142 +}
11143 +
11144 +static const struct vm_operations_struct pax_vm_ops = {
11145 + .close = pax_emuplt_close,
11146 + .fault = pax_emuplt_fault
11147 +};
11148 +
11149 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11150 +{
11151 + int ret;
11152 +
11153 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11154 + vma->vm_mm = current->mm;
11155 + vma->vm_start = addr;
11156 + vma->vm_end = addr + PAGE_SIZE;
11157 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11158 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11159 + vma->vm_ops = &pax_vm_ops;
11160 +
11161 + ret = insert_vm_struct(current->mm, vma);
11162 + if (ret)
11163 + return ret;
11164 +
11165 + ++current->mm->total_vm;
11166 + return 0;
11167 +}
11168 +#endif
11169 +
11170 +/*
11171 + * PaX: decide what to do with offenders (regs->pc = fault address)
11172 + *
11173 + * returns 1 when task should be killed
11174 + * 2 when patched PLT trampoline was detected
11175 + * 3 when unpatched PLT trampoline was detected
11176 + */
11177 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11178 +{
11179 +
11180 +#ifdef CONFIG_PAX_EMUPLT
11181 + int err;
11182 +
11183 + do { /* PaX: patched PLT emulation #1 */
11184 + unsigned int sethi1, sethi2, jmpl;
11185 +
11186 + err = get_user(sethi1, (unsigned int *)regs->pc);
11187 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11188 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11189 +
11190 + if (err)
11191 + break;
11192 +
11193 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11194 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11195 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11196 + {
11197 + unsigned int addr;
11198 +
11199 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11200 + addr = regs->u_regs[UREG_G1];
11201 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11202 + regs->pc = addr;
11203 + regs->npc = addr+4;
11204 + return 2;
11205 + }
11206 + } while (0);
11207 +
11208 + do { /* PaX: patched PLT emulation #2 */
11209 + unsigned int ba;
11210 +
11211 + err = get_user(ba, (unsigned int *)regs->pc);
11212 +
11213 + if (err)
11214 + break;
11215 +
11216 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11217 + unsigned int addr;
11218 +
11219 + if ((ba & 0xFFC00000U) == 0x30800000U)
11220 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11221 + else
11222 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11223 + regs->pc = addr;
11224 + regs->npc = addr+4;
11225 + return 2;
11226 + }
11227 + } while (0);
11228 +
11229 + do { /* PaX: patched PLT emulation #3 */
11230 + unsigned int sethi, bajmpl, nop;
11231 +
11232 + err = get_user(sethi, (unsigned int *)regs->pc);
11233 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11234 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11235 +
11236 + if (err)
11237 + break;
11238 +
11239 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11240 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11241 + nop == 0x01000000U)
11242 + {
11243 + unsigned int addr;
11244 +
11245 + addr = (sethi & 0x003FFFFFU) << 10;
11246 + regs->u_regs[UREG_G1] = addr;
11247 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11248 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11249 + else
11250 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11251 + regs->pc = addr;
11252 + regs->npc = addr+4;
11253 + return 2;
11254 + }
11255 + } while (0);
11256 +
11257 + do { /* PaX: unpatched PLT emulation step 1 */
11258 + unsigned int sethi, ba, nop;
11259 +
11260 + err = get_user(sethi, (unsigned int *)regs->pc);
11261 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11262 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11263 +
11264 + if (err)
11265 + break;
11266 +
11267 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11268 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11269 + nop == 0x01000000U)
11270 + {
11271 + unsigned int addr, save, call;
11272 +
11273 + if ((ba & 0xFFC00000U) == 0x30800000U)
11274 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11275 + else
11276 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11277 +
11278 + err = get_user(save, (unsigned int *)addr);
11279 + err |= get_user(call, (unsigned int *)(addr+4));
11280 + err |= get_user(nop, (unsigned int *)(addr+8));
11281 + if (err)
11282 + break;
11283 +
11284 +#ifdef CONFIG_PAX_DLRESOLVE
11285 + if (save == 0x9DE3BFA8U &&
11286 + (call & 0xC0000000U) == 0x40000000U &&
11287 + nop == 0x01000000U)
11288 + {
11289 + struct vm_area_struct *vma;
11290 + unsigned long call_dl_resolve;
11291 +
11292 + down_read(&current->mm->mmap_sem);
11293 + call_dl_resolve = current->mm->call_dl_resolve;
11294 + up_read(&current->mm->mmap_sem);
11295 + if (likely(call_dl_resolve))
11296 + goto emulate;
11297 +
11298 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11299 +
11300 + down_write(&current->mm->mmap_sem);
11301 + if (current->mm->call_dl_resolve) {
11302 + call_dl_resolve = current->mm->call_dl_resolve;
11303 + up_write(&current->mm->mmap_sem);
11304 + if (vma)
11305 + kmem_cache_free(vm_area_cachep, vma);
11306 + goto emulate;
11307 + }
11308 +
11309 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11310 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11311 + up_write(&current->mm->mmap_sem);
11312 + if (vma)
11313 + kmem_cache_free(vm_area_cachep, vma);
11314 + return 1;
11315 + }
11316 +
11317 + if (pax_insert_vma(vma, call_dl_resolve)) {
11318 + up_write(&current->mm->mmap_sem);
11319 + kmem_cache_free(vm_area_cachep, vma);
11320 + return 1;
11321 + }
11322 +
11323 + current->mm->call_dl_resolve = call_dl_resolve;
11324 + up_write(&current->mm->mmap_sem);
11325 +
11326 +emulate:
11327 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11328 + regs->pc = call_dl_resolve;
11329 + regs->npc = addr+4;
11330 + return 3;
11331 + }
11332 +#endif
11333 +
11334 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11335 + if ((save & 0xFFC00000U) == 0x05000000U &&
11336 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11337 + nop == 0x01000000U)
11338 + {
11339 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11340 + regs->u_regs[UREG_G2] = addr + 4;
11341 + addr = (save & 0x003FFFFFU) << 10;
11342 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11343 + regs->pc = addr;
11344 + regs->npc = addr+4;
11345 + return 3;
11346 + }
11347 + }
11348 + } while (0);
11349 +
11350 + do { /* PaX: unpatched PLT emulation step 2 */
11351 + unsigned int save, call, nop;
11352 +
11353 + err = get_user(save, (unsigned int *)(regs->pc-4));
11354 + err |= get_user(call, (unsigned int *)regs->pc);
11355 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11356 + if (err)
11357 + break;
11358 +
11359 + if (save == 0x9DE3BFA8U &&
11360 + (call & 0xC0000000U) == 0x40000000U &&
11361 + nop == 0x01000000U)
11362 + {
11363 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11364 +
11365 + regs->u_regs[UREG_RETPC] = regs->pc;
11366 + regs->pc = dl_resolve;
11367 + regs->npc = dl_resolve+4;
11368 + return 3;
11369 + }
11370 + } while (0);
11371 +#endif
11372 +
11373 + return 1;
11374 +}
11375 +
11376 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11377 +{
11378 + unsigned long i;
11379 +
11380 + printk(KERN_ERR "PAX: bytes at PC: ");
11381 + for (i = 0; i < 8; i++) {
11382 + unsigned int c;
11383 + if (get_user(c, (unsigned int *)pc+i))
11384 + printk(KERN_CONT "???????? ");
11385 + else
11386 + printk(KERN_CONT "%08x ", c);
11387 + }
11388 + printk("\n");
11389 +}
11390 +#endif
11391 +
11392 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11393 int text_fault)
11394 {
11395 @@ -229,6 +503,24 @@ good_area:
11396 if (!(vma->vm_flags & VM_WRITE))
11397 goto bad_area;
11398 } else {
11399 +
11400 +#ifdef CONFIG_PAX_PAGEEXEC
11401 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11402 + up_read(&mm->mmap_sem);
11403 + switch (pax_handle_fetch_fault(regs)) {
11404 +
11405 +#ifdef CONFIG_PAX_EMUPLT
11406 + case 2:
11407 + case 3:
11408 + return;
11409 +#endif
11410 +
11411 + }
11412 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11413 + do_group_exit(SIGKILL);
11414 + }
11415 +#endif
11416 +
11417 /* Allow reads even for write-only mappings */
11418 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11419 goto bad_area;
11420 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11421 index 4ced3fc..234f1e4 100644
11422 --- a/arch/sparc/mm/fault_64.c
11423 +++ b/arch/sparc/mm/fault_64.c
11424 @@ -22,6 +22,9 @@
11425 #include <linux/kdebug.h>
11426 #include <linux/percpu.h>
11427 #include <linux/context_tracking.h>
11428 +#include <linux/slab.h>
11429 +#include <linux/pagemap.h>
11430 +#include <linux/compiler.h>
11431
11432 #include <asm/page.h>
11433 #include <asm/pgtable.h>
11434 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11435 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11436 regs->tpc);
11437 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11438 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11439 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11440 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11441 dump_stack();
11442 unhandled_fault(regs->tpc, current, regs);
11443 @@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11444 show_regs(regs);
11445 }
11446
11447 +#ifdef CONFIG_PAX_PAGEEXEC
11448 +#ifdef CONFIG_PAX_DLRESOLVE
11449 +static void pax_emuplt_close(struct vm_area_struct *vma)
11450 +{
11451 + vma->vm_mm->call_dl_resolve = 0UL;
11452 +}
11453 +
11454 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11455 +{
11456 + unsigned int *kaddr;
11457 +
11458 + vmf->page = alloc_page(GFP_HIGHUSER);
11459 + if (!vmf->page)
11460 + return VM_FAULT_OOM;
11461 +
11462 + kaddr = kmap(vmf->page);
11463 + memset(kaddr, 0, PAGE_SIZE);
11464 + kaddr[0] = 0x9DE3BFA8U; /* save */
11465 + flush_dcache_page(vmf->page);
11466 + kunmap(vmf->page);
11467 + return VM_FAULT_MAJOR;
11468 +}
11469 +
11470 +static const struct vm_operations_struct pax_vm_ops = {
11471 + .close = pax_emuplt_close,
11472 + .fault = pax_emuplt_fault
11473 +};
11474 +
11475 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11476 +{
11477 + int ret;
11478 +
11479 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11480 + vma->vm_mm = current->mm;
11481 + vma->vm_start = addr;
11482 + vma->vm_end = addr + PAGE_SIZE;
11483 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11484 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11485 + vma->vm_ops = &pax_vm_ops;
11486 +
11487 + ret = insert_vm_struct(current->mm, vma);
11488 + if (ret)
11489 + return ret;
11490 +
11491 + ++current->mm->total_vm;
11492 + return 0;
11493 +}
11494 +#endif
11495 +
11496 +/*
11497 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11498 + *
11499 + * returns 1 when task should be killed
11500 + * 2 when patched PLT trampoline was detected
11501 + * 3 when unpatched PLT trampoline was detected
11502 + */
11503 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11504 +{
11505 +
11506 +#ifdef CONFIG_PAX_EMUPLT
11507 + int err;
11508 +
11509 + do { /* PaX: patched PLT emulation #1 */
11510 + unsigned int sethi1, sethi2, jmpl;
11511 +
11512 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11513 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11514 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11515 +
11516 + if (err)
11517 + break;
11518 +
11519 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11520 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11521 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11522 + {
11523 + unsigned long addr;
11524 +
11525 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11526 + addr = regs->u_regs[UREG_G1];
11527 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11528 +
11529 + if (test_thread_flag(TIF_32BIT))
11530 + addr &= 0xFFFFFFFFUL;
11531 +
11532 + regs->tpc = addr;
11533 + regs->tnpc = addr+4;
11534 + return 2;
11535 + }
11536 + } while (0);
11537 +
11538 + do { /* PaX: patched PLT emulation #2 */
11539 + unsigned int ba;
11540 +
11541 + err = get_user(ba, (unsigned int *)regs->tpc);
11542 +
11543 + if (err)
11544 + break;
11545 +
11546 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11547 + unsigned long addr;
11548 +
11549 + if ((ba & 0xFFC00000U) == 0x30800000U)
11550 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11551 + else
11552 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11553 +
11554 + if (test_thread_flag(TIF_32BIT))
11555 + addr &= 0xFFFFFFFFUL;
11556 +
11557 + regs->tpc = addr;
11558 + regs->tnpc = addr+4;
11559 + return 2;
11560 + }
11561 + } while (0);
11562 +
11563 + do { /* PaX: patched PLT emulation #3 */
11564 + unsigned int sethi, bajmpl, nop;
11565 +
11566 + err = get_user(sethi, (unsigned int *)regs->tpc);
11567 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11568 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11569 +
11570 + if (err)
11571 + break;
11572 +
11573 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11574 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11575 + nop == 0x01000000U)
11576 + {
11577 + unsigned long addr;
11578 +
11579 + addr = (sethi & 0x003FFFFFU) << 10;
11580 + regs->u_regs[UREG_G1] = addr;
11581 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11582 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11583 + else
11584 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11585 +
11586 + if (test_thread_flag(TIF_32BIT))
11587 + addr &= 0xFFFFFFFFUL;
11588 +
11589 + regs->tpc = addr;
11590 + regs->tnpc = addr+4;
11591 + return 2;
11592 + }
11593 + } while (0);
11594 +
11595 + do { /* PaX: patched PLT emulation #4 */
11596 + unsigned int sethi, mov1, call, mov2;
11597 +
11598 + err = get_user(sethi, (unsigned int *)regs->tpc);
11599 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11600 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11601 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11602 +
11603 + if (err)
11604 + break;
11605 +
11606 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11607 + mov1 == 0x8210000FU &&
11608 + (call & 0xC0000000U) == 0x40000000U &&
11609 + mov2 == 0x9E100001U)
11610 + {
11611 + unsigned long addr;
11612 +
11613 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11614 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11615 +
11616 + if (test_thread_flag(TIF_32BIT))
11617 + addr &= 0xFFFFFFFFUL;
11618 +
11619 + regs->tpc = addr;
11620 + regs->tnpc = addr+4;
11621 + return 2;
11622 + }
11623 + } while (0);
11624 +
11625 + do { /* PaX: patched PLT emulation #5 */
11626 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11627 +
11628 + err = get_user(sethi, (unsigned int *)regs->tpc);
11629 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11630 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11631 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11632 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11633 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11634 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11635 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11636 +
11637 + if (err)
11638 + break;
11639 +
11640 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11641 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11642 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11643 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11644 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11645 + sllx == 0x83287020U &&
11646 + jmpl == 0x81C04005U &&
11647 + nop == 0x01000000U)
11648 + {
11649 + unsigned long addr;
11650 +
11651 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11652 + regs->u_regs[UREG_G1] <<= 32;
11653 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11654 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11655 + regs->tpc = addr;
11656 + regs->tnpc = addr+4;
11657 + return 2;
11658 + }
11659 + } while (0);
11660 +
11661 + do { /* PaX: patched PLT emulation #6 */
11662 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11663 +
11664 + err = get_user(sethi, (unsigned int *)regs->tpc);
11665 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11666 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11667 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11668 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11669 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11670 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11671 +
11672 + if (err)
11673 + break;
11674 +
11675 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11676 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11677 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11678 + sllx == 0x83287020U &&
11679 + (or & 0xFFFFE000U) == 0x8A116000U &&
11680 + jmpl == 0x81C04005U &&
11681 + nop == 0x01000000U)
11682 + {
11683 + unsigned long addr;
11684 +
11685 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11686 + regs->u_regs[UREG_G1] <<= 32;
11687 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11688 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11689 + regs->tpc = addr;
11690 + regs->tnpc = addr+4;
11691 + return 2;
11692 + }
11693 + } while (0);
11694 +
11695 + do { /* PaX: unpatched PLT emulation step 1 */
11696 + unsigned int sethi, ba, nop;
11697 +
11698 + err = get_user(sethi, (unsigned int *)regs->tpc);
11699 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11700 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11701 +
11702 + if (err)
11703 + break;
11704 +
11705 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11706 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11707 + nop == 0x01000000U)
11708 + {
11709 + unsigned long addr;
11710 + unsigned int save, call;
11711 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11712 +
11713 + if ((ba & 0xFFC00000U) == 0x30800000U)
11714 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11715 + else
11716 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11717 +
11718 + if (test_thread_flag(TIF_32BIT))
11719 + addr &= 0xFFFFFFFFUL;
11720 +
11721 + err = get_user(save, (unsigned int *)addr);
11722 + err |= get_user(call, (unsigned int *)(addr+4));
11723 + err |= get_user(nop, (unsigned int *)(addr+8));
11724 + if (err)
11725 + break;
11726 +
11727 +#ifdef CONFIG_PAX_DLRESOLVE
11728 + if (save == 0x9DE3BFA8U &&
11729 + (call & 0xC0000000U) == 0x40000000U &&
11730 + nop == 0x01000000U)
11731 + {
11732 + struct vm_area_struct *vma;
11733 + unsigned long call_dl_resolve;
11734 +
11735 + down_read(&current->mm->mmap_sem);
11736 + call_dl_resolve = current->mm->call_dl_resolve;
11737 + up_read(&current->mm->mmap_sem);
11738 + if (likely(call_dl_resolve))
11739 + goto emulate;
11740 +
11741 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11742 +
11743 + down_write(&current->mm->mmap_sem);
11744 + if (current->mm->call_dl_resolve) {
11745 + call_dl_resolve = current->mm->call_dl_resolve;
11746 + up_write(&current->mm->mmap_sem);
11747 + if (vma)
11748 + kmem_cache_free(vm_area_cachep, vma);
11749 + goto emulate;
11750 + }
11751 +
11752 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11753 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11754 + up_write(&current->mm->mmap_sem);
11755 + if (vma)
11756 + kmem_cache_free(vm_area_cachep, vma);
11757 + return 1;
11758 + }
11759 +
11760 + if (pax_insert_vma(vma, call_dl_resolve)) {
11761 + up_write(&current->mm->mmap_sem);
11762 + kmem_cache_free(vm_area_cachep, vma);
11763 + return 1;
11764 + }
11765 +
11766 + current->mm->call_dl_resolve = call_dl_resolve;
11767 + up_write(&current->mm->mmap_sem);
11768 +
11769 +emulate:
11770 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11771 + regs->tpc = call_dl_resolve;
11772 + regs->tnpc = addr+4;
11773 + return 3;
11774 + }
11775 +#endif
11776 +
11777 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11778 + if ((save & 0xFFC00000U) == 0x05000000U &&
11779 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11780 + nop == 0x01000000U)
11781 + {
11782 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11783 + regs->u_regs[UREG_G2] = addr + 4;
11784 + addr = (save & 0x003FFFFFU) << 10;
11785 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11786 +
11787 + if (test_thread_flag(TIF_32BIT))
11788 + addr &= 0xFFFFFFFFUL;
11789 +
11790 + regs->tpc = addr;
11791 + regs->tnpc = addr+4;
11792 + return 3;
11793 + }
11794 +
11795 + /* PaX: 64-bit PLT stub */
11796 + err = get_user(sethi1, (unsigned int *)addr);
11797 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11798 + err |= get_user(or1, (unsigned int *)(addr+8));
11799 + err |= get_user(or2, (unsigned int *)(addr+12));
11800 + err |= get_user(sllx, (unsigned int *)(addr+16));
11801 + err |= get_user(add, (unsigned int *)(addr+20));
11802 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11803 + err |= get_user(nop, (unsigned int *)(addr+28));
11804 + if (err)
11805 + break;
11806 +
11807 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11808 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11809 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11810 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11811 + sllx == 0x89293020U &&
11812 + add == 0x8A010005U &&
11813 + jmpl == 0x89C14000U &&
11814 + nop == 0x01000000U)
11815 + {
11816 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11817 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11818 + regs->u_regs[UREG_G4] <<= 32;
11819 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11820 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11821 + regs->u_regs[UREG_G4] = addr + 24;
11822 + addr = regs->u_regs[UREG_G5];
11823 + regs->tpc = addr;
11824 + regs->tnpc = addr+4;
11825 + return 3;
11826 + }
11827 + }
11828 + } while (0);
11829 +
11830 +#ifdef CONFIG_PAX_DLRESOLVE
11831 + do { /* PaX: unpatched PLT emulation step 2 */
11832 + unsigned int save, call, nop;
11833 +
11834 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11835 + err |= get_user(call, (unsigned int *)regs->tpc);
11836 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11837 + if (err)
11838 + break;
11839 +
11840 + if (save == 0x9DE3BFA8U &&
11841 + (call & 0xC0000000U) == 0x40000000U &&
11842 + nop == 0x01000000U)
11843 + {
11844 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11845 +
11846 + if (test_thread_flag(TIF_32BIT))
11847 + dl_resolve &= 0xFFFFFFFFUL;
11848 +
11849 + regs->u_regs[UREG_RETPC] = regs->tpc;
11850 + regs->tpc = dl_resolve;
11851 + regs->tnpc = dl_resolve+4;
11852 + return 3;
11853 + }
11854 + } while (0);
11855 +#endif
11856 +
11857 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11858 + unsigned int sethi, ba, nop;
11859 +
11860 + err = get_user(sethi, (unsigned int *)regs->tpc);
11861 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11862 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11863 +
11864 + if (err)
11865 + break;
11866 +
11867 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11868 + (ba & 0xFFF00000U) == 0x30600000U &&
11869 + nop == 0x01000000U)
11870 + {
11871 + unsigned long addr;
11872 +
11873 + addr = (sethi & 0x003FFFFFU) << 10;
11874 + regs->u_regs[UREG_G1] = addr;
11875 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11876 +
11877 + if (test_thread_flag(TIF_32BIT))
11878 + addr &= 0xFFFFFFFFUL;
11879 +
11880 + regs->tpc = addr;
11881 + regs->tnpc = addr+4;
11882 + return 2;
11883 + }
11884 + } while (0);
11885 +
11886 +#endif
11887 +
11888 + return 1;
11889 +}
11890 +
11891 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11892 +{
11893 + unsigned long i;
11894 +
11895 + printk(KERN_ERR "PAX: bytes at PC: ");
11896 + for (i = 0; i < 8; i++) {
11897 + unsigned int c;
11898 + if (get_user(c, (unsigned int *)pc+i))
11899 + printk(KERN_CONT "???????? ");
11900 + else
11901 + printk(KERN_CONT "%08x ", c);
11902 + }
11903 + printk("\n");
11904 +}
11905 +#endif
11906 +
11907 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11908 {
11909 enum ctx_state prev_state = exception_enter();
11910 @@ -352,6 +815,29 @@ retry:
11911 if (!vma)
11912 goto bad_area;
11913
11914 +#ifdef CONFIG_PAX_PAGEEXEC
11915 + /* PaX: detect ITLB misses on non-exec pages */
11916 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11917 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11918 + {
11919 + if (address != regs->tpc)
11920 + goto good_area;
11921 +
11922 + up_read(&mm->mmap_sem);
11923 + switch (pax_handle_fetch_fault(regs)) {
11924 +
11925 +#ifdef CONFIG_PAX_EMUPLT
11926 + case 2:
11927 + case 3:
11928 + return;
11929 +#endif
11930 +
11931 + }
11932 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11933 + do_group_exit(SIGKILL);
11934 + }
11935 +#endif
11936 +
11937 /* Pure DTLB misses do not tell us whether the fault causing
11938 * load/store/atomic was a write or not, it only says that there
11939 * was no match. So in such a case we (carefully) read the
11940 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11941 index d329537..2c3746a 100644
11942 --- a/arch/sparc/mm/hugetlbpage.c
11943 +++ b/arch/sparc/mm/hugetlbpage.c
11944 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11945 unsigned long addr,
11946 unsigned long len,
11947 unsigned long pgoff,
11948 - unsigned long flags)
11949 + unsigned long flags,
11950 + unsigned long offset)
11951 {
11952 + struct mm_struct *mm = current->mm;
11953 unsigned long task_size = TASK_SIZE;
11954 struct vm_unmapped_area_info info;
11955
11956 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11957
11958 info.flags = 0;
11959 info.length = len;
11960 - info.low_limit = TASK_UNMAPPED_BASE;
11961 + info.low_limit = mm->mmap_base;
11962 info.high_limit = min(task_size, VA_EXCLUDE_START);
11963 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11964 info.align_offset = 0;
11965 + info.threadstack_offset = offset;
11966 addr = vm_unmapped_area(&info);
11967
11968 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11969 VM_BUG_ON(addr != -ENOMEM);
11970 info.low_limit = VA_EXCLUDE_END;
11971 +
11972 +#ifdef CONFIG_PAX_RANDMMAP
11973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11974 + info.low_limit += mm->delta_mmap;
11975 +#endif
11976 +
11977 info.high_limit = task_size;
11978 addr = vm_unmapped_area(&info);
11979 }
11980 @@ -55,7 +64,8 @@ static unsigned long
11981 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11982 const unsigned long len,
11983 const unsigned long pgoff,
11984 - const unsigned long flags)
11985 + const unsigned long flags,
11986 + const unsigned long offset)
11987 {
11988 struct mm_struct *mm = current->mm;
11989 unsigned long addr = addr0;
11990 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11991 info.high_limit = mm->mmap_base;
11992 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11993 info.align_offset = 0;
11994 + info.threadstack_offset = offset;
11995 addr = vm_unmapped_area(&info);
11996
11997 /*
11998 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11999 VM_BUG_ON(addr != -ENOMEM);
12000 info.flags = 0;
12001 info.low_limit = TASK_UNMAPPED_BASE;
12002 +
12003 +#ifdef CONFIG_PAX_RANDMMAP
12004 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12005 + info.low_limit += mm->delta_mmap;
12006 +#endif
12007 +
12008 info.high_limit = STACK_TOP32;
12009 addr = vm_unmapped_area(&info);
12010 }
12011 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12012 struct mm_struct *mm = current->mm;
12013 struct vm_area_struct *vma;
12014 unsigned long task_size = TASK_SIZE;
12015 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12016
12017 if (test_thread_flag(TIF_32BIT))
12018 task_size = STACK_TOP32;
12019 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12020 return addr;
12021 }
12022
12023 +#ifdef CONFIG_PAX_RANDMMAP
12024 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12025 +#endif
12026 +
12027 if (addr) {
12028 addr = ALIGN(addr, HPAGE_SIZE);
12029 vma = find_vma(mm, addr);
12030 - if (task_size - len >= addr &&
12031 - (!vma || addr + len <= vma->vm_start))
12032 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12033 return addr;
12034 }
12035 if (mm->get_unmapped_area == arch_get_unmapped_area)
12036 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12037 - pgoff, flags);
12038 + pgoff, flags, offset);
12039 else
12040 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12041 - pgoff, flags);
12042 + pgoff, flags, offset);
12043 }
12044
12045 pte_t *huge_pte_alloc(struct mm_struct *mm,
12046 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12047 index ed3c969..42fe48d 100644
12048 --- a/arch/sparc/mm/init_64.c
12049 +++ b/arch/sparc/mm/init_64.c
12050 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12051 int num_kernel_image_mappings;
12052
12053 #ifdef CONFIG_DEBUG_DCFLUSH
12054 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12055 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12056 #ifdef CONFIG_SMP
12057 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12058 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12059 #endif
12060 #endif
12061
12062 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12063 {
12064 BUG_ON(tlb_type == hypervisor);
12065 #ifdef CONFIG_DEBUG_DCFLUSH
12066 - atomic_inc(&dcpage_flushes);
12067 + atomic_inc_unchecked(&dcpage_flushes);
12068 #endif
12069
12070 #ifdef DCACHE_ALIASING_POSSIBLE
12071 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12072
12073 #ifdef CONFIG_DEBUG_DCFLUSH
12074 seq_printf(m, "DCPageFlushes\t: %d\n",
12075 - atomic_read(&dcpage_flushes));
12076 + atomic_read_unchecked(&dcpage_flushes));
12077 #ifdef CONFIG_SMP
12078 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12079 - atomic_read(&dcpage_flushes_xcall));
12080 + atomic_read_unchecked(&dcpage_flushes_xcall));
12081 #endif /* CONFIG_SMP */
12082 #endif /* CONFIG_DEBUG_DCFLUSH */
12083 }
12084 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12085 index 85258ca..df97c79 100644
12086 --- a/arch/tile/Kconfig
12087 +++ b/arch/tile/Kconfig
12088 @@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12089
12090 config KEXEC
12091 bool "kexec system call"
12092 + depends on !GRKERNSEC_KMEM
12093 ---help---
12094 kexec is a system call that implements the ability to shutdown your
12095 current kernel, and to start another kernel. It is like a reboot
12096 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12097 index ad220ee..2f537b3 100644
12098 --- a/arch/tile/include/asm/atomic_64.h
12099 +++ b/arch/tile/include/asm/atomic_64.h
12100 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12101
12102 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12103
12104 +#define atomic64_read_unchecked(v) atomic64_read(v)
12105 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12106 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12107 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12108 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12109 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12110 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12111 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12112 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12113 +
12114 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12115 #define smp_mb__before_atomic_dec() smp_mb()
12116 #define smp_mb__after_atomic_dec() smp_mb()
12117 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12118 index 6160761..00cac88 100644
12119 --- a/arch/tile/include/asm/cache.h
12120 +++ b/arch/tile/include/asm/cache.h
12121 @@ -15,11 +15,12 @@
12122 #ifndef _ASM_TILE_CACHE_H
12123 #define _ASM_TILE_CACHE_H
12124
12125 +#include <linux/const.h>
12126 #include <arch/chip.h>
12127
12128 /* bytes per L1 data cache line */
12129 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12130 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12131 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12132
12133 /* bytes per L2 cache line */
12134 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12135 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12136 index b6cde32..c0cb736 100644
12137 --- a/arch/tile/include/asm/uaccess.h
12138 +++ b/arch/tile/include/asm/uaccess.h
12139 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12140 const void __user *from,
12141 unsigned long n)
12142 {
12143 - int sz = __compiletime_object_size(to);
12144 + size_t sz = __compiletime_object_size(to);
12145
12146 - if (likely(sz == -1 || sz >= n))
12147 + if (likely(sz == (size_t)-1 || sz >= n))
12148 n = _copy_from_user(to, from, n);
12149 else
12150 copy_from_user_overflow();
12151 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12152 index e514899..f8743c4 100644
12153 --- a/arch/tile/mm/hugetlbpage.c
12154 +++ b/arch/tile/mm/hugetlbpage.c
12155 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12156 info.high_limit = TASK_SIZE;
12157 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12158 info.align_offset = 0;
12159 + info.threadstack_offset = 0;
12160 return vm_unmapped_area(&info);
12161 }
12162
12163 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12164 info.high_limit = current->mm->mmap_base;
12165 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12166 info.align_offset = 0;
12167 + info.threadstack_offset = 0;
12168 addr = vm_unmapped_area(&info);
12169
12170 /*
12171 diff --git a/arch/um/Makefile b/arch/um/Makefile
12172 index 36e658a..71a5c5a 100644
12173 --- a/arch/um/Makefile
12174 +++ b/arch/um/Makefile
12175 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12176 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12177 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12178
12179 +ifdef CONSTIFY_PLUGIN
12180 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12181 +endif
12182 +
12183 #This will adjust *FLAGS accordingly to the platform.
12184 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12185
12186 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12187 index 19e1bdd..3665b77 100644
12188 --- a/arch/um/include/asm/cache.h
12189 +++ b/arch/um/include/asm/cache.h
12190 @@ -1,6 +1,7 @@
12191 #ifndef __UM_CACHE_H
12192 #define __UM_CACHE_H
12193
12194 +#include <linux/const.h>
12195
12196 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12197 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12198 @@ -12,6 +13,6 @@
12199 # define L1_CACHE_SHIFT 5
12200 #endif
12201
12202 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12203 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12204
12205 #endif
12206 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12207 index 2e0a6b1..a64d0f5 100644
12208 --- a/arch/um/include/asm/kmap_types.h
12209 +++ b/arch/um/include/asm/kmap_types.h
12210 @@ -8,6 +8,6 @@
12211
12212 /* No more #include "asm/arch/kmap_types.h" ! */
12213
12214 -#define KM_TYPE_NR 14
12215 +#define KM_TYPE_NR 15
12216
12217 #endif
12218 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12219 index 5ff53d9..5850cdf 100644
12220 --- a/arch/um/include/asm/page.h
12221 +++ b/arch/um/include/asm/page.h
12222 @@ -14,6 +14,9 @@
12223 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12224 #define PAGE_MASK (~(PAGE_SIZE-1))
12225
12226 +#define ktla_ktva(addr) (addr)
12227 +#define ktva_ktla(addr) (addr)
12228 +
12229 #ifndef __ASSEMBLY__
12230
12231 struct page;
12232 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12233 index 0032f92..cd151e0 100644
12234 --- a/arch/um/include/asm/pgtable-3level.h
12235 +++ b/arch/um/include/asm/pgtable-3level.h
12236 @@ -58,6 +58,7 @@
12237 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12238 #define pud_populate(mm, pud, pmd) \
12239 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12240 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12241
12242 #ifdef CONFIG_64BIT
12243 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12244 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12245 index f17bca8..48adb87 100644
12246 --- a/arch/um/kernel/process.c
12247 +++ b/arch/um/kernel/process.c
12248 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12249 return 2;
12250 }
12251
12252 -/*
12253 - * Only x86 and x86_64 have an arch_align_stack().
12254 - * All other arches have "#define arch_align_stack(x) (x)"
12255 - * in their asm/exec.h
12256 - * As this is included in UML from asm-um/system-generic.h,
12257 - * we can use it to behave as the subarch does.
12258 - */
12259 -#ifndef arch_align_stack
12260 -unsigned long arch_align_stack(unsigned long sp)
12261 -{
12262 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12263 - sp -= get_random_int() % 8192;
12264 - return sp & ~0xf;
12265 -}
12266 -#endif
12267 -
12268 unsigned long get_wchan(struct task_struct *p)
12269 {
12270 unsigned long stack_page, sp, ip;
12271 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12272 index ad8f795..2c7eec6 100644
12273 --- a/arch/unicore32/include/asm/cache.h
12274 +++ b/arch/unicore32/include/asm/cache.h
12275 @@ -12,8 +12,10 @@
12276 #ifndef __UNICORE_CACHE_H__
12277 #define __UNICORE_CACHE_H__
12278
12279 -#define L1_CACHE_SHIFT (5)
12280 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12281 +#include <linux/const.h>
12282 +
12283 +#define L1_CACHE_SHIFT 5
12284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12285
12286 /*
12287 * Memory returned by kmalloc() may be used for DMA, so we must make
12288 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12289 index 6b8b429..7b21fe4 100644
12290 --- a/arch/x86/Kconfig
12291 +++ b/arch/x86/Kconfig
12292 @@ -127,7 +127,7 @@ config X86
12293 select RTC_LIB
12294 select HAVE_DEBUG_STACKOVERFLOW
12295 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12296 - select HAVE_CC_STACKPROTECTOR
12297 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12298 select GENERIC_CPU_AUTOPROBE
12299 select HAVE_ARCH_AUDITSYSCALL
12300
12301 @@ -251,7 +251,7 @@ config X86_HT
12302
12303 config X86_32_LAZY_GS
12304 def_bool y
12305 - depends on X86_32 && !CC_STACKPROTECTOR
12306 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12307
12308 config ARCH_HWEIGHT_CFLAGS
12309 string
12310 @@ -545,6 +545,7 @@ config SCHED_OMIT_FRAME_POINTER
12311
12312 menuconfig HYPERVISOR_GUEST
12313 bool "Linux guest support"
12314 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12315 ---help---
12316 Say Y here to enable options for running Linux under various hyper-
12317 visors. This option enables basic hypervisor detection and platform
12318 @@ -1054,6 +1055,7 @@ choice
12319
12320 config NOHIGHMEM
12321 bool "off"
12322 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12323 ---help---
12324 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12325 However, the address space of 32-bit x86 processors is only 4
12326 @@ -1090,6 +1092,7 @@ config NOHIGHMEM
12327
12328 config HIGHMEM4G
12329 bool "4GB"
12330 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12331 ---help---
12332 Select this if you have a 32-bit processor and between 1 and 4
12333 gigabytes of physical RAM.
12334 @@ -1142,7 +1145,7 @@ config PAGE_OFFSET
12335 hex
12336 default 0xB0000000 if VMSPLIT_3G_OPT
12337 default 0x80000000 if VMSPLIT_2G
12338 - default 0x78000000 if VMSPLIT_2G_OPT
12339 + default 0x70000000 if VMSPLIT_2G_OPT
12340 default 0x40000000 if VMSPLIT_1G
12341 default 0xC0000000
12342 depends on X86_32
12343 @@ -1555,6 +1558,7 @@ source kernel/Kconfig.hz
12344
12345 config KEXEC
12346 bool "kexec system call"
12347 + depends on !GRKERNSEC_KMEM
12348 ---help---
12349 kexec is a system call that implements the ability to shutdown your
12350 current kernel, and to start another kernel. It is like a reboot
12351 @@ -1706,7 +1710,9 @@ config X86_NEED_RELOCS
12352
12353 config PHYSICAL_ALIGN
12354 hex "Alignment value to which kernel should be aligned"
12355 - default "0x200000"
12356 + default "0x1000000"
12357 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12358 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12359 range 0x2000 0x1000000 if X86_32
12360 range 0x200000 0x1000000 if X86_64
12361 ---help---
12362 @@ -1789,6 +1795,7 @@ config COMPAT_VDSO
12363 def_bool n
12364 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12365 depends on X86_32 || IA32_EMULATION
12366 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12367 ---help---
12368 Certain buggy versions of glibc will crash if they are
12369 presented with a 32-bit vDSO that is not mapped at the address
12370 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12371 index 6983314..54ad7e8 100644
12372 --- a/arch/x86/Kconfig.cpu
12373 +++ b/arch/x86/Kconfig.cpu
12374 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12375
12376 config X86_F00F_BUG
12377 def_bool y
12378 - depends on M586MMX || M586TSC || M586 || M486
12379 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12380
12381 config X86_INVD_BUG
12382 def_bool y
12383 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12384
12385 config X86_ALIGNMENT_16
12386 def_bool y
12387 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12388 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12389
12390 config X86_INTEL_USERCOPY
12391 def_bool y
12392 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12393 # generates cmov.
12394 config X86_CMOV
12395 def_bool y
12396 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12397 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12398
12399 config X86_MINIMUM_CPU_FAMILY
12400 int
12401 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12402 index 61bd2ad..50b625d 100644
12403 --- a/arch/x86/Kconfig.debug
12404 +++ b/arch/x86/Kconfig.debug
12405 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12406 config DEBUG_RODATA
12407 bool "Write protect kernel read-only data structures"
12408 default y
12409 - depends on DEBUG_KERNEL
12410 + depends on DEBUG_KERNEL && BROKEN
12411 ---help---
12412 Mark the kernel read-only data as write-protected in the pagetables,
12413 in order to catch accidental (and incorrect) writes to such const
12414 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12415
12416 config DEBUG_SET_MODULE_RONX
12417 bool "Set loadable kernel module data as NX and text as RO"
12418 - depends on MODULES
12419 + depends on MODULES && BROKEN
12420 ---help---
12421 This option helps catch unintended modifications to loadable
12422 kernel module's text and read-only data. It also prevents execution
12423 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12424 index 33f71b0..c2cefa2 100644
12425 --- a/arch/x86/Makefile
12426 +++ b/arch/x86/Makefile
12427 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12428 # CPU-specific tuning. Anything which can be shared with UML should go here.
12429 include $(srctree)/arch/x86/Makefile_32.cpu
12430 KBUILD_CFLAGS += $(cflags-y)
12431 -
12432 - # temporary until string.h is fixed
12433 - KBUILD_CFLAGS += -ffreestanding
12434 else
12435 BITS := 64
12436 UTS_MACHINE := x86_64
12437 @@ -114,6 +111,9 @@ else
12438 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12439 endif
12440
12441 +# temporary until string.h is fixed
12442 +KBUILD_CFLAGS += -ffreestanding
12443 +
12444 # Make sure compiler does not have buggy stack-protector support.
12445 ifdef CONFIG_CC_STACKPROTECTOR
12446 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12447 @@ -271,3 +271,12 @@ define archhelp
12448 echo ' FDINITRD=file initrd for the booted kernel'
12449 echo ' kvmconfig - Enable additional options for guest kernel support'
12450 endef
12451 +
12452 +define OLD_LD
12453 +
12454 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12455 +*** Please upgrade your binutils to 2.18 or newer
12456 +endef
12457 +
12458 +archprepare:
12459 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12460 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12461 index dbe8dd2..2f0a98f 100644
12462 --- a/arch/x86/boot/Makefile
12463 +++ b/arch/x86/boot/Makefile
12464 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12465 # ---------------------------------------------------------------------------
12466
12467 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12468 +ifdef CONSTIFY_PLUGIN
12469 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12470 +endif
12471 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12472 GCOV_PROFILE := n
12473
12474 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12475 index 878e4b9..20537ab 100644
12476 --- a/arch/x86/boot/bitops.h
12477 +++ b/arch/x86/boot/bitops.h
12478 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12479 u8 v;
12480 const u32 *p = (const u32 *)addr;
12481
12482 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12483 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12484 return v;
12485 }
12486
12487 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12488
12489 static inline void set_bit(int nr, void *addr)
12490 {
12491 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12492 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12493 }
12494
12495 #endif /* BOOT_BITOPS_H */
12496 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12497 index bd49ec6..94c7f58 100644
12498 --- a/arch/x86/boot/boot.h
12499 +++ b/arch/x86/boot/boot.h
12500 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12501 static inline u16 ds(void)
12502 {
12503 u16 seg;
12504 - asm("movw %%ds,%0" : "=rm" (seg));
12505 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12506 return seg;
12507 }
12508
12509 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12510 index 0fcd913..3bb5c42 100644
12511 --- a/arch/x86/boot/compressed/Makefile
12512 +++ b/arch/x86/boot/compressed/Makefile
12513 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12514 KBUILD_CFLAGS += -mno-mmx -mno-sse
12515 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12516 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12517 +ifdef CONSTIFY_PLUGIN
12518 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12519 +endif
12520
12521 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12522 GCOV_PROFILE := n
12523 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12524 index a53440e..c3dbf1e 100644
12525 --- a/arch/x86/boot/compressed/efi_stub_32.S
12526 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12527 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12528 * parameter 2, ..., param n. To make things easy, we save the return
12529 * address of efi_call_phys in a global variable.
12530 */
12531 - popl %ecx
12532 - movl %ecx, saved_return_addr(%edx)
12533 - /* get the function pointer into ECX*/
12534 - popl %ecx
12535 - movl %ecx, efi_rt_function_ptr(%edx)
12536 + popl saved_return_addr(%edx)
12537 + popl efi_rt_function_ptr(%edx)
12538
12539 /*
12540 * 3. Call the physical function.
12541 */
12542 - call *%ecx
12543 + call *efi_rt_function_ptr(%edx)
12544
12545 /*
12546 * 4. Balance the stack. And because EAX contain the return value,
12547 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12548 1: popl %edx
12549 subl $1b, %edx
12550
12551 - movl efi_rt_function_ptr(%edx), %ecx
12552 - pushl %ecx
12553 + pushl efi_rt_function_ptr(%edx)
12554
12555 /*
12556 * 10. Push the saved return address onto the stack and return.
12557 */
12558 - movl saved_return_addr(%edx), %ecx
12559 - pushl %ecx
12560 - ret
12561 + jmpl *saved_return_addr(%edx)
12562 ENDPROC(efi_call_phys)
12563 .previous
12564
12565 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12566 index cbed140..5f2ca57 100644
12567 --- a/arch/x86/boot/compressed/head_32.S
12568 +++ b/arch/x86/boot/compressed/head_32.S
12569 @@ -140,10 +140,10 @@ preferred_addr:
12570 addl %eax, %ebx
12571 notl %eax
12572 andl %eax, %ebx
12573 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12574 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12575 jge 1f
12576 #endif
12577 - movl $LOAD_PHYSICAL_ADDR, %ebx
12578 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12579 1:
12580
12581 /* Target address to relocate to for decompression */
12582 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12583 index 0d558ee..58f257e 100644
12584 --- a/arch/x86/boot/compressed/head_64.S
12585 +++ b/arch/x86/boot/compressed/head_64.S
12586 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12587 addl %eax, %ebx
12588 notl %eax
12589 andl %eax, %ebx
12590 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12591 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12592 jge 1f
12593 #endif
12594 - movl $LOAD_PHYSICAL_ADDR, %ebx
12595 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12596 1:
12597
12598 /* Target address to relocate to for decompression */
12599 @@ -322,10 +322,10 @@ preferred_addr:
12600 addq %rax, %rbp
12601 notq %rax
12602 andq %rax, %rbp
12603 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12604 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12605 jge 1f
12606 #endif
12607 - movq $LOAD_PHYSICAL_ADDR, %rbp
12608 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12609 1:
12610
12611 /* Target address to relocate to for decompression */
12612 @@ -431,8 +431,8 @@ gdt:
12613 .long gdt
12614 .word 0
12615 .quad 0x0000000000000000 /* NULL descriptor */
12616 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12617 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12618 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12619 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12620 .quad 0x0080890000000000 /* TS descriptor */
12621 .quad 0x0000000000000000 /* TS continued */
12622 gdt_end:
12623 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12624 index 57ab74d..7c52182 100644
12625 --- a/arch/x86/boot/compressed/misc.c
12626 +++ b/arch/x86/boot/compressed/misc.c
12627 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12628 * Calculate the delta between where vmlinux was linked to load
12629 * and where it was actually loaded.
12630 */
12631 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12632 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12633 if (!delta) {
12634 debug_putstr("No relocation needed... ");
12635 return;
12636 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12637 Elf32_Ehdr ehdr;
12638 Elf32_Phdr *phdrs, *phdr;
12639 #endif
12640 - void *dest;
12641 + void *dest, *prev;
12642 int i;
12643
12644 memcpy(&ehdr, output, sizeof(ehdr));
12645 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12646 case PT_LOAD:
12647 #ifdef CONFIG_RELOCATABLE
12648 dest = output;
12649 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12650 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12651 #else
12652 dest = (void *)(phdr->p_paddr);
12653 #endif
12654 memcpy(dest,
12655 output + phdr->p_offset,
12656 phdr->p_filesz);
12657 + if (i)
12658 + memset(prev, 0xff, dest - prev);
12659 + prev = dest + phdr->p_filesz;
12660 break;
12661 default: /* Ignore other PT_* */ break;
12662 }
12663 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12664 error("Destination address too large");
12665 #endif
12666 #ifndef CONFIG_RELOCATABLE
12667 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12668 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12669 error("Wrong destination address");
12670 #endif
12671
12672 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12673 index 1fd7d57..0f7d096 100644
12674 --- a/arch/x86/boot/cpucheck.c
12675 +++ b/arch/x86/boot/cpucheck.c
12676 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12677 u32 ecx = MSR_K7_HWCR;
12678 u32 eax, edx;
12679
12680 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12681 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12682 eax &= ~(1 << 15);
12683 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12684 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12685
12686 get_cpuflags(); /* Make sure it really did something */
12687 err = check_cpuflags();
12688 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12689 u32 ecx = MSR_VIA_FCR;
12690 u32 eax, edx;
12691
12692 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12693 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12694 eax |= (1<<1)|(1<<7);
12695 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12696 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12697
12698 set_bit(X86_FEATURE_CX8, cpu.flags);
12699 err = check_cpuflags();
12700 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12701 u32 eax, edx;
12702 u32 level = 1;
12703
12704 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12705 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12706 - asm("cpuid"
12707 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12708 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12709 + asm volatile("cpuid"
12710 : "+a" (level), "=d" (cpu.flags[0])
12711 : : "ecx", "ebx");
12712 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12713 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12714
12715 err = check_cpuflags();
12716 } else if (err == 0x01 &&
12717 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12718 index 84c2234..3ef6360 100644
12719 --- a/arch/x86/boot/header.S
12720 +++ b/arch/x86/boot/header.S
12721 @@ -420,10 +420,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12722 # single linked list of
12723 # struct setup_data
12724
12725 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12726 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12727
12728 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12729 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12730 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12731 +#else
12732 #define VO_INIT_SIZE (VO__end - VO__text)
12733 +#endif
12734 #if ZO_INIT_SIZE > VO_INIT_SIZE
12735 #define INIT_SIZE ZO_INIT_SIZE
12736 #else
12737 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12738 index db75d07..8e6d0af 100644
12739 --- a/arch/x86/boot/memory.c
12740 +++ b/arch/x86/boot/memory.c
12741 @@ -19,7 +19,7 @@
12742
12743 static int detect_memory_e820(void)
12744 {
12745 - int count = 0;
12746 + unsigned int count = 0;
12747 struct biosregs ireg, oreg;
12748 struct e820entry *desc = boot_params.e820_map;
12749 static struct e820entry buf; /* static so it is zeroed */
12750 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12751 index ba3e100..6501b8f 100644
12752 --- a/arch/x86/boot/video-vesa.c
12753 +++ b/arch/x86/boot/video-vesa.c
12754 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12755
12756 boot_params.screen_info.vesapm_seg = oreg.es;
12757 boot_params.screen_info.vesapm_off = oreg.di;
12758 + boot_params.screen_info.vesapm_size = oreg.cx;
12759 }
12760
12761 /*
12762 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12763 index 43eda28..5ab5fdb 100644
12764 --- a/arch/x86/boot/video.c
12765 +++ b/arch/x86/boot/video.c
12766 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12767 static unsigned int get_entry(void)
12768 {
12769 char entry_buf[4];
12770 - int i, len = 0;
12771 + unsigned int i, len = 0;
12772 int key;
12773 unsigned int v;
12774
12775 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12776 index 9105655..41779c1 100644
12777 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12778 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12779 @@ -8,6 +8,8 @@
12780 * including this sentence is retained in full.
12781 */
12782
12783 +#include <asm/alternative-asm.h>
12784 +
12785 .extern crypto_ft_tab
12786 .extern crypto_it_tab
12787 .extern crypto_fl_tab
12788 @@ -70,6 +72,8 @@
12789 je B192; \
12790 leaq 32(r9),r9;
12791
12792 +#define ret pax_force_retaddr; ret
12793 +
12794 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12795 movq r1,r2; \
12796 movq r3,r4; \
12797 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12798 index 477e9d7..c92c7d8 100644
12799 --- a/arch/x86/crypto/aesni-intel_asm.S
12800 +++ b/arch/x86/crypto/aesni-intel_asm.S
12801 @@ -31,6 +31,7 @@
12802
12803 #include <linux/linkage.h>
12804 #include <asm/inst.h>
12805 +#include <asm/alternative-asm.h>
12806
12807 #ifdef __x86_64__
12808 .data
12809 @@ -205,7 +206,7 @@ enc: .octa 0x2
12810 * num_initial_blocks = b mod 4
12811 * encrypt the initial num_initial_blocks blocks and apply ghash on
12812 * the ciphertext
12813 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12814 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12815 * are clobbered
12816 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12817 */
12818 @@ -214,8 +215,8 @@ enc: .octa 0x2
12819 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12820 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12821 mov arg7, %r10 # %r10 = AAD
12822 - mov arg8, %r12 # %r12 = aadLen
12823 - mov %r12, %r11
12824 + mov arg8, %r15 # %r15 = aadLen
12825 + mov %r15, %r11
12826 pxor %xmm\i, %xmm\i
12827 _get_AAD_loop\num_initial_blocks\operation:
12828 movd (%r10), \TMP1
12829 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12830 psrldq $4, %xmm\i
12831 pxor \TMP1, %xmm\i
12832 add $4, %r10
12833 - sub $4, %r12
12834 + sub $4, %r15
12835 jne _get_AAD_loop\num_initial_blocks\operation
12836 cmp $16, %r11
12837 je _get_AAD_loop2_done\num_initial_blocks\operation
12838 - mov $16, %r12
12839 + mov $16, %r15
12840 _get_AAD_loop2\num_initial_blocks\operation:
12841 psrldq $4, %xmm\i
12842 - sub $4, %r12
12843 - cmp %r11, %r12
12844 + sub $4, %r15
12845 + cmp %r11, %r15
12846 jne _get_AAD_loop2\num_initial_blocks\operation
12847 _get_AAD_loop2_done\num_initial_blocks\operation:
12848 movdqa SHUF_MASK(%rip), %xmm14
12849 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12850 * num_initial_blocks = b mod 4
12851 * encrypt the initial num_initial_blocks blocks and apply ghash on
12852 * the ciphertext
12853 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12854 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12855 * are clobbered
12856 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12857 */
12858 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12859 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12860 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12861 mov arg7, %r10 # %r10 = AAD
12862 - mov arg8, %r12 # %r12 = aadLen
12863 - mov %r12, %r11
12864 + mov arg8, %r15 # %r15 = aadLen
12865 + mov %r15, %r11
12866 pxor %xmm\i, %xmm\i
12867 _get_AAD_loop\num_initial_blocks\operation:
12868 movd (%r10), \TMP1
12869 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12870 psrldq $4, %xmm\i
12871 pxor \TMP1, %xmm\i
12872 add $4, %r10
12873 - sub $4, %r12
12874 + sub $4, %r15
12875 jne _get_AAD_loop\num_initial_blocks\operation
12876 cmp $16, %r11
12877 je _get_AAD_loop2_done\num_initial_blocks\operation
12878 - mov $16, %r12
12879 + mov $16, %r15
12880 _get_AAD_loop2\num_initial_blocks\operation:
12881 psrldq $4, %xmm\i
12882 - sub $4, %r12
12883 - cmp %r11, %r12
12884 + sub $4, %r15
12885 + cmp %r11, %r15
12886 jne _get_AAD_loop2\num_initial_blocks\operation
12887 _get_AAD_loop2_done\num_initial_blocks\operation:
12888 movdqa SHUF_MASK(%rip), %xmm14
12889 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12890 *
12891 *****************************************************************************/
12892 ENTRY(aesni_gcm_dec)
12893 - push %r12
12894 + push %r15
12895 push %r13
12896 push %r14
12897 mov %rsp, %r14
12898 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12899 */
12900 sub $VARIABLE_OFFSET, %rsp
12901 and $~63, %rsp # align rsp to 64 bytes
12902 - mov %arg6, %r12
12903 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12904 + mov %arg6, %r15
12905 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12906 movdqa SHUF_MASK(%rip), %xmm2
12907 PSHUFB_XMM %xmm2, %xmm13
12908
12909 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12910 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12911 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12912 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12913 - mov %r13, %r12
12914 - and $(3<<4), %r12
12915 + mov %r13, %r15
12916 + and $(3<<4), %r15
12917 jz _initial_num_blocks_is_0_decrypt
12918 - cmp $(2<<4), %r12
12919 + cmp $(2<<4), %r15
12920 jb _initial_num_blocks_is_1_decrypt
12921 je _initial_num_blocks_is_2_decrypt
12922 _initial_num_blocks_is_3_decrypt:
12923 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12924 sub $16, %r11
12925 add %r13, %r11
12926 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12927 - lea SHIFT_MASK+16(%rip), %r12
12928 - sub %r13, %r12
12929 + lea SHIFT_MASK+16(%rip), %r15
12930 + sub %r13, %r15
12931 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12932 # (%r13 is the number of bytes in plaintext mod 16)
12933 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12934 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12935 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12936
12937 movdqa %xmm1, %xmm2
12938 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12939 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12940 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12941 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12942 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12943 pand %xmm1, %xmm2
12944 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12945 sub $1, %r13
12946 jne _less_than_8_bytes_left_decrypt
12947 _multiple_of_16_bytes_decrypt:
12948 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12949 - shl $3, %r12 # convert into number of bits
12950 - movd %r12d, %xmm15 # len(A) in %xmm15
12951 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12952 + shl $3, %r15 # convert into number of bits
12953 + movd %r15d, %xmm15 # len(A) in %xmm15
12954 shl $3, %arg4 # len(C) in bits (*128)
12955 MOVQ_R64_XMM %arg4, %xmm1
12956 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12957 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12958 mov %r14, %rsp
12959 pop %r14
12960 pop %r13
12961 - pop %r12
12962 + pop %r15
12963 + pax_force_retaddr
12964 ret
12965 ENDPROC(aesni_gcm_dec)
12966
12967 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12968 * poly = x^128 + x^127 + x^126 + x^121 + 1
12969 ***************************************************************************/
12970 ENTRY(aesni_gcm_enc)
12971 - push %r12
12972 + push %r15
12973 push %r13
12974 push %r14
12975 mov %rsp, %r14
12976 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12977 #
12978 sub $VARIABLE_OFFSET, %rsp
12979 and $~63, %rsp
12980 - mov %arg6, %r12
12981 - movdqu (%r12), %xmm13
12982 + mov %arg6, %r15
12983 + movdqu (%r15), %xmm13
12984 movdqa SHUF_MASK(%rip), %xmm2
12985 PSHUFB_XMM %xmm2, %xmm13
12986
12987 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12988 movdqa %xmm13, HashKey(%rsp)
12989 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12990 and $-16, %r13
12991 - mov %r13, %r12
12992 + mov %r13, %r15
12993
12994 # Encrypt first few blocks
12995
12996 - and $(3<<4), %r12
12997 + and $(3<<4), %r15
12998 jz _initial_num_blocks_is_0_encrypt
12999 - cmp $(2<<4), %r12
13000 + cmp $(2<<4), %r15
13001 jb _initial_num_blocks_is_1_encrypt
13002 je _initial_num_blocks_is_2_encrypt
13003 _initial_num_blocks_is_3_encrypt:
13004 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13005 sub $16, %r11
13006 add %r13, %r11
13007 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13008 - lea SHIFT_MASK+16(%rip), %r12
13009 - sub %r13, %r12
13010 + lea SHIFT_MASK+16(%rip), %r15
13011 + sub %r13, %r15
13012 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13013 # (%r13 is the number of bytes in plaintext mod 16)
13014 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13015 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13016 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13017 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13018 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13019 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13020 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13021 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13022 movdqa SHUF_MASK(%rip), %xmm10
13023 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13024 sub $1, %r13
13025 jne _less_than_8_bytes_left_encrypt
13026 _multiple_of_16_bytes_encrypt:
13027 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13028 - shl $3, %r12
13029 - movd %r12d, %xmm15 # len(A) in %xmm15
13030 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13031 + shl $3, %r15
13032 + movd %r15d, %xmm15 # len(A) in %xmm15
13033 shl $3, %arg4 # len(C) in bits (*128)
13034 MOVQ_R64_XMM %arg4, %xmm1
13035 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13036 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13037 mov %r14, %rsp
13038 pop %r14
13039 pop %r13
13040 - pop %r12
13041 + pop %r15
13042 + pax_force_retaddr
13043 ret
13044 ENDPROC(aesni_gcm_enc)
13045
13046 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13047 pxor %xmm1, %xmm0
13048 movaps %xmm0, (TKEYP)
13049 add $0x10, TKEYP
13050 + pax_force_retaddr
13051 ret
13052 ENDPROC(_key_expansion_128)
13053 ENDPROC(_key_expansion_256a)
13054 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13055 shufps $0b01001110, %xmm2, %xmm1
13056 movaps %xmm1, 0x10(TKEYP)
13057 add $0x20, TKEYP
13058 + pax_force_retaddr
13059 ret
13060 ENDPROC(_key_expansion_192a)
13061
13062 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13063
13064 movaps %xmm0, (TKEYP)
13065 add $0x10, TKEYP
13066 + pax_force_retaddr
13067 ret
13068 ENDPROC(_key_expansion_192b)
13069
13070 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13071 pxor %xmm1, %xmm2
13072 movaps %xmm2, (TKEYP)
13073 add $0x10, TKEYP
13074 + pax_force_retaddr
13075 ret
13076 ENDPROC(_key_expansion_256b)
13077
13078 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13079 #ifndef __x86_64__
13080 popl KEYP
13081 #endif
13082 + pax_force_retaddr
13083 ret
13084 ENDPROC(aesni_set_key)
13085
13086 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13087 popl KLEN
13088 popl KEYP
13089 #endif
13090 + pax_force_retaddr
13091 ret
13092 ENDPROC(aesni_enc)
13093
13094 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13095 AESENC KEY STATE
13096 movaps 0x70(TKEYP), KEY
13097 AESENCLAST KEY STATE
13098 + pax_force_retaddr
13099 ret
13100 ENDPROC(_aesni_enc1)
13101
13102 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13103 AESENCLAST KEY STATE2
13104 AESENCLAST KEY STATE3
13105 AESENCLAST KEY STATE4
13106 + pax_force_retaddr
13107 ret
13108 ENDPROC(_aesni_enc4)
13109
13110 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13111 popl KLEN
13112 popl KEYP
13113 #endif
13114 + pax_force_retaddr
13115 ret
13116 ENDPROC(aesni_dec)
13117
13118 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13119 AESDEC KEY STATE
13120 movaps 0x70(TKEYP), KEY
13121 AESDECLAST KEY STATE
13122 + pax_force_retaddr
13123 ret
13124 ENDPROC(_aesni_dec1)
13125
13126 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13127 AESDECLAST KEY STATE2
13128 AESDECLAST KEY STATE3
13129 AESDECLAST KEY STATE4
13130 + pax_force_retaddr
13131 ret
13132 ENDPROC(_aesni_dec4)
13133
13134 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13135 popl KEYP
13136 popl LEN
13137 #endif
13138 + pax_force_retaddr
13139 ret
13140 ENDPROC(aesni_ecb_enc)
13141
13142 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13143 popl KEYP
13144 popl LEN
13145 #endif
13146 + pax_force_retaddr
13147 ret
13148 ENDPROC(aesni_ecb_dec)
13149
13150 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13151 popl LEN
13152 popl IVP
13153 #endif
13154 + pax_force_retaddr
13155 ret
13156 ENDPROC(aesni_cbc_enc)
13157
13158 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13159 popl LEN
13160 popl IVP
13161 #endif
13162 + pax_force_retaddr
13163 ret
13164 ENDPROC(aesni_cbc_dec)
13165
13166 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13167 mov $1, TCTR_LOW
13168 MOVQ_R64_XMM TCTR_LOW INC
13169 MOVQ_R64_XMM CTR TCTR_LOW
13170 + pax_force_retaddr
13171 ret
13172 ENDPROC(_aesni_inc_init)
13173
13174 @@ -2579,6 +2598,7 @@ _aesni_inc:
13175 .Linc_low:
13176 movaps CTR, IV
13177 PSHUFB_XMM BSWAP_MASK IV
13178 + pax_force_retaddr
13179 ret
13180 ENDPROC(_aesni_inc)
13181
13182 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13183 .Lctr_enc_ret:
13184 movups IV, (IVP)
13185 .Lctr_enc_just_ret:
13186 + pax_force_retaddr
13187 ret
13188 ENDPROC(aesni_ctr_enc)
13189
13190 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13191 pxor INC, STATE4
13192 movdqu STATE4, 0x70(OUTP)
13193
13194 + pax_force_retaddr
13195 ret
13196 ENDPROC(aesni_xts_crypt8)
13197
13198 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13199 index 246c670..466e2d6 100644
13200 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13201 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13202 @@ -21,6 +21,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206 +#include <asm/alternative-asm.h>
13207
13208 .file "blowfish-x86_64-asm.S"
13209 .text
13210 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13211 jnz .L__enc_xor;
13212
13213 write_block();
13214 + pax_force_retaddr
13215 ret;
13216 .L__enc_xor:
13217 xor_block();
13218 + pax_force_retaddr
13219 ret;
13220 ENDPROC(__blowfish_enc_blk)
13221
13222 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13223
13224 movq %r11, %rbp;
13225
13226 + pax_force_retaddr
13227 ret;
13228 ENDPROC(blowfish_dec_blk)
13229
13230 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13231
13232 popq %rbx;
13233 popq %rbp;
13234 + pax_force_retaddr
13235 ret;
13236
13237 .L__enc_xor4:
13238 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13239
13240 popq %rbx;
13241 popq %rbp;
13242 + pax_force_retaddr
13243 ret;
13244 ENDPROC(__blowfish_enc_blk_4way)
13245
13246 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13247 popq %rbx;
13248 popq %rbp;
13249
13250 + pax_force_retaddr
13251 ret;
13252 ENDPROC(blowfish_dec_blk_4way)
13253 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13254 index ce71f92..1dce7ec 100644
13255 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13256 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13257 @@ -16,6 +16,7 @@
13258 */
13259
13260 #include <linux/linkage.h>
13261 +#include <asm/alternative-asm.h>
13262
13263 #define CAMELLIA_TABLE_BYTE_LEN 272
13264
13265 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13266 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13267 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13268 %rcx, (%r9));
13269 + pax_force_retaddr
13270 ret;
13271 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13272
13273 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13274 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13275 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13276 %rax, (%r9));
13277 + pax_force_retaddr
13278 ret;
13279 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13280
13281 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13282 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13283 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13284
13285 + pax_force_retaddr
13286 ret;
13287
13288 .align 8
13289 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13290 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13291 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13292
13293 + pax_force_retaddr
13294 ret;
13295
13296 .align 8
13297 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13298 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13299 %xmm8, %rsi);
13300
13301 + pax_force_retaddr
13302 ret;
13303 ENDPROC(camellia_ecb_enc_16way)
13304
13305 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13306 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13307 %xmm8, %rsi);
13308
13309 + pax_force_retaddr
13310 ret;
13311 ENDPROC(camellia_ecb_dec_16way)
13312
13313 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13314 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13315 %xmm8, %rsi);
13316
13317 + pax_force_retaddr
13318 ret;
13319 ENDPROC(camellia_cbc_dec_16way)
13320
13321 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13322 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13323 %xmm8, %rsi);
13324
13325 + pax_force_retaddr
13326 ret;
13327 ENDPROC(camellia_ctr_16way)
13328
13329 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13330 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13331 %xmm8, %rsi);
13332
13333 + pax_force_retaddr
13334 ret;
13335 ENDPROC(camellia_xts_crypt_16way)
13336
13337 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13338 index 0e0b886..5a3123c 100644
13339 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13340 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13341 @@ -11,6 +11,7 @@
13342 */
13343
13344 #include <linux/linkage.h>
13345 +#include <asm/alternative-asm.h>
13346
13347 #define CAMELLIA_TABLE_BYTE_LEN 272
13348
13349 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13350 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13351 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13352 %rcx, (%r9));
13353 + pax_force_retaddr
13354 ret;
13355 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13356
13357 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13358 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13359 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13360 %rax, (%r9));
13361 + pax_force_retaddr
13362 ret;
13363 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13364
13365 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13366 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13367 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13368
13369 + pax_force_retaddr
13370 ret;
13371
13372 .align 8
13373 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13374 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13375 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13376
13377 + pax_force_retaddr
13378 ret;
13379
13380 .align 8
13381 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13382
13383 vzeroupper;
13384
13385 + pax_force_retaddr
13386 ret;
13387 ENDPROC(camellia_ecb_enc_32way)
13388
13389 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13390
13391 vzeroupper;
13392
13393 + pax_force_retaddr
13394 ret;
13395 ENDPROC(camellia_ecb_dec_32way)
13396
13397 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13398
13399 vzeroupper;
13400
13401 + pax_force_retaddr
13402 ret;
13403 ENDPROC(camellia_cbc_dec_32way)
13404
13405 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13406
13407 vzeroupper;
13408
13409 + pax_force_retaddr
13410 ret;
13411 ENDPROC(camellia_ctr_32way)
13412
13413 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13414
13415 vzeroupper;
13416
13417 + pax_force_retaddr
13418 ret;
13419 ENDPROC(camellia_xts_crypt_32way)
13420
13421 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13422 index 310319c..db3d7b5 100644
13423 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13424 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13425 @@ -21,6 +21,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429 +#include <asm/alternative-asm.h>
13430
13431 .file "camellia-x86_64-asm_64.S"
13432 .text
13433 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13434 enc_outunpack(mov, RT1);
13435
13436 movq RRBP, %rbp;
13437 + pax_force_retaddr
13438 ret;
13439
13440 .L__enc_xor:
13441 enc_outunpack(xor, RT1);
13442
13443 movq RRBP, %rbp;
13444 + pax_force_retaddr
13445 ret;
13446 ENDPROC(__camellia_enc_blk)
13447
13448 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13449 dec_outunpack();
13450
13451 movq RRBP, %rbp;
13452 + pax_force_retaddr
13453 ret;
13454 ENDPROC(camellia_dec_blk)
13455
13456 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13457
13458 movq RRBP, %rbp;
13459 popq %rbx;
13460 + pax_force_retaddr
13461 ret;
13462
13463 .L__enc2_xor:
13464 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13465
13466 movq RRBP, %rbp;
13467 popq %rbx;
13468 + pax_force_retaddr
13469 ret;
13470 ENDPROC(__camellia_enc_blk_2way)
13471
13472 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13473
13474 movq RRBP, %rbp;
13475 movq RXOR, %rbx;
13476 + pax_force_retaddr
13477 ret;
13478 ENDPROC(camellia_dec_blk_2way)
13479 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13480 index c35fd5d..2d8c7db 100644
13481 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13482 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13483 @@ -24,6 +24,7 @@
13484 */
13485
13486 #include <linux/linkage.h>
13487 +#include <asm/alternative-asm.h>
13488
13489 .file "cast5-avx-x86_64-asm_64.S"
13490
13491 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13492 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13493 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13494
13495 + pax_force_retaddr
13496 ret;
13497 ENDPROC(__cast5_enc_blk16)
13498
13499 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13500 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13501 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13502
13503 + pax_force_retaddr
13504 ret;
13505
13506 .L__skip_dec:
13507 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13508 vmovdqu RR4, (6*4*4)(%r11);
13509 vmovdqu RL4, (7*4*4)(%r11);
13510
13511 + pax_force_retaddr
13512 ret;
13513 ENDPROC(cast5_ecb_enc_16way)
13514
13515 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13516 vmovdqu RR4, (6*4*4)(%r11);
13517 vmovdqu RL4, (7*4*4)(%r11);
13518
13519 + pax_force_retaddr
13520 ret;
13521 ENDPROC(cast5_ecb_dec_16way)
13522
13523 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13524 * %rdx: src
13525 */
13526
13527 - pushq %r12;
13528 + pushq %r14;
13529
13530 movq %rsi, %r11;
13531 - movq %rdx, %r12;
13532 + movq %rdx, %r14;
13533
13534 vmovdqu (0*16)(%rdx), RL1;
13535 vmovdqu (1*16)(%rdx), RR1;
13536 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13537 call __cast5_dec_blk16;
13538
13539 /* xor with src */
13540 - vmovq (%r12), RX;
13541 + vmovq (%r14), RX;
13542 vpshufd $0x4f, RX, RX;
13543 vpxor RX, RR1, RR1;
13544 - vpxor 0*16+8(%r12), RL1, RL1;
13545 - vpxor 1*16+8(%r12), RR2, RR2;
13546 - vpxor 2*16+8(%r12), RL2, RL2;
13547 - vpxor 3*16+8(%r12), RR3, RR3;
13548 - vpxor 4*16+8(%r12), RL3, RL3;
13549 - vpxor 5*16+8(%r12), RR4, RR4;
13550 - vpxor 6*16+8(%r12), RL4, RL4;
13551 + vpxor 0*16+8(%r14), RL1, RL1;
13552 + vpxor 1*16+8(%r14), RR2, RR2;
13553 + vpxor 2*16+8(%r14), RL2, RL2;
13554 + vpxor 3*16+8(%r14), RR3, RR3;
13555 + vpxor 4*16+8(%r14), RL3, RL3;
13556 + vpxor 5*16+8(%r14), RR4, RR4;
13557 + vpxor 6*16+8(%r14), RL4, RL4;
13558
13559 vmovdqu RR1, (0*16)(%r11);
13560 vmovdqu RL1, (1*16)(%r11);
13561 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13562 vmovdqu RR4, (6*16)(%r11);
13563 vmovdqu RL4, (7*16)(%r11);
13564
13565 - popq %r12;
13566 + popq %r14;
13567
13568 + pax_force_retaddr
13569 ret;
13570 ENDPROC(cast5_cbc_dec_16way)
13571
13572 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13573 * %rcx: iv (big endian, 64bit)
13574 */
13575
13576 - pushq %r12;
13577 + pushq %r14;
13578
13579 movq %rsi, %r11;
13580 - movq %rdx, %r12;
13581 + movq %rdx, %r14;
13582
13583 vpcmpeqd RTMP, RTMP, RTMP;
13584 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13585 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13586 call __cast5_enc_blk16;
13587
13588 /* dst = src ^ iv */
13589 - vpxor (0*16)(%r12), RR1, RR1;
13590 - vpxor (1*16)(%r12), RL1, RL1;
13591 - vpxor (2*16)(%r12), RR2, RR2;
13592 - vpxor (3*16)(%r12), RL2, RL2;
13593 - vpxor (4*16)(%r12), RR3, RR3;
13594 - vpxor (5*16)(%r12), RL3, RL3;
13595 - vpxor (6*16)(%r12), RR4, RR4;
13596 - vpxor (7*16)(%r12), RL4, RL4;
13597 + vpxor (0*16)(%r14), RR1, RR1;
13598 + vpxor (1*16)(%r14), RL1, RL1;
13599 + vpxor (2*16)(%r14), RR2, RR2;
13600 + vpxor (3*16)(%r14), RL2, RL2;
13601 + vpxor (4*16)(%r14), RR3, RR3;
13602 + vpxor (5*16)(%r14), RL3, RL3;
13603 + vpxor (6*16)(%r14), RR4, RR4;
13604 + vpxor (7*16)(%r14), RL4, RL4;
13605 vmovdqu RR1, (0*16)(%r11);
13606 vmovdqu RL1, (1*16)(%r11);
13607 vmovdqu RR2, (2*16)(%r11);
13608 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13609 vmovdqu RR4, (6*16)(%r11);
13610 vmovdqu RL4, (7*16)(%r11);
13611
13612 - popq %r12;
13613 + popq %r14;
13614
13615 + pax_force_retaddr
13616 ret;
13617 ENDPROC(cast5_ctr_16way)
13618 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13619 index e3531f8..e123f35 100644
13620 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13621 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13622 @@ -24,6 +24,7 @@
13623 */
13624
13625 #include <linux/linkage.h>
13626 +#include <asm/alternative-asm.h>
13627 #include "glue_helper-asm-avx.S"
13628
13629 .file "cast6-avx-x86_64-asm_64.S"
13630 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13631 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13632 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13633
13634 + pax_force_retaddr
13635 ret;
13636 ENDPROC(__cast6_enc_blk8)
13637
13638 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13639 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13640 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13641
13642 + pax_force_retaddr
13643 ret;
13644 ENDPROC(__cast6_dec_blk8)
13645
13646 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13647
13648 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13649
13650 + pax_force_retaddr
13651 ret;
13652 ENDPROC(cast6_ecb_enc_8way)
13653
13654 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13655
13656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13657
13658 + pax_force_retaddr
13659 ret;
13660 ENDPROC(cast6_ecb_dec_8way)
13661
13662 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13663 * %rdx: src
13664 */
13665
13666 - pushq %r12;
13667 + pushq %r14;
13668
13669 movq %rsi, %r11;
13670 - movq %rdx, %r12;
13671 + movq %rdx, %r14;
13672
13673 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13674
13675 call __cast6_dec_blk8;
13676
13677 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13678 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13679
13680 - popq %r12;
13681 + popq %r14;
13682
13683 + pax_force_retaddr
13684 ret;
13685 ENDPROC(cast6_cbc_dec_8way)
13686
13687 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13688 * %rcx: iv (little endian, 128bit)
13689 */
13690
13691 - pushq %r12;
13692 + pushq %r14;
13693
13694 movq %rsi, %r11;
13695 - movq %rdx, %r12;
13696 + movq %rdx, %r14;
13697
13698 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13699 RD2, RX, RKR, RKM);
13700
13701 call __cast6_enc_blk8;
13702
13703 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13704 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13705
13706 - popq %r12;
13707 + popq %r14;
13708
13709 + pax_force_retaddr
13710 ret;
13711 ENDPROC(cast6_ctr_8way)
13712
13713 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13714 /* dst <= regs xor IVs(in dst) */
13715 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13716
13717 + pax_force_retaddr
13718 ret;
13719 ENDPROC(cast6_xts_enc_8way)
13720
13721 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13722 /* dst <= regs xor IVs(in dst) */
13723 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13724
13725 + pax_force_retaddr
13726 ret;
13727 ENDPROC(cast6_xts_dec_8way)
13728 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13729 index dbc4339..de6e120 100644
13730 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13731 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13732 @@ -45,6 +45,7 @@
13733
13734 #include <asm/inst.h>
13735 #include <linux/linkage.h>
13736 +#include <asm/alternative-asm.h>
13737
13738 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13739
13740 @@ -312,6 +313,7 @@ do_return:
13741 popq %rsi
13742 popq %rdi
13743 popq %rbx
13744 + pax_force_retaddr
13745 ret
13746
13747 ################################################################
13748 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13749 index 185fad4..ff4cd36 100644
13750 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13751 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13752 @@ -18,6 +18,7 @@
13753
13754 #include <linux/linkage.h>
13755 #include <asm/inst.h>
13756 +#include <asm/alternative-asm.h>
13757
13758 .data
13759
13760 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13761 psrlq $1, T2
13762 pxor T2, T1
13763 pxor T1, DATA
13764 + pax_force_retaddr
13765 ret
13766 ENDPROC(__clmul_gf128mul_ble)
13767
13768 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13769 call __clmul_gf128mul_ble
13770 PSHUFB_XMM BSWAP DATA
13771 movups DATA, (%rdi)
13772 + pax_force_retaddr
13773 ret
13774 ENDPROC(clmul_ghash_mul)
13775
13776 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13777 PSHUFB_XMM BSWAP DATA
13778 movups DATA, (%rdi)
13779 .Lupdate_just_ret:
13780 + pax_force_retaddr
13781 ret
13782 ENDPROC(clmul_ghash_update)
13783 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13784 index 9279e0b..c4b3d2c 100644
13785 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13786 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13787 @@ -1,4 +1,5 @@
13788 #include <linux/linkage.h>
13789 +#include <asm/alternative-asm.h>
13790
13791 # enter salsa20_encrypt_bytes
13792 ENTRY(salsa20_encrypt_bytes)
13793 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13794 add %r11,%rsp
13795 mov %rdi,%rax
13796 mov %rsi,%rdx
13797 + pax_force_retaddr
13798 ret
13799 # bytesatleast65:
13800 ._bytesatleast65:
13801 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13802 add %r11,%rsp
13803 mov %rdi,%rax
13804 mov %rsi,%rdx
13805 + pax_force_retaddr
13806 ret
13807 ENDPROC(salsa20_keysetup)
13808
13809 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13810 add %r11,%rsp
13811 mov %rdi,%rax
13812 mov %rsi,%rdx
13813 + pax_force_retaddr
13814 ret
13815 ENDPROC(salsa20_ivsetup)
13816 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13817 index 2f202f4..d9164d6 100644
13818 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13819 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13820 @@ -24,6 +24,7 @@
13821 */
13822
13823 #include <linux/linkage.h>
13824 +#include <asm/alternative-asm.h>
13825 #include "glue_helper-asm-avx.S"
13826
13827 .file "serpent-avx-x86_64-asm_64.S"
13828 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13829 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13830 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13831
13832 + pax_force_retaddr
13833 ret;
13834 ENDPROC(__serpent_enc_blk8_avx)
13835
13836 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13837 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13838 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13839
13840 + pax_force_retaddr
13841 ret;
13842 ENDPROC(__serpent_dec_blk8_avx)
13843
13844 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13845
13846 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13847
13848 + pax_force_retaddr
13849 ret;
13850 ENDPROC(serpent_ecb_enc_8way_avx)
13851
13852 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13853
13854 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13855
13856 + pax_force_retaddr
13857 ret;
13858 ENDPROC(serpent_ecb_dec_8way_avx)
13859
13860 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13861
13862 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13863
13864 + pax_force_retaddr
13865 ret;
13866 ENDPROC(serpent_cbc_dec_8way_avx)
13867
13868 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13869
13870 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13871
13872 + pax_force_retaddr
13873 ret;
13874 ENDPROC(serpent_ctr_8way_avx)
13875
13876 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13877 /* dst <= regs xor IVs(in dst) */
13878 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13879
13880 + pax_force_retaddr
13881 ret;
13882 ENDPROC(serpent_xts_enc_8way_avx)
13883
13884 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13885 /* dst <= regs xor IVs(in dst) */
13886 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13887
13888 + pax_force_retaddr
13889 ret;
13890 ENDPROC(serpent_xts_dec_8way_avx)
13891 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13892 index b222085..abd483c 100644
13893 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13894 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13895 @@ -15,6 +15,7 @@
13896 */
13897
13898 #include <linux/linkage.h>
13899 +#include <asm/alternative-asm.h>
13900 #include "glue_helper-asm-avx2.S"
13901
13902 .file "serpent-avx2-asm_64.S"
13903 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13904 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13905 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13906
13907 + pax_force_retaddr
13908 ret;
13909 ENDPROC(__serpent_enc_blk16)
13910
13911 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13912 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13913 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13914
13915 + pax_force_retaddr
13916 ret;
13917 ENDPROC(__serpent_dec_blk16)
13918
13919 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13920
13921 vzeroupper;
13922
13923 + pax_force_retaddr
13924 ret;
13925 ENDPROC(serpent_ecb_enc_16way)
13926
13927 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13928
13929 vzeroupper;
13930
13931 + pax_force_retaddr
13932 ret;
13933 ENDPROC(serpent_ecb_dec_16way)
13934
13935 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13936
13937 vzeroupper;
13938
13939 + pax_force_retaddr
13940 ret;
13941 ENDPROC(serpent_cbc_dec_16way)
13942
13943 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13944
13945 vzeroupper;
13946
13947 + pax_force_retaddr
13948 ret;
13949 ENDPROC(serpent_ctr_16way)
13950
13951 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13952
13953 vzeroupper;
13954
13955 + pax_force_retaddr
13956 ret;
13957 ENDPROC(serpent_xts_enc_16way)
13958
13959 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13960
13961 vzeroupper;
13962
13963 + pax_force_retaddr
13964 ret;
13965 ENDPROC(serpent_xts_dec_16way)
13966 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13967 index acc066c..1559cc4 100644
13968 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13969 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13970 @@ -25,6 +25,7 @@
13971 */
13972
13973 #include <linux/linkage.h>
13974 +#include <asm/alternative-asm.h>
13975
13976 .file "serpent-sse2-x86_64-asm_64.S"
13977 .text
13978 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13979 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13980 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13981
13982 + pax_force_retaddr
13983 ret;
13984
13985 .L__enc_xor8:
13986 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13987 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13988
13989 + pax_force_retaddr
13990 ret;
13991 ENDPROC(__serpent_enc_blk_8way)
13992
13993 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13994 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13995 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13996
13997 + pax_force_retaddr
13998 ret;
13999 ENDPROC(serpent_dec_blk_8way)
14000 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14001 index a410950..9dfe7ad 100644
14002 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14003 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14004 @@ -29,6 +29,7 @@
14005 */
14006
14007 #include <linux/linkage.h>
14008 +#include <asm/alternative-asm.h>
14009
14010 #define CTX %rdi // arg1
14011 #define BUF %rsi // arg2
14012 @@ -75,9 +76,9 @@
14013
14014 push %rbx
14015 push %rbp
14016 - push %r12
14017 + push %r14
14018
14019 - mov %rsp, %r12
14020 + mov %rsp, %r14
14021 sub $64, %rsp # allocate workspace
14022 and $~15, %rsp # align stack
14023
14024 @@ -99,11 +100,12 @@
14025 xor %rax, %rax
14026 rep stosq
14027
14028 - mov %r12, %rsp # deallocate workspace
14029 + mov %r14, %rsp # deallocate workspace
14030
14031 - pop %r12
14032 + pop %r14
14033 pop %rbp
14034 pop %rbx
14035 + pax_force_retaddr
14036 ret
14037
14038 ENDPROC(\name)
14039 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14040 index 642f156..51a513c 100644
14041 --- a/arch/x86/crypto/sha256-avx-asm.S
14042 +++ b/arch/x86/crypto/sha256-avx-asm.S
14043 @@ -49,6 +49,7 @@
14044
14045 #ifdef CONFIG_AS_AVX
14046 #include <linux/linkage.h>
14047 +#include <asm/alternative-asm.h>
14048
14049 ## assume buffers not aligned
14050 #define VMOVDQ vmovdqu
14051 @@ -460,6 +461,7 @@ done_hash:
14052 popq %r13
14053 popq %rbp
14054 popq %rbx
14055 + pax_force_retaddr
14056 ret
14057 ENDPROC(sha256_transform_avx)
14058
14059 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14060 index 9e86944..3795e6a 100644
14061 --- a/arch/x86/crypto/sha256-avx2-asm.S
14062 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14063 @@ -50,6 +50,7 @@
14064
14065 #ifdef CONFIG_AS_AVX2
14066 #include <linux/linkage.h>
14067 +#include <asm/alternative-asm.h>
14068
14069 ## assume buffers not aligned
14070 #define VMOVDQ vmovdqu
14071 @@ -720,6 +721,7 @@ done_hash:
14072 popq %r12
14073 popq %rbp
14074 popq %rbx
14075 + pax_force_retaddr
14076 ret
14077 ENDPROC(sha256_transform_rorx)
14078
14079 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14080 index f833b74..8c62a9e 100644
14081 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14082 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14083 @@ -47,6 +47,7 @@
14084 ########################################################################
14085
14086 #include <linux/linkage.h>
14087 +#include <asm/alternative-asm.h>
14088
14089 ## assume buffers not aligned
14090 #define MOVDQ movdqu
14091 @@ -471,6 +472,7 @@ done_hash:
14092 popq %rbp
14093 popq %rbx
14094
14095 + pax_force_retaddr
14096 ret
14097 ENDPROC(sha256_transform_ssse3)
14098
14099 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14100 index 974dde9..a823ff9 100644
14101 --- a/arch/x86/crypto/sha512-avx-asm.S
14102 +++ b/arch/x86/crypto/sha512-avx-asm.S
14103 @@ -49,6 +49,7 @@
14104
14105 #ifdef CONFIG_AS_AVX
14106 #include <linux/linkage.h>
14107 +#include <asm/alternative-asm.h>
14108
14109 .text
14110
14111 @@ -364,6 +365,7 @@ updateblock:
14112 mov frame_RSPSAVE(%rsp), %rsp
14113
14114 nowork:
14115 + pax_force_retaddr
14116 ret
14117 ENDPROC(sha512_transform_avx)
14118
14119 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14120 index 568b961..ed20c37 100644
14121 --- a/arch/x86/crypto/sha512-avx2-asm.S
14122 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14123 @@ -51,6 +51,7 @@
14124
14125 #ifdef CONFIG_AS_AVX2
14126 #include <linux/linkage.h>
14127 +#include <asm/alternative-asm.h>
14128
14129 .text
14130
14131 @@ -678,6 +679,7 @@ done_hash:
14132
14133 # Restore Stack Pointer
14134 mov frame_RSPSAVE(%rsp), %rsp
14135 + pax_force_retaddr
14136 ret
14137 ENDPROC(sha512_transform_rorx)
14138
14139 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14140 index fb56855..6edd768 100644
14141 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14142 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14143 @@ -48,6 +48,7 @@
14144 ########################################################################
14145
14146 #include <linux/linkage.h>
14147 +#include <asm/alternative-asm.h>
14148
14149 .text
14150
14151 @@ -363,6 +364,7 @@ updateblock:
14152 mov frame_RSPSAVE(%rsp), %rsp
14153
14154 nowork:
14155 + pax_force_retaddr
14156 ret
14157 ENDPROC(sha512_transform_ssse3)
14158
14159 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14160 index 0505813..b067311 100644
14161 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14162 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14163 @@ -24,6 +24,7 @@
14164 */
14165
14166 #include <linux/linkage.h>
14167 +#include <asm/alternative-asm.h>
14168 #include "glue_helper-asm-avx.S"
14169
14170 .file "twofish-avx-x86_64-asm_64.S"
14171 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14172 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14173 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14174
14175 + pax_force_retaddr
14176 ret;
14177 ENDPROC(__twofish_enc_blk8)
14178
14179 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14180 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14181 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14182
14183 + pax_force_retaddr
14184 ret;
14185 ENDPROC(__twofish_dec_blk8)
14186
14187 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14188
14189 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14190
14191 + pax_force_retaddr
14192 ret;
14193 ENDPROC(twofish_ecb_enc_8way)
14194
14195 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14196
14197 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14198
14199 + pax_force_retaddr
14200 ret;
14201 ENDPROC(twofish_ecb_dec_8way)
14202
14203 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14204 * %rdx: src
14205 */
14206
14207 - pushq %r12;
14208 + pushq %r14;
14209
14210 movq %rsi, %r11;
14211 - movq %rdx, %r12;
14212 + movq %rdx, %r14;
14213
14214 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14215
14216 call __twofish_dec_blk8;
14217
14218 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14219 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14220
14221 - popq %r12;
14222 + popq %r14;
14223
14224 + pax_force_retaddr
14225 ret;
14226 ENDPROC(twofish_cbc_dec_8way)
14227
14228 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14229 * %rcx: iv (little endian, 128bit)
14230 */
14231
14232 - pushq %r12;
14233 + pushq %r14;
14234
14235 movq %rsi, %r11;
14236 - movq %rdx, %r12;
14237 + movq %rdx, %r14;
14238
14239 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14240 RD2, RX0, RX1, RY0);
14241
14242 call __twofish_enc_blk8;
14243
14244 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14245 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14246
14247 - popq %r12;
14248 + popq %r14;
14249
14250 + pax_force_retaddr
14251 ret;
14252 ENDPROC(twofish_ctr_8way)
14253
14254 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14255 /* dst <= regs xor IVs(in dst) */
14256 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14257
14258 + pax_force_retaddr
14259 ret;
14260 ENDPROC(twofish_xts_enc_8way)
14261
14262 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14263 /* dst <= regs xor IVs(in dst) */
14264 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14265
14266 + pax_force_retaddr
14267 ret;
14268 ENDPROC(twofish_xts_dec_8way)
14269 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14270 index 1c3b7ce..02f578d 100644
14271 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14272 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14273 @@ -21,6 +21,7 @@
14274 */
14275
14276 #include <linux/linkage.h>
14277 +#include <asm/alternative-asm.h>
14278
14279 .file "twofish-x86_64-asm-3way.S"
14280 .text
14281 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14282 popq %r13;
14283 popq %r14;
14284 popq %r15;
14285 + pax_force_retaddr
14286 ret;
14287
14288 .L__enc_xor3:
14289 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14290 popq %r13;
14291 popq %r14;
14292 popq %r15;
14293 + pax_force_retaddr
14294 ret;
14295 ENDPROC(__twofish_enc_blk_3way)
14296
14297 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14298 popq %r13;
14299 popq %r14;
14300 popq %r15;
14301 + pax_force_retaddr
14302 ret;
14303 ENDPROC(twofish_dec_blk_3way)
14304 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14305 index a039d21..524b8b2 100644
14306 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14307 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14308 @@ -22,6 +22,7 @@
14309
14310 #include <linux/linkage.h>
14311 #include <asm/asm-offsets.h>
14312 +#include <asm/alternative-asm.h>
14313
14314 #define a_offset 0
14315 #define b_offset 4
14316 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14317
14318 popq R1
14319 movq $1,%rax
14320 + pax_force_retaddr
14321 ret
14322 ENDPROC(twofish_enc_blk)
14323
14324 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14325
14326 popq R1
14327 movq $1,%rax
14328 + pax_force_retaddr
14329 ret
14330 ENDPROC(twofish_dec_blk)
14331 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14332 index d21ff89..6da8e6e 100644
14333 --- a/arch/x86/ia32/ia32_aout.c
14334 +++ b/arch/x86/ia32/ia32_aout.c
14335 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14336 unsigned long dump_start, dump_size;
14337 struct user32 dump;
14338
14339 + memset(&dump, 0, sizeof(dump));
14340 +
14341 fs = get_fs();
14342 set_fs(KERNEL_DS);
14343 has_dumped = 1;
14344 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14345 index 2206757..85cbcfa 100644
14346 --- a/arch/x86/ia32/ia32_signal.c
14347 +++ b/arch/x86/ia32/ia32_signal.c
14348 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14349 if (__get_user(set.sig[0], &frame->sc.oldmask)
14350 || (_COMPAT_NSIG_WORDS > 1
14351 && __copy_from_user((((char *) &set.sig) + 4),
14352 - &frame->extramask,
14353 + frame->extramask,
14354 sizeof(frame->extramask))))
14355 goto badframe;
14356
14357 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14358 sp -= frame_size;
14359 /* Align the stack pointer according to the i386 ABI,
14360 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14361 - sp = ((sp + 4) & -16ul) - 4;
14362 + sp = ((sp - 12) & -16ul) - 4;
14363 return (void __user *) sp;
14364 }
14365
14366 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14367 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14368 sigreturn);
14369 else
14370 - restorer = &frame->retcode;
14371 + restorer = frame->retcode;
14372 }
14373
14374 put_user_try {
14375 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14376 * These are actually not used anymore, but left because some
14377 * gdb versions depend on them as a marker.
14378 */
14379 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14380 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14381 } put_user_catch(err);
14382
14383 if (err)
14384 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14385 0xb8,
14386 __NR_ia32_rt_sigreturn,
14387 0x80cd,
14388 - 0,
14389 + 0
14390 };
14391
14392 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14393 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14394
14395 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14396 restorer = ksig->ka.sa.sa_restorer;
14397 + else if (current->mm->context.vdso)
14398 + /* Return stub is in 32bit vsyscall page */
14399 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14400 else
14401 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14402 - rt_sigreturn);
14403 + restorer = frame->retcode;
14404 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14405
14406 /*
14407 * Not actually used anymore, but left because some gdb
14408 * versions need it.
14409 */
14410 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14411 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14412 } put_user_catch(err);
14413
14414 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14415 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14416 index 4299eb0..c0687a7 100644
14417 --- a/arch/x86/ia32/ia32entry.S
14418 +++ b/arch/x86/ia32/ia32entry.S
14419 @@ -15,8 +15,10 @@
14420 #include <asm/irqflags.h>
14421 #include <asm/asm.h>
14422 #include <asm/smap.h>
14423 +#include <asm/pgtable.h>
14424 #include <linux/linkage.h>
14425 #include <linux/err.h>
14426 +#include <asm/alternative-asm.h>
14427
14428 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14429 #include <linux/elf-em.h>
14430 @@ -62,12 +64,12 @@
14431 */
14432 .macro LOAD_ARGS32 offset, _r9=0
14433 .if \_r9
14434 - movl \offset+16(%rsp),%r9d
14435 + movl \offset+R9(%rsp),%r9d
14436 .endif
14437 - movl \offset+40(%rsp),%ecx
14438 - movl \offset+48(%rsp),%edx
14439 - movl \offset+56(%rsp),%esi
14440 - movl \offset+64(%rsp),%edi
14441 + movl \offset+RCX(%rsp),%ecx
14442 + movl \offset+RDX(%rsp),%edx
14443 + movl \offset+RSI(%rsp),%esi
14444 + movl \offset+RDI(%rsp),%edi
14445 movl %eax,%eax /* zero extension */
14446 .endm
14447
14448 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14449 ENDPROC(native_irq_enable_sysexit)
14450 #endif
14451
14452 + .macro pax_enter_kernel_user
14453 + pax_set_fptr_mask
14454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14455 + call pax_enter_kernel_user
14456 +#endif
14457 + .endm
14458 +
14459 + .macro pax_exit_kernel_user
14460 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14461 + call pax_exit_kernel_user
14462 +#endif
14463 +#ifdef CONFIG_PAX_RANDKSTACK
14464 + pushq %rax
14465 + pushq %r11
14466 + call pax_randomize_kstack
14467 + popq %r11
14468 + popq %rax
14469 +#endif
14470 + .endm
14471 +
14472 + .macro pax_erase_kstack
14473 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14474 + call pax_erase_kstack
14475 +#endif
14476 + .endm
14477 +
14478 /*
14479 * 32bit SYSENTER instruction entry.
14480 *
14481 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14482 CFI_REGISTER rsp,rbp
14483 SWAPGS_UNSAFE_STACK
14484 movq PER_CPU_VAR(kernel_stack), %rsp
14485 - addq $(KERNEL_STACK_OFFSET),%rsp
14486 - /*
14487 - * No need to follow this irqs on/off section: the syscall
14488 - * disabled irqs, here we enable it straight after entry:
14489 - */
14490 - ENABLE_INTERRUPTS(CLBR_NONE)
14491 movl %ebp,%ebp /* zero extension */
14492 pushq_cfi $__USER32_DS
14493 /*CFI_REL_OFFSET ss,0*/
14494 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14495 CFI_REL_OFFSET rsp,0
14496 pushfq_cfi
14497 /*CFI_REL_OFFSET rflags,0*/
14498 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14499 - CFI_REGISTER rip,r10
14500 + orl $X86_EFLAGS_IF,(%rsp)
14501 + GET_THREAD_INFO(%r11)
14502 + movl TI_sysenter_return(%r11), %r11d
14503 + CFI_REGISTER rip,r11
14504 pushq_cfi $__USER32_CS
14505 /*CFI_REL_OFFSET cs,0*/
14506 movl %eax, %eax
14507 - pushq_cfi %r10
14508 + pushq_cfi %r11
14509 CFI_REL_OFFSET rip,0
14510 pushq_cfi %rax
14511 cld
14512 SAVE_ARGS 0,1,0
14513 + pax_enter_kernel_user
14514 +
14515 +#ifdef CONFIG_PAX_RANDKSTACK
14516 + pax_erase_kstack
14517 +#endif
14518 +
14519 + /*
14520 + * No need to follow this irqs on/off section: the syscall
14521 + * disabled irqs, here we enable it straight after entry:
14522 + */
14523 + ENABLE_INTERRUPTS(CLBR_NONE)
14524 /* no need to do an access_ok check here because rbp has been
14525 32bit zero extended */
14526 +
14527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14528 + addq pax_user_shadow_base,%rbp
14529 + ASM_PAX_OPEN_USERLAND
14530 +#endif
14531 +
14532 ASM_STAC
14533 1: movl (%rbp),%ebp
14534 _ASM_EXTABLE(1b,ia32_badarg)
14535 ASM_CLAC
14536 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14537 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14538 +
14539 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14540 + ASM_PAX_CLOSE_USERLAND
14541 +#endif
14542 +
14543 + GET_THREAD_INFO(%r11)
14544 + orl $TS_COMPAT,TI_status(%r11)
14545 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14546 CFI_REMEMBER_STATE
14547 jnz sysenter_tracesys
14548 cmpq $(IA32_NR_syscalls-1),%rax
14549 @@ -162,15 +209,18 @@ sysenter_do_call:
14550 sysenter_dispatch:
14551 call *ia32_sys_call_table(,%rax,8)
14552 movq %rax,RAX-ARGOFFSET(%rsp)
14553 + GET_THREAD_INFO(%r11)
14554 DISABLE_INTERRUPTS(CLBR_NONE)
14555 TRACE_IRQS_OFF
14556 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14557 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14558 jnz sysexit_audit
14559 sysexit_from_sys_call:
14560 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14561 + pax_exit_kernel_user
14562 + pax_erase_kstack
14563 + andl $~TS_COMPAT,TI_status(%r11)
14564 /* clear IF, that popfq doesn't enable interrupts early */
14565 - andl $~0x200,EFLAGS-R11(%rsp)
14566 - movl RIP-R11(%rsp),%edx /* User %eip */
14567 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14568 + movl RIP(%rsp),%edx /* User %eip */
14569 CFI_REGISTER rip,rdx
14570 RESTORE_ARGS 0,24,0,0,0,0
14571 xorq %r8,%r8
14572 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14573 movl %eax,%esi /* 2nd arg: syscall number */
14574 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14575 call __audit_syscall_entry
14576 +
14577 + pax_erase_kstack
14578 +
14579 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14580 cmpq $(IA32_NR_syscalls-1),%rax
14581 ja ia32_badsys
14582 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14583 .endm
14584
14585 .macro auditsys_exit exit
14586 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14588 jnz ia32_ret_from_sys_call
14589 TRACE_IRQS_ON
14590 ENABLE_INTERRUPTS(CLBR_NONE)
14591 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14592 1: setbe %al /* 1 if error, 0 if not */
14593 movzbl %al,%edi /* zero-extend that into %edi */
14594 call __audit_syscall_exit
14595 + GET_THREAD_INFO(%r11)
14596 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14597 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14598 DISABLE_INTERRUPTS(CLBR_NONE)
14599 TRACE_IRQS_OFF
14600 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14601 + testl %edi,TI_flags(%r11)
14602 jz \exit
14603 CLEAR_RREGS -ARGOFFSET
14604 jmp int_with_check
14605 @@ -237,7 +291,7 @@ sysexit_audit:
14606
14607 sysenter_tracesys:
14608 #ifdef CONFIG_AUDITSYSCALL
14609 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14610 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14611 jz sysenter_auditsys
14612 #endif
14613 SAVE_REST
14614 @@ -249,6 +303,9 @@ sysenter_tracesys:
14615 RESTORE_REST
14616 cmpq $(IA32_NR_syscalls-1),%rax
14617 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14618 +
14619 + pax_erase_kstack
14620 +
14621 jmp sysenter_do_call
14622 CFI_ENDPROC
14623 ENDPROC(ia32_sysenter_target)
14624 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14625 ENTRY(ia32_cstar_target)
14626 CFI_STARTPROC32 simple
14627 CFI_SIGNAL_FRAME
14628 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14629 + CFI_DEF_CFA rsp,0
14630 CFI_REGISTER rip,rcx
14631 /*CFI_REGISTER rflags,r11*/
14632 SWAPGS_UNSAFE_STACK
14633 movl %esp,%r8d
14634 CFI_REGISTER rsp,r8
14635 movq PER_CPU_VAR(kernel_stack),%rsp
14636 + SAVE_ARGS 8*6,0,0
14637 + pax_enter_kernel_user
14638 +
14639 +#ifdef CONFIG_PAX_RANDKSTACK
14640 + pax_erase_kstack
14641 +#endif
14642 +
14643 /*
14644 * No need to follow this irqs on/off section: the syscall
14645 * disabled irqs and here we enable it straight after entry:
14646 */
14647 ENABLE_INTERRUPTS(CLBR_NONE)
14648 - SAVE_ARGS 8,0,0
14649 movl %eax,%eax /* zero extension */
14650 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14651 movq %rcx,RIP-ARGOFFSET(%rsp)
14652 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14653 /* no need to do an access_ok check here because r8 has been
14654 32bit zero extended */
14655 /* hardware stack frame is complete now */
14656 +
14657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14658 + ASM_PAX_OPEN_USERLAND
14659 + movq pax_user_shadow_base,%r8
14660 + addq RSP-ARGOFFSET(%rsp),%r8
14661 +#endif
14662 +
14663 ASM_STAC
14664 1: movl (%r8),%r9d
14665 _ASM_EXTABLE(1b,ia32_badarg)
14666 ASM_CLAC
14667 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14668 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14669 +
14670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14671 + ASM_PAX_CLOSE_USERLAND
14672 +#endif
14673 +
14674 + GET_THREAD_INFO(%r11)
14675 + orl $TS_COMPAT,TI_status(%r11)
14676 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14677 CFI_REMEMBER_STATE
14678 jnz cstar_tracesys
14679 cmpq $IA32_NR_syscalls-1,%rax
14680 @@ -319,13 +395,16 @@ cstar_do_call:
14681 cstar_dispatch:
14682 call *ia32_sys_call_table(,%rax,8)
14683 movq %rax,RAX-ARGOFFSET(%rsp)
14684 + GET_THREAD_INFO(%r11)
14685 DISABLE_INTERRUPTS(CLBR_NONE)
14686 TRACE_IRQS_OFF
14687 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14688 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14689 jnz sysretl_audit
14690 sysretl_from_sys_call:
14691 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14692 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14693 + pax_exit_kernel_user
14694 + pax_erase_kstack
14695 + andl $~TS_COMPAT,TI_status(%r11)
14696 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14697 movl RIP-ARGOFFSET(%rsp),%ecx
14698 CFI_REGISTER rip,rcx
14699 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14700 @@ -352,7 +431,7 @@ sysretl_audit:
14701
14702 cstar_tracesys:
14703 #ifdef CONFIG_AUDITSYSCALL
14704 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14705 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14706 jz cstar_auditsys
14707 #endif
14708 xchgl %r9d,%ebp
14709 @@ -366,11 +445,19 @@ cstar_tracesys:
14710 xchgl %ebp,%r9d
14711 cmpq $(IA32_NR_syscalls-1),%rax
14712 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14713 +
14714 + pax_erase_kstack
14715 +
14716 jmp cstar_do_call
14717 END(ia32_cstar_target)
14718
14719 ia32_badarg:
14720 ASM_CLAC
14721 +
14722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14723 + ASM_PAX_CLOSE_USERLAND
14724 +#endif
14725 +
14726 movq $-EFAULT,%rax
14727 jmp ia32_sysret
14728 CFI_ENDPROC
14729 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14730 CFI_REL_OFFSET rip,RIP-RIP
14731 PARAVIRT_ADJUST_EXCEPTION_FRAME
14732 SWAPGS
14733 - /*
14734 - * No need to follow this irqs on/off section: the syscall
14735 - * disabled irqs and here we enable it straight after entry:
14736 - */
14737 - ENABLE_INTERRUPTS(CLBR_NONE)
14738 movl %eax,%eax
14739 pushq_cfi %rax
14740 cld
14741 /* note the registers are not zero extended to the sf.
14742 this could be a problem. */
14743 SAVE_ARGS 0,1,0
14744 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14745 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14746 + pax_enter_kernel_user
14747 +
14748 +#ifdef CONFIG_PAX_RANDKSTACK
14749 + pax_erase_kstack
14750 +#endif
14751 +
14752 + /*
14753 + * No need to follow this irqs on/off section: the syscall
14754 + * disabled irqs and here we enable it straight after entry:
14755 + */
14756 + ENABLE_INTERRUPTS(CLBR_NONE)
14757 + GET_THREAD_INFO(%r11)
14758 + orl $TS_COMPAT,TI_status(%r11)
14759 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14760 jnz ia32_tracesys
14761 cmpq $(IA32_NR_syscalls-1),%rax
14762 ja ia32_badsys
14763 @@ -442,6 +536,9 @@ ia32_tracesys:
14764 RESTORE_REST
14765 cmpq $(IA32_NR_syscalls-1),%rax
14766 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14767 +
14768 + pax_erase_kstack
14769 +
14770 jmp ia32_do_call
14771 END(ia32_syscall)
14772
14773 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14774 index 8e0ceec..af13504 100644
14775 --- a/arch/x86/ia32/sys_ia32.c
14776 +++ b/arch/x86/ia32/sys_ia32.c
14777 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14778 */
14779 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14780 {
14781 - typeof(ubuf->st_uid) uid = 0;
14782 - typeof(ubuf->st_gid) gid = 0;
14783 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14784 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14785 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14786 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14787 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14788 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14789 index 372231c..51b537d 100644
14790 --- a/arch/x86/include/asm/alternative-asm.h
14791 +++ b/arch/x86/include/asm/alternative-asm.h
14792 @@ -18,6 +18,45 @@
14793 .endm
14794 #endif
14795
14796 +#ifdef KERNEXEC_PLUGIN
14797 + .macro pax_force_retaddr_bts rip=0
14798 + btsq $63,\rip(%rsp)
14799 + .endm
14800 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14801 + .macro pax_force_retaddr rip=0, reload=0
14802 + btsq $63,\rip(%rsp)
14803 + .endm
14804 + .macro pax_force_fptr ptr
14805 + btsq $63,\ptr
14806 + .endm
14807 + .macro pax_set_fptr_mask
14808 + .endm
14809 +#endif
14810 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14811 + .macro pax_force_retaddr rip=0, reload=0
14812 + .if \reload
14813 + pax_set_fptr_mask
14814 + .endif
14815 + orq %r12,\rip(%rsp)
14816 + .endm
14817 + .macro pax_force_fptr ptr
14818 + orq %r12,\ptr
14819 + .endm
14820 + .macro pax_set_fptr_mask
14821 + movabs $0x8000000000000000,%r12
14822 + .endm
14823 +#endif
14824 +#else
14825 + .macro pax_force_retaddr rip=0, reload=0
14826 + .endm
14827 + .macro pax_force_fptr ptr
14828 + .endm
14829 + .macro pax_force_retaddr_bts rip=0
14830 + .endm
14831 + .macro pax_set_fptr_mask
14832 + .endm
14833 +#endif
14834 +
14835 .macro altinstruction_entry orig alt feature orig_len alt_len
14836 .long \orig - .
14837 .long \alt - .
14838 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14839 index 0a3f9c9..c9d081d 100644
14840 --- a/arch/x86/include/asm/alternative.h
14841 +++ b/arch/x86/include/asm/alternative.h
14842 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14843 ".pushsection .discard,\"aw\",@progbits\n" \
14844 DISCARD_ENTRY(1) \
14845 ".popsection\n" \
14846 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14847 + ".pushsection .altinstr_replacement, \"a\"\n" \
14848 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14849 ".popsection"
14850
14851 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14852 DISCARD_ENTRY(1) \
14853 DISCARD_ENTRY(2) \
14854 ".popsection\n" \
14855 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14856 + ".pushsection .altinstr_replacement, \"a\"\n" \
14857 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14858 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14859 ".popsection"
14860 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14861 index 19b0eba..12254cd 100644
14862 --- a/arch/x86/include/asm/apic.h
14863 +++ b/arch/x86/include/asm/apic.h
14864 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14865
14866 #ifdef CONFIG_X86_LOCAL_APIC
14867
14868 -extern unsigned int apic_verbosity;
14869 +extern int apic_verbosity;
14870 extern int local_apic_timer_c2_ok;
14871
14872 extern int disable_apic;
14873 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14874 index 20370c6..a2eb9b0 100644
14875 --- a/arch/x86/include/asm/apm.h
14876 +++ b/arch/x86/include/asm/apm.h
14877 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14878 __asm__ __volatile__(APM_DO_ZERO_SEGS
14879 "pushl %%edi\n\t"
14880 "pushl %%ebp\n\t"
14881 - "lcall *%%cs:apm_bios_entry\n\t"
14882 + "lcall *%%ss:apm_bios_entry\n\t"
14883 "setc %%al\n\t"
14884 "popl %%ebp\n\t"
14885 "popl %%edi\n\t"
14886 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14887 __asm__ __volatile__(APM_DO_ZERO_SEGS
14888 "pushl %%edi\n\t"
14889 "pushl %%ebp\n\t"
14890 - "lcall *%%cs:apm_bios_entry\n\t"
14891 + "lcall *%%ss:apm_bios_entry\n\t"
14892 "setc %%bl\n\t"
14893 "popl %%ebp\n\t"
14894 "popl %%edi\n\t"
14895 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14896 index b17f4f4..9620151 100644
14897 --- a/arch/x86/include/asm/atomic.h
14898 +++ b/arch/x86/include/asm/atomic.h
14899 @@ -23,7 +23,18 @@
14900 */
14901 static inline int atomic_read(const atomic_t *v)
14902 {
14903 - return (*(volatile int *)&(v)->counter);
14904 + return (*(volatile const int *)&(v)->counter);
14905 +}
14906 +
14907 +/**
14908 + * atomic_read_unchecked - read atomic variable
14909 + * @v: pointer of type atomic_unchecked_t
14910 + *
14911 + * Atomically reads the value of @v.
14912 + */
14913 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14914 +{
14915 + return (*(volatile const int *)&(v)->counter);
14916 }
14917
14918 /**
14919 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14920 }
14921
14922 /**
14923 + * atomic_set_unchecked - set atomic variable
14924 + * @v: pointer of type atomic_unchecked_t
14925 + * @i: required value
14926 + *
14927 + * Atomically sets the value of @v to @i.
14928 + */
14929 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14930 +{
14931 + v->counter = i;
14932 +}
14933 +
14934 +/**
14935 * atomic_add - add integer to atomic variable
14936 * @i: integer value to add
14937 * @v: pointer of type atomic_t
14938 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14939 */
14940 static inline void atomic_add(int i, atomic_t *v)
14941 {
14942 - asm volatile(LOCK_PREFIX "addl %1,%0"
14943 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14944 +
14945 +#ifdef CONFIG_PAX_REFCOUNT
14946 + "jno 0f\n"
14947 + LOCK_PREFIX "subl %1,%0\n"
14948 + "int $4\n0:\n"
14949 + _ASM_EXTABLE(0b, 0b)
14950 +#endif
14951 +
14952 + : "+m" (v->counter)
14953 + : "ir" (i));
14954 +}
14955 +
14956 +/**
14957 + * atomic_add_unchecked - add integer to atomic variable
14958 + * @i: integer value to add
14959 + * @v: pointer of type atomic_unchecked_t
14960 + *
14961 + * Atomically adds @i to @v.
14962 + */
14963 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14964 +{
14965 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14966 : "+m" (v->counter)
14967 : "ir" (i));
14968 }
14969 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14970 */
14971 static inline void atomic_sub(int i, atomic_t *v)
14972 {
14973 - asm volatile(LOCK_PREFIX "subl %1,%0"
14974 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14975 +
14976 +#ifdef CONFIG_PAX_REFCOUNT
14977 + "jno 0f\n"
14978 + LOCK_PREFIX "addl %1,%0\n"
14979 + "int $4\n0:\n"
14980 + _ASM_EXTABLE(0b, 0b)
14981 +#endif
14982 +
14983 + : "+m" (v->counter)
14984 + : "ir" (i));
14985 +}
14986 +
14987 +/**
14988 + * atomic_sub_unchecked - subtract integer from atomic variable
14989 + * @i: integer value to subtract
14990 + * @v: pointer of type atomic_unchecked_t
14991 + *
14992 + * Atomically subtracts @i from @v.
14993 + */
14994 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14995 +{
14996 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14997 : "+m" (v->counter)
14998 : "ir" (i));
14999 }
15000 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15001 */
15002 static inline int atomic_sub_and_test(int i, atomic_t *v)
15003 {
15004 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15005 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15006 }
15007
15008 /**
15009 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15010 */
15011 static inline void atomic_inc(atomic_t *v)
15012 {
15013 - asm volatile(LOCK_PREFIX "incl %0"
15014 + asm volatile(LOCK_PREFIX "incl %0\n"
15015 +
15016 +#ifdef CONFIG_PAX_REFCOUNT
15017 + "jno 0f\n"
15018 + LOCK_PREFIX "decl %0\n"
15019 + "int $4\n0:\n"
15020 + _ASM_EXTABLE(0b, 0b)
15021 +#endif
15022 +
15023 + : "+m" (v->counter));
15024 +}
15025 +
15026 +/**
15027 + * atomic_inc_unchecked - increment atomic variable
15028 + * @v: pointer of type atomic_unchecked_t
15029 + *
15030 + * Atomically increments @v by 1.
15031 + */
15032 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15033 +{
15034 + asm volatile(LOCK_PREFIX "incl %0\n"
15035 : "+m" (v->counter));
15036 }
15037
15038 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15039 */
15040 static inline void atomic_dec(atomic_t *v)
15041 {
15042 - asm volatile(LOCK_PREFIX "decl %0"
15043 + asm volatile(LOCK_PREFIX "decl %0\n"
15044 +
15045 +#ifdef CONFIG_PAX_REFCOUNT
15046 + "jno 0f\n"
15047 + LOCK_PREFIX "incl %0\n"
15048 + "int $4\n0:\n"
15049 + _ASM_EXTABLE(0b, 0b)
15050 +#endif
15051 +
15052 + : "+m" (v->counter));
15053 +}
15054 +
15055 +/**
15056 + * atomic_dec_unchecked - decrement atomic variable
15057 + * @v: pointer of type atomic_unchecked_t
15058 + *
15059 + * Atomically decrements @v by 1.
15060 + */
15061 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15062 +{
15063 + asm volatile(LOCK_PREFIX "decl %0\n"
15064 : "+m" (v->counter));
15065 }
15066
15067 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15068 */
15069 static inline int atomic_dec_and_test(atomic_t *v)
15070 {
15071 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15072 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15073 }
15074
15075 /**
15076 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15077 */
15078 static inline int atomic_inc_and_test(atomic_t *v)
15079 {
15080 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15081 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15082 +}
15083 +
15084 +/**
15085 + * atomic_inc_and_test_unchecked - increment and test
15086 + * @v: pointer of type atomic_unchecked_t
15087 + *
15088 + * Atomically increments @v by 1
15089 + * and returns true if the result is zero, or false for all
15090 + * other cases.
15091 + */
15092 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15093 +{
15094 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15095 }
15096
15097 /**
15098 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15099 */
15100 static inline int atomic_add_negative(int i, atomic_t *v)
15101 {
15102 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15103 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15104 }
15105
15106 /**
15107 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15108 */
15109 static inline int atomic_add_return(int i, atomic_t *v)
15110 {
15111 + return i + xadd_check_overflow(&v->counter, i);
15112 +}
15113 +
15114 +/**
15115 + * atomic_add_return_unchecked - add integer and return
15116 + * @i: integer value to add
15117 + * @v: pointer of type atomic_unchecked_t
15118 + *
15119 + * Atomically adds @i to @v and returns @i + @v
15120 + */
15121 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15122 +{
15123 return i + xadd(&v->counter, i);
15124 }
15125
15126 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15127 }
15128
15129 #define atomic_inc_return(v) (atomic_add_return(1, v))
15130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15131 +{
15132 + return atomic_add_return_unchecked(1, v);
15133 +}
15134 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15135
15136 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15137 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15138 +{
15139 + return cmpxchg(&v->counter, old, new);
15140 +}
15141 +
15142 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15143 {
15144 return cmpxchg(&v->counter, old, new);
15145 }
15146 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15147 return xchg(&v->counter, new);
15148 }
15149
15150 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15151 +{
15152 + return xchg(&v->counter, new);
15153 +}
15154 +
15155 /**
15156 * __atomic_add_unless - add unless the number is already a given value
15157 * @v: pointer of type atomic_t
15158 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15159 * Atomically adds @a to @v, so long as @v was not already @u.
15160 * Returns the old value of @v.
15161 */
15162 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15163 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15164 {
15165 - int c, old;
15166 + int c, old, new;
15167 c = atomic_read(v);
15168 for (;;) {
15169 - if (unlikely(c == (u)))
15170 + if (unlikely(c == u))
15171 break;
15172 - old = atomic_cmpxchg((v), c, c + (a));
15173 +
15174 + asm volatile("addl %2,%0\n"
15175 +
15176 +#ifdef CONFIG_PAX_REFCOUNT
15177 + "jno 0f\n"
15178 + "subl %2,%0\n"
15179 + "int $4\n0:\n"
15180 + _ASM_EXTABLE(0b, 0b)
15181 +#endif
15182 +
15183 + : "=r" (new)
15184 + : "0" (c), "ir" (a));
15185 +
15186 + old = atomic_cmpxchg(v, c, new);
15187 if (likely(old == c))
15188 break;
15189 c = old;
15190 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15191 }
15192
15193 /**
15194 + * atomic_inc_not_zero_hint - increment if not null
15195 + * @v: pointer of type atomic_t
15196 + * @hint: probable value of the atomic before the increment
15197 + *
15198 + * This version of atomic_inc_not_zero() gives a hint of probable
15199 + * value of the atomic. This helps processor to not read the memory
15200 + * before doing the atomic read/modify/write cycle, lowering
15201 + * number of bus transactions on some arches.
15202 + *
15203 + * Returns: 0 if increment was not done, 1 otherwise.
15204 + */
15205 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15206 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15207 +{
15208 + int val, c = hint, new;
15209 +
15210 + /* sanity test, should be removed by compiler if hint is a constant */
15211 + if (!hint)
15212 + return __atomic_add_unless(v, 1, 0);
15213 +
15214 + do {
15215 + asm volatile("incl %0\n"
15216 +
15217 +#ifdef CONFIG_PAX_REFCOUNT
15218 + "jno 0f\n"
15219 + "decl %0\n"
15220 + "int $4\n0:\n"
15221 + _ASM_EXTABLE(0b, 0b)
15222 +#endif
15223 +
15224 + : "=r" (new)
15225 + : "0" (c));
15226 +
15227 + val = atomic_cmpxchg(v, c, new);
15228 + if (val == c)
15229 + return 1;
15230 + c = val;
15231 + } while (c);
15232 +
15233 + return 0;
15234 +}
15235 +
15236 +/**
15237 * atomic_inc_short - increment of a short integer
15238 * @v: pointer to type int
15239 *
15240 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15241 #endif
15242
15243 /* These are x86-specific, used by some header files */
15244 -#define atomic_clear_mask(mask, addr) \
15245 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15246 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15247 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15248 +{
15249 + asm volatile(LOCK_PREFIX "andl %1,%0"
15250 + : "+m" (v->counter)
15251 + : "r" (~(mask))
15252 + : "memory");
15253 +}
15254
15255 -#define atomic_set_mask(mask, addr) \
15256 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15257 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15258 - : "memory")
15259 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15260 +{
15261 + asm volatile(LOCK_PREFIX "andl %1,%0"
15262 + : "+m" (v->counter)
15263 + : "r" (~(mask))
15264 + : "memory");
15265 +}
15266 +
15267 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15268 +{
15269 + asm volatile(LOCK_PREFIX "orl %1,%0"
15270 + : "+m" (v->counter)
15271 + : "r" (mask)
15272 + : "memory");
15273 +}
15274 +
15275 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15276 +{
15277 + asm volatile(LOCK_PREFIX "orl %1,%0"
15278 + : "+m" (v->counter)
15279 + : "r" (mask)
15280 + : "memory");
15281 +}
15282
15283 /* Atomic operations are already serializing on x86 */
15284 #define smp_mb__before_atomic_dec() barrier()
15285 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15286 index b154de7..bf18a5a 100644
15287 --- a/arch/x86/include/asm/atomic64_32.h
15288 +++ b/arch/x86/include/asm/atomic64_32.h
15289 @@ -12,6 +12,14 @@ typedef struct {
15290 u64 __aligned(8) counter;
15291 } atomic64_t;
15292
15293 +#ifdef CONFIG_PAX_REFCOUNT
15294 +typedef struct {
15295 + u64 __aligned(8) counter;
15296 +} atomic64_unchecked_t;
15297 +#else
15298 +typedef atomic64_t atomic64_unchecked_t;
15299 +#endif
15300 +
15301 #define ATOMIC64_INIT(val) { (val) }
15302
15303 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15304 @@ -37,21 +45,31 @@ typedef struct {
15305 ATOMIC64_DECL_ONE(sym##_386)
15306
15307 ATOMIC64_DECL_ONE(add_386);
15308 +ATOMIC64_DECL_ONE(add_unchecked_386);
15309 ATOMIC64_DECL_ONE(sub_386);
15310 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15311 ATOMIC64_DECL_ONE(inc_386);
15312 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15313 ATOMIC64_DECL_ONE(dec_386);
15314 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15315 #endif
15316
15317 #define alternative_atomic64(f, out, in...) \
15318 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15319
15320 ATOMIC64_DECL(read);
15321 +ATOMIC64_DECL(read_unchecked);
15322 ATOMIC64_DECL(set);
15323 +ATOMIC64_DECL(set_unchecked);
15324 ATOMIC64_DECL(xchg);
15325 ATOMIC64_DECL(add_return);
15326 +ATOMIC64_DECL(add_return_unchecked);
15327 ATOMIC64_DECL(sub_return);
15328 +ATOMIC64_DECL(sub_return_unchecked);
15329 ATOMIC64_DECL(inc_return);
15330 +ATOMIC64_DECL(inc_return_unchecked);
15331 ATOMIC64_DECL(dec_return);
15332 +ATOMIC64_DECL(dec_return_unchecked);
15333 ATOMIC64_DECL(dec_if_positive);
15334 ATOMIC64_DECL(inc_not_zero);
15335 ATOMIC64_DECL(add_unless);
15336 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15337 }
15338
15339 /**
15340 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15341 + * @p: pointer to type atomic64_unchecked_t
15342 + * @o: expected value
15343 + * @n: new value
15344 + *
15345 + * Atomically sets @v to @n if it was equal to @o and returns
15346 + * the old value.
15347 + */
15348 +
15349 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15350 +{
15351 + return cmpxchg64(&v->counter, o, n);
15352 +}
15353 +
15354 +/**
15355 * atomic64_xchg - xchg atomic64 variable
15356 * @v: pointer to type atomic64_t
15357 * @n: value to assign
15358 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15359 }
15360
15361 /**
15362 + * atomic64_set_unchecked - set atomic64 variable
15363 + * @v: pointer to type atomic64_unchecked_t
15364 + * @n: value to assign
15365 + *
15366 + * Atomically sets the value of @v to @n.
15367 + */
15368 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15369 +{
15370 + unsigned high = (unsigned)(i >> 32);
15371 + unsigned low = (unsigned)i;
15372 + alternative_atomic64(set, /* no output */,
15373 + "S" (v), "b" (low), "c" (high)
15374 + : "eax", "edx", "memory");
15375 +}
15376 +
15377 +/**
15378 * atomic64_read - read atomic64 variable
15379 * @v: pointer to type atomic64_t
15380 *
15381 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15382 }
15383
15384 /**
15385 + * atomic64_read_unchecked - read atomic64 variable
15386 + * @v: pointer to type atomic64_unchecked_t
15387 + *
15388 + * Atomically reads the value of @v and returns it.
15389 + */
15390 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15391 +{
15392 + long long r;
15393 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15394 + return r;
15395 + }
15396 +
15397 +/**
15398 * atomic64_add_return - add and return
15399 * @i: integer value to add
15400 * @v: pointer to type atomic64_t
15401 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15402 return i;
15403 }
15404
15405 +/**
15406 + * atomic64_add_return_unchecked - add and return
15407 + * @i: integer value to add
15408 + * @v: pointer to type atomic64_unchecked_t
15409 + *
15410 + * Atomically adds @i to @v and returns @i + *@v
15411 + */
15412 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15413 +{
15414 + alternative_atomic64(add_return_unchecked,
15415 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15416 + ASM_NO_INPUT_CLOBBER("memory"));
15417 + return i;
15418 +}
15419 +
15420 /*
15421 * Other variants with different arithmetic operators:
15422 */
15423 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15424 return a;
15425 }
15426
15427 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15428 +{
15429 + long long a;
15430 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15431 + "S" (v) : "memory", "ecx");
15432 + return a;
15433 +}
15434 +
15435 static inline long long atomic64_dec_return(atomic64_t *v)
15436 {
15437 long long a;
15438 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15439 }
15440
15441 /**
15442 + * atomic64_add_unchecked - add integer to atomic64 variable
15443 + * @i: integer value to add
15444 + * @v: pointer to type atomic64_unchecked_t
15445 + *
15446 + * Atomically adds @i to @v.
15447 + */
15448 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15449 +{
15450 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15451 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15452 + ASM_NO_INPUT_CLOBBER("memory"));
15453 + return i;
15454 +}
15455 +
15456 +/**
15457 * atomic64_sub - subtract the atomic64 variable
15458 * @i: integer value to subtract
15459 * @v: pointer to type atomic64_t
15460 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15461 index 46e9052..ae45136 100644
15462 --- a/arch/x86/include/asm/atomic64_64.h
15463 +++ b/arch/x86/include/asm/atomic64_64.h
15464 @@ -18,7 +18,19 @@
15465 */
15466 static inline long atomic64_read(const atomic64_t *v)
15467 {
15468 - return (*(volatile long *)&(v)->counter);
15469 + return (*(volatile const long *)&(v)->counter);
15470 +}
15471 +
15472 +/**
15473 + * atomic64_read_unchecked - read atomic64 variable
15474 + * @v: pointer of type atomic64_unchecked_t
15475 + *
15476 + * Atomically reads the value of @v.
15477 + * Doesn't imply a read memory barrier.
15478 + */
15479 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15480 +{
15481 + return (*(volatile const long *)&(v)->counter);
15482 }
15483
15484 /**
15485 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15486 }
15487
15488 /**
15489 + * atomic64_set_unchecked - set atomic64 variable
15490 + * @v: pointer to type atomic64_unchecked_t
15491 + * @i: required value
15492 + *
15493 + * Atomically sets the value of @v to @i.
15494 + */
15495 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15496 +{
15497 + v->counter = i;
15498 +}
15499 +
15500 +/**
15501 * atomic64_add - add integer to atomic64 variable
15502 * @i: integer value to add
15503 * @v: pointer to type atomic64_t
15504 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15505 */
15506 static inline void atomic64_add(long i, atomic64_t *v)
15507 {
15508 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15509 +
15510 +#ifdef CONFIG_PAX_REFCOUNT
15511 + "jno 0f\n"
15512 + LOCK_PREFIX "subq %1,%0\n"
15513 + "int $4\n0:\n"
15514 + _ASM_EXTABLE(0b, 0b)
15515 +#endif
15516 +
15517 + : "=m" (v->counter)
15518 + : "er" (i), "m" (v->counter));
15519 +}
15520 +
15521 +/**
15522 + * atomic64_add_unchecked - add integer to atomic64 variable
15523 + * @i: integer value to add
15524 + * @v: pointer to type atomic64_unchecked_t
15525 + *
15526 + * Atomically adds @i to @v.
15527 + */
15528 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15529 +{
15530 asm volatile(LOCK_PREFIX "addq %1,%0"
15531 : "=m" (v->counter)
15532 : "er" (i), "m" (v->counter));
15533 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15534 */
15535 static inline void atomic64_sub(long i, atomic64_t *v)
15536 {
15537 - asm volatile(LOCK_PREFIX "subq %1,%0"
15538 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15539 +
15540 +#ifdef CONFIG_PAX_REFCOUNT
15541 + "jno 0f\n"
15542 + LOCK_PREFIX "addq %1,%0\n"
15543 + "int $4\n0:\n"
15544 + _ASM_EXTABLE(0b, 0b)
15545 +#endif
15546 +
15547 + : "=m" (v->counter)
15548 + : "er" (i), "m" (v->counter));
15549 +}
15550 +
15551 +/**
15552 + * atomic64_sub_unchecked - subtract the atomic64 variable
15553 + * @i: integer value to subtract
15554 + * @v: pointer to type atomic64_unchecked_t
15555 + *
15556 + * Atomically subtracts @i from @v.
15557 + */
15558 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15559 +{
15560 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15561 : "=m" (v->counter)
15562 : "er" (i), "m" (v->counter));
15563 }
15564 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15565 */
15566 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15567 {
15568 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15569 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15570 }
15571
15572 /**
15573 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15574 */
15575 static inline void atomic64_inc(atomic64_t *v)
15576 {
15577 + asm volatile(LOCK_PREFIX "incq %0\n"
15578 +
15579 +#ifdef CONFIG_PAX_REFCOUNT
15580 + "jno 0f\n"
15581 + LOCK_PREFIX "decq %0\n"
15582 + "int $4\n0:\n"
15583 + _ASM_EXTABLE(0b, 0b)
15584 +#endif
15585 +
15586 + : "=m" (v->counter)
15587 + : "m" (v->counter));
15588 +}
15589 +
15590 +/**
15591 + * atomic64_inc_unchecked - increment atomic64 variable
15592 + * @v: pointer to type atomic64_unchecked_t
15593 + *
15594 + * Atomically increments @v by 1.
15595 + */
15596 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15597 +{
15598 asm volatile(LOCK_PREFIX "incq %0"
15599 : "=m" (v->counter)
15600 : "m" (v->counter));
15601 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15602 */
15603 static inline void atomic64_dec(atomic64_t *v)
15604 {
15605 - asm volatile(LOCK_PREFIX "decq %0"
15606 + asm volatile(LOCK_PREFIX "decq %0\n"
15607 +
15608 +#ifdef CONFIG_PAX_REFCOUNT
15609 + "jno 0f\n"
15610 + LOCK_PREFIX "incq %0\n"
15611 + "int $4\n0:\n"
15612 + _ASM_EXTABLE(0b, 0b)
15613 +#endif
15614 +
15615 + : "=m" (v->counter)
15616 + : "m" (v->counter));
15617 +}
15618 +
15619 +/**
15620 + * atomic64_dec_unchecked - decrement atomic64 variable
15621 + * @v: pointer to type atomic64_t
15622 + *
15623 + * Atomically decrements @v by 1.
15624 + */
15625 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15626 +{
15627 + asm volatile(LOCK_PREFIX "decq %0\n"
15628 : "=m" (v->counter)
15629 : "m" (v->counter));
15630 }
15631 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15632 */
15633 static inline int atomic64_dec_and_test(atomic64_t *v)
15634 {
15635 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15636 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15637 }
15638
15639 /**
15640 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15641 */
15642 static inline int atomic64_inc_and_test(atomic64_t *v)
15643 {
15644 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15645 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15646 }
15647
15648 /**
15649 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15650 */
15651 static inline int atomic64_add_negative(long i, atomic64_t *v)
15652 {
15653 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15654 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15655 }
15656
15657 /**
15658 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15659 */
15660 static inline long atomic64_add_return(long i, atomic64_t *v)
15661 {
15662 + return i + xadd_check_overflow(&v->counter, i);
15663 +}
15664 +
15665 +/**
15666 + * atomic64_add_return_unchecked - add and return
15667 + * @i: integer value to add
15668 + * @v: pointer to type atomic64_unchecked_t
15669 + *
15670 + * Atomically adds @i to @v and returns @i + @v
15671 + */
15672 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15673 +{
15674 return i + xadd(&v->counter, i);
15675 }
15676
15677 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15678 }
15679
15680 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15681 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15682 +{
15683 + return atomic64_add_return_unchecked(1, v);
15684 +}
15685 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15686
15687 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15688 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15689 return cmpxchg(&v->counter, old, new);
15690 }
15691
15692 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15693 +{
15694 + return cmpxchg(&v->counter, old, new);
15695 +}
15696 +
15697 static inline long atomic64_xchg(atomic64_t *v, long new)
15698 {
15699 return xchg(&v->counter, new);
15700 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15701 */
15702 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15703 {
15704 - long c, old;
15705 + long c, old, new;
15706 c = atomic64_read(v);
15707 for (;;) {
15708 - if (unlikely(c == (u)))
15709 + if (unlikely(c == u))
15710 break;
15711 - old = atomic64_cmpxchg((v), c, c + (a));
15712 +
15713 + asm volatile("add %2,%0\n"
15714 +
15715 +#ifdef CONFIG_PAX_REFCOUNT
15716 + "jno 0f\n"
15717 + "sub %2,%0\n"
15718 + "int $4\n0:\n"
15719 + _ASM_EXTABLE(0b, 0b)
15720 +#endif
15721 +
15722 + : "=r" (new)
15723 + : "0" (c), "ir" (a));
15724 +
15725 + old = atomic64_cmpxchg(v, c, new);
15726 if (likely(old == c))
15727 break;
15728 c = old;
15729 }
15730 - return c != (u);
15731 + return c != u;
15732 }
15733
15734 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15735 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15736 index 69bbb48..32517fe 100644
15737 --- a/arch/x86/include/asm/barrier.h
15738 +++ b/arch/x86/include/asm/barrier.h
15739 @@ -107,7 +107,7 @@
15740 do { \
15741 compiletime_assert_atomic_type(*p); \
15742 smp_mb(); \
15743 - ACCESS_ONCE(*p) = (v); \
15744 + ACCESS_ONCE_RW(*p) = (v); \
15745 } while (0)
15746
15747 #define smp_load_acquire(p) \
15748 @@ -124,7 +124,7 @@ do { \
15749 do { \
15750 compiletime_assert_atomic_type(*p); \
15751 barrier(); \
15752 - ACCESS_ONCE(*p) = (v); \
15753 + ACCESS_ONCE_RW(*p) = (v); \
15754 } while (0)
15755
15756 #define smp_load_acquire(p) \
15757 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15758 index 9fc1af7..fc71228 100644
15759 --- a/arch/x86/include/asm/bitops.h
15760 +++ b/arch/x86/include/asm/bitops.h
15761 @@ -49,7 +49,7 @@
15762 * a mask operation on a byte.
15763 */
15764 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15765 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15766 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15767 #define CONST_MASK(nr) (1 << ((nr) & 7))
15768
15769 /**
15770 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15771 */
15772 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15773 {
15774 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15775 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15776 }
15777
15778 /**
15779 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15780 */
15781 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15782 {
15783 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15784 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15785 }
15786
15787 /**
15788 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15789 */
15790 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15791 {
15792 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15793 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15794 }
15795
15796 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15797 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15798 *
15799 * Undefined if no bit exists, so code should check against 0 first.
15800 */
15801 -static inline unsigned long __ffs(unsigned long word)
15802 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15803 {
15804 asm("rep; bsf %1,%0"
15805 : "=r" (word)
15806 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15807 *
15808 * Undefined if no zero exists, so code should check against ~0UL first.
15809 */
15810 -static inline unsigned long ffz(unsigned long word)
15811 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15812 {
15813 asm("rep; bsf %1,%0"
15814 : "=r" (word)
15815 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15816 *
15817 * Undefined if no set bit exists, so code should check against 0 first.
15818 */
15819 -static inline unsigned long __fls(unsigned long word)
15820 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15821 {
15822 asm("bsr %1,%0"
15823 : "=r" (word)
15824 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15825 * set bit if value is nonzero. The last (most significant) bit is
15826 * at position 32.
15827 */
15828 -static inline int fls(int x)
15829 +static inline int __intentional_overflow(-1) fls(int x)
15830 {
15831 int r;
15832
15833 @@ -478,7 +478,7 @@ static inline int fls(int x)
15834 * at position 64.
15835 */
15836 #ifdef CONFIG_X86_64
15837 -static __always_inline int fls64(__u64 x)
15838 +static __always_inline long fls64(__u64 x)
15839 {
15840 int bitpos = -1;
15841 /*
15842 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15843 index 4fa687a..60f2d39 100644
15844 --- a/arch/x86/include/asm/boot.h
15845 +++ b/arch/x86/include/asm/boot.h
15846 @@ -6,10 +6,15 @@
15847 #include <uapi/asm/boot.h>
15848
15849 /* Physical address where kernel should be loaded. */
15850 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15851 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15852 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15853 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15854
15855 +#ifndef __ASSEMBLY__
15856 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15857 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15858 +#endif
15859 +
15860 /* Minimum kernel alignment, as a power of two */
15861 #ifdef CONFIG_X86_64
15862 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15863 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15864 index 48f99f1..d78ebf9 100644
15865 --- a/arch/x86/include/asm/cache.h
15866 +++ b/arch/x86/include/asm/cache.h
15867 @@ -5,12 +5,13 @@
15868
15869 /* L1 cache line size */
15870 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15871 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15872 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15873
15874 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15875 +#define __read_only __attribute__((__section__(".data..read_only")))
15876
15877 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15878 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15879 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15880
15881 #ifdef CONFIG_X86_VSMP
15882 #ifdef CONFIG_SMP
15883 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15884 index 9863ee3..4a1f8e1 100644
15885 --- a/arch/x86/include/asm/cacheflush.h
15886 +++ b/arch/x86/include/asm/cacheflush.h
15887 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15888 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15889
15890 if (pg_flags == _PGMT_DEFAULT)
15891 - return -1;
15892 + return ~0UL;
15893 else if (pg_flags == _PGMT_WC)
15894 return _PAGE_CACHE_WC;
15895 else if (pg_flags == _PGMT_UC_MINUS)
15896 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15897 index cb4c73b..c473c29 100644
15898 --- a/arch/x86/include/asm/calling.h
15899 +++ b/arch/x86/include/asm/calling.h
15900 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15901 #define RSP 152
15902 #define SS 160
15903
15904 -#define ARGOFFSET R11
15905 -#define SWFRAME ORIG_RAX
15906 +#define ARGOFFSET R15
15907
15908 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15909 - subq $9*8+\addskip, %rsp
15910 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15911 - movq_cfi rdi, 8*8
15912 - movq_cfi rsi, 7*8
15913 - movq_cfi rdx, 6*8
15914 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15915 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15916 + movq_cfi rdi, RDI
15917 + movq_cfi rsi, RSI
15918 + movq_cfi rdx, RDX
15919
15920 .if \save_rcx
15921 - movq_cfi rcx, 5*8
15922 + movq_cfi rcx, RCX
15923 .endif
15924
15925 - movq_cfi rax, 4*8
15926 + movq_cfi rax, RAX
15927
15928 .if \save_r891011
15929 - movq_cfi r8, 3*8
15930 - movq_cfi r9, 2*8
15931 - movq_cfi r10, 1*8
15932 - movq_cfi r11, 0*8
15933 + movq_cfi r8, R8
15934 + movq_cfi r9, R9
15935 + movq_cfi r10, R10
15936 + movq_cfi r11, R11
15937 .endif
15938
15939 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15940 + movq_cfi r12, R12
15941 +#endif
15942 +
15943 .endm
15944
15945 -#define ARG_SKIP (9*8)
15946 +#define ARG_SKIP ORIG_RAX
15947
15948 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15949 rstor_r8910=1, rstor_rdx=1
15950 +
15951 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15952 + movq_cfi_restore R12, r12
15953 +#endif
15954 +
15955 .if \rstor_r11
15956 - movq_cfi_restore 0*8, r11
15957 + movq_cfi_restore R11, r11
15958 .endif
15959
15960 .if \rstor_r8910
15961 - movq_cfi_restore 1*8, r10
15962 - movq_cfi_restore 2*8, r9
15963 - movq_cfi_restore 3*8, r8
15964 + movq_cfi_restore R10, r10
15965 + movq_cfi_restore R9, r9
15966 + movq_cfi_restore R8, r8
15967 .endif
15968
15969 .if \rstor_rax
15970 - movq_cfi_restore 4*8, rax
15971 + movq_cfi_restore RAX, rax
15972 .endif
15973
15974 .if \rstor_rcx
15975 - movq_cfi_restore 5*8, rcx
15976 + movq_cfi_restore RCX, rcx
15977 .endif
15978
15979 .if \rstor_rdx
15980 - movq_cfi_restore 6*8, rdx
15981 + movq_cfi_restore RDX, rdx
15982 .endif
15983
15984 - movq_cfi_restore 7*8, rsi
15985 - movq_cfi_restore 8*8, rdi
15986 + movq_cfi_restore RSI, rsi
15987 + movq_cfi_restore RDI, rdi
15988
15989 - .if ARG_SKIP+\addskip > 0
15990 - addq $ARG_SKIP+\addskip, %rsp
15991 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15992 + .if ORIG_RAX+\addskip > 0
15993 + addq $ORIG_RAX+\addskip, %rsp
15994 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15995 .endif
15996 .endm
15997
15998 - .macro LOAD_ARGS offset, skiprax=0
15999 - movq \offset(%rsp), %r11
16000 - movq \offset+8(%rsp), %r10
16001 - movq \offset+16(%rsp), %r9
16002 - movq \offset+24(%rsp), %r8
16003 - movq \offset+40(%rsp), %rcx
16004 - movq \offset+48(%rsp), %rdx
16005 - movq \offset+56(%rsp), %rsi
16006 - movq \offset+64(%rsp), %rdi
16007 + .macro LOAD_ARGS skiprax=0
16008 + movq R11(%rsp), %r11
16009 + movq R10(%rsp), %r10
16010 + movq R9(%rsp), %r9
16011 + movq R8(%rsp), %r8
16012 + movq RCX(%rsp), %rcx
16013 + movq RDX(%rsp), %rdx
16014 + movq RSI(%rsp), %rsi
16015 + movq RDI(%rsp), %rdi
16016 .if \skiprax
16017 .else
16018 - movq \offset+72(%rsp), %rax
16019 + movq RAX(%rsp), %rax
16020 .endif
16021 .endm
16022
16023 -#define REST_SKIP (6*8)
16024 -
16025 .macro SAVE_REST
16026 - subq $REST_SKIP, %rsp
16027 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16028 - movq_cfi rbx, 5*8
16029 - movq_cfi rbp, 4*8
16030 - movq_cfi r12, 3*8
16031 - movq_cfi r13, 2*8
16032 - movq_cfi r14, 1*8
16033 - movq_cfi r15, 0*8
16034 + movq_cfi rbx, RBX
16035 + movq_cfi rbp, RBP
16036 +
16037 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16038 + movq_cfi r12, R12
16039 +#endif
16040 +
16041 + movq_cfi r13, R13
16042 + movq_cfi r14, R14
16043 + movq_cfi r15, R15
16044 .endm
16045
16046 .macro RESTORE_REST
16047 - movq_cfi_restore 0*8, r15
16048 - movq_cfi_restore 1*8, r14
16049 - movq_cfi_restore 2*8, r13
16050 - movq_cfi_restore 3*8, r12
16051 - movq_cfi_restore 4*8, rbp
16052 - movq_cfi_restore 5*8, rbx
16053 - addq $REST_SKIP, %rsp
16054 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16055 + movq_cfi_restore R15, r15
16056 + movq_cfi_restore R14, r14
16057 + movq_cfi_restore R13, r13
16058 +
16059 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16060 + movq_cfi_restore R12, r12
16061 +#endif
16062 +
16063 + movq_cfi_restore RBP, rbp
16064 + movq_cfi_restore RBX, rbx
16065 .endm
16066
16067 .macro SAVE_ALL
16068 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16069 index f50de69..2b0a458 100644
16070 --- a/arch/x86/include/asm/checksum_32.h
16071 +++ b/arch/x86/include/asm/checksum_32.h
16072 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16073 int len, __wsum sum,
16074 int *src_err_ptr, int *dst_err_ptr);
16075
16076 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16077 + int len, __wsum sum,
16078 + int *src_err_ptr, int *dst_err_ptr);
16079 +
16080 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16081 + int len, __wsum sum,
16082 + int *src_err_ptr, int *dst_err_ptr);
16083 +
16084 /*
16085 * Note: when you get a NULL pointer exception here this means someone
16086 * passed in an incorrect kernel address to one of these functions.
16087 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16088
16089 might_sleep();
16090 stac();
16091 - ret = csum_partial_copy_generic((__force void *)src, dst,
16092 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16093 len, sum, err_ptr, NULL);
16094 clac();
16095
16096 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16097 might_sleep();
16098 if (access_ok(VERIFY_WRITE, dst, len)) {
16099 stac();
16100 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16101 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16102 len, sum, NULL, err_ptr);
16103 clac();
16104 return ret;
16105 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16106 index d47786a..2d8883e 100644
16107 --- a/arch/x86/include/asm/cmpxchg.h
16108 +++ b/arch/x86/include/asm/cmpxchg.h
16109 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16110 __compiletime_error("Bad argument size for cmpxchg");
16111 extern void __xadd_wrong_size(void)
16112 __compiletime_error("Bad argument size for xadd");
16113 +extern void __xadd_check_overflow_wrong_size(void)
16114 + __compiletime_error("Bad argument size for xadd_check_overflow");
16115 extern void __add_wrong_size(void)
16116 __compiletime_error("Bad argument size for add");
16117 +extern void __add_check_overflow_wrong_size(void)
16118 + __compiletime_error("Bad argument size for add_check_overflow");
16119
16120 /*
16121 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16122 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16123 __ret; \
16124 })
16125
16126 +#ifdef CONFIG_PAX_REFCOUNT
16127 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16128 + ({ \
16129 + __typeof__ (*(ptr)) __ret = (arg); \
16130 + switch (sizeof(*(ptr))) { \
16131 + case __X86_CASE_L: \
16132 + asm volatile (lock #op "l %0, %1\n" \
16133 + "jno 0f\n" \
16134 + "mov %0,%1\n" \
16135 + "int $4\n0:\n" \
16136 + _ASM_EXTABLE(0b, 0b) \
16137 + : "+r" (__ret), "+m" (*(ptr)) \
16138 + : : "memory", "cc"); \
16139 + break; \
16140 + case __X86_CASE_Q: \
16141 + asm volatile (lock #op "q %q0, %1\n" \
16142 + "jno 0f\n" \
16143 + "mov %0,%1\n" \
16144 + "int $4\n0:\n" \
16145 + _ASM_EXTABLE(0b, 0b) \
16146 + : "+r" (__ret), "+m" (*(ptr)) \
16147 + : : "memory", "cc"); \
16148 + break; \
16149 + default: \
16150 + __ ## op ## _check_overflow_wrong_size(); \
16151 + } \
16152 + __ret; \
16153 + })
16154 +#else
16155 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16156 +#endif
16157 +
16158 /*
16159 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16160 * Since this is generally used to protect other memory information, we
16161 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16162 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16163 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16164
16165 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16166 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16167 +
16168 #define __add(ptr, inc, lock) \
16169 ({ \
16170 __typeof__ (*(ptr)) __ret = (inc); \
16171 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16172 index 59c6c40..5e0b22c 100644
16173 --- a/arch/x86/include/asm/compat.h
16174 +++ b/arch/x86/include/asm/compat.h
16175 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16176 typedef u32 compat_uint_t;
16177 typedef u32 compat_ulong_t;
16178 typedef u64 __attribute__((aligned(4))) compat_u64;
16179 -typedef u32 compat_uptr_t;
16180 +typedef u32 __user compat_uptr_t;
16181
16182 struct compat_timespec {
16183 compat_time_t tv_sec;
16184 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16185 index e265ff9..72c253b 100644
16186 --- a/arch/x86/include/asm/cpufeature.h
16187 +++ b/arch/x86/include/asm/cpufeature.h
16188 @@ -203,7 +203,7 @@
16189 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16190 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16191 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16192 -
16193 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16194
16195 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16196 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16197 @@ -211,7 +211,7 @@
16198 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16199 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16200 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16201 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16202 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16203 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16204 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16205 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16206 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16207 #undef cpu_has_centaur_mcr
16208 #define cpu_has_centaur_mcr 0
16209
16210 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16211 #endif /* CONFIG_X86_64 */
16212
16213 #if __GNUC__ >= 4
16214 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16215
16216 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16217 t_warn:
16218 - warn_pre_alternatives();
16219 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16220 + warn_pre_alternatives();
16221 return false;
16222 #endif
16223
16224 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16225 ".section .discard,\"aw\",@progbits\n"
16226 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16227 ".previous\n"
16228 - ".section .altinstr_replacement,\"ax\"\n"
16229 + ".section .altinstr_replacement,\"a\"\n"
16230 "3: movb $1,%0\n"
16231 "4:\n"
16232 ".previous\n"
16233 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16234 " .byte 2b - 1b\n" /* src len */
16235 " .byte 4f - 3f\n" /* repl len */
16236 ".previous\n"
16237 - ".section .altinstr_replacement,\"ax\"\n"
16238 + ".section .altinstr_replacement,\"a\"\n"
16239 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16240 "4:\n"
16241 ".previous\n"
16242 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16243 ".section .discard,\"aw\",@progbits\n"
16244 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16245 ".previous\n"
16246 - ".section .altinstr_replacement,\"ax\"\n"
16247 + ".section .altinstr_replacement,\"a\"\n"
16248 "3: movb $0,%0\n"
16249 "4:\n"
16250 ".previous\n"
16251 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16252 ".section .discard,\"aw\",@progbits\n"
16253 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16254 ".previous\n"
16255 - ".section .altinstr_replacement,\"ax\"\n"
16256 + ".section .altinstr_replacement,\"a\"\n"
16257 "5: movb $1,%0\n"
16258 "6:\n"
16259 ".previous\n"
16260 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16261 index 50d033a..37deb26 100644
16262 --- a/arch/x86/include/asm/desc.h
16263 +++ b/arch/x86/include/asm/desc.h
16264 @@ -4,6 +4,7 @@
16265 #include <asm/desc_defs.h>
16266 #include <asm/ldt.h>
16267 #include <asm/mmu.h>
16268 +#include <asm/pgtable.h>
16269
16270 #include <linux/smp.h>
16271 #include <linux/percpu.h>
16272 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16273
16274 desc->type = (info->read_exec_only ^ 1) << 1;
16275 desc->type |= info->contents << 2;
16276 + desc->type |= info->seg_not_present ^ 1;
16277
16278 desc->s = 1;
16279 desc->dpl = 0x3;
16280 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16281 }
16282
16283 extern struct desc_ptr idt_descr;
16284 -extern gate_desc idt_table[];
16285 -extern struct desc_ptr debug_idt_descr;
16286 -extern gate_desc debug_idt_table[];
16287 -
16288 -struct gdt_page {
16289 - struct desc_struct gdt[GDT_ENTRIES];
16290 -} __attribute__((aligned(PAGE_SIZE)));
16291 -
16292 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16293 +extern gate_desc idt_table[IDT_ENTRIES];
16294 +extern const struct desc_ptr debug_idt_descr;
16295 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16296
16297 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16298 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16299 {
16300 - return per_cpu(gdt_page, cpu).gdt;
16301 + return cpu_gdt_table[cpu];
16302 }
16303
16304 #ifdef CONFIG_X86_64
16305 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16306 unsigned long base, unsigned dpl, unsigned flags,
16307 unsigned short seg)
16308 {
16309 - gate->a = (seg << 16) | (base & 0xffff);
16310 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16311 + gate->gate.offset_low = base;
16312 + gate->gate.seg = seg;
16313 + gate->gate.reserved = 0;
16314 + gate->gate.type = type;
16315 + gate->gate.s = 0;
16316 + gate->gate.dpl = dpl;
16317 + gate->gate.p = 1;
16318 + gate->gate.offset_high = base >> 16;
16319 }
16320
16321 #endif
16322 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16323
16324 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16325 {
16326 + pax_open_kernel();
16327 memcpy(&idt[entry], gate, sizeof(*gate));
16328 + pax_close_kernel();
16329 }
16330
16331 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16332 {
16333 + pax_open_kernel();
16334 memcpy(&ldt[entry], desc, 8);
16335 + pax_close_kernel();
16336 }
16337
16338 static inline void
16339 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16340 default: size = sizeof(*gdt); break;
16341 }
16342
16343 + pax_open_kernel();
16344 memcpy(&gdt[entry], desc, size);
16345 + pax_close_kernel();
16346 }
16347
16348 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16349 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16350
16351 static inline void native_load_tr_desc(void)
16352 {
16353 + pax_open_kernel();
16354 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16355 + pax_close_kernel();
16356 }
16357
16358 static inline void native_load_gdt(const struct desc_ptr *dtr)
16359 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16360 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16361 unsigned int i;
16362
16363 + pax_open_kernel();
16364 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16365 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16366 + pax_close_kernel();
16367 }
16368
16369 #define _LDT_empty(info) \
16370 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16371 preempt_enable();
16372 }
16373
16374 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16375 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16376 {
16377 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16378 }
16379 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16380 }
16381
16382 #ifdef CONFIG_X86_64
16383 -static inline void set_nmi_gate(int gate, void *addr)
16384 +static inline void set_nmi_gate(int gate, const void *addr)
16385 {
16386 gate_desc s;
16387
16388 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16389 #endif
16390
16391 #ifdef CONFIG_TRACING
16392 -extern struct desc_ptr trace_idt_descr;
16393 -extern gate_desc trace_idt_table[];
16394 +extern const struct desc_ptr trace_idt_descr;
16395 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16396 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16397 {
16398 write_idt_entry(trace_idt_table, entry, gate);
16399 }
16400
16401 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16402 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16403 unsigned dpl, unsigned ist, unsigned seg)
16404 {
16405 gate_desc s;
16406 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16407 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16408 #endif
16409
16410 -static inline void _set_gate(int gate, unsigned type, void *addr,
16411 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16412 unsigned dpl, unsigned ist, unsigned seg)
16413 {
16414 gate_desc s;
16415 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16416 #define set_intr_gate(n, addr) \
16417 do { \
16418 BUG_ON((unsigned)n > 0xFF); \
16419 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16420 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16421 __KERNEL_CS); \
16422 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16423 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16424 0, 0, __KERNEL_CS); \
16425 } while (0)
16426
16427 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16428 /*
16429 * This routine sets up an interrupt gate at directory privilege level 3.
16430 */
16431 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16432 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16433 {
16434 BUG_ON((unsigned)n > 0xFF);
16435 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16436 }
16437
16438 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16439 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16440 {
16441 BUG_ON((unsigned)n > 0xFF);
16442 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16443 }
16444
16445 -static inline void set_trap_gate(unsigned int n, void *addr)
16446 +static inline void set_trap_gate(unsigned int n, const void *addr)
16447 {
16448 BUG_ON((unsigned)n > 0xFF);
16449 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16450 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16451 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16452 {
16453 BUG_ON((unsigned)n > 0xFF);
16454 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16455 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16456 }
16457
16458 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16459 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16460 {
16461 BUG_ON((unsigned)n > 0xFF);
16462 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16463 }
16464
16465 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16466 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16467 {
16468 BUG_ON((unsigned)n > 0xFF);
16469 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16470 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16471 else
16472 load_idt((const struct desc_ptr *)&idt_descr);
16473 }
16474 +
16475 +#ifdef CONFIG_X86_32
16476 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16477 +{
16478 + struct desc_struct d;
16479 +
16480 + if (likely(limit))
16481 + limit = (limit - 1UL) >> PAGE_SHIFT;
16482 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16483 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16484 +}
16485 +#endif
16486 +
16487 #endif /* _ASM_X86_DESC_H */
16488 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16489 index 278441f..b95a174 100644
16490 --- a/arch/x86/include/asm/desc_defs.h
16491 +++ b/arch/x86/include/asm/desc_defs.h
16492 @@ -31,6 +31,12 @@ struct desc_struct {
16493 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16494 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16495 };
16496 + struct {
16497 + u16 offset_low;
16498 + u16 seg;
16499 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16500 + unsigned offset_high: 16;
16501 + } gate;
16502 };
16503 } __attribute__((packed));
16504
16505 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16506 index ced283a..ffe04cc 100644
16507 --- a/arch/x86/include/asm/div64.h
16508 +++ b/arch/x86/include/asm/div64.h
16509 @@ -39,7 +39,7 @@
16510 __mod; \
16511 })
16512
16513 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16514 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16515 {
16516 union {
16517 u64 v64;
16518 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16519 index 2c71182..731124d 100644
16520 --- a/arch/x86/include/asm/elf.h
16521 +++ b/arch/x86/include/asm/elf.h
16522 @@ -243,7 +243,25 @@ extern int force_personality32;
16523 the loader. We need to make sure that it is out of the way of the program
16524 that it will "exec", and that there is sufficient room for the brk. */
16525
16526 +#ifdef CONFIG_PAX_SEGMEXEC
16527 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16528 +#else
16529 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16530 +#endif
16531 +
16532 +#ifdef CONFIG_PAX_ASLR
16533 +#ifdef CONFIG_X86_32
16534 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16535 +
16536 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16537 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16538 +#else
16539 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16540 +
16541 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16542 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16543 +#endif
16544 +#endif
16545
16546 /* This yields a mask that user programs can use to figure out what
16547 instruction set this CPU supports. This could be done in user space,
16548 @@ -292,16 +310,12 @@ do { \
16549
16550 #define ARCH_DLINFO \
16551 do { \
16552 - if (vdso_enabled) \
16553 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16554 - (unsigned long)current->mm->context.vdso); \
16555 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16556 } while (0)
16557
16558 #define ARCH_DLINFO_X32 \
16559 do { \
16560 - if (vdso_enabled) \
16561 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16562 - (unsigned long)current->mm->context.vdso); \
16563 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16564 } while (0)
16565
16566 #define AT_SYSINFO 32
16567 @@ -316,7 +330,7 @@ else \
16568
16569 #endif /* !CONFIG_X86_32 */
16570
16571 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16572 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16573
16574 #define VDSO_ENTRY \
16575 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16576 @@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16577 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16578 #define compat_arch_setup_additional_pages syscall32_setup_pages
16579
16580 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16581 -#define arch_randomize_brk arch_randomize_brk
16582 -
16583 /*
16584 * True on X86_32 or when emulating IA32 on X86_64
16585 */
16586 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16587 index 77a99ac..39ff7f5 100644
16588 --- a/arch/x86/include/asm/emergency-restart.h
16589 +++ b/arch/x86/include/asm/emergency-restart.h
16590 @@ -1,6 +1,6 @@
16591 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16592 #define _ASM_X86_EMERGENCY_RESTART_H
16593
16594 -extern void machine_emergency_restart(void);
16595 +extern void machine_emergency_restart(void) __noreturn;
16596
16597 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16598 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16599 index 1c7eefe..d0e4702 100644
16600 --- a/arch/x86/include/asm/floppy.h
16601 +++ b/arch/x86/include/asm/floppy.h
16602 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16603 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16604 } fd_routine[] = {
16605 {
16606 - request_dma,
16607 - free_dma,
16608 - get_dma_residue,
16609 - dma_mem_alloc,
16610 - hard_dma_setup
16611 + ._request_dma = request_dma,
16612 + ._free_dma = free_dma,
16613 + ._get_dma_residue = get_dma_residue,
16614 + ._dma_mem_alloc = dma_mem_alloc,
16615 + ._dma_setup = hard_dma_setup
16616 },
16617 {
16618 - vdma_request_dma,
16619 - vdma_nop,
16620 - vdma_get_dma_residue,
16621 - vdma_mem_alloc,
16622 - vdma_dma_setup
16623 + ._request_dma = vdma_request_dma,
16624 + ._free_dma = vdma_nop,
16625 + ._get_dma_residue = vdma_get_dma_residue,
16626 + ._dma_mem_alloc = vdma_mem_alloc,
16627 + ._dma_setup = vdma_dma_setup
16628 }
16629 };
16630
16631 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16632 index cea1c76..6c0d79b 100644
16633 --- a/arch/x86/include/asm/fpu-internal.h
16634 +++ b/arch/x86/include/asm/fpu-internal.h
16635 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16636 #define user_insn(insn, output, input...) \
16637 ({ \
16638 int err; \
16639 + pax_open_userland(); \
16640 asm volatile(ASM_STAC "\n" \
16641 - "1:" #insn "\n\t" \
16642 + "1:" \
16643 + __copyuser_seg \
16644 + #insn "\n\t" \
16645 "2: " ASM_CLAC "\n" \
16646 ".section .fixup,\"ax\"\n" \
16647 "3: movl $-1,%[err]\n" \
16648 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16649 _ASM_EXTABLE(1b, 3b) \
16650 : [err] "=r" (err), output \
16651 : "0"(0), input); \
16652 + pax_close_userland(); \
16653 err; \
16654 })
16655
16656 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16657 "fnclex\n\t"
16658 "emms\n\t"
16659 "fildl %P[addr]" /* set F?P to defined value */
16660 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16661 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16662 }
16663
16664 return fpu_restore_checking(&tsk->thread.fpu);
16665 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16666 index b4c1f54..e290c08 100644
16667 --- a/arch/x86/include/asm/futex.h
16668 +++ b/arch/x86/include/asm/futex.h
16669 @@ -12,6 +12,7 @@
16670 #include <asm/smap.h>
16671
16672 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16673 + typecheck(u32 __user *, uaddr); \
16674 asm volatile("\t" ASM_STAC "\n" \
16675 "1:\t" insn "\n" \
16676 "2:\t" ASM_CLAC "\n" \
16677 @@ -20,15 +21,16 @@
16678 "\tjmp\t2b\n" \
16679 "\t.previous\n" \
16680 _ASM_EXTABLE(1b, 3b) \
16681 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16682 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16683 : "i" (-EFAULT), "0" (oparg), "1" (0))
16684
16685 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16686 + typecheck(u32 __user *, uaddr); \
16687 asm volatile("\t" ASM_STAC "\n" \
16688 "1:\tmovl %2, %0\n" \
16689 "\tmovl\t%0, %3\n" \
16690 "\t" insn "\n" \
16691 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16692 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16693 "\tjnz\t1b\n" \
16694 "3:\t" ASM_CLAC "\n" \
16695 "\t.section .fixup,\"ax\"\n" \
16696 @@ -38,7 +40,7 @@
16697 _ASM_EXTABLE(1b, 4b) \
16698 _ASM_EXTABLE(2b, 4b) \
16699 : "=&a" (oldval), "=&r" (ret), \
16700 - "+m" (*uaddr), "=&r" (tem) \
16701 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16702 : "r" (oparg), "i" (-EFAULT), "1" (0))
16703
16704 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16705 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16706
16707 pagefault_disable();
16708
16709 + pax_open_userland();
16710 switch (op) {
16711 case FUTEX_OP_SET:
16712 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16713 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16714 break;
16715 case FUTEX_OP_ADD:
16716 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16717 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16718 uaddr, oparg);
16719 break;
16720 case FUTEX_OP_OR:
16721 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16722 default:
16723 ret = -ENOSYS;
16724 }
16725 + pax_close_userland();
16726
16727 pagefault_enable();
16728
16729 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16730 index a307b75..ec74ca2 100644
16731 --- a/arch/x86/include/asm/hw_irq.h
16732 +++ b/arch/x86/include/asm/hw_irq.h
16733 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16734 extern void enable_IO_APIC(void);
16735
16736 /* Statistics */
16737 -extern atomic_t irq_err_count;
16738 -extern atomic_t irq_mis_count;
16739 +extern atomic_unchecked_t irq_err_count;
16740 +extern atomic_unchecked_t irq_mis_count;
16741
16742 /* EISA */
16743 extern void eisa_set_level_irq(unsigned int irq);
16744 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16745 index a203659..9889f1c 100644
16746 --- a/arch/x86/include/asm/i8259.h
16747 +++ b/arch/x86/include/asm/i8259.h
16748 @@ -62,7 +62,7 @@ struct legacy_pic {
16749 void (*init)(int auto_eoi);
16750 int (*irq_pending)(unsigned int irq);
16751 void (*make_irq)(unsigned int irq);
16752 -};
16753 +} __do_const;
16754
16755 extern struct legacy_pic *legacy_pic;
16756 extern struct legacy_pic null_legacy_pic;
16757 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16758 index b8237d8..3e8864e 100644
16759 --- a/arch/x86/include/asm/io.h
16760 +++ b/arch/x86/include/asm/io.h
16761 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16762 "m" (*(volatile type __force *)addr) barrier); }
16763
16764 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16765 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16766 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16767 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16768 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16769
16770 build_mmio_read(__readb, "b", unsigned char, "=q", )
16771 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16772 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16773 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16774 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16775
16776 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16777 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16778 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16779 * this function
16780 */
16781
16782 -static inline phys_addr_t virt_to_phys(volatile void *address)
16783 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16784 {
16785 return __pa(address);
16786 }
16787 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16788 return ioremap_nocache(offset, size);
16789 }
16790
16791 -extern void iounmap(volatile void __iomem *addr);
16792 +extern void iounmap(const volatile void __iomem *addr);
16793
16794 extern void set_iounmap_nonlazy(void);
16795
16796 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16797
16798 #include <linux/vmalloc.h>
16799
16800 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16801 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16802 +{
16803 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16804 +}
16805 +
16806 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16807 +{
16808 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16809 +}
16810 +
16811 /*
16812 * Convert a virtual cached pointer to an uncached pointer
16813 */
16814 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16815 index bba3cf8..06bc8da 100644
16816 --- a/arch/x86/include/asm/irqflags.h
16817 +++ b/arch/x86/include/asm/irqflags.h
16818 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16819 sti; \
16820 sysexit
16821
16822 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16823 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16824 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16825 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16826 +
16827 #else
16828 #define INTERRUPT_RETURN iret
16829 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16830 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16831 index 9454c16..e4100e3 100644
16832 --- a/arch/x86/include/asm/kprobes.h
16833 +++ b/arch/x86/include/asm/kprobes.h
16834 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16835 #define RELATIVEJUMP_SIZE 5
16836 #define RELATIVECALL_OPCODE 0xe8
16837 #define RELATIVE_ADDR_SIZE 4
16838 -#define MAX_STACK_SIZE 64
16839 -#define MIN_STACK_SIZE(ADDR) \
16840 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16841 - THREAD_SIZE - (unsigned long)(ADDR))) \
16842 - ? (MAX_STACK_SIZE) \
16843 - : (((unsigned long)current_thread_info()) + \
16844 - THREAD_SIZE - (unsigned long)(ADDR)))
16845 +#define MAX_STACK_SIZE 64UL
16846 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16847
16848 #define flush_insn_slot(p) do { } while (0)
16849
16850 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16851 index 4ad6560..75c7bdd 100644
16852 --- a/arch/x86/include/asm/local.h
16853 +++ b/arch/x86/include/asm/local.h
16854 @@ -10,33 +10,97 @@ typedef struct {
16855 atomic_long_t a;
16856 } local_t;
16857
16858 +typedef struct {
16859 + atomic_long_unchecked_t a;
16860 +} local_unchecked_t;
16861 +
16862 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16863
16864 #define local_read(l) atomic_long_read(&(l)->a)
16865 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16866 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16867 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16868
16869 static inline void local_inc(local_t *l)
16870 {
16871 - asm volatile(_ASM_INC "%0"
16872 + asm volatile(_ASM_INC "%0\n"
16873 +
16874 +#ifdef CONFIG_PAX_REFCOUNT
16875 + "jno 0f\n"
16876 + _ASM_DEC "%0\n"
16877 + "int $4\n0:\n"
16878 + _ASM_EXTABLE(0b, 0b)
16879 +#endif
16880 +
16881 + : "+m" (l->a.counter));
16882 +}
16883 +
16884 +static inline void local_inc_unchecked(local_unchecked_t *l)
16885 +{
16886 + asm volatile(_ASM_INC "%0\n"
16887 : "+m" (l->a.counter));
16888 }
16889
16890 static inline void local_dec(local_t *l)
16891 {
16892 - asm volatile(_ASM_DEC "%0"
16893 + asm volatile(_ASM_DEC "%0\n"
16894 +
16895 +#ifdef CONFIG_PAX_REFCOUNT
16896 + "jno 0f\n"
16897 + _ASM_INC "%0\n"
16898 + "int $4\n0:\n"
16899 + _ASM_EXTABLE(0b, 0b)
16900 +#endif
16901 +
16902 + : "+m" (l->a.counter));
16903 +}
16904 +
16905 +static inline void local_dec_unchecked(local_unchecked_t *l)
16906 +{
16907 + asm volatile(_ASM_DEC "%0\n"
16908 : "+m" (l->a.counter));
16909 }
16910
16911 static inline void local_add(long i, local_t *l)
16912 {
16913 - asm volatile(_ASM_ADD "%1,%0"
16914 + asm volatile(_ASM_ADD "%1,%0\n"
16915 +
16916 +#ifdef CONFIG_PAX_REFCOUNT
16917 + "jno 0f\n"
16918 + _ASM_SUB "%1,%0\n"
16919 + "int $4\n0:\n"
16920 + _ASM_EXTABLE(0b, 0b)
16921 +#endif
16922 +
16923 + : "+m" (l->a.counter)
16924 + : "ir" (i));
16925 +}
16926 +
16927 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16928 +{
16929 + asm volatile(_ASM_ADD "%1,%0\n"
16930 : "+m" (l->a.counter)
16931 : "ir" (i));
16932 }
16933
16934 static inline void local_sub(long i, local_t *l)
16935 {
16936 - asm volatile(_ASM_SUB "%1,%0"
16937 + asm volatile(_ASM_SUB "%1,%0\n"
16938 +
16939 +#ifdef CONFIG_PAX_REFCOUNT
16940 + "jno 0f\n"
16941 + _ASM_ADD "%1,%0\n"
16942 + "int $4\n0:\n"
16943 + _ASM_EXTABLE(0b, 0b)
16944 +#endif
16945 +
16946 + : "+m" (l->a.counter)
16947 + : "ir" (i));
16948 +}
16949 +
16950 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16951 +{
16952 + asm volatile(_ASM_SUB "%1,%0\n"
16953 : "+m" (l->a.counter)
16954 : "ir" (i));
16955 }
16956 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16957 */
16958 static inline int local_sub_and_test(long i, local_t *l)
16959 {
16960 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16961 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16962 }
16963
16964 /**
16965 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16966 */
16967 static inline int local_dec_and_test(local_t *l)
16968 {
16969 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16970 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16971 }
16972
16973 /**
16974 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16975 */
16976 static inline int local_inc_and_test(local_t *l)
16977 {
16978 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16979 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16980 }
16981
16982 /**
16983 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16984 */
16985 static inline int local_add_negative(long i, local_t *l)
16986 {
16987 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16988 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16989 }
16990
16991 /**
16992 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16993 static inline long local_add_return(long i, local_t *l)
16994 {
16995 long __i = i;
16996 + asm volatile(_ASM_XADD "%0, %1\n"
16997 +
16998 +#ifdef CONFIG_PAX_REFCOUNT
16999 + "jno 0f\n"
17000 + _ASM_MOV "%0,%1\n"
17001 + "int $4\n0:\n"
17002 + _ASM_EXTABLE(0b, 0b)
17003 +#endif
17004 +
17005 + : "+r" (i), "+m" (l->a.counter)
17006 + : : "memory");
17007 + return i + __i;
17008 +}
17009 +
17010 +/**
17011 + * local_add_return_unchecked - add and return
17012 + * @i: integer value to add
17013 + * @l: pointer to type local_unchecked_t
17014 + *
17015 + * Atomically adds @i to @l and returns @i + @l
17016 + */
17017 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17018 +{
17019 + long __i = i;
17020 asm volatile(_ASM_XADD "%0, %1;"
17021 : "+r" (i), "+m" (l->a.counter)
17022 : : "memory");
17023 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17024
17025 #define local_cmpxchg(l, o, n) \
17026 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17027 +#define local_cmpxchg_unchecked(l, o, n) \
17028 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17029 /* Always has a lock prefix */
17030 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17031
17032 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17033 new file mode 100644
17034 index 0000000..2bfd3ba
17035 --- /dev/null
17036 +++ b/arch/x86/include/asm/mman.h
17037 @@ -0,0 +1,15 @@
17038 +#ifndef _X86_MMAN_H
17039 +#define _X86_MMAN_H
17040 +
17041 +#include <uapi/asm/mman.h>
17042 +
17043 +#ifdef __KERNEL__
17044 +#ifndef __ASSEMBLY__
17045 +#ifdef CONFIG_X86_32
17046 +#define arch_mmap_check i386_mmap_check
17047 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17048 +#endif
17049 +#endif
17050 +#endif
17051 +
17052 +#endif /* X86_MMAN_H */
17053 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17054 index 5f55e69..e20bfb1 100644
17055 --- a/arch/x86/include/asm/mmu.h
17056 +++ b/arch/x86/include/asm/mmu.h
17057 @@ -9,7 +9,7 @@
17058 * we put the segment information here.
17059 */
17060 typedef struct {
17061 - void *ldt;
17062 + struct desc_struct *ldt;
17063 int size;
17064
17065 #ifdef CONFIG_X86_64
17066 @@ -18,7 +18,19 @@ typedef struct {
17067 #endif
17068
17069 struct mutex lock;
17070 - void *vdso;
17071 + unsigned long vdso;
17072 +
17073 +#ifdef CONFIG_X86_32
17074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17075 + unsigned long user_cs_base;
17076 + unsigned long user_cs_limit;
17077 +
17078 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17079 + cpumask_t cpu_user_cs_mask;
17080 +#endif
17081 +
17082 +#endif
17083 +#endif
17084 } mm_context_t;
17085
17086 #ifdef CONFIG_SMP
17087 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17088 index be12c53..4d24039 100644
17089 --- a/arch/x86/include/asm/mmu_context.h
17090 +++ b/arch/x86/include/asm/mmu_context.h
17091 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17092
17093 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17094 {
17095 +
17096 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17097 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17098 + unsigned int i;
17099 + pgd_t *pgd;
17100 +
17101 + pax_open_kernel();
17102 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17103 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17104 + set_pgd_batched(pgd+i, native_make_pgd(0));
17105 + pax_close_kernel();
17106 + }
17107 +#endif
17108 +
17109 #ifdef CONFIG_SMP
17110 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17111 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17112 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17113 struct task_struct *tsk)
17114 {
17115 unsigned cpu = smp_processor_id();
17116 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17117 + int tlbstate = TLBSTATE_OK;
17118 +#endif
17119
17120 if (likely(prev != next)) {
17121 #ifdef CONFIG_SMP
17122 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17123 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17124 +#endif
17125 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17126 this_cpu_write(cpu_tlbstate.active_mm, next);
17127 #endif
17128 cpumask_set_cpu(cpu, mm_cpumask(next));
17129
17130 /* Re-load page tables */
17131 +#ifdef CONFIG_PAX_PER_CPU_PGD
17132 + pax_open_kernel();
17133 +
17134 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17135 + if (static_cpu_has(X86_FEATURE_PCID))
17136 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17137 + else
17138 +#endif
17139 +
17140 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17141 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17142 + pax_close_kernel();
17143 + 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));
17144 +
17145 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17146 + if (static_cpu_has(X86_FEATURE_PCID)) {
17147 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17148 + u64 descriptor[2];
17149 + descriptor[0] = PCID_USER;
17150 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17151 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17152 + descriptor[0] = PCID_KERNEL;
17153 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17154 + }
17155 + } else {
17156 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17157 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17158 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17159 + else
17160 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17161 + }
17162 + } else
17163 +#endif
17164 +
17165 + load_cr3(get_cpu_pgd(cpu, kernel));
17166 +#else
17167 load_cr3(next->pgd);
17168 +#endif
17169
17170 /* Stop flush ipis for the previous mm */
17171 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17172 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17173 /* Load the LDT, if the LDT is different: */
17174 if (unlikely(prev->context.ldt != next->context.ldt))
17175 load_LDT_nolock(&next->context);
17176 +
17177 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17178 + if (!(__supported_pte_mask & _PAGE_NX)) {
17179 + smp_mb__before_clear_bit();
17180 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17181 + smp_mb__after_clear_bit();
17182 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17183 + }
17184 +#endif
17185 +
17186 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17187 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17188 + prev->context.user_cs_limit != next->context.user_cs_limit))
17189 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17190 +#ifdef CONFIG_SMP
17191 + else if (unlikely(tlbstate != TLBSTATE_OK))
17192 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17193 +#endif
17194 +#endif
17195 +
17196 }
17197 + else {
17198 +
17199 +#ifdef CONFIG_PAX_PER_CPU_PGD
17200 + pax_open_kernel();
17201 +
17202 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17203 + if (static_cpu_has(X86_FEATURE_PCID))
17204 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17205 + else
17206 +#endif
17207 +
17208 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17209 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17210 + pax_close_kernel();
17211 + 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));
17212 +
17213 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17214 + if (static_cpu_has(X86_FEATURE_PCID)) {
17215 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17216 + u64 descriptor[2];
17217 + descriptor[0] = PCID_USER;
17218 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17219 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17220 + descriptor[0] = PCID_KERNEL;
17221 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17222 + }
17223 + } else {
17224 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17225 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17226 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17227 + else
17228 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17229 + }
17230 + } else
17231 +#endif
17232 +
17233 + load_cr3(get_cpu_pgd(cpu, kernel));
17234 +#endif
17235 +
17236 #ifdef CONFIG_SMP
17237 - else {
17238 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17239 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17240
17241 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17242 * tlb flush IPI delivery. We must reload CR3
17243 * to make sure to use no freed page tables.
17244 */
17245 +
17246 +#ifndef CONFIG_PAX_PER_CPU_PGD
17247 load_cr3(next->pgd);
17248 +#endif
17249 +
17250 load_LDT_nolock(&next->context);
17251 +
17252 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17253 + if (!(__supported_pte_mask & _PAGE_NX))
17254 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17255 +#endif
17256 +
17257 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17258 +#ifdef CONFIG_PAX_PAGEEXEC
17259 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17260 +#endif
17261 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17262 +#endif
17263 +
17264 }
17265 +#endif
17266 }
17267 -#endif
17268 }
17269
17270 #define activate_mm(prev, next) \
17271 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17272 index e3b7819..b257c64 100644
17273 --- a/arch/x86/include/asm/module.h
17274 +++ b/arch/x86/include/asm/module.h
17275 @@ -5,6 +5,7 @@
17276
17277 #ifdef CONFIG_X86_64
17278 /* X86_64 does not define MODULE_PROC_FAMILY */
17279 +#define MODULE_PROC_FAMILY ""
17280 #elif defined CONFIG_M486
17281 #define MODULE_PROC_FAMILY "486 "
17282 #elif defined CONFIG_M586
17283 @@ -57,8 +58,20 @@
17284 #error unknown processor family
17285 #endif
17286
17287 -#ifdef CONFIG_X86_32
17288 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17289 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17290 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17291 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17292 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17293 +#else
17294 +#define MODULE_PAX_KERNEXEC ""
17295 #endif
17296
17297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17298 +#define MODULE_PAX_UDEREF "UDEREF "
17299 +#else
17300 +#define MODULE_PAX_UDEREF ""
17301 +#endif
17302 +
17303 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17304 +
17305 #endif /* _ASM_X86_MODULE_H */
17306 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17307 index 5f2fc44..106caa6 100644
17308 --- a/arch/x86/include/asm/nmi.h
17309 +++ b/arch/x86/include/asm/nmi.h
17310 @@ -36,26 +36,35 @@ enum {
17311
17312 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17313
17314 +struct nmiaction;
17315 +
17316 +struct nmiwork {
17317 + const struct nmiaction *action;
17318 + u64 max_duration;
17319 + struct irq_work irq_work;
17320 +};
17321 +
17322 struct nmiaction {
17323 struct list_head list;
17324 nmi_handler_t handler;
17325 - u64 max_duration;
17326 - struct irq_work irq_work;
17327 unsigned long flags;
17328 const char *name;
17329 -};
17330 + struct nmiwork *work;
17331 +} __do_const;
17332
17333 #define register_nmi_handler(t, fn, fg, n, init...) \
17334 ({ \
17335 - static struct nmiaction init fn##_na = { \
17336 + static struct nmiwork fn##_nw; \
17337 + static const struct nmiaction init fn##_na = { \
17338 .handler = (fn), \
17339 .name = (n), \
17340 .flags = (fg), \
17341 + .work = &fn##_nw, \
17342 }; \
17343 __register_nmi_handler((t), &fn##_na); \
17344 })
17345
17346 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17347 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17348
17349 void unregister_nmi_handler(unsigned int, const char *);
17350
17351 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17352 index 775873d..04cd306 100644
17353 --- a/arch/x86/include/asm/page.h
17354 +++ b/arch/x86/include/asm/page.h
17355 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17356 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17357
17358 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17359 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17360
17361 #define __boot_va(x) __va(x)
17362 #define __boot_pa(x) __pa(x)
17363 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17364 * virt_to_page(kaddr) returns a valid pointer if and only if
17365 * virt_addr_valid(kaddr) returns true.
17366 */
17367 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17368 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17369 extern bool __virt_addr_valid(unsigned long kaddr);
17370 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17371
17372 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17373 +#define virt_to_page(kaddr) \
17374 + ({ \
17375 + const void *__kaddr = (const void *)(kaddr); \
17376 + BUG_ON(!virt_addr_valid(__kaddr)); \
17377 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17378 + })
17379 +#else
17380 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17381 +#endif
17382 +
17383 #endif /* __ASSEMBLY__ */
17384
17385 #include <asm-generic/memory_model.h>
17386 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17387 index 0f1ddee..e2fc3d1 100644
17388 --- a/arch/x86/include/asm/page_64.h
17389 +++ b/arch/x86/include/asm/page_64.h
17390 @@ -7,9 +7,9 @@
17391
17392 /* duplicated to the one in bootmem.h */
17393 extern unsigned long max_pfn;
17394 -extern unsigned long phys_base;
17395 +extern const unsigned long phys_base;
17396
17397 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17398 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17399 {
17400 unsigned long y = x - __START_KERNEL_map;
17401
17402 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17403 index cd6e1610..70f4418 100644
17404 --- a/arch/x86/include/asm/paravirt.h
17405 +++ b/arch/x86/include/asm/paravirt.h
17406 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17407 return (pmd_t) { ret };
17408 }
17409
17410 -static inline pmdval_t pmd_val(pmd_t pmd)
17411 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17412 {
17413 pmdval_t ret;
17414
17415 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17416 val);
17417 }
17418
17419 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17420 +{
17421 + pgdval_t val = native_pgd_val(pgd);
17422 +
17423 + if (sizeof(pgdval_t) > sizeof(long))
17424 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17425 + val, (u64)val >> 32);
17426 + else
17427 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17428 + val);
17429 +}
17430 +
17431 static inline void pgd_clear(pgd_t *pgdp)
17432 {
17433 set_pgd(pgdp, __pgd(0));
17434 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17435 pv_mmu_ops.set_fixmap(idx, phys, flags);
17436 }
17437
17438 +#ifdef CONFIG_PAX_KERNEXEC
17439 +static inline unsigned long pax_open_kernel(void)
17440 +{
17441 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17442 +}
17443 +
17444 +static inline unsigned long pax_close_kernel(void)
17445 +{
17446 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17447 +}
17448 +#else
17449 +static inline unsigned long pax_open_kernel(void) { return 0; }
17450 +static inline unsigned long pax_close_kernel(void) { return 0; }
17451 +#endif
17452 +
17453 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17454
17455 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17456 @@ -906,7 +933,7 @@ extern void default_banner(void);
17457
17458 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17459 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17460 -#define PARA_INDIRECT(addr) *%cs:addr
17461 +#define PARA_INDIRECT(addr) *%ss:addr
17462 #endif
17463
17464 #define INTERRUPT_RETURN \
17465 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17466 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17467 CLBR_NONE, \
17468 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17469 +
17470 +#define GET_CR0_INTO_RDI \
17471 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17472 + mov %rax,%rdi
17473 +
17474 +#define SET_RDI_INTO_CR0 \
17475 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17476 +
17477 +#define GET_CR3_INTO_RDI \
17478 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17479 + mov %rax,%rdi
17480 +
17481 +#define SET_RDI_INTO_CR3 \
17482 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17483 +
17484 #endif /* CONFIG_X86_32 */
17485
17486 #endif /* __ASSEMBLY__ */
17487 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17488 index 7549b8b..f0edfda 100644
17489 --- a/arch/x86/include/asm/paravirt_types.h
17490 +++ b/arch/x86/include/asm/paravirt_types.h
17491 @@ -84,7 +84,7 @@ struct pv_init_ops {
17492 */
17493 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17494 unsigned long addr, unsigned len);
17495 -};
17496 +} __no_const __no_randomize_layout;
17497
17498
17499 struct pv_lazy_ops {
17500 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17501 void (*enter)(void);
17502 void (*leave)(void);
17503 void (*flush)(void);
17504 -};
17505 +} __no_randomize_layout;
17506
17507 struct pv_time_ops {
17508 unsigned long long (*sched_clock)(void);
17509 unsigned long long (*steal_clock)(int cpu);
17510 unsigned long (*get_tsc_khz)(void);
17511 -};
17512 +} __no_const __no_randomize_layout;
17513
17514 struct pv_cpu_ops {
17515 /* hooks for various privileged instructions */
17516 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17517
17518 void (*start_context_switch)(struct task_struct *prev);
17519 void (*end_context_switch)(struct task_struct *next);
17520 -};
17521 +} __no_const __no_randomize_layout;
17522
17523 struct pv_irq_ops {
17524 /*
17525 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17526 #ifdef CONFIG_X86_64
17527 void (*adjust_exception_frame)(void);
17528 #endif
17529 -};
17530 +} __no_randomize_layout;
17531
17532 struct pv_apic_ops {
17533 #ifdef CONFIG_X86_LOCAL_APIC
17534 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17535 unsigned long start_eip,
17536 unsigned long start_esp);
17537 #endif
17538 -};
17539 +} __no_const __no_randomize_layout;
17540
17541 struct pv_mmu_ops {
17542 unsigned long (*read_cr2)(void);
17543 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17544 struct paravirt_callee_save make_pud;
17545
17546 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17547 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17548 #endif /* PAGETABLE_LEVELS == 4 */
17549 #endif /* PAGETABLE_LEVELS >= 3 */
17550
17551 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17552 an mfn. We can tell which is which from the index. */
17553 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17554 phys_addr_t phys, pgprot_t flags);
17555 -};
17556 +
17557 +#ifdef CONFIG_PAX_KERNEXEC
17558 + unsigned long (*pax_open_kernel)(void);
17559 + unsigned long (*pax_close_kernel)(void);
17560 +#endif
17561 +
17562 +} __no_randomize_layout;
17563
17564 struct arch_spinlock;
17565 #ifdef CONFIG_SMP
17566 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17567 struct pv_lock_ops {
17568 struct paravirt_callee_save lock_spinning;
17569 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17570 -};
17571 +} __no_randomize_layout;
17572
17573 /* This contains all the paravirt structures: we get a convenient
17574 * number for each function using the offset which we use to indicate
17575 - * what to patch. */
17576 + * what to patch.
17577 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17578 + */
17579 +
17580 struct paravirt_patch_template {
17581 struct pv_init_ops pv_init_ops;
17582 struct pv_time_ops pv_time_ops;
17583 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17584 struct pv_apic_ops pv_apic_ops;
17585 struct pv_mmu_ops pv_mmu_ops;
17586 struct pv_lock_ops pv_lock_ops;
17587 -};
17588 +} __no_randomize_layout;
17589
17590 extern struct pv_info pv_info;
17591 extern struct pv_init_ops pv_init_ops;
17592 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17593 index c4412e9..90e88c5 100644
17594 --- a/arch/x86/include/asm/pgalloc.h
17595 +++ b/arch/x86/include/asm/pgalloc.h
17596 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17597 pmd_t *pmd, pte_t *pte)
17598 {
17599 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17600 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17601 +}
17602 +
17603 +static inline void pmd_populate_user(struct mm_struct *mm,
17604 + pmd_t *pmd, pte_t *pte)
17605 +{
17606 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17607 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17608 }
17609
17610 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17611
17612 #ifdef CONFIG_X86_PAE
17613 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17614 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17615 +{
17616 + pud_populate(mm, pudp, pmd);
17617 +}
17618 #else /* !CONFIG_X86_PAE */
17619 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17620 {
17621 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17622 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17623 }
17624 +
17625 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17626 +{
17627 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17628 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17629 +}
17630 #endif /* CONFIG_X86_PAE */
17631
17632 #if PAGETABLE_LEVELS > 3
17633 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17634 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17635 }
17636
17637 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17638 +{
17639 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17640 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17641 +}
17642 +
17643 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17644 {
17645 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17646 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17647 index 0d193e2..bf59aeb 100644
17648 --- a/arch/x86/include/asm/pgtable-2level.h
17649 +++ b/arch/x86/include/asm/pgtable-2level.h
17650 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17651
17652 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17653 {
17654 + pax_open_kernel();
17655 *pmdp = pmd;
17656 + pax_close_kernel();
17657 }
17658
17659 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17660 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17661 index 81bb91b..9392125 100644
17662 --- a/arch/x86/include/asm/pgtable-3level.h
17663 +++ b/arch/x86/include/asm/pgtable-3level.h
17664 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17665
17666 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17667 {
17668 + pax_open_kernel();
17669 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17670 + pax_close_kernel();
17671 }
17672
17673 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17674 {
17675 + pax_open_kernel();
17676 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17677 + pax_close_kernel();
17678 }
17679
17680 /*
17681 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17682 index b459ddf..b44081b 100644
17683 --- a/arch/x86/include/asm/pgtable.h
17684 +++ b/arch/x86/include/asm/pgtable.h
17685 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17686
17687 #ifndef __PAGETABLE_PUD_FOLDED
17688 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17689 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17690 #define pgd_clear(pgd) native_pgd_clear(pgd)
17691 #endif
17692
17693 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17694
17695 #define arch_end_context_switch(prev) do {} while(0)
17696
17697 +#define pax_open_kernel() native_pax_open_kernel()
17698 +#define pax_close_kernel() native_pax_close_kernel()
17699 #endif /* CONFIG_PARAVIRT */
17700
17701 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17702 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17703 +
17704 +#ifdef CONFIG_PAX_KERNEXEC
17705 +static inline unsigned long native_pax_open_kernel(void)
17706 +{
17707 + unsigned long cr0;
17708 +
17709 + preempt_disable();
17710 + barrier();
17711 + cr0 = read_cr0() ^ X86_CR0_WP;
17712 + BUG_ON(cr0 & X86_CR0_WP);
17713 + write_cr0(cr0);
17714 + return cr0 ^ X86_CR0_WP;
17715 +}
17716 +
17717 +static inline unsigned long native_pax_close_kernel(void)
17718 +{
17719 + unsigned long cr0;
17720 +
17721 + cr0 = read_cr0() ^ X86_CR0_WP;
17722 + BUG_ON(!(cr0 & X86_CR0_WP));
17723 + write_cr0(cr0);
17724 + barrier();
17725 + preempt_enable_no_resched();
17726 + return cr0 ^ X86_CR0_WP;
17727 +}
17728 +#else
17729 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17730 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17731 +#endif
17732 +
17733 /*
17734 * The following only work if pte_present() is true.
17735 * Undefined behaviour if not..
17736 */
17737 +static inline int pte_user(pte_t pte)
17738 +{
17739 + return pte_val(pte) & _PAGE_USER;
17740 +}
17741 +
17742 static inline int pte_dirty(pte_t pte)
17743 {
17744 return pte_flags(pte) & _PAGE_DIRTY;
17745 @@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17746 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17747 }
17748
17749 +static inline unsigned long pgd_pfn(pgd_t pgd)
17750 +{
17751 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17752 +}
17753 +
17754 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17755
17756 static inline int pmd_large(pmd_t pte)
17757 @@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17758 return pte_clear_flags(pte, _PAGE_RW);
17759 }
17760
17761 +static inline pte_t pte_mkread(pte_t pte)
17762 +{
17763 + return __pte(pte_val(pte) | _PAGE_USER);
17764 +}
17765 +
17766 static inline pte_t pte_mkexec(pte_t pte)
17767 {
17768 - return pte_clear_flags(pte, _PAGE_NX);
17769 +#ifdef CONFIG_X86_PAE
17770 + if (__supported_pte_mask & _PAGE_NX)
17771 + return pte_clear_flags(pte, _PAGE_NX);
17772 + else
17773 +#endif
17774 + return pte_set_flags(pte, _PAGE_USER);
17775 +}
17776 +
17777 +static inline pte_t pte_exprotect(pte_t pte)
17778 +{
17779 +#ifdef CONFIG_X86_PAE
17780 + if (__supported_pte_mask & _PAGE_NX)
17781 + return pte_set_flags(pte, _PAGE_NX);
17782 + else
17783 +#endif
17784 + return pte_clear_flags(pte, _PAGE_USER);
17785 }
17786
17787 static inline pte_t pte_mkdirty(pte_t pte)
17788 @@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17789 #endif
17790
17791 #ifndef __ASSEMBLY__
17792 +
17793 +#ifdef CONFIG_PAX_PER_CPU_PGD
17794 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17795 +enum cpu_pgd_type {kernel = 0, user = 1};
17796 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17797 +{
17798 + return cpu_pgd[cpu][type];
17799 +}
17800 +#endif
17801 +
17802 #include <linux/mm_types.h>
17803 #include <linux/mmdebug.h>
17804 #include <linux/log2.h>
17805 @@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17806 * Currently stuck as a macro due to indirect forward reference to
17807 * linux/mmzone.h's __section_mem_map_addr() definition:
17808 */
17809 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17810 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17811
17812 /* Find an entry in the second-level page table.. */
17813 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17814 @@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17815 * Currently stuck as a macro due to indirect forward reference to
17816 * linux/mmzone.h's __section_mem_map_addr() definition:
17817 */
17818 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17819 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17820
17821 /* to find an entry in a page-table-directory. */
17822 static inline unsigned long pud_index(unsigned long address)
17823 @@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17824
17825 static inline int pgd_bad(pgd_t pgd)
17826 {
17827 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17828 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17829 }
17830
17831 static inline int pgd_none(pgd_t pgd)
17832 @@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17833 * pgd_offset() returns a (pgd_t *)
17834 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17835 */
17836 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17837 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17838 +
17839 +#ifdef CONFIG_PAX_PER_CPU_PGD
17840 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17841 +#endif
17842 +
17843 /*
17844 * a shortcut which implies the use of the kernel's pgd, instead
17845 * of a process's
17846 @@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17847 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17848 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17849
17850 +#ifdef CONFIG_X86_32
17851 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17852 +#else
17853 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17854 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17855 +
17856 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17857 +#ifdef __ASSEMBLY__
17858 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17859 +#else
17860 +extern unsigned long pax_user_shadow_base;
17861 +extern pgdval_t clone_pgd_mask;
17862 +#endif
17863 +#endif
17864 +
17865 +#endif
17866 +
17867 #ifndef __ASSEMBLY__
17868
17869 extern int direct_gbpages;
17870 @@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17871 * dst and src can be on the same page, but the range must not overlap,
17872 * and must not cross a page boundary.
17873 */
17874 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17875 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17876 {
17877 - memcpy(dst, src, count * sizeof(pgd_t));
17878 + pax_open_kernel();
17879 + while (count--)
17880 + *dst++ = *src++;
17881 + pax_close_kernel();
17882 }
17883
17884 +#ifdef CONFIG_PAX_PER_CPU_PGD
17885 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17886 +#endif
17887 +
17888 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17889 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17890 +#else
17891 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17892 +#endif
17893 +
17894 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17895 static inline int page_level_shift(enum pg_level level)
17896 {
17897 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17898 index 9ee3221..b979c6b 100644
17899 --- a/arch/x86/include/asm/pgtable_32.h
17900 +++ b/arch/x86/include/asm/pgtable_32.h
17901 @@ -25,9 +25,6 @@
17902 struct mm_struct;
17903 struct vm_area_struct;
17904
17905 -extern pgd_t swapper_pg_dir[1024];
17906 -extern pgd_t initial_page_table[1024];
17907 -
17908 static inline void pgtable_cache_init(void) { }
17909 static inline void check_pgt_cache(void) { }
17910 void paging_init(void);
17911 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17912 # include <asm/pgtable-2level.h>
17913 #endif
17914
17915 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17916 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17917 +#ifdef CONFIG_X86_PAE
17918 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17919 +#endif
17920 +
17921 #if defined(CONFIG_HIGHPTE)
17922 #define pte_offset_map(dir, address) \
17923 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17924 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17925 /* Clear a kernel PTE and flush it from the TLB */
17926 #define kpte_clear_flush(ptep, vaddr) \
17927 do { \
17928 + pax_open_kernel(); \
17929 pte_clear(&init_mm, (vaddr), (ptep)); \
17930 + pax_close_kernel(); \
17931 __flush_tlb_one((vaddr)); \
17932 } while (0)
17933
17934 #endif /* !__ASSEMBLY__ */
17935
17936 +#define HAVE_ARCH_UNMAPPED_AREA
17937 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17938 +
17939 /*
17940 * kern_addr_valid() is (1) for FLATMEM and (0) for
17941 * SPARSEMEM and DISCONTIGMEM
17942 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17943 index ed5903b..c7fe163 100644
17944 --- a/arch/x86/include/asm/pgtable_32_types.h
17945 +++ b/arch/x86/include/asm/pgtable_32_types.h
17946 @@ -8,7 +8,7 @@
17947 */
17948 #ifdef CONFIG_X86_PAE
17949 # include <asm/pgtable-3level_types.h>
17950 -# define PMD_SIZE (1UL << PMD_SHIFT)
17951 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17952 # define PMD_MASK (~(PMD_SIZE - 1))
17953 #else
17954 # include <asm/pgtable-2level_types.h>
17955 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17956 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17957 #endif
17958
17959 +#ifdef CONFIG_PAX_KERNEXEC
17960 +#ifndef __ASSEMBLY__
17961 +extern unsigned char MODULES_EXEC_VADDR[];
17962 +extern unsigned char MODULES_EXEC_END[];
17963 +#endif
17964 +#include <asm/boot.h>
17965 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17966 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17967 +#else
17968 +#define ktla_ktva(addr) (addr)
17969 +#define ktva_ktla(addr) (addr)
17970 +#endif
17971 +
17972 #define MODULES_VADDR VMALLOC_START
17973 #define MODULES_END VMALLOC_END
17974 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17975 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17976 index e22c1db..23a625a 100644
17977 --- a/arch/x86/include/asm/pgtable_64.h
17978 +++ b/arch/x86/include/asm/pgtable_64.h
17979 @@ -16,10 +16,14 @@
17980
17981 extern pud_t level3_kernel_pgt[512];
17982 extern pud_t level3_ident_pgt[512];
17983 +extern pud_t level3_vmalloc_start_pgt[512];
17984 +extern pud_t level3_vmalloc_end_pgt[512];
17985 +extern pud_t level3_vmemmap_pgt[512];
17986 +extern pud_t level2_vmemmap_pgt[512];
17987 extern pmd_t level2_kernel_pgt[512];
17988 extern pmd_t level2_fixmap_pgt[512];
17989 -extern pmd_t level2_ident_pgt[512];
17990 -extern pgd_t init_level4_pgt[];
17991 +extern pmd_t level2_ident_pgt[512*2];
17992 +extern pgd_t init_level4_pgt[512];
17993
17994 #define swapper_pg_dir init_level4_pgt
17995
17996 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17997
17998 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17999 {
18000 + pax_open_kernel();
18001 *pmdp = pmd;
18002 + pax_close_kernel();
18003 }
18004
18005 static inline void native_pmd_clear(pmd_t *pmd)
18006 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18007
18008 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18009 {
18010 + pax_open_kernel();
18011 *pudp = pud;
18012 + pax_close_kernel();
18013 }
18014
18015 static inline void native_pud_clear(pud_t *pud)
18016 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18017
18018 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18019 {
18020 + pax_open_kernel();
18021 + *pgdp = pgd;
18022 + pax_close_kernel();
18023 +}
18024 +
18025 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18026 +{
18027 *pgdp = pgd;
18028 }
18029
18030 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18031 index c883bf7..19970b3 100644
18032 --- a/arch/x86/include/asm/pgtable_64_types.h
18033 +++ b/arch/x86/include/asm/pgtable_64_types.h
18034 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18035 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18036 #define MODULES_END _AC(0xffffffffff000000, UL)
18037 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18038 +#define MODULES_EXEC_VADDR MODULES_VADDR
18039 +#define MODULES_EXEC_END MODULES_END
18040 +
18041 +#define ktla_ktva(addr) (addr)
18042 +#define ktva_ktla(addr) (addr)
18043
18044 #define EARLY_DYNAMIC_PAGE_TABLES 64
18045
18046 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18047 index eb3d449..8d95316 100644
18048 --- a/arch/x86/include/asm/pgtable_types.h
18049 +++ b/arch/x86/include/asm/pgtable_types.h
18050 @@ -16,13 +16,12 @@
18051 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18052 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18053 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18054 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18055 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18056 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18057 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18058 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18059 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18060 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18061 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18062 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18063 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18064 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18065
18066 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18067 @@ -40,7 +39,6 @@
18068 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18069 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18070 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18071 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18072 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18073 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18074 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18075 @@ -87,8 +85,10 @@
18076
18077 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18078 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18079 -#else
18080 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18081 #define _PAGE_NX (_AT(pteval_t, 0))
18082 +#else
18083 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18084 #endif
18085
18086 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18087 @@ -147,6 +147,9 @@
18088 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18089 _PAGE_ACCESSED)
18090
18091 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18092 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18093 +
18094 #define __PAGE_KERNEL_EXEC \
18095 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18096 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18097 @@ -157,7 +160,7 @@
18098 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18099 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18100 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18101 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18102 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18103 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18104 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18105 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18106 @@ -214,7 +217,7 @@
18107 #ifdef CONFIG_X86_64
18108 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18109 #else
18110 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18111 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18112 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18113 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18114 #endif
18115 @@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18116 {
18117 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18118 }
18119 +#endif
18120
18121 +#if PAGETABLE_LEVELS == 3
18122 +#include <asm-generic/pgtable-nopud.h>
18123 +#endif
18124 +
18125 +#if PAGETABLE_LEVELS == 2
18126 +#include <asm-generic/pgtable-nopmd.h>
18127 +#endif
18128 +
18129 +#ifndef __ASSEMBLY__
18130 #if PAGETABLE_LEVELS > 3
18131 typedef struct { pudval_t pud; } pud_t;
18132
18133 @@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18134 return pud.pud;
18135 }
18136 #else
18137 -#include <asm-generic/pgtable-nopud.h>
18138 -
18139 static inline pudval_t native_pud_val(pud_t pud)
18140 {
18141 return native_pgd_val(pud.pgd);
18142 @@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18143 return pmd.pmd;
18144 }
18145 #else
18146 -#include <asm-generic/pgtable-nopmd.h>
18147 -
18148 static inline pmdval_t native_pmd_val(pmd_t pmd)
18149 {
18150 return native_pgd_val(pmd.pud.pgd);
18151 @@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18152
18153 extern pteval_t __supported_pte_mask;
18154 extern void set_nx(void);
18155 -extern int nx_enabled;
18156
18157 #define pgprot_writecombine pgprot_writecombine
18158 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18159 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18160 index 7024c12..71c46b9 100644
18161 --- a/arch/x86/include/asm/preempt.h
18162 +++ b/arch/x86/include/asm/preempt.h
18163 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18164 */
18165 static __always_inline bool __preempt_count_dec_and_test(void)
18166 {
18167 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18168 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18169 }
18170
18171 /*
18172 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18173 index a4ea023..33aa874 100644
18174 --- a/arch/x86/include/asm/processor.h
18175 +++ b/arch/x86/include/asm/processor.h
18176 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18177 /* Index into per_cpu list: */
18178 u16 cpu_index;
18179 u32 microcode;
18180 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18181 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18182
18183 #define X86_VENDOR_INTEL 0
18184 #define X86_VENDOR_CYRIX 1
18185 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18186 : "memory");
18187 }
18188
18189 +/* invpcid (%rdx),%rax */
18190 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18191 +
18192 +#define INVPCID_SINGLE_ADDRESS 0UL
18193 +#define INVPCID_SINGLE_CONTEXT 1UL
18194 +#define INVPCID_ALL_GLOBAL 2UL
18195 +#define INVPCID_ALL_MONGLOBAL 3UL
18196 +
18197 +#define PCID_KERNEL 0UL
18198 +#define PCID_USER 1UL
18199 +#define PCID_NOFLUSH (1UL << 63)
18200 +
18201 static inline void load_cr3(pgd_t *pgdir)
18202 {
18203 - write_cr3(__pa(pgdir));
18204 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18205 }
18206
18207 #ifdef CONFIG_X86_32
18208 @@ -283,7 +295,7 @@ struct tss_struct {
18209
18210 } ____cacheline_aligned;
18211
18212 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18213 +extern struct tss_struct init_tss[NR_CPUS];
18214
18215 /*
18216 * Save the original ist values for checking stack pointers during debugging
18217 @@ -479,6 +491,7 @@ struct thread_struct {
18218 unsigned short ds;
18219 unsigned short fsindex;
18220 unsigned short gsindex;
18221 + unsigned short ss;
18222 #endif
18223 #ifdef CONFIG_X86_32
18224 unsigned long ip;
18225 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18226 extern unsigned long mmu_cr4_features;
18227 extern u32 *trampoline_cr4_features;
18228
18229 -static inline void set_in_cr4(unsigned long mask)
18230 -{
18231 - unsigned long cr4;
18232 -
18233 - mmu_cr4_features |= mask;
18234 - if (trampoline_cr4_features)
18235 - *trampoline_cr4_features = mmu_cr4_features;
18236 - cr4 = read_cr4();
18237 - cr4 |= mask;
18238 - write_cr4(cr4);
18239 -}
18240 -
18241 -static inline void clear_in_cr4(unsigned long mask)
18242 -{
18243 - unsigned long cr4;
18244 -
18245 - mmu_cr4_features &= ~mask;
18246 - if (trampoline_cr4_features)
18247 - *trampoline_cr4_features = mmu_cr4_features;
18248 - cr4 = read_cr4();
18249 - cr4 &= ~mask;
18250 - write_cr4(cr4);
18251 -}
18252 +extern void set_in_cr4(unsigned long mask);
18253 +extern void clear_in_cr4(unsigned long mask);
18254
18255 typedef struct {
18256 unsigned long seg;
18257 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18258 */
18259 #define TASK_SIZE PAGE_OFFSET
18260 #define TASK_SIZE_MAX TASK_SIZE
18261 +
18262 +#ifdef CONFIG_PAX_SEGMEXEC
18263 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18264 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18265 +#else
18266 #define STACK_TOP TASK_SIZE
18267 -#define STACK_TOP_MAX STACK_TOP
18268 +#endif
18269 +
18270 +#define STACK_TOP_MAX TASK_SIZE
18271
18272 #define INIT_THREAD { \
18273 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18274 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18275 .vm86_info = NULL, \
18276 .sysenter_cs = __KERNEL_CS, \
18277 .io_bitmap_ptr = NULL, \
18278 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18279 */
18280 #define INIT_TSS { \
18281 .x86_tss = { \
18282 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18283 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18284 .ss0 = __KERNEL_DS, \
18285 .ss1 = __KERNEL_CS, \
18286 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18287 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18288 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18289
18290 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18291 -#define KSTK_TOP(info) \
18292 -({ \
18293 - unsigned long *__ptr = (unsigned long *)(info); \
18294 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18295 -})
18296 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18297
18298 /*
18299 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18300 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18301 #define task_pt_regs(task) \
18302 ({ \
18303 struct pt_regs *__regs__; \
18304 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18305 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18306 __regs__ - 1; \
18307 })
18308
18309 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18310 /*
18311 * User space process size. 47bits minus one guard page.
18312 */
18313 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18314 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18315
18316 /* This decides where the kernel will search for a free chunk of vm
18317 * space during mmap's.
18318 */
18319 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18320 - 0xc0000000 : 0xFFFFe000)
18321 + 0xc0000000 : 0xFFFFf000)
18322
18323 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18324 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18325 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18326 #define STACK_TOP_MAX TASK_SIZE_MAX
18327
18328 #define INIT_THREAD { \
18329 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18330 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18331 }
18332
18333 #define INIT_TSS { \
18334 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18335 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18336 }
18337
18338 /*
18339 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18340 */
18341 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18342
18343 +#ifdef CONFIG_PAX_SEGMEXEC
18344 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18345 +#endif
18346 +
18347 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18348
18349 /* Get/set a process' ability to use the timestamp counter instruction */
18350 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18351 return 0;
18352 }
18353
18354 -extern unsigned long arch_align_stack(unsigned long sp);
18355 +#define arch_align_stack(x) ((x) & ~0xfUL)
18356 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18357
18358 void default_idle(void);
18359 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18360 #define xen_set_default_idle 0
18361 #endif
18362
18363 -void stop_this_cpu(void *dummy);
18364 +void stop_this_cpu(void *dummy) __noreturn;
18365 void df_debug(struct pt_regs *regs, long error_code);
18366 #endif /* _ASM_X86_PROCESSOR_H */
18367 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18368 index 14fd6fd..6740420 100644
18369 --- a/arch/x86/include/asm/ptrace.h
18370 +++ b/arch/x86/include/asm/ptrace.h
18371 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18372 }
18373
18374 /*
18375 - * user_mode_vm(regs) determines whether a register set came from user mode.
18376 + * user_mode(regs) determines whether a register set came from user mode.
18377 * This is true if V8086 mode was enabled OR if the register set was from
18378 * protected mode with RPL-3 CS value. This tricky test checks that with
18379 * one comparison. Many places in the kernel can bypass this full check
18380 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18381 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18382 + * be used.
18383 */
18384 -static inline int user_mode(struct pt_regs *regs)
18385 +static inline int user_mode_novm(struct pt_regs *regs)
18386 {
18387 #ifdef CONFIG_X86_32
18388 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18389 #else
18390 - return !!(regs->cs & 3);
18391 + return !!(regs->cs & SEGMENT_RPL_MASK);
18392 #endif
18393 }
18394
18395 -static inline int user_mode_vm(struct pt_regs *regs)
18396 +static inline int user_mode(struct pt_regs *regs)
18397 {
18398 #ifdef CONFIG_X86_32
18399 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18400 USER_RPL;
18401 #else
18402 - return user_mode(regs);
18403 + return user_mode_novm(regs);
18404 #endif
18405 }
18406
18407 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18408 #ifdef CONFIG_X86_64
18409 static inline bool user_64bit_mode(struct pt_regs *regs)
18410 {
18411 + unsigned long cs = regs->cs & 0xffff;
18412 #ifndef CONFIG_PARAVIRT
18413 /*
18414 * On non-paravirt systems, this is the only long mode CPL 3
18415 * selector. We do not allow long mode selectors in the LDT.
18416 */
18417 - return regs->cs == __USER_CS;
18418 + return cs == __USER_CS;
18419 #else
18420 /* Headers are too twisted for this to go in paravirt.h. */
18421 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18422 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18423 #endif
18424 }
18425
18426 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18427 * Traps from the kernel do not save sp and ss.
18428 * Use the helper function to retrieve sp.
18429 */
18430 - if (offset == offsetof(struct pt_regs, sp) &&
18431 - regs->cs == __KERNEL_CS)
18432 - return kernel_stack_pointer(regs);
18433 + if (offset == offsetof(struct pt_regs, sp)) {
18434 + unsigned long cs = regs->cs & 0xffff;
18435 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18436 + return kernel_stack_pointer(regs);
18437 + }
18438 #endif
18439 return *(unsigned long *)((unsigned long)regs + offset);
18440 }
18441 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18442 index 9c6b890..5305f53 100644
18443 --- a/arch/x86/include/asm/realmode.h
18444 +++ b/arch/x86/include/asm/realmode.h
18445 @@ -22,16 +22,14 @@ struct real_mode_header {
18446 #endif
18447 /* APM/BIOS reboot */
18448 u32 machine_real_restart_asm;
18449 -#ifdef CONFIG_X86_64
18450 u32 machine_real_restart_seg;
18451 -#endif
18452 };
18453
18454 /* This must match data at trampoline_32/64.S */
18455 struct trampoline_header {
18456 #ifdef CONFIG_X86_32
18457 u32 start;
18458 - u16 gdt_pad;
18459 + u16 boot_cs;
18460 u16 gdt_limit;
18461 u32 gdt_base;
18462 #else
18463 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18464 index a82c4f1..ac45053 100644
18465 --- a/arch/x86/include/asm/reboot.h
18466 +++ b/arch/x86/include/asm/reboot.h
18467 @@ -6,13 +6,13 @@
18468 struct pt_regs;
18469
18470 struct machine_ops {
18471 - void (*restart)(char *cmd);
18472 - void (*halt)(void);
18473 - void (*power_off)(void);
18474 + void (* __noreturn restart)(char *cmd);
18475 + void (* __noreturn halt)(void);
18476 + void (* __noreturn power_off)(void);
18477 void (*shutdown)(void);
18478 void (*crash_shutdown)(struct pt_regs *);
18479 - void (*emergency_restart)(void);
18480 -};
18481 + void (* __noreturn emergency_restart)(void);
18482 +} __no_const;
18483
18484 extern struct machine_ops machine_ops;
18485
18486 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18487 index 8f7866a..e442f20 100644
18488 --- a/arch/x86/include/asm/rmwcc.h
18489 +++ b/arch/x86/include/asm/rmwcc.h
18490 @@ -3,7 +3,34 @@
18491
18492 #ifdef CC_HAVE_ASM_GOTO
18493
18494 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18495 +#ifdef CONFIG_PAX_REFCOUNT
18496 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18497 +do { \
18498 + asm_volatile_goto (fullop \
18499 + ";jno 0f\n" \
18500 + fullantiop \
18501 + ";int $4\n0:\n" \
18502 + _ASM_EXTABLE(0b, 0b) \
18503 + ";j" cc " %l[cc_label]" \
18504 + : : "m" (var), ## __VA_ARGS__ \
18505 + : "memory" : cc_label); \
18506 + return 0; \
18507 +cc_label: \
18508 + return 1; \
18509 +} while (0)
18510 +#else
18511 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18512 +do { \
18513 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18514 + : : "m" (var), ## __VA_ARGS__ \
18515 + : "memory" : cc_label); \
18516 + return 0; \
18517 +cc_label: \
18518 + return 1; \
18519 +} while (0)
18520 +#endif
18521 +
18522 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18523 do { \
18524 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18525 : : "m" (var), ## __VA_ARGS__ \
18526 @@ -13,15 +40,46 @@ cc_label: \
18527 return 1; \
18528 } while (0)
18529
18530 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18531 - __GEN_RMWcc(op " " arg0, var, cc)
18532 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18533 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18534
18535 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18536 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18537 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18538 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18539 +
18540 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18541 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18542 +
18543 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18544 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18545
18546 #else /* !CC_HAVE_ASM_GOTO */
18547
18548 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18549 +#ifdef CONFIG_PAX_REFCOUNT
18550 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18551 +do { \
18552 + char c; \
18553 + asm volatile (fullop \
18554 + ";jno 0f\n" \
18555 + fullantiop \
18556 + ";int $4\n0:\n" \
18557 + _ASM_EXTABLE(0b, 0b) \
18558 + "; set" cc " %1" \
18559 + : "+m" (var), "=qm" (c) \
18560 + : __VA_ARGS__ : "memory"); \
18561 + return c != 0; \
18562 +} while (0)
18563 +#else
18564 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18565 +do { \
18566 + char c; \
18567 + asm volatile (fullop "; set" cc " %1" \
18568 + : "+m" (var), "=qm" (c) \
18569 + : __VA_ARGS__ : "memory"); \
18570 + return c != 0; \
18571 +} while (0)
18572 +#endif
18573 +
18574 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18575 do { \
18576 char c; \
18577 asm volatile (fullop "; set" cc " %1" \
18578 @@ -30,11 +88,17 @@ do { \
18579 return c != 0; \
18580 } while (0)
18581
18582 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18583 - __GEN_RMWcc(op " " arg0, var, cc)
18584 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18585 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18586 +
18587 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18588 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18589 +
18590 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18591 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18592
18593 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18594 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18595 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18596 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18597
18598 #endif /* CC_HAVE_ASM_GOTO */
18599
18600 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18601 index cad82c9..2e5c5c1 100644
18602 --- a/arch/x86/include/asm/rwsem.h
18603 +++ b/arch/x86/include/asm/rwsem.h
18604 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18605 {
18606 asm volatile("# beginning down_read\n\t"
18607 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18608 +
18609 +#ifdef CONFIG_PAX_REFCOUNT
18610 + "jno 0f\n"
18611 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18612 + "int $4\n0:\n"
18613 + _ASM_EXTABLE(0b, 0b)
18614 +#endif
18615 +
18616 /* adds 0x00000001 */
18617 " jns 1f\n"
18618 " call call_rwsem_down_read_failed\n"
18619 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18620 "1:\n\t"
18621 " mov %1,%2\n\t"
18622 " add %3,%2\n\t"
18623 +
18624 +#ifdef CONFIG_PAX_REFCOUNT
18625 + "jno 0f\n"
18626 + "sub %3,%2\n"
18627 + "int $4\n0:\n"
18628 + _ASM_EXTABLE(0b, 0b)
18629 +#endif
18630 +
18631 " jle 2f\n\t"
18632 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18633 " jnz 1b\n\t"
18634 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18635 long tmp;
18636 asm volatile("# beginning down_write\n\t"
18637 LOCK_PREFIX " xadd %1,(%2)\n\t"
18638 +
18639 +#ifdef CONFIG_PAX_REFCOUNT
18640 + "jno 0f\n"
18641 + "mov %1,(%2)\n"
18642 + "int $4\n0:\n"
18643 + _ASM_EXTABLE(0b, 0b)
18644 +#endif
18645 +
18646 /* adds 0xffff0001, returns the old value */
18647 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18648 /* was the active mask 0 before? */
18649 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18650 long tmp;
18651 asm volatile("# beginning __up_read\n\t"
18652 LOCK_PREFIX " xadd %1,(%2)\n\t"
18653 +
18654 +#ifdef CONFIG_PAX_REFCOUNT
18655 + "jno 0f\n"
18656 + "mov %1,(%2)\n"
18657 + "int $4\n0:\n"
18658 + _ASM_EXTABLE(0b, 0b)
18659 +#endif
18660 +
18661 /* subtracts 1, returns the old value */
18662 " jns 1f\n\t"
18663 " call call_rwsem_wake\n" /* expects old value in %edx */
18664 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18665 long tmp;
18666 asm volatile("# beginning __up_write\n\t"
18667 LOCK_PREFIX " xadd %1,(%2)\n\t"
18668 +
18669 +#ifdef CONFIG_PAX_REFCOUNT
18670 + "jno 0f\n"
18671 + "mov %1,(%2)\n"
18672 + "int $4\n0:\n"
18673 + _ASM_EXTABLE(0b, 0b)
18674 +#endif
18675 +
18676 /* subtracts 0xffff0001, returns the old value */
18677 " jns 1f\n\t"
18678 " call call_rwsem_wake\n" /* expects old value in %edx */
18679 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18680 {
18681 asm volatile("# beginning __downgrade_write\n\t"
18682 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18683 +
18684 +#ifdef CONFIG_PAX_REFCOUNT
18685 + "jno 0f\n"
18686 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18687 + "int $4\n0:\n"
18688 + _ASM_EXTABLE(0b, 0b)
18689 +#endif
18690 +
18691 /*
18692 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18693 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18694 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18695 */
18696 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18697 {
18698 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18699 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18700 +
18701 +#ifdef CONFIG_PAX_REFCOUNT
18702 + "jno 0f\n"
18703 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18704 + "int $4\n0:\n"
18705 + _ASM_EXTABLE(0b, 0b)
18706 +#endif
18707 +
18708 : "+m" (sem->count)
18709 : "er" (delta));
18710 }
18711 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18712 */
18713 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18714 {
18715 - return delta + xadd(&sem->count, delta);
18716 + return delta + xadd_check_overflow(&sem->count, delta);
18717 }
18718
18719 #endif /* __KERNEL__ */
18720 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18721 index 6f1c3a8..7744f19 100644
18722 --- a/arch/x86/include/asm/segment.h
18723 +++ b/arch/x86/include/asm/segment.h
18724 @@ -64,10 +64,15 @@
18725 * 26 - ESPFIX small SS
18726 * 27 - per-cpu [ offset to per-cpu data area ]
18727 * 28 - stack_canary-20 [ for stack protector ]
18728 - * 29 - unused
18729 - * 30 - unused
18730 + * 29 - PCI BIOS CS
18731 + * 30 - PCI BIOS DS
18732 * 31 - TSS for double fault handler
18733 */
18734 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18735 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18736 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18737 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18738 +
18739 #define GDT_ENTRY_TLS_MIN 6
18740 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18741
18742 @@ -79,6 +84,8 @@
18743
18744 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18745
18746 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18747 +
18748 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18749
18750 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18751 @@ -104,6 +111,12 @@
18752 #define __KERNEL_STACK_CANARY 0
18753 #endif
18754
18755 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18756 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18757 +
18758 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18759 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18760 +
18761 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18762
18763 /*
18764 @@ -141,7 +154,7 @@
18765 */
18766
18767 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18768 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18769 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18770
18771
18772 #else
18773 @@ -165,6 +178,8 @@
18774 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18775 #define __USER32_DS __USER_DS
18776
18777 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18778 +
18779 #define GDT_ENTRY_TSS 8 /* needs two entries */
18780 #define GDT_ENTRY_LDT 10 /* needs two entries */
18781 #define GDT_ENTRY_TLS_MIN 12
18782 @@ -173,6 +188,8 @@
18783 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18784 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18785
18786 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18787 +
18788 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18789 #define FS_TLS 0
18790 #define GS_TLS 1
18791 @@ -180,12 +197,14 @@
18792 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18793 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18794
18795 -#define GDT_ENTRIES 16
18796 +#define GDT_ENTRIES 17
18797
18798 #endif
18799
18800 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18801 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18802 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18803 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18804 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18805 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18806 #ifndef CONFIG_PARAVIRT
18807 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18808 {
18809 unsigned long __limit;
18810 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18811 - return __limit + 1;
18812 + return __limit;
18813 }
18814
18815 #endif /* !__ASSEMBLY__ */
18816 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18817 index 8d3120f..352b440 100644
18818 --- a/arch/x86/include/asm/smap.h
18819 +++ b/arch/x86/include/asm/smap.h
18820 @@ -25,11 +25,40 @@
18821
18822 #include <asm/alternative-asm.h>
18823
18824 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18825 +#define ASM_PAX_OPEN_USERLAND \
18826 + 661: jmp 663f; \
18827 + .pushsection .altinstr_replacement, "a" ; \
18828 + 662: pushq %rax; nop; \
18829 + .popsection ; \
18830 + .pushsection .altinstructions, "a" ; \
18831 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18832 + .popsection ; \
18833 + call __pax_open_userland; \
18834 + popq %rax; \
18835 + 663:
18836 +
18837 +#define ASM_PAX_CLOSE_USERLAND \
18838 + 661: jmp 663f; \
18839 + .pushsection .altinstr_replacement, "a" ; \
18840 + 662: pushq %rax; nop; \
18841 + .popsection; \
18842 + .pushsection .altinstructions, "a" ; \
18843 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18844 + .popsection; \
18845 + call __pax_close_userland; \
18846 + popq %rax; \
18847 + 663:
18848 +#else
18849 +#define ASM_PAX_OPEN_USERLAND
18850 +#define ASM_PAX_CLOSE_USERLAND
18851 +#endif
18852 +
18853 #ifdef CONFIG_X86_SMAP
18854
18855 #define ASM_CLAC \
18856 661: ASM_NOP3 ; \
18857 - .pushsection .altinstr_replacement, "ax" ; \
18858 + .pushsection .altinstr_replacement, "a" ; \
18859 662: __ASM_CLAC ; \
18860 .popsection ; \
18861 .pushsection .altinstructions, "a" ; \
18862 @@ -38,7 +67,7 @@
18863
18864 #define ASM_STAC \
18865 661: ASM_NOP3 ; \
18866 - .pushsection .altinstr_replacement, "ax" ; \
18867 + .pushsection .altinstr_replacement, "a" ; \
18868 662: __ASM_STAC ; \
18869 .popsection ; \
18870 .pushsection .altinstructions, "a" ; \
18871 @@ -56,6 +85,37 @@
18872
18873 #include <asm/alternative.h>
18874
18875 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18876 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18877 +
18878 +extern void __pax_open_userland(void);
18879 +static __always_inline unsigned long pax_open_userland(void)
18880 +{
18881 +
18882 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18883 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18884 + :
18885 + : [open] "i" (__pax_open_userland)
18886 + : "memory", "rax");
18887 +#endif
18888 +
18889 + return 0;
18890 +}
18891 +
18892 +extern void __pax_close_userland(void);
18893 +static __always_inline unsigned long pax_close_userland(void)
18894 +{
18895 +
18896 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18897 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18898 + :
18899 + : [close] "i" (__pax_close_userland)
18900 + : "memory", "rax");
18901 +#endif
18902 +
18903 + return 0;
18904 +}
18905 +
18906 #ifdef CONFIG_X86_SMAP
18907
18908 static __always_inline void clac(void)
18909 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18910 index 8cd27e0..7f05ec8 100644
18911 --- a/arch/x86/include/asm/smp.h
18912 +++ b/arch/x86/include/asm/smp.h
18913 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18914 /* cpus sharing the last level cache: */
18915 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18916 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18917 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18918 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18919
18920 static inline struct cpumask *cpu_sibling_mask(int cpu)
18921 {
18922 @@ -78,7 +78,7 @@ struct smp_ops {
18923
18924 void (*send_call_func_ipi)(const struct cpumask *mask);
18925 void (*send_call_func_single_ipi)(int cpu);
18926 -};
18927 +} __no_const;
18928
18929 /* Globals due to paravirt */
18930 extern void set_cpu_sibling_map(int cpu);
18931 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18932 extern int safe_smp_processor_id(void);
18933
18934 #elif defined(CONFIG_X86_64_SMP)
18935 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18936 -
18937 -#define stack_smp_processor_id() \
18938 -({ \
18939 - struct thread_info *ti; \
18940 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18941 - ti->cpu; \
18942 -})
18943 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18944 +#define stack_smp_processor_id() raw_smp_processor_id()
18945 #define safe_smp_processor_id() smp_processor_id()
18946
18947 #endif
18948 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18949 index 0f62f54..cb5d0dd 100644
18950 --- a/arch/x86/include/asm/spinlock.h
18951 +++ b/arch/x86/include/asm/spinlock.h
18952 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18953 static inline void arch_read_lock(arch_rwlock_t *rw)
18954 {
18955 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18956 +
18957 +#ifdef CONFIG_PAX_REFCOUNT
18958 + "jno 0f\n"
18959 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18960 + "int $4\n0:\n"
18961 + _ASM_EXTABLE(0b, 0b)
18962 +#endif
18963 +
18964 "jns 1f\n"
18965 "call __read_lock_failed\n\t"
18966 "1:\n"
18967 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18968 static inline void arch_write_lock(arch_rwlock_t *rw)
18969 {
18970 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18971 +
18972 +#ifdef CONFIG_PAX_REFCOUNT
18973 + "jno 0f\n"
18974 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18975 + "int $4\n0:\n"
18976 + _ASM_EXTABLE(0b, 0b)
18977 +#endif
18978 +
18979 "jz 1f\n"
18980 "call __write_lock_failed\n\t"
18981 "1:\n"
18982 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18983
18984 static inline void arch_read_unlock(arch_rwlock_t *rw)
18985 {
18986 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18987 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18988 +
18989 +#ifdef CONFIG_PAX_REFCOUNT
18990 + "jno 0f\n"
18991 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18992 + "int $4\n0:\n"
18993 + _ASM_EXTABLE(0b, 0b)
18994 +#endif
18995 +
18996 :"+m" (rw->lock) : : "memory");
18997 }
18998
18999 static inline void arch_write_unlock(arch_rwlock_t *rw)
19000 {
19001 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19002 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19003 +
19004 +#ifdef CONFIG_PAX_REFCOUNT
19005 + "jno 0f\n"
19006 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19007 + "int $4\n0:\n"
19008 + _ASM_EXTABLE(0b, 0b)
19009 +#endif
19010 +
19011 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19012 }
19013
19014 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19015 index 6a99859..03cb807 100644
19016 --- a/arch/x86/include/asm/stackprotector.h
19017 +++ b/arch/x86/include/asm/stackprotector.h
19018 @@ -47,7 +47,7 @@
19019 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19020 */
19021 #define GDT_STACK_CANARY_INIT \
19022 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19023 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19024
19025 /*
19026 * Initialize the stackprotector canary value.
19027 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19028
19029 static inline void load_stack_canary_segment(void)
19030 {
19031 -#ifdef CONFIG_X86_32
19032 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19033 asm volatile ("mov %0, %%gs" : : "r" (0));
19034 #endif
19035 }
19036 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19037 index 70bbe39..4ae2bd4 100644
19038 --- a/arch/x86/include/asm/stacktrace.h
19039 +++ b/arch/x86/include/asm/stacktrace.h
19040 @@ -11,28 +11,20 @@
19041
19042 extern int kstack_depth_to_print;
19043
19044 -struct thread_info;
19045 +struct task_struct;
19046 struct stacktrace_ops;
19047
19048 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19049 - unsigned long *stack,
19050 - unsigned long bp,
19051 - const struct stacktrace_ops *ops,
19052 - void *data,
19053 - unsigned long *end,
19054 - int *graph);
19055 +typedef unsigned long walk_stack_t(struct task_struct *task,
19056 + void *stack_start,
19057 + unsigned long *stack,
19058 + unsigned long bp,
19059 + const struct stacktrace_ops *ops,
19060 + void *data,
19061 + unsigned long *end,
19062 + int *graph);
19063
19064 -extern unsigned long
19065 -print_context_stack(struct thread_info *tinfo,
19066 - unsigned long *stack, unsigned long bp,
19067 - const struct stacktrace_ops *ops, void *data,
19068 - unsigned long *end, int *graph);
19069 -
19070 -extern unsigned long
19071 -print_context_stack_bp(struct thread_info *tinfo,
19072 - unsigned long *stack, unsigned long bp,
19073 - const struct stacktrace_ops *ops, void *data,
19074 - unsigned long *end, int *graph);
19075 +extern walk_stack_t print_context_stack;
19076 +extern walk_stack_t print_context_stack_bp;
19077
19078 /* Generic stack tracer with callbacks */
19079
19080 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19081 void (*address)(void *data, unsigned long address, int reliable);
19082 /* On negative return stop dumping */
19083 int (*stack)(void *data, char *name);
19084 - walk_stack_t walk_stack;
19085 + walk_stack_t *walk_stack;
19086 };
19087
19088 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19089 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19090 index d7f3b3b..3cc39f1 100644
19091 --- a/arch/x86/include/asm/switch_to.h
19092 +++ b/arch/x86/include/asm/switch_to.h
19093 @@ -108,7 +108,7 @@ do { \
19094 "call __switch_to\n\t" \
19095 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19096 __switch_canary \
19097 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19098 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19099 "movq %%rax,%%rdi\n\t" \
19100 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19101 "jnz ret_from_fork\n\t" \
19102 @@ -119,7 +119,7 @@ do { \
19103 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19104 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19105 [_tif_fork] "i" (_TIF_FORK), \
19106 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19107 + [thread_info] "m" (current_tinfo), \
19108 [current_task] "m" (current_task) \
19109 __switch_canary_iparam \
19110 : "memory", "cc" __EXTRA_CLOBBER)
19111 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19112 index 47e5de2..d3dda54 100644
19113 --- a/arch/x86/include/asm/thread_info.h
19114 +++ b/arch/x86/include/asm/thread_info.h
19115 @@ -24,7 +24,6 @@ struct exec_domain;
19116 #include <linux/atomic.h>
19117
19118 struct thread_info {
19119 - struct task_struct *task; /* main task structure */
19120 struct exec_domain *exec_domain; /* execution domain */
19121 __u32 flags; /* low level flags */
19122 __u32 status; /* thread synchronous flags */
19123 @@ -33,13 +32,13 @@ struct thread_info {
19124 mm_segment_t addr_limit;
19125 struct restart_block restart_block;
19126 void __user *sysenter_return;
19127 + unsigned long lowest_stack;
19128 unsigned int sig_on_uaccess_error:1;
19129 unsigned int uaccess_err:1; /* uaccess failed */
19130 };
19131
19132 -#define INIT_THREAD_INFO(tsk) \
19133 +#define INIT_THREAD_INFO \
19134 { \
19135 - .task = &tsk, \
19136 .exec_domain = &default_exec_domain, \
19137 .flags = 0, \
19138 .cpu = 0, \
19139 @@ -50,7 +49,7 @@ struct thread_info {
19140 }, \
19141 }
19142
19143 -#define init_thread_info (init_thread_union.thread_info)
19144 +#define init_thread_info (init_thread_union.stack)
19145 #define init_stack (init_thread_union.stack)
19146
19147 #else /* !__ASSEMBLY__ */
19148 @@ -90,6 +89,7 @@ struct thread_info {
19149 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19150 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19151 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19152 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19153
19154 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19155 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19156 @@ -113,17 +113,18 @@ struct thread_info {
19157 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19158 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19159 #define _TIF_X32 (1 << TIF_X32)
19160 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19161
19162 /* work to do in syscall_trace_enter() */
19163 #define _TIF_WORK_SYSCALL_ENTRY \
19164 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19165 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19166 - _TIF_NOHZ)
19167 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19168
19169 /* work to do in syscall_trace_leave() */
19170 #define _TIF_WORK_SYSCALL_EXIT \
19171 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19172 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19173 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19174
19175 /* work to do on interrupt/exception return */
19176 #define _TIF_WORK_MASK \
19177 @@ -134,7 +135,7 @@ struct thread_info {
19178 /* work to do on any return to user space */
19179 #define _TIF_ALLWORK_MASK \
19180 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19181 - _TIF_NOHZ)
19182 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19183
19184 /* Only used for 64 bit */
19185 #define _TIF_DO_NOTIFY_MASK \
19186 @@ -149,7 +150,6 @@ struct thread_info {
19187 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19188
19189 #define STACK_WARN (THREAD_SIZE/8)
19190 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19191
19192 /*
19193 * macros/functions for gaining access to the thread information structure
19194 @@ -160,26 +160,18 @@ struct thread_info {
19195
19196 DECLARE_PER_CPU(unsigned long, kernel_stack);
19197
19198 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19199 +
19200 static inline struct thread_info *current_thread_info(void)
19201 {
19202 - struct thread_info *ti;
19203 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19204 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19205 - return ti;
19206 + return this_cpu_read_stable(current_tinfo);
19207 }
19208
19209 #else /* !__ASSEMBLY__ */
19210
19211 /* how to get the thread information struct from ASM */
19212 #define GET_THREAD_INFO(reg) \
19213 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19214 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19215 -
19216 -/*
19217 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19218 - * a certain register (to be used in assembler memory operands).
19219 - */
19220 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19221 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19222
19223 #endif
19224
19225 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19226 extern void arch_task_cache_init(void);
19227 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19228 extern void arch_release_task_struct(struct task_struct *tsk);
19229 +
19230 +#define __HAVE_THREAD_FUNCTIONS
19231 +#define task_thread_info(task) (&(task)->tinfo)
19232 +#define task_stack_page(task) ((task)->stack)
19233 +#define setup_thread_stack(p, org) do {} while (0)
19234 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19235 +
19236 #endif
19237 #endif /* _ASM_X86_THREAD_INFO_H */
19238 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19239 index 04905bf..49203ca 100644
19240 --- a/arch/x86/include/asm/tlbflush.h
19241 +++ b/arch/x86/include/asm/tlbflush.h
19242 @@ -17,18 +17,44 @@
19243
19244 static inline void __native_flush_tlb(void)
19245 {
19246 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19247 + u64 descriptor[2];
19248 +
19249 + descriptor[0] = PCID_KERNEL;
19250 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19251 + return;
19252 + }
19253 +
19254 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19255 + if (static_cpu_has(X86_FEATURE_PCID)) {
19256 + unsigned int cpu = raw_get_cpu();
19257 +
19258 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19259 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19260 + raw_put_cpu_no_resched();
19261 + return;
19262 + }
19263 +#endif
19264 +
19265 native_write_cr3(native_read_cr3());
19266 }
19267
19268 static inline void __native_flush_tlb_global_irq_disabled(void)
19269 {
19270 - unsigned long cr4;
19271 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19272 + u64 descriptor[2];
19273
19274 - cr4 = native_read_cr4();
19275 - /* clear PGE */
19276 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19277 - /* write old PGE again and flush TLBs */
19278 - native_write_cr4(cr4);
19279 + descriptor[0] = PCID_KERNEL;
19280 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19281 + } else {
19282 + unsigned long cr4;
19283 +
19284 + cr4 = native_read_cr4();
19285 + /* clear PGE */
19286 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19287 + /* write old PGE again and flush TLBs */
19288 + native_write_cr4(cr4);
19289 + }
19290 }
19291
19292 static inline void __native_flush_tlb_global(void)
19293 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19294
19295 static inline void __native_flush_tlb_single(unsigned long addr)
19296 {
19297 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19298 + u64 descriptor[2];
19299 +
19300 + descriptor[0] = PCID_KERNEL;
19301 + descriptor[1] = addr;
19302 +
19303 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19304 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19305 + if (addr < TASK_SIZE_MAX)
19306 + descriptor[1] += pax_user_shadow_base;
19307 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19308 + }
19309 +
19310 + descriptor[0] = PCID_USER;
19311 + descriptor[1] = addr;
19312 +#endif
19313 +
19314 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19315 + return;
19316 + }
19317 +
19318 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19319 + if (static_cpu_has(X86_FEATURE_PCID)) {
19320 + unsigned int cpu = raw_get_cpu();
19321 +
19322 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19323 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19324 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19325 + raw_put_cpu_no_resched();
19326 +
19327 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19328 + addr += pax_user_shadow_base;
19329 + }
19330 +#endif
19331 +
19332 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19333 }
19334
19335 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19336 index 0d592e0..7437fcc 100644
19337 --- a/arch/x86/include/asm/uaccess.h
19338 +++ b/arch/x86/include/asm/uaccess.h
19339 @@ -7,6 +7,7 @@
19340 #include <linux/compiler.h>
19341 #include <linux/thread_info.h>
19342 #include <linux/string.h>
19343 +#include <linux/spinlock.h>
19344 #include <asm/asm.h>
19345 #include <asm/page.h>
19346 #include <asm/smap.h>
19347 @@ -29,7 +30,12 @@
19348
19349 #define get_ds() (KERNEL_DS)
19350 #define get_fs() (current_thread_info()->addr_limit)
19351 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19352 +void __set_fs(mm_segment_t x);
19353 +void set_fs(mm_segment_t x);
19354 +#else
19355 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19356 +#endif
19357
19358 #define segment_eq(a, b) ((a).seg == (b).seg)
19359
19360 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19361 * checks that the pointer is in the user space range - after calling
19362 * this function, memory access functions may still return -EFAULT.
19363 */
19364 -#define access_ok(type, addr, size) \
19365 - likely(!__range_not_ok(addr, size, user_addr_max()))
19366 +extern int _cond_resched(void);
19367 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19368 +#define access_ok(type, addr, size) \
19369 +({ \
19370 + unsigned long __size = size; \
19371 + unsigned long __addr = (unsigned long)addr; \
19372 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19373 + if (__ret_ao && __size) { \
19374 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19375 + unsigned long __end_ao = __addr + __size - 1; \
19376 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19377 + while (__addr_ao <= __end_ao) { \
19378 + char __c_ao; \
19379 + __addr_ao += PAGE_SIZE; \
19380 + if (__size > PAGE_SIZE) \
19381 + _cond_resched(); \
19382 + if (__get_user(__c_ao, (char __user *)__addr)) \
19383 + break; \
19384 + if (type != VERIFY_WRITE) { \
19385 + __addr = __addr_ao; \
19386 + continue; \
19387 + } \
19388 + if (__put_user(__c_ao, (char __user *)__addr)) \
19389 + break; \
19390 + __addr = __addr_ao; \
19391 + } \
19392 + } \
19393 + } \
19394 + __ret_ao; \
19395 +})
19396
19397 /*
19398 * The exception table consists of pairs of addresses relative to the
19399 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19400 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19401 __chk_user_ptr(ptr); \
19402 might_fault(); \
19403 + pax_open_userland(); \
19404 asm volatile("call __get_user_%P3" \
19405 : "=a" (__ret_gu), "=r" (__val_gu) \
19406 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19407 (x) = (__typeof__(*(ptr))) __val_gu; \
19408 + pax_close_userland(); \
19409 __ret_gu; \
19410 })
19411
19412 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19413 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19414 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19415
19416 -
19417 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19418 +#define __copyuser_seg "gs;"
19419 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19420 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19421 +#else
19422 +#define __copyuser_seg
19423 +#define __COPYUSER_SET_ES
19424 +#define __COPYUSER_RESTORE_ES
19425 +#endif
19426
19427 #ifdef CONFIG_X86_32
19428 #define __put_user_asm_u64(x, addr, err, errret) \
19429 asm volatile(ASM_STAC "\n" \
19430 - "1: movl %%eax,0(%2)\n" \
19431 - "2: movl %%edx,4(%2)\n" \
19432 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19433 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19434 "3: " ASM_CLAC "\n" \
19435 ".section .fixup,\"ax\"\n" \
19436 "4: movl %3,%0\n" \
19437 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19438
19439 #define __put_user_asm_ex_u64(x, addr) \
19440 asm volatile(ASM_STAC "\n" \
19441 - "1: movl %%eax,0(%1)\n" \
19442 - "2: movl %%edx,4(%1)\n" \
19443 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19444 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19445 "3: " ASM_CLAC "\n" \
19446 _ASM_EXTABLE_EX(1b, 2b) \
19447 _ASM_EXTABLE_EX(2b, 3b) \
19448 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19449 __typeof__(*(ptr)) __pu_val; \
19450 __chk_user_ptr(ptr); \
19451 might_fault(); \
19452 - __pu_val = x; \
19453 + __pu_val = (x); \
19454 + pax_open_userland(); \
19455 switch (sizeof(*(ptr))) { \
19456 case 1: \
19457 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19458 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19459 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19460 break; \
19461 } \
19462 + pax_close_userland(); \
19463 __ret_pu; \
19464 })
19465
19466 @@ -355,8 +401,10 @@ do { \
19467 } while (0)
19468
19469 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19470 +do { \
19471 + pax_open_userland(); \
19472 asm volatile(ASM_STAC "\n" \
19473 - "1: mov"itype" %2,%"rtype"1\n" \
19474 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19475 "2: " ASM_CLAC "\n" \
19476 ".section .fixup,\"ax\"\n" \
19477 "3: mov %3,%0\n" \
19478 @@ -364,8 +412,10 @@ do { \
19479 " jmp 2b\n" \
19480 ".previous\n" \
19481 _ASM_EXTABLE(1b, 3b) \
19482 - : "=r" (err), ltype(x) \
19483 - : "m" (__m(addr)), "i" (errret), "0" (err))
19484 + : "=r" (err), ltype (x) \
19485 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19486 + pax_close_userland(); \
19487 +} while (0)
19488
19489 #define __get_user_size_ex(x, ptr, size) \
19490 do { \
19491 @@ -389,7 +439,7 @@ do { \
19492 } while (0)
19493
19494 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19495 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19496 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19497 "2:\n" \
19498 _ASM_EXTABLE_EX(1b, 2b) \
19499 : ltype(x) : "m" (__m(addr)))
19500 @@ -406,13 +456,24 @@ do { \
19501 int __gu_err; \
19502 unsigned long __gu_val; \
19503 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19504 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19505 + (x) = (__typeof__(*(ptr)))__gu_val; \
19506 __gu_err; \
19507 })
19508
19509 /* FIXME: this hack is definitely wrong -AK */
19510 struct __large_struct { unsigned long buf[100]; };
19511 -#define __m(x) (*(struct __large_struct __user *)(x))
19512 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19513 +#define ____m(x) \
19514 +({ \
19515 + unsigned long ____x = (unsigned long)(x); \
19516 + if (____x < pax_user_shadow_base) \
19517 + ____x += pax_user_shadow_base; \
19518 + (typeof(x))____x; \
19519 +})
19520 +#else
19521 +#define ____m(x) (x)
19522 +#endif
19523 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19524
19525 /*
19526 * Tell gcc we read from memory instead of writing: this is because
19527 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19528 * aliasing issues.
19529 */
19530 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19531 +do { \
19532 + pax_open_userland(); \
19533 asm volatile(ASM_STAC "\n" \
19534 - "1: mov"itype" %"rtype"1,%2\n" \
19535 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19536 "2: " ASM_CLAC "\n" \
19537 ".section .fixup,\"ax\"\n" \
19538 "3: mov %3,%0\n" \
19539 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19540 ".previous\n" \
19541 _ASM_EXTABLE(1b, 3b) \
19542 : "=r"(err) \
19543 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19544 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19545 + pax_close_userland(); \
19546 +} while (0)
19547
19548 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19549 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19550 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19551 "2:\n" \
19552 _ASM_EXTABLE_EX(1b, 2b) \
19553 : : ltype(x), "m" (__m(addr)))
19554 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19555 */
19556 #define uaccess_try do { \
19557 current_thread_info()->uaccess_err = 0; \
19558 + pax_open_userland(); \
19559 stac(); \
19560 barrier();
19561
19562 #define uaccess_catch(err) \
19563 clac(); \
19564 + pax_close_userland(); \
19565 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19566 } while (0)
19567
19568 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19569 * On error, the variable @x is set to zero.
19570 */
19571
19572 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19573 +#define __get_user(x, ptr) get_user((x), (ptr))
19574 +#else
19575 #define __get_user(x, ptr) \
19576 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19577 +#endif
19578
19579 /**
19580 * __put_user: - Write a simple value into user space, with less checking.
19581 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19582 * Returns zero on success, or -EFAULT on error.
19583 */
19584
19585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19586 +#define __put_user(x, ptr) put_user((x), (ptr))
19587 +#else
19588 #define __put_user(x, ptr) \
19589 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19590 +#endif
19591
19592 #define __get_user_unaligned __get_user
19593 #define __put_user_unaligned __put_user
19594 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19595 #define get_user_ex(x, ptr) do { \
19596 unsigned long __gue_val; \
19597 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19598 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19599 + (x) = (__typeof__(*(ptr)))__gue_val; \
19600 } while (0)
19601
19602 #define put_user_try uaccess_try
19603 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19604 __typeof__(ptr) __uval = (uval); \
19605 __typeof__(*(ptr)) __old = (old); \
19606 __typeof__(*(ptr)) __new = (new); \
19607 + pax_open_userland(); \
19608 switch (size) { \
19609 case 1: \
19610 { \
19611 asm volatile("\t" ASM_STAC "\n" \
19612 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19613 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19614 "2:\t" ASM_CLAC "\n" \
19615 "\t.section .fixup, \"ax\"\n" \
19616 "3:\tmov %3, %0\n" \
19617 "\tjmp 2b\n" \
19618 "\t.previous\n" \
19619 _ASM_EXTABLE(1b, 3b) \
19620 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19621 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19622 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19623 : "memory" \
19624 ); \
19625 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19626 case 2: \
19627 { \
19628 asm volatile("\t" ASM_STAC "\n" \
19629 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19630 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19631 "2:\t" ASM_CLAC "\n" \
19632 "\t.section .fixup, \"ax\"\n" \
19633 "3:\tmov %3, %0\n" \
19634 "\tjmp 2b\n" \
19635 "\t.previous\n" \
19636 _ASM_EXTABLE(1b, 3b) \
19637 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19638 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19639 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19640 : "memory" \
19641 ); \
19642 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19643 case 4: \
19644 { \
19645 asm volatile("\t" ASM_STAC "\n" \
19646 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19647 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19648 "2:\t" ASM_CLAC "\n" \
19649 "\t.section .fixup, \"ax\"\n" \
19650 "3:\tmov %3, %0\n" \
19651 "\tjmp 2b\n" \
19652 "\t.previous\n" \
19653 _ASM_EXTABLE(1b, 3b) \
19654 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19655 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19656 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19657 : "memory" \
19658 ); \
19659 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19660 __cmpxchg_wrong_size(); \
19661 \
19662 asm volatile("\t" ASM_STAC "\n" \
19663 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19664 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19665 "2:\t" ASM_CLAC "\n" \
19666 "\t.section .fixup, \"ax\"\n" \
19667 "3:\tmov %3, %0\n" \
19668 "\tjmp 2b\n" \
19669 "\t.previous\n" \
19670 _ASM_EXTABLE(1b, 3b) \
19671 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19672 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19673 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19674 : "memory" \
19675 ); \
19676 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19677 default: \
19678 __cmpxchg_wrong_size(); \
19679 } \
19680 + pax_close_userland(); \
19681 *__uval = __old; \
19682 __ret; \
19683 })
19684 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19685
19686 #define ARCH_HAS_NOCACHE_UACCESS 1
19687
19688 -#ifdef CONFIG_X86_32
19689 -# include <asm/uaccess_32.h>
19690 -#else
19691 -# include <asm/uaccess_64.h>
19692 -#endif
19693 -
19694 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19695 - unsigned n);
19696 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19697 - unsigned n);
19698 -
19699 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19700 # define copy_user_diag __compiletime_error
19701 #else
19702 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19703 extern void copy_user_diag("copy_from_user() buffer size is too small")
19704 copy_from_user_overflow(void);
19705 extern void copy_user_diag("copy_to_user() buffer size is too small")
19706 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19707 +copy_to_user_overflow(void);
19708
19709 #undef copy_user_diag
19710
19711 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19712
19713 extern void
19714 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19715 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19716 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19717 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19718
19719 #else
19720 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19721
19722 #endif
19723
19724 +#ifdef CONFIG_X86_32
19725 +# include <asm/uaccess_32.h>
19726 +#else
19727 +# include <asm/uaccess_64.h>
19728 +#endif
19729 +
19730 static inline unsigned long __must_check
19731 copy_from_user(void *to, const void __user *from, unsigned long n)
19732 {
19733 - int sz = __compiletime_object_size(to);
19734 + size_t sz = __compiletime_object_size(to);
19735
19736 might_fault();
19737
19738 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19739 * case, and do only runtime checking for non-constant sizes.
19740 */
19741
19742 - if (likely(sz < 0 || sz >= n))
19743 - n = _copy_from_user(to, from, n);
19744 - else if(__builtin_constant_p(n))
19745 - copy_from_user_overflow();
19746 - else
19747 - __copy_from_user_overflow(sz, n);
19748 + if (likely(sz != (size_t)-1 && sz < n)) {
19749 + if(__builtin_constant_p(n))
19750 + copy_from_user_overflow();
19751 + else
19752 + __copy_from_user_overflow(sz, n);
19753 + } if (access_ok(VERIFY_READ, from, n))
19754 + n = __copy_from_user(to, from, n);
19755 + else if ((long)n > 0)
19756 + memset(to, 0, n);
19757
19758 return n;
19759 }
19760 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19761 static inline unsigned long __must_check
19762 copy_to_user(void __user *to, const void *from, unsigned long n)
19763 {
19764 - int sz = __compiletime_object_size(from);
19765 + size_t sz = __compiletime_object_size(from);
19766
19767 might_fault();
19768
19769 /* See the comment in copy_from_user() above. */
19770 - if (likely(sz < 0 || sz >= n))
19771 - n = _copy_to_user(to, from, n);
19772 - else if(__builtin_constant_p(n))
19773 - copy_to_user_overflow();
19774 - else
19775 - __copy_to_user_overflow(sz, n);
19776 + if (likely(sz != (size_t)-1 && sz < n)) {
19777 + if(__builtin_constant_p(n))
19778 + copy_to_user_overflow();
19779 + else
19780 + __copy_to_user_overflow(sz, n);
19781 + } else if (access_ok(VERIFY_WRITE, to, n))
19782 + n = __copy_to_user(to, from, n);
19783
19784 return n;
19785 }
19786 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19787 index 3c03a5d..1071638 100644
19788 --- a/arch/x86/include/asm/uaccess_32.h
19789 +++ b/arch/x86/include/asm/uaccess_32.h
19790 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19791 static __always_inline unsigned long __must_check
19792 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19793 {
19794 + if ((long)n < 0)
19795 + return n;
19796 +
19797 + check_object_size(from, n, true);
19798 +
19799 if (__builtin_constant_p(n)) {
19800 unsigned long ret;
19801
19802 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19803 __copy_to_user(void __user *to, const void *from, unsigned long n)
19804 {
19805 might_fault();
19806 +
19807 return __copy_to_user_inatomic(to, from, n);
19808 }
19809
19810 static __always_inline unsigned long
19811 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19812 {
19813 + if ((long)n < 0)
19814 + return n;
19815 +
19816 /* Avoid zeroing the tail if the copy fails..
19817 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19818 * but as the zeroing behaviour is only significant when n is not
19819 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19820 __copy_from_user(void *to, const void __user *from, unsigned long n)
19821 {
19822 might_fault();
19823 +
19824 + if ((long)n < 0)
19825 + return n;
19826 +
19827 + check_object_size(to, n, false);
19828 +
19829 if (__builtin_constant_p(n)) {
19830 unsigned long ret;
19831
19832 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19833 const void __user *from, unsigned long n)
19834 {
19835 might_fault();
19836 +
19837 + if ((long)n < 0)
19838 + return n;
19839 +
19840 if (__builtin_constant_p(n)) {
19841 unsigned long ret;
19842
19843 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19844 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19845 unsigned long n)
19846 {
19847 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19848 + if ((long)n < 0)
19849 + return n;
19850 +
19851 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19852 }
19853
19854 #endif /* _ASM_X86_UACCESS_32_H */
19855 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19856 index 12a26b9..206c200 100644
19857 --- a/arch/x86/include/asm/uaccess_64.h
19858 +++ b/arch/x86/include/asm/uaccess_64.h
19859 @@ -10,6 +10,9 @@
19860 #include <asm/alternative.h>
19861 #include <asm/cpufeature.h>
19862 #include <asm/page.h>
19863 +#include <asm/pgtable.h>
19864 +
19865 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19866
19867 /*
19868 * Copy To/From Userspace
19869 @@ -17,14 +20,14 @@
19870
19871 /* Handles exceptions in both to and from, but doesn't do access_ok */
19872 __must_check unsigned long
19873 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19874 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19875 __must_check unsigned long
19876 -copy_user_generic_string(void *to, const void *from, unsigned len);
19877 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19878 __must_check unsigned long
19879 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19880 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19881
19882 static __always_inline __must_check unsigned long
19883 -copy_user_generic(void *to, const void *from, unsigned len)
19884 +copy_user_generic(void *to, const void *from, unsigned long len)
19885 {
19886 unsigned ret;
19887
19888 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19889 }
19890
19891 __must_check unsigned long
19892 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19893 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19894
19895 static __always_inline __must_check
19896 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19897 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19898 {
19899 - int ret = 0;
19900 + size_t sz = __compiletime_object_size(dst);
19901 + unsigned ret = 0;
19902 +
19903 + if (size > INT_MAX)
19904 + return size;
19905 +
19906 + check_object_size(dst, size, false);
19907 +
19908 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19909 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19910 + return size;
19911 +#endif
19912 +
19913 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19914 + if(__builtin_constant_p(size))
19915 + copy_from_user_overflow();
19916 + else
19917 + __copy_from_user_overflow(sz, size);
19918 + return size;
19919 + }
19920
19921 if (!__builtin_constant_p(size))
19922 - return copy_user_generic(dst, (__force void *)src, size);
19923 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19924 switch (size) {
19925 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19926 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19927 ret, "b", "b", "=q", 1);
19928 return ret;
19929 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19930 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19931 ret, "w", "w", "=r", 2);
19932 return ret;
19933 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19934 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19935 ret, "l", "k", "=r", 4);
19936 return ret;
19937 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19938 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19939 ret, "q", "", "=r", 8);
19940 return ret;
19941 case 10:
19942 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19943 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19944 ret, "q", "", "=r", 10);
19945 if (unlikely(ret))
19946 return ret;
19947 __get_user_asm(*(u16 *)(8 + (char *)dst),
19948 - (u16 __user *)(8 + (char __user *)src),
19949 + (const u16 __user *)(8 + (const char __user *)src),
19950 ret, "w", "w", "=r", 2);
19951 return ret;
19952 case 16:
19953 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19954 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19955 ret, "q", "", "=r", 16);
19956 if (unlikely(ret))
19957 return ret;
19958 __get_user_asm(*(u64 *)(8 + (char *)dst),
19959 - (u64 __user *)(8 + (char __user *)src),
19960 + (const u64 __user *)(8 + (const char __user *)src),
19961 ret, "q", "", "=r", 8);
19962 return ret;
19963 default:
19964 - return copy_user_generic(dst, (__force void *)src, size);
19965 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19966 }
19967 }
19968
19969 static __always_inline __must_check
19970 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19971 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19972 {
19973 might_fault();
19974 return __copy_from_user_nocheck(dst, src, size);
19975 }
19976
19977 static __always_inline __must_check
19978 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19979 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19980 {
19981 - int ret = 0;
19982 + size_t sz = __compiletime_object_size(src);
19983 + unsigned ret = 0;
19984 +
19985 + if (size > INT_MAX)
19986 + return size;
19987 +
19988 + check_object_size(src, size, true);
19989 +
19990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19991 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19992 + return size;
19993 +#endif
19994 +
19995 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19996 + if(__builtin_constant_p(size))
19997 + copy_to_user_overflow();
19998 + else
19999 + __copy_to_user_overflow(sz, size);
20000 + return size;
20001 + }
20002
20003 if (!__builtin_constant_p(size))
20004 - return copy_user_generic((__force void *)dst, src, size);
20005 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20006 switch (size) {
20007 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20008 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20009 ret, "b", "b", "iq", 1);
20010 return ret;
20011 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20012 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20013 ret, "w", "w", "ir", 2);
20014 return ret;
20015 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20016 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20017 ret, "l", "k", "ir", 4);
20018 return ret;
20019 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20020 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20021 ret, "q", "", "er", 8);
20022 return ret;
20023 case 10:
20024 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20025 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20026 ret, "q", "", "er", 10);
20027 if (unlikely(ret))
20028 return ret;
20029 asm("":::"memory");
20030 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20031 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20032 ret, "w", "w", "ir", 2);
20033 return ret;
20034 case 16:
20035 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20036 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20037 ret, "q", "", "er", 16);
20038 if (unlikely(ret))
20039 return ret;
20040 asm("":::"memory");
20041 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20042 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20043 ret, "q", "", "er", 8);
20044 return ret;
20045 default:
20046 - return copy_user_generic((__force void *)dst, src, size);
20047 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20048 }
20049 }
20050
20051 static __always_inline __must_check
20052 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20053 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20054 {
20055 might_fault();
20056 return __copy_to_user_nocheck(dst, src, size);
20057 }
20058
20059 static __always_inline __must_check
20060 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20061 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20062 {
20063 - int ret = 0;
20064 + unsigned ret = 0;
20065
20066 might_fault();
20067 +
20068 + if (size > INT_MAX)
20069 + return size;
20070 +
20071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20072 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20073 + return size;
20074 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20075 + return size;
20076 +#endif
20077 +
20078 if (!__builtin_constant_p(size))
20079 - return copy_user_generic((__force void *)dst,
20080 - (__force void *)src, size);
20081 + return copy_user_generic((__force_kernel void *)____m(dst),
20082 + (__force_kernel const void *)____m(src), size);
20083 switch (size) {
20084 case 1: {
20085 u8 tmp;
20086 - __get_user_asm(tmp, (u8 __user *)src,
20087 + __get_user_asm(tmp, (const u8 __user *)src,
20088 ret, "b", "b", "=q", 1);
20089 if (likely(!ret))
20090 __put_user_asm(tmp, (u8 __user *)dst,
20091 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20092 }
20093 case 2: {
20094 u16 tmp;
20095 - __get_user_asm(tmp, (u16 __user *)src,
20096 + __get_user_asm(tmp, (const u16 __user *)src,
20097 ret, "w", "w", "=r", 2);
20098 if (likely(!ret))
20099 __put_user_asm(tmp, (u16 __user *)dst,
20100 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20101
20102 case 4: {
20103 u32 tmp;
20104 - __get_user_asm(tmp, (u32 __user *)src,
20105 + __get_user_asm(tmp, (const u32 __user *)src,
20106 ret, "l", "k", "=r", 4);
20107 if (likely(!ret))
20108 __put_user_asm(tmp, (u32 __user *)dst,
20109 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20110 }
20111 case 8: {
20112 u64 tmp;
20113 - __get_user_asm(tmp, (u64 __user *)src,
20114 + __get_user_asm(tmp, (const u64 __user *)src,
20115 ret, "q", "", "=r", 8);
20116 if (likely(!ret))
20117 __put_user_asm(tmp, (u64 __user *)dst,
20118 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20119 return ret;
20120 }
20121 default:
20122 - return copy_user_generic((__force void *)dst,
20123 - (__force void *)src, size);
20124 + return copy_user_generic((__force_kernel void *)____m(dst),
20125 + (__force_kernel const void *)____m(src), size);
20126 }
20127 }
20128
20129 -static __must_check __always_inline int
20130 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20131 +static __must_check __always_inline unsigned long
20132 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20133 {
20134 return __copy_from_user_nocheck(dst, src, size);
20135 }
20136
20137 -static __must_check __always_inline int
20138 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20139 +static __must_check __always_inline unsigned long
20140 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20141 {
20142 return __copy_to_user_nocheck(dst, src, size);
20143 }
20144
20145 -extern long __copy_user_nocache(void *dst, const void __user *src,
20146 - unsigned size, int zerorest);
20147 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20148 + unsigned long size, int zerorest);
20149
20150 -static inline int
20151 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20152 +static inline unsigned long
20153 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20154 {
20155 might_fault();
20156 +
20157 + if (size > INT_MAX)
20158 + return size;
20159 +
20160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20161 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20162 + return size;
20163 +#endif
20164 +
20165 return __copy_user_nocache(dst, src, size, 1);
20166 }
20167
20168 -static inline int
20169 +static inline unsigned long
20170 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20171 - unsigned size)
20172 + unsigned long size)
20173 {
20174 + if (size > INT_MAX)
20175 + return size;
20176 +
20177 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20178 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20179 + return size;
20180 +#endif
20181 +
20182 return __copy_user_nocache(dst, src, size, 0);
20183 }
20184
20185 unsigned long
20186 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20187 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20188
20189 #endif /* _ASM_X86_UACCESS_64_H */
20190 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20191 index 5b238981..77fdd78 100644
20192 --- a/arch/x86/include/asm/word-at-a-time.h
20193 +++ b/arch/x86/include/asm/word-at-a-time.h
20194 @@ -11,7 +11,7 @@
20195 * and shift, for example.
20196 */
20197 struct word_at_a_time {
20198 - const unsigned long one_bits, high_bits;
20199 + unsigned long one_bits, high_bits;
20200 };
20201
20202 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20203 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20204 index e45e4da..44e8572 100644
20205 --- a/arch/x86/include/asm/x86_init.h
20206 +++ b/arch/x86/include/asm/x86_init.h
20207 @@ -129,7 +129,7 @@ struct x86_init_ops {
20208 struct x86_init_timers timers;
20209 struct x86_init_iommu iommu;
20210 struct x86_init_pci pci;
20211 -};
20212 +} __no_const;
20213
20214 /**
20215 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20216 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20217 void (*setup_percpu_clockev)(void);
20218 void (*early_percpu_clock_init)(void);
20219 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20220 -};
20221 +} __no_const;
20222
20223 struct timespec;
20224
20225 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20226 void (*save_sched_clock_state)(void);
20227 void (*restore_sched_clock_state)(void);
20228 void (*apic_post_init)(void);
20229 -};
20230 +} __no_const;
20231
20232 struct pci_dev;
20233 struct msi_msg;
20234 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20235 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20236 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20237 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20238 -};
20239 +} __no_const;
20240
20241 struct IO_APIC_route_entry;
20242 struct io_apic_irq_attr;
20243 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20244 unsigned int destination, int vector,
20245 struct io_apic_irq_attr *attr);
20246 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20247 -};
20248 +} __no_const;
20249
20250 extern struct x86_init_ops x86_init;
20251 extern struct x86_cpuinit_ops x86_cpuinit;
20252 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20253 index c949923..c22bfa4 100644
20254 --- a/arch/x86/include/asm/xen/page.h
20255 +++ b/arch/x86/include/asm/xen/page.h
20256 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20257 extern struct page *m2p_find_override(unsigned long mfn);
20258 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20259
20260 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20261 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20262 {
20263 unsigned long mfn;
20264
20265 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20266 index d949ef2..479b9d1 100644
20267 --- a/arch/x86/include/asm/xsave.h
20268 +++ b/arch/x86/include/asm/xsave.h
20269 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20270 if (unlikely(err))
20271 return -EFAULT;
20272
20273 + pax_open_userland();
20274 __asm__ __volatile__(ASM_STAC "\n"
20275 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20276 + "1:"
20277 + __copyuser_seg
20278 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20279 "2: " ASM_CLAC "\n"
20280 ".section .fixup,\"ax\"\n"
20281 "3: movl $-1,%[err]\n"
20282 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20283 : [err] "=r" (err)
20284 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20285 : "memory");
20286 + pax_close_userland();
20287 return err;
20288 }
20289
20290 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20291 {
20292 int err;
20293 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20294 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20295 u32 lmask = mask;
20296 u32 hmask = mask >> 32;
20297
20298 + pax_open_userland();
20299 __asm__ __volatile__(ASM_STAC "\n"
20300 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20301 + "1:"
20302 + __copyuser_seg
20303 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20304 "2: " ASM_CLAC "\n"
20305 ".section .fixup,\"ax\"\n"
20306 "3: movl $-1,%[err]\n"
20307 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20308 : [err] "=r" (err)
20309 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20310 : "memory"); /* memory required? */
20311 + pax_close_userland();
20312 return err;
20313 }
20314
20315 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20316 index bbae024..e1528f9 100644
20317 --- a/arch/x86/include/uapi/asm/e820.h
20318 +++ b/arch/x86/include/uapi/asm/e820.h
20319 @@ -63,7 +63,7 @@ struct e820map {
20320 #define ISA_START_ADDRESS 0xa0000
20321 #define ISA_END_ADDRESS 0x100000
20322
20323 -#define BIOS_BEGIN 0x000a0000
20324 +#define BIOS_BEGIN 0x000c0000
20325 #define BIOS_END 0x00100000
20326
20327 #define BIOS_ROM_BASE 0xffe00000
20328 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20329 index 7b0a55a..ad115bf 100644
20330 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20331 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20332 @@ -49,7 +49,6 @@
20333 #define EFLAGS 144
20334 #define RSP 152
20335 #define SS 160
20336 -#define ARGOFFSET R11
20337 #endif /* __ASSEMBLY__ */
20338
20339 /* top of stack page */
20340 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20341 index f4d9600..b45af01 100644
20342 --- a/arch/x86/kernel/Makefile
20343 +++ b/arch/x86/kernel/Makefile
20344 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20345 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20346 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20347 obj-y += probe_roms.o
20348 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20349 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20350 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20351 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20352 obj-$(CONFIG_X86_64) += vsyscall_64.o
20353 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20354 index 86281ff..e046fc2 100644
20355 --- a/arch/x86/kernel/acpi/boot.c
20356 +++ b/arch/x86/kernel/acpi/boot.c
20357 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20358 * If your system is blacklisted here, but you find that acpi=force
20359 * works for you, please contact linux-acpi@vger.kernel.org
20360 */
20361 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20362 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20363 /*
20364 * Boxes that need ACPI disabled
20365 */
20366 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20367 };
20368
20369 /* second table for DMI checks that should run after early-quirks */
20370 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20371 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20372 /*
20373 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20374 * which includes some code which overrides all temperature
20375 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20376 index 3136820..e2c6577 100644
20377 --- a/arch/x86/kernel/acpi/sleep.c
20378 +++ b/arch/x86/kernel/acpi/sleep.c
20379 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20380 #else /* CONFIG_64BIT */
20381 #ifdef CONFIG_SMP
20382 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20383 +
20384 + pax_open_kernel();
20385 early_gdt_descr.address =
20386 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20387 + pax_close_kernel();
20388 +
20389 initial_gs = per_cpu_offset(smp_processor_id());
20390 #endif
20391 initial_code = (unsigned long)wakeup_long64;
20392 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20393 index 665c6b7..eae4d56 100644
20394 --- a/arch/x86/kernel/acpi/wakeup_32.S
20395 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20396 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20397 # and restore the stack ... but you need gdt for this to work
20398 movl saved_context_esp, %esp
20399
20400 - movl %cs:saved_magic, %eax
20401 - cmpl $0x12345678, %eax
20402 + cmpl $0x12345678, saved_magic
20403 jne bogus_magic
20404
20405 # jump to place where we left off
20406 - movl saved_eip, %eax
20407 - jmp *%eax
20408 + jmp *(saved_eip)
20409
20410 bogus_magic:
20411 jmp bogus_magic
20412 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20413 index df94598..b7162f9 100644
20414 --- a/arch/x86/kernel/alternative.c
20415 +++ b/arch/x86/kernel/alternative.c
20416 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20417 */
20418 for (a = start; a < end; a++) {
20419 instr = (u8 *)&a->instr_offset + a->instr_offset;
20420 +
20421 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20422 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20423 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20424 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20425 +#endif
20426 +
20427 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20428 BUG_ON(a->replacementlen > a->instrlen);
20429 BUG_ON(a->instrlen > sizeof(insnbuf));
20430 @@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20431 add_nops(insnbuf + a->replacementlen,
20432 a->instrlen - a->replacementlen);
20433
20434 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20435 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20436 + instr = ktva_ktla(instr);
20437 +#endif
20438 +
20439 text_poke_early(instr, insnbuf, a->instrlen);
20440 }
20441 }
20442 @@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20443 for (poff = start; poff < end; poff++) {
20444 u8 *ptr = (u8 *)poff + *poff;
20445
20446 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20447 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20448 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20449 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20450 +#endif
20451 +
20452 if (!*poff || ptr < text || ptr >= text_end)
20453 continue;
20454 /* turn DS segment override prefix into lock prefix */
20455 - if (*ptr == 0x3e)
20456 + if (*ktla_ktva(ptr) == 0x3e)
20457 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20458 }
20459 mutex_unlock(&text_mutex);
20460 @@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20461 for (poff = start; poff < end; poff++) {
20462 u8 *ptr = (u8 *)poff + *poff;
20463
20464 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20465 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20466 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20467 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20468 +#endif
20469 +
20470 if (!*poff || ptr < text || ptr >= text_end)
20471 continue;
20472 /* turn lock prefix into DS segment override prefix */
20473 - if (*ptr == 0xf0)
20474 + if (*ktla_ktva(ptr) == 0xf0)
20475 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20476 }
20477 mutex_unlock(&text_mutex);
20478 @@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20479
20480 BUG_ON(p->len > MAX_PATCH_LEN);
20481 /* prep the buffer with the original instructions */
20482 - memcpy(insnbuf, p->instr, p->len);
20483 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20484 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20485 (unsigned long)p->instr, p->len);
20486
20487 @@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20488 if (!uniproc_patched || num_possible_cpus() == 1)
20489 free_init_pages("SMP alternatives",
20490 (unsigned long)__smp_locks,
20491 - (unsigned long)__smp_locks_end);
20492 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20493 #endif
20494
20495 apply_paravirt(__parainstructions, __parainstructions_end);
20496 @@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20497 * instructions. And on the local CPU you need to be protected again NMI or MCE
20498 * handlers seeing an inconsistent instruction while you patch.
20499 */
20500 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20501 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20502 size_t len)
20503 {
20504 unsigned long flags;
20505 local_irq_save(flags);
20506 - memcpy(addr, opcode, len);
20507 +
20508 + pax_open_kernel();
20509 + memcpy(ktla_ktva(addr), opcode, len);
20510 sync_core();
20511 + pax_close_kernel();
20512 +
20513 local_irq_restore(flags);
20514 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20515 that causes hangs on some VIA CPUs. */
20516 @@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20517 */
20518 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20519 {
20520 - unsigned long flags;
20521 - char *vaddr;
20522 + unsigned char *vaddr = ktla_ktva(addr);
20523 struct page *pages[2];
20524 - int i;
20525 + size_t i;
20526
20527 if (!core_kernel_text((unsigned long)addr)) {
20528 - pages[0] = vmalloc_to_page(addr);
20529 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20530 + pages[0] = vmalloc_to_page(vaddr);
20531 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20532 } else {
20533 - pages[0] = virt_to_page(addr);
20534 + pages[0] = virt_to_page(vaddr);
20535 WARN_ON(!PageReserved(pages[0]));
20536 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20537 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20538 }
20539 BUG_ON(!pages[0]);
20540 - local_irq_save(flags);
20541 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20542 - if (pages[1])
20543 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20544 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20545 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20546 - clear_fixmap(FIX_TEXT_POKE0);
20547 - if (pages[1])
20548 - clear_fixmap(FIX_TEXT_POKE1);
20549 - local_flush_tlb();
20550 - sync_core();
20551 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20552 - that causes hangs on some VIA CPUs. */
20553 + text_poke_early(addr, opcode, len);
20554 for (i = 0; i < len; i++)
20555 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20556 - local_irq_restore(flags);
20557 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20558 return addr;
20559 }
20560
20561 @@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20562 if (likely(!bp_patching_in_progress))
20563 return 0;
20564
20565 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20566 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20567 return 0;
20568
20569 /* set up the specified breakpoint handler */
20570 @@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20571 */
20572 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20573 {
20574 - unsigned char int3 = 0xcc;
20575 + const unsigned char int3 = 0xcc;
20576
20577 bp_int3_handler = handler;
20578 bp_int3_addr = (u8 *)addr + sizeof(int3);
20579 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20580 index ad28db7..c538b2c 100644
20581 --- a/arch/x86/kernel/apic/apic.c
20582 +++ b/arch/x86/kernel/apic/apic.c
20583 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20584 /*
20585 * Debug level, exported for io_apic.c
20586 */
20587 -unsigned int apic_verbosity;
20588 +int apic_verbosity;
20589
20590 int pic_mode;
20591
20592 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20593 apic_write(APIC_ESR, 0);
20594 v = apic_read(APIC_ESR);
20595 ack_APIC_irq();
20596 - atomic_inc(&irq_err_count);
20597 + atomic_inc_unchecked(&irq_err_count);
20598
20599 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20600 smp_processor_id(), v);
20601 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20602 index 7c1b294..e71d27f 100644
20603 --- a/arch/x86/kernel/apic/apic_flat_64.c
20604 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20605 @@ -154,7 +154,7 @@ static int flat_probe(void)
20606 return 1;
20607 }
20608
20609 -static struct apic apic_flat = {
20610 +static struct apic apic_flat __read_only = {
20611 .name = "flat",
20612 .probe = flat_probe,
20613 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20614 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20615 return 0;
20616 }
20617
20618 -static struct apic apic_physflat = {
20619 +static struct apic apic_physflat __read_only = {
20620
20621 .name = "physical flat",
20622 .probe = physflat_probe,
20623 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20624 index 8c7c982..a225910 100644
20625 --- a/arch/x86/kernel/apic/apic_noop.c
20626 +++ b/arch/x86/kernel/apic/apic_noop.c
20627 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20628 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20629 }
20630
20631 -struct apic apic_noop = {
20632 +struct apic apic_noop __read_only = {
20633 .name = "noop",
20634 .probe = noop_probe,
20635 .acpi_madt_oem_check = NULL,
20636 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20637 index e4840aa..e7d9dac 100644
20638 --- a/arch/x86/kernel/apic/bigsmp_32.c
20639 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20640 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20641 return dmi_bigsmp;
20642 }
20643
20644 -static struct apic apic_bigsmp = {
20645 +static struct apic apic_bigsmp __read_only = {
20646
20647 .name = "bigsmp",
20648 .probe = probe_bigsmp,
20649 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20650 index 992060e..ecdc3b3 100644
20651 --- a/arch/x86/kernel/apic/io_apic.c
20652 +++ b/arch/x86/kernel/apic/io_apic.c
20653 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20654 }
20655 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20656
20657 -void lock_vector_lock(void)
20658 +void lock_vector_lock(void) __acquires(vector_lock)
20659 {
20660 /* Used to the online set of cpus does not change
20661 * during assign_irq_vector.
20662 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20663 raw_spin_lock(&vector_lock);
20664 }
20665
20666 -void unlock_vector_lock(void)
20667 +void unlock_vector_lock(void) __releases(vector_lock)
20668 {
20669 raw_spin_unlock(&vector_lock);
20670 }
20671 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20672 ack_APIC_irq();
20673 }
20674
20675 -atomic_t irq_mis_count;
20676 +atomic_unchecked_t irq_mis_count;
20677
20678 #ifdef CONFIG_GENERIC_PENDING_IRQ
20679 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20680 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20681 * at the cpu.
20682 */
20683 if (!(v & (1 << (i & 0x1f)))) {
20684 - atomic_inc(&irq_mis_count);
20685 + atomic_inc_unchecked(&irq_mis_count);
20686
20687 eoi_ioapic_irq(irq, cfg);
20688 }
20689 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20690 index cceb352..a635fd8 100644
20691 --- a/arch/x86/kernel/apic/probe_32.c
20692 +++ b/arch/x86/kernel/apic/probe_32.c
20693 @@ -72,7 +72,7 @@ static int probe_default(void)
20694 return 1;
20695 }
20696
20697 -static struct apic apic_default = {
20698 +static struct apic apic_default __read_only = {
20699
20700 .name = "default",
20701 .probe = probe_default,
20702 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20703 index e66766b..1c008ba 100644
20704 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20705 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20706 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20707 return notifier_from_errno(err);
20708 }
20709
20710 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20711 +static struct notifier_block x2apic_cpu_notifier = {
20712 .notifier_call = update_clusterinfo,
20713 };
20714
20715 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20716 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20717 }
20718
20719 -static struct apic apic_x2apic_cluster = {
20720 +static struct apic apic_x2apic_cluster __read_only = {
20721
20722 .name = "cluster x2apic",
20723 .probe = x2apic_cluster_probe,
20724 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20725 index 6d600eb..0300c00 100644
20726 --- a/arch/x86/kernel/apic/x2apic_phys.c
20727 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20728 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20729 return apic == &apic_x2apic_phys;
20730 }
20731
20732 -static struct apic apic_x2apic_phys = {
20733 +static struct apic apic_x2apic_phys __read_only = {
20734
20735 .name = "physical x2apic",
20736 .probe = x2apic_phys_probe,
20737 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20738 index 7834389..4ffc9c8 100644
20739 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20740 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20741 @@ -350,7 +350,7 @@ static int uv_probe(void)
20742 return apic == &apic_x2apic_uv_x;
20743 }
20744
20745 -static struct apic __refdata apic_x2apic_uv_x = {
20746 +static struct apic apic_x2apic_uv_x __read_only = {
20747
20748 .name = "UV large system",
20749 .probe = uv_probe,
20750 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20751 index 3ab0343..814c4787 100644
20752 --- a/arch/x86/kernel/apm_32.c
20753 +++ b/arch/x86/kernel/apm_32.c
20754 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20755 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20756 * even though they are called in protected mode.
20757 */
20758 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20759 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20760 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20761
20762 static const char driver_version[] = "1.16ac"; /* no spaces */
20763 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20764 BUG_ON(cpu != 0);
20765 gdt = get_cpu_gdt_table(cpu);
20766 save_desc_40 = gdt[0x40 / 8];
20767 +
20768 + pax_open_kernel();
20769 gdt[0x40 / 8] = bad_bios_desc;
20770 + pax_close_kernel();
20771
20772 apm_irq_save(flags);
20773 APM_DO_SAVE_SEGS;
20774 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20775 &call->esi);
20776 APM_DO_RESTORE_SEGS;
20777 apm_irq_restore(flags);
20778 +
20779 + pax_open_kernel();
20780 gdt[0x40 / 8] = save_desc_40;
20781 + pax_close_kernel();
20782 +
20783 put_cpu();
20784
20785 return call->eax & 0xff;
20786 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20787 BUG_ON(cpu != 0);
20788 gdt = get_cpu_gdt_table(cpu);
20789 save_desc_40 = gdt[0x40 / 8];
20790 +
20791 + pax_open_kernel();
20792 gdt[0x40 / 8] = bad_bios_desc;
20793 + pax_close_kernel();
20794
20795 apm_irq_save(flags);
20796 APM_DO_SAVE_SEGS;
20797 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20798 &call->eax);
20799 APM_DO_RESTORE_SEGS;
20800 apm_irq_restore(flags);
20801 +
20802 + pax_open_kernel();
20803 gdt[0x40 / 8] = save_desc_40;
20804 + pax_close_kernel();
20805 +
20806 put_cpu();
20807 return error;
20808 }
20809 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20810 * code to that CPU.
20811 */
20812 gdt = get_cpu_gdt_table(0);
20813 +
20814 + pax_open_kernel();
20815 set_desc_base(&gdt[APM_CS >> 3],
20816 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20817 set_desc_base(&gdt[APM_CS_16 >> 3],
20818 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20819 set_desc_base(&gdt[APM_DS >> 3],
20820 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20821 + pax_close_kernel();
20822
20823 proc_create("apm", 0, NULL, &apm_file_ops);
20824
20825 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20826 index 9f6b934..cf5ffb3 100644
20827 --- a/arch/x86/kernel/asm-offsets.c
20828 +++ b/arch/x86/kernel/asm-offsets.c
20829 @@ -32,6 +32,8 @@ void common(void) {
20830 OFFSET(TI_flags, thread_info, flags);
20831 OFFSET(TI_status, thread_info, status);
20832 OFFSET(TI_addr_limit, thread_info, addr_limit);
20833 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20834 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20835
20836 BLANK();
20837 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20838 @@ -52,8 +54,26 @@ void common(void) {
20839 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20840 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20841 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20842 +
20843 +#ifdef CONFIG_PAX_KERNEXEC
20844 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20845 #endif
20846
20847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20848 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20849 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20850 +#ifdef CONFIG_X86_64
20851 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20852 +#endif
20853 +#endif
20854 +
20855 +#endif
20856 +
20857 + BLANK();
20858 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20859 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20860 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20861 +
20862 #ifdef CONFIG_XEN
20863 BLANK();
20864 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20865 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20866 index e7c798b..2b2019b 100644
20867 --- a/arch/x86/kernel/asm-offsets_64.c
20868 +++ b/arch/x86/kernel/asm-offsets_64.c
20869 @@ -77,6 +77,7 @@ int main(void)
20870 BLANK();
20871 #undef ENTRY
20872
20873 + DEFINE(TSS_size, sizeof(struct tss_struct));
20874 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20875 BLANK();
20876
20877 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20878 index 7fd54f0..0691410 100644
20879 --- a/arch/x86/kernel/cpu/Makefile
20880 +++ b/arch/x86/kernel/cpu/Makefile
20881 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20882 CFLAGS_REMOVE_perf_event.o = -pg
20883 endif
20884
20885 -# Make sure load_percpu_segment has no stackprotector
20886 -nostackp := $(call cc-option, -fno-stack-protector)
20887 -CFLAGS_common.o := $(nostackp)
20888 -
20889 obj-y := intel_cacheinfo.o scattered.o topology.o
20890 obj-y += proc.o capflags.o powerflags.o common.o
20891 obj-y += rdrand.o
20892 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20893 index ce8b8ff..d7d8851 100644
20894 --- a/arch/x86/kernel/cpu/amd.c
20895 +++ b/arch/x86/kernel/cpu/amd.c
20896 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20897 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20898 {
20899 /* AMD errata T13 (order #21922) */
20900 - if ((c->x86 == 6)) {
20901 + if (c->x86 == 6) {
20902 /* Duron Rev A0 */
20903 if (c->x86_model == 3 && c->x86_mask == 0)
20904 size = 64;
20905 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20906 index a135239..41fb30a 100644
20907 --- a/arch/x86/kernel/cpu/common.c
20908 +++ b/arch/x86/kernel/cpu/common.c
20909 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20910
20911 static const struct cpu_dev *this_cpu = &default_cpu;
20912
20913 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20914 -#ifdef CONFIG_X86_64
20915 - /*
20916 - * We need valid kernel segments for data and code in long mode too
20917 - * IRET will check the segment types kkeil 2000/10/28
20918 - * Also sysret mandates a special GDT layout
20919 - *
20920 - * TLS descriptors are currently at a different place compared to i386.
20921 - * Hopefully nobody expects them at a fixed place (Wine?)
20922 - */
20923 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20924 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20925 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20926 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20927 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20928 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20929 -#else
20930 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20931 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20932 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20933 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20934 - /*
20935 - * Segments used for calling PnP BIOS have byte granularity.
20936 - * They code segments and data segments have fixed 64k limits,
20937 - * the transfer segment sizes are set at run time.
20938 - */
20939 - /* 32-bit code */
20940 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20941 - /* 16-bit code */
20942 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20943 - /* 16-bit data */
20944 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20945 - /* 16-bit data */
20946 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20947 - /* 16-bit data */
20948 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20949 - /*
20950 - * The APM segments have byte granularity and their bases
20951 - * are set at run time. All have 64k limits.
20952 - */
20953 - /* 32-bit code */
20954 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20955 - /* 16-bit code */
20956 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20957 - /* data */
20958 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20959 -
20960 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20961 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20962 - GDT_STACK_CANARY_INIT
20963 -#endif
20964 -} };
20965 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20966 -
20967 static int __init x86_xsave_setup(char *s)
20968 {
20969 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20970 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20971 }
20972 }
20973
20974 +#ifdef CONFIG_X86_64
20975 +static __init int setup_disable_pcid(char *arg)
20976 +{
20977 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20978 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20979 +
20980 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20981 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20982 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20983 +#endif
20984 +
20985 + return 1;
20986 +}
20987 +__setup("nopcid", setup_disable_pcid);
20988 +
20989 +static void setup_pcid(struct cpuinfo_x86 *c)
20990 +{
20991 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20992 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20993 +
20994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20995 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20996 + pax_open_kernel();
20997 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20998 + pax_close_kernel();
20999 + printk("PAX: slow and weak UDEREF enabled\n");
21000 + } else
21001 + printk("PAX: UDEREF disabled\n");
21002 +#endif
21003 +
21004 + return;
21005 + }
21006 +
21007 + printk("PAX: PCID detected\n");
21008 + set_in_cr4(X86_CR4_PCIDE);
21009 +
21010 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21011 + pax_open_kernel();
21012 + clone_pgd_mask = ~(pgdval_t)0UL;
21013 + pax_close_kernel();
21014 + if (pax_user_shadow_base)
21015 + printk("PAX: weak UDEREF enabled\n");
21016 + else {
21017 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21018 + printk("PAX: strong UDEREF enabled\n");
21019 + }
21020 +#endif
21021 +
21022 + if (cpu_has(c, X86_FEATURE_INVPCID))
21023 + printk("PAX: INVPCID detected\n");
21024 +}
21025 +#endif
21026 +
21027 /*
21028 * Some CPU features depend on higher CPUID levels, which may not always
21029 * be available due to CPUID level capping or broken virtualization
21030 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21031 {
21032 struct desc_ptr gdt_descr;
21033
21034 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21035 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21036 gdt_descr.size = GDT_SIZE - 1;
21037 load_gdt(&gdt_descr);
21038 /* Reload the per-cpu base */
21039 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21040 setup_smep(c);
21041 setup_smap(c);
21042
21043 +#ifdef CONFIG_X86_64
21044 + setup_pcid(c);
21045 +#endif
21046 +
21047 /*
21048 * The vendor-specific functions might have changed features.
21049 * Now we do "generic changes."
21050 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21051 /* Filter out anything that depends on CPUID levels we don't have */
21052 filter_cpuid_features(c, true);
21053
21054 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21055 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21056 +#endif
21057 +
21058 /* If the model name is still unset, do table lookup. */
21059 if (!c->x86_model_id[0]) {
21060 const char *p;
21061 @@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21062 }
21063 __setup("clearcpuid=", setup_disablecpuid);
21064
21065 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21066 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21067 +
21068 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21069 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21070 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21071 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21072
21073 #ifdef CONFIG_X86_64
21074 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21075 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21076 - (unsigned long) debug_idt_table };
21077 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21078 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21079
21080 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21081 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21082 @@ -1246,7 +1255,7 @@ void cpu_init(void)
21083 load_ucode_ap();
21084
21085 cpu = stack_smp_processor_id();
21086 - t = &per_cpu(init_tss, cpu);
21087 + t = init_tss + cpu;
21088 oist = &per_cpu(orig_ist, cpu);
21089
21090 #ifdef CONFIG_NUMA
21091 @@ -1281,7 +1290,6 @@ void cpu_init(void)
21092 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21093 barrier();
21094
21095 - x86_configure_nx();
21096 enable_x2apic();
21097
21098 /*
21099 @@ -1333,7 +1341,7 @@ void cpu_init(void)
21100 {
21101 int cpu = smp_processor_id();
21102 struct task_struct *curr = current;
21103 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21104 + struct tss_struct *t = init_tss + cpu;
21105 struct thread_struct *thread = &curr->thread;
21106
21107 show_ucode_info_early();
21108 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21109 index a952e9c..58a4cbb 100644
21110 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21111 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21112 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21113 };
21114
21115 #ifdef CONFIG_AMD_NB
21116 +static struct attribute *default_attrs_amd_nb[] = {
21117 + &type.attr,
21118 + &level.attr,
21119 + &coherency_line_size.attr,
21120 + &physical_line_partition.attr,
21121 + &ways_of_associativity.attr,
21122 + &number_of_sets.attr,
21123 + &size.attr,
21124 + &shared_cpu_map.attr,
21125 + &shared_cpu_list.attr,
21126 + NULL,
21127 + NULL,
21128 + NULL,
21129 + NULL
21130 +};
21131 +
21132 static struct attribute **amd_l3_attrs(void)
21133 {
21134 static struct attribute **attrs;
21135 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21136
21137 n = ARRAY_SIZE(default_attrs);
21138
21139 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21140 - n += 2;
21141 -
21142 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21143 - n += 1;
21144 -
21145 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21146 - if (attrs == NULL)
21147 - return attrs = default_attrs;
21148 -
21149 - for (n = 0; default_attrs[n]; n++)
21150 - attrs[n] = default_attrs[n];
21151 + attrs = default_attrs_amd_nb;
21152
21153 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21154 attrs[n++] = &cache_disable_0.attr;
21155 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21156 .default_attrs = default_attrs,
21157 };
21158
21159 +#ifdef CONFIG_AMD_NB
21160 +static struct kobj_type ktype_cache_amd_nb = {
21161 + .sysfs_ops = &sysfs_ops,
21162 + .default_attrs = default_attrs_amd_nb,
21163 +};
21164 +#endif
21165 +
21166 static struct kobj_type ktype_percpu_entry = {
21167 .sysfs_ops = &sysfs_ops,
21168 };
21169 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21170 return retval;
21171 }
21172
21173 +#ifdef CONFIG_AMD_NB
21174 + amd_l3_attrs();
21175 +#endif
21176 +
21177 for (i = 0; i < num_cache_leaves; i++) {
21178 + struct kobj_type *ktype;
21179 +
21180 this_object = INDEX_KOBJECT_PTR(cpu, i);
21181 this_object->cpu = cpu;
21182 this_object->index = i;
21183
21184 this_leaf = CPUID4_INFO_IDX(cpu, i);
21185
21186 - ktype_cache.default_attrs = default_attrs;
21187 + ktype = &ktype_cache;
21188 #ifdef CONFIG_AMD_NB
21189 if (this_leaf->base.nb)
21190 - ktype_cache.default_attrs = amd_l3_attrs();
21191 + ktype = &ktype_cache_amd_nb;
21192 #endif
21193 retval = kobject_init_and_add(&(this_object->kobj),
21194 - &ktype_cache,
21195 + ktype,
21196 per_cpu(ici_cache_kobject, cpu),
21197 "index%1lu", i);
21198 if (unlikely(retval)) {
21199 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21200 index 68317c8..c860d41 100644
21201 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21202 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21203 @@ -45,6 +45,7 @@
21204 #include <asm/processor.h>
21205 #include <asm/mce.h>
21206 #include <asm/msr.h>
21207 +#include <asm/local.h>
21208
21209 #include "mce-internal.h"
21210
21211 @@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21212 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21213 m->cs, m->ip);
21214
21215 - if (m->cs == __KERNEL_CS)
21216 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21217 print_symbol("{%s}", m->ip);
21218 pr_cont("\n");
21219 }
21220 @@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21221
21222 #define PANIC_TIMEOUT 5 /* 5 seconds */
21223
21224 -static atomic_t mce_paniced;
21225 +static atomic_unchecked_t mce_paniced;
21226
21227 static int fake_panic;
21228 -static atomic_t mce_fake_paniced;
21229 +static atomic_unchecked_t mce_fake_paniced;
21230
21231 /* Panic in progress. Enable interrupts and wait for final IPI */
21232 static void wait_for_panic(void)
21233 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21234 /*
21235 * Make sure only one CPU runs in machine check panic
21236 */
21237 - if (atomic_inc_return(&mce_paniced) > 1)
21238 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21239 wait_for_panic();
21240 barrier();
21241
21242 @@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21243 console_verbose();
21244 } else {
21245 /* Don't log too much for fake panic */
21246 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21247 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21248 return;
21249 }
21250 /* First print corrected ones that are still unlogged */
21251 @@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21252 if (!fake_panic) {
21253 if (panic_timeout == 0)
21254 panic_timeout = mca_cfg.panic_timeout;
21255 - panic(msg);
21256 + panic("%s", msg);
21257 } else
21258 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21259 }
21260 @@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21261 * might have been modified by someone else.
21262 */
21263 rmb();
21264 - if (atomic_read(&mce_paniced))
21265 + if (atomic_read_unchecked(&mce_paniced))
21266 wait_for_panic();
21267 if (!mca_cfg.monarch_timeout)
21268 goto out;
21269 @@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21270 }
21271
21272 /* Call the installed machine check handler for this CPU setup. */
21273 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21274 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21275 unexpected_machine_check;
21276
21277 /*
21278 @@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21279 return;
21280 }
21281
21282 + pax_open_kernel();
21283 machine_check_vector = do_machine_check;
21284 + pax_close_kernel();
21285
21286 __mcheck_cpu_init_generic();
21287 __mcheck_cpu_init_vendor(c);
21288 @@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21289 */
21290
21291 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21292 -static int mce_chrdev_open_count; /* #times opened */
21293 +static local_t mce_chrdev_open_count; /* #times opened */
21294 static int mce_chrdev_open_exclu; /* already open exclusive? */
21295
21296 static int mce_chrdev_open(struct inode *inode, struct file *file)
21297 @@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21298 spin_lock(&mce_chrdev_state_lock);
21299
21300 if (mce_chrdev_open_exclu ||
21301 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21302 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21303 spin_unlock(&mce_chrdev_state_lock);
21304
21305 return -EBUSY;
21306 @@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21307
21308 if (file->f_flags & O_EXCL)
21309 mce_chrdev_open_exclu = 1;
21310 - mce_chrdev_open_count++;
21311 + local_inc(&mce_chrdev_open_count);
21312
21313 spin_unlock(&mce_chrdev_state_lock);
21314
21315 @@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21316 {
21317 spin_lock(&mce_chrdev_state_lock);
21318
21319 - mce_chrdev_open_count--;
21320 + local_dec(&mce_chrdev_open_count);
21321 mce_chrdev_open_exclu = 0;
21322
21323 spin_unlock(&mce_chrdev_state_lock);
21324 @@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21325
21326 for (i = 0; i < mca_cfg.banks; i++) {
21327 struct mce_bank *b = &mce_banks[i];
21328 - struct device_attribute *a = &b->attr;
21329 + device_attribute_no_const *a = &b->attr;
21330
21331 sysfs_attr_init(&a->attr);
21332 a->attr.name = b->attrname;
21333 @@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21334 static void mce_reset(void)
21335 {
21336 cpu_missing = 0;
21337 - atomic_set(&mce_fake_paniced, 0);
21338 + atomic_set_unchecked(&mce_fake_paniced, 0);
21339 atomic_set(&mce_executing, 0);
21340 atomic_set(&mce_callin, 0);
21341 atomic_set(&global_nwo, 0);
21342 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21343 index a304298..49b6d06 100644
21344 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21345 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21346 @@ -10,6 +10,7 @@
21347 #include <asm/processor.h>
21348 #include <asm/mce.h>
21349 #include <asm/msr.h>
21350 +#include <asm/pgtable.h>
21351
21352 /* By default disabled */
21353 int mce_p5_enabled __read_mostly;
21354 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21355 if (!cpu_has(c, X86_FEATURE_MCE))
21356 return;
21357
21358 + pax_open_kernel();
21359 machine_check_vector = pentium_machine_check;
21360 + pax_close_kernel();
21361 /* Make sure the vector pointer is visible before we enable MCEs: */
21362 wmb();
21363
21364 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21365 index 7dc5564..1273569 100644
21366 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21367 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21368 @@ -9,6 +9,7 @@
21369 #include <asm/processor.h>
21370 #include <asm/mce.h>
21371 #include <asm/msr.h>
21372 +#include <asm/pgtable.h>
21373
21374 /* Machine check handler for WinChip C6: */
21375 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21376 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21377 {
21378 u32 lo, hi;
21379
21380 + pax_open_kernel();
21381 machine_check_vector = winchip_machine_check;
21382 + pax_close_kernel();
21383 /* Make sure the vector pointer is visible before we enable MCEs: */
21384 wmb();
21385
21386 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21387 index 15c9876..0a43909 100644
21388 --- a/arch/x86/kernel/cpu/microcode/core.c
21389 +++ b/arch/x86/kernel/cpu/microcode/core.c
21390 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21391 return NOTIFY_OK;
21392 }
21393
21394 -static struct notifier_block __refdata mc_cpu_notifier = {
21395 +static struct notifier_block mc_cpu_notifier = {
21396 .notifier_call = mc_cpu_callback,
21397 };
21398
21399 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21400 index a276fa7..e66810f 100644
21401 --- a/arch/x86/kernel/cpu/microcode/intel.c
21402 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21403 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21404
21405 static int get_ucode_user(void *to, const void *from, size_t n)
21406 {
21407 - return copy_from_user(to, from, n);
21408 + return copy_from_user(to, (const void __force_user *)from, n);
21409 }
21410
21411 static enum ucode_state
21412 request_microcode_user(int cpu, const void __user *buf, size_t size)
21413 {
21414 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21415 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21416 }
21417
21418 static void microcode_fini_cpu(int cpu)
21419 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21420 index f961de9..8a9d332 100644
21421 --- a/arch/x86/kernel/cpu/mtrr/main.c
21422 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21423 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21424 u64 size_or_mask, size_and_mask;
21425 static bool mtrr_aps_delayed_init;
21426
21427 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21428 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21429
21430 const struct mtrr_ops *mtrr_if;
21431
21432 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21433 index df5e41f..816c719 100644
21434 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21435 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21436 @@ -25,7 +25,7 @@ struct mtrr_ops {
21437 int (*validate_add_page)(unsigned long base, unsigned long size,
21438 unsigned int type);
21439 int (*have_wrcomb)(void);
21440 -};
21441 +} __do_const;
21442
21443 extern int generic_get_free_region(unsigned long base, unsigned long size,
21444 int replace_reg);
21445 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21446 index ae407f7..39c5b00 100644
21447 --- a/arch/x86/kernel/cpu/perf_event.c
21448 +++ b/arch/x86/kernel/cpu/perf_event.c
21449 @@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21450 pr_info("no hardware sampling interrupt available.\n");
21451 }
21452
21453 -static struct attribute_group x86_pmu_format_group = {
21454 +static attribute_group_no_const x86_pmu_format_group = {
21455 .name = "format",
21456 .attrs = NULL,
21457 };
21458 @@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21459 NULL,
21460 };
21461
21462 -static struct attribute_group x86_pmu_events_group = {
21463 +static attribute_group_no_const x86_pmu_events_group = {
21464 .name = "events",
21465 .attrs = events_attr,
21466 };
21467 @@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21468 if (idx > GDT_ENTRIES)
21469 return 0;
21470
21471 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21472 + desc = get_cpu_gdt_table(smp_processor_id());
21473 }
21474
21475 return get_desc_base(desc + idx);
21476 @@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21477 break;
21478
21479 perf_callchain_store(entry, frame.return_address);
21480 - fp = frame.next_frame;
21481 + fp = (const void __force_user *)frame.next_frame;
21482 }
21483 }
21484
21485 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21486 index 639d128..e92d7e5 100644
21487 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21488 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21489 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21490 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21491 {
21492 struct attribute **attrs;
21493 - struct attribute_group *attr_group;
21494 + attribute_group_no_const *attr_group;
21495 int i = 0, j;
21496
21497 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21498 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21499 index adb02aa..9688c02 100644
21500 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21501 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21502 @@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21503 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21504
21505 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21506 - u64 capabilities;
21507 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21508
21509 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21510 - x86_pmu.intel_cap.capabilities = capabilities;
21511 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21512 + x86_pmu.intel_cap.capabilities = capabilities;
21513 }
21514
21515 intel_ds_init();
21516 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21517 index 619f769..d510008 100644
21518 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21519 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21520 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21521 NULL,
21522 };
21523
21524 -static struct attribute_group rapl_pmu_events_group = {
21525 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21526 .name = "events",
21527 .attrs = NULL, /* patched at runtime */
21528 };
21529 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21530 index 65bbbea..1438d9e 100644
21531 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21532 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21533 @@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21534 static int __init uncore_type_init(struct intel_uncore_type *type)
21535 {
21536 struct intel_uncore_pmu *pmus;
21537 - struct attribute_group *attr_group;
21538 + attribute_group_no_const *attr_group;
21539 struct attribute **attrs;
21540 int i, j;
21541
21542 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21543 index 90236f0..54cb20d 100644
21544 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21545 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21546 @@ -503,7 +503,7 @@ struct intel_uncore_box {
21547 struct uncore_event_desc {
21548 struct kobj_attribute attr;
21549 const char *config;
21550 -};
21551 +} __do_const;
21552
21553 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21554 { \
21555 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21556 index 3225ae6c..ee3c6db 100644
21557 --- a/arch/x86/kernel/cpuid.c
21558 +++ b/arch/x86/kernel/cpuid.c
21559 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21560 return notifier_from_errno(err);
21561 }
21562
21563 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21564 +static struct notifier_block cpuid_class_cpu_notifier =
21565 {
21566 .notifier_call = cpuid_class_cpu_callback,
21567 };
21568 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21569 index 507de80..ebaae2a 100644
21570 --- a/arch/x86/kernel/crash.c
21571 +++ b/arch/x86/kernel/crash.c
21572 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21573 #ifdef CONFIG_X86_32
21574 struct pt_regs fixed_regs;
21575
21576 - if (!user_mode_vm(regs)) {
21577 + if (!user_mode(regs)) {
21578 crash_fixup_ss_esp(&fixed_regs, regs);
21579 regs = &fixed_regs;
21580 }
21581 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21582 index afa64ad..dce67dd 100644
21583 --- a/arch/x86/kernel/crash_dump_64.c
21584 +++ b/arch/x86/kernel/crash_dump_64.c
21585 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21586 return -ENOMEM;
21587
21588 if (userbuf) {
21589 - if (copy_to_user(buf, vaddr + offset, csize)) {
21590 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21591 iounmap(vaddr);
21592 return -EFAULT;
21593 }
21594 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21595 index f6dfd93..892ade4 100644
21596 --- a/arch/x86/kernel/doublefault.c
21597 +++ b/arch/x86/kernel/doublefault.c
21598 @@ -12,7 +12,7 @@
21599
21600 #define DOUBLEFAULT_STACKSIZE (1024)
21601 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21602 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21603 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21604
21605 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21606
21607 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21608 unsigned long gdt, tss;
21609
21610 native_store_gdt(&gdt_desc);
21611 - gdt = gdt_desc.address;
21612 + gdt = (unsigned long)gdt_desc.address;
21613
21614 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21615
21616 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21617 /* 0x2 bit is always set */
21618 .flags = X86_EFLAGS_SF | 0x2,
21619 .sp = STACK_START,
21620 - .es = __USER_DS,
21621 + .es = __KERNEL_DS,
21622 .cs = __KERNEL_CS,
21623 .ss = __KERNEL_DS,
21624 - .ds = __USER_DS,
21625 + .ds = __KERNEL_DS,
21626 .fs = __KERNEL_PERCPU,
21627
21628 .__cr3 = __pa_nodebug(swapper_pg_dir),
21629 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21630 index d9c12d3..7858b62 100644
21631 --- a/arch/x86/kernel/dumpstack.c
21632 +++ b/arch/x86/kernel/dumpstack.c
21633 @@ -2,6 +2,9 @@
21634 * Copyright (C) 1991, 1992 Linus Torvalds
21635 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21636 */
21637 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21638 +#define __INCLUDED_BY_HIDESYM 1
21639 +#endif
21640 #include <linux/kallsyms.h>
21641 #include <linux/kprobes.h>
21642 #include <linux/uaccess.h>
21643 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21644 static void
21645 print_ftrace_graph_addr(unsigned long addr, void *data,
21646 const struct stacktrace_ops *ops,
21647 - struct thread_info *tinfo, int *graph)
21648 + struct task_struct *task, int *graph)
21649 {
21650 - struct task_struct *task;
21651 unsigned long ret_addr;
21652 int index;
21653
21654 if (addr != (unsigned long)return_to_handler)
21655 return;
21656
21657 - task = tinfo->task;
21658 index = task->curr_ret_stack;
21659
21660 if (!task->ret_stack || index < *graph)
21661 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21662 static inline void
21663 print_ftrace_graph_addr(unsigned long addr, void *data,
21664 const struct stacktrace_ops *ops,
21665 - struct thread_info *tinfo, int *graph)
21666 + struct task_struct *task, int *graph)
21667 { }
21668 #endif
21669
21670 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21671 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21672 */
21673
21674 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21675 - void *p, unsigned int size, void *end)
21676 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21677 {
21678 - void *t = tinfo;
21679 if (end) {
21680 if (p < end && p >= (end-THREAD_SIZE))
21681 return 1;
21682 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21683 }
21684
21685 unsigned long
21686 -print_context_stack(struct thread_info *tinfo,
21687 +print_context_stack(struct task_struct *task, void *stack_start,
21688 unsigned long *stack, unsigned long bp,
21689 const struct stacktrace_ops *ops, void *data,
21690 unsigned long *end, int *graph)
21691 {
21692 struct stack_frame *frame = (struct stack_frame *)bp;
21693
21694 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21695 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21696 unsigned long addr;
21697
21698 addr = *stack;
21699 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21700 } else {
21701 ops->address(data, addr, 0);
21702 }
21703 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21704 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21705 }
21706 stack++;
21707 }
21708 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21709 EXPORT_SYMBOL_GPL(print_context_stack);
21710
21711 unsigned long
21712 -print_context_stack_bp(struct thread_info *tinfo,
21713 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21714 unsigned long *stack, unsigned long bp,
21715 const struct stacktrace_ops *ops, void *data,
21716 unsigned long *end, int *graph)
21717 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21718 struct stack_frame *frame = (struct stack_frame *)bp;
21719 unsigned long *ret_addr = &frame->return_address;
21720
21721 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21722 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21723 unsigned long addr = *ret_addr;
21724
21725 if (!__kernel_text_address(addr))
21726 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21727 ops->address(data, addr, 1);
21728 frame = frame->next_frame;
21729 ret_addr = &frame->return_address;
21730 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21731 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21732 }
21733
21734 return (unsigned long)frame;
21735 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21736 static void print_trace_address(void *data, unsigned long addr, int reliable)
21737 {
21738 touch_nmi_watchdog();
21739 - printk(data);
21740 + printk("%s", (char *)data);
21741 printk_stack_address(addr, reliable);
21742 }
21743
21744 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21745 }
21746 EXPORT_SYMBOL_GPL(oops_begin);
21747
21748 +extern void gr_handle_kernel_exploit(void);
21749 +
21750 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21751 {
21752 if (regs && kexec_should_crash(current))
21753 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21754 panic("Fatal exception in interrupt");
21755 if (panic_on_oops)
21756 panic("Fatal exception");
21757 - do_exit(signr);
21758 +
21759 + gr_handle_kernel_exploit();
21760 +
21761 + do_group_exit(signr);
21762 }
21763
21764 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21765 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21766 print_modules();
21767 show_regs(regs);
21768 #ifdef CONFIG_X86_32
21769 - if (user_mode_vm(regs)) {
21770 + if (user_mode(regs)) {
21771 sp = regs->sp;
21772 ss = regs->ss & 0xffff;
21773 } else {
21774 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21775 unsigned long flags = oops_begin();
21776 int sig = SIGSEGV;
21777
21778 - if (!user_mode_vm(regs))
21779 + if (!user_mode(regs))
21780 report_bug(regs->ip, regs);
21781
21782 if (__die(str, regs, err))
21783 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21784 index 5abd4cd..c65733b 100644
21785 --- a/arch/x86/kernel/dumpstack_32.c
21786 +++ b/arch/x86/kernel/dumpstack_32.c
21787 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21788 bp = stack_frame(task, regs);
21789
21790 for (;;) {
21791 - struct thread_info *context;
21792 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21793 void *end_stack;
21794
21795 end_stack = is_hardirq_stack(stack, cpu);
21796 if (!end_stack)
21797 end_stack = is_softirq_stack(stack, cpu);
21798
21799 - context = task_thread_info(task);
21800 - bp = ops->walk_stack(context, stack, bp, ops, data,
21801 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21802 end_stack, &graph);
21803
21804 /* Stop if not on irq stack */
21805 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21806 int i;
21807
21808 show_regs_print_info(KERN_EMERG);
21809 - __show_regs(regs, !user_mode_vm(regs));
21810 + __show_regs(regs, !user_mode(regs));
21811
21812 /*
21813 * When in-kernel, we also print out the stack and code at the
21814 * time of the fault..
21815 */
21816 - if (!user_mode_vm(regs)) {
21817 + if (!user_mode(regs)) {
21818 unsigned int code_prologue = code_bytes * 43 / 64;
21819 unsigned int code_len = code_bytes;
21820 unsigned char c;
21821 u8 *ip;
21822 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21823
21824 pr_emerg("Stack:\n");
21825 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21826
21827 pr_emerg("Code:");
21828
21829 - ip = (u8 *)regs->ip - code_prologue;
21830 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21831 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21832 /* try starting at IP */
21833 - ip = (u8 *)regs->ip;
21834 + ip = (u8 *)regs->ip + cs_base;
21835 code_len = code_len - code_prologue + 1;
21836 }
21837 for (i = 0; i < code_len; i++, ip++) {
21838 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21839 pr_cont(" Bad EIP value.");
21840 break;
21841 }
21842 - if (ip == (u8 *)regs->ip)
21843 + if (ip == (u8 *)regs->ip + cs_base)
21844 pr_cont(" <%02x>", c);
21845 else
21846 pr_cont(" %02x", c);
21847 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21848 {
21849 unsigned short ud2;
21850
21851 + ip = ktla_ktva(ip);
21852 if (ip < PAGE_OFFSET)
21853 return 0;
21854 if (probe_kernel_address((unsigned short *)ip, ud2))
21855 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21856
21857 return ud2 == 0x0b0f;
21858 }
21859 +
21860 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21861 +void pax_check_alloca(unsigned long size)
21862 +{
21863 + unsigned long sp = (unsigned long)&sp, stack_left;
21864 +
21865 + /* all kernel stacks are of the same size */
21866 + stack_left = sp & (THREAD_SIZE - 1);
21867 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21868 +}
21869 +EXPORT_SYMBOL(pax_check_alloca);
21870 +#endif
21871 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21872 index 1abcb50..6c8d702 100644
21873 --- a/arch/x86/kernel/dumpstack_64.c
21874 +++ b/arch/x86/kernel/dumpstack_64.c
21875 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21876 const struct stacktrace_ops *ops, void *data)
21877 {
21878 const unsigned cpu = get_cpu();
21879 - struct thread_info *tinfo;
21880 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21881 unsigned long dummy;
21882 unsigned used = 0;
21883 int graph = 0;
21884 int done = 0;
21885 + void *stack_start;
21886
21887 if (!task)
21888 task = current;
21889 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21890 * current stack address. If the stacks consist of nested
21891 * exceptions
21892 */
21893 - tinfo = task_thread_info(task);
21894 while (!done) {
21895 unsigned long *stack_end;
21896 enum stack_type stype;
21897 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21898 if (ops->stack(data, id) < 0)
21899 break;
21900
21901 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21902 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21903 data, stack_end, &graph);
21904 ops->stack(data, "<EOE>");
21905 /*
21906 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21907 * second-to-last pointer (index -2 to end) in the
21908 * exception stack:
21909 */
21910 + if ((u16)stack_end[-1] != __KERNEL_DS)
21911 + goto out;
21912 stack = (unsigned long *) stack_end[-2];
21913 done = 0;
21914 break;
21915 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21916
21917 if (ops->stack(data, "IRQ") < 0)
21918 break;
21919 - bp = ops->walk_stack(tinfo, stack, bp,
21920 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21921 ops, data, stack_end, &graph);
21922 /*
21923 * We link to the next stack (which would be
21924 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21925 /*
21926 * This handles the process stack:
21927 */
21928 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21929 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21930 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21931 +out:
21932 put_cpu();
21933 }
21934 EXPORT_SYMBOL(dump_trace);
21935 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21936
21937 return ud2 == 0x0b0f;
21938 }
21939 +
21940 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21941 +void pax_check_alloca(unsigned long size)
21942 +{
21943 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21944 + unsigned cpu, used;
21945 + char *id;
21946 +
21947 + /* check the process stack first */
21948 + stack_start = (unsigned long)task_stack_page(current);
21949 + stack_end = stack_start + THREAD_SIZE;
21950 + if (likely(stack_start <= sp && sp < stack_end)) {
21951 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21952 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21953 + return;
21954 + }
21955 +
21956 + cpu = get_cpu();
21957 +
21958 + /* check the irq stacks */
21959 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21960 + stack_start = stack_end - IRQ_STACK_SIZE;
21961 + if (stack_start <= sp && sp < stack_end) {
21962 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21963 + put_cpu();
21964 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21965 + return;
21966 + }
21967 +
21968 + /* check the exception stacks */
21969 + used = 0;
21970 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21971 + stack_start = stack_end - EXCEPTION_STKSZ;
21972 + if (stack_end && stack_start <= sp && sp < stack_end) {
21973 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21974 + put_cpu();
21975 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21976 + return;
21977 + }
21978 +
21979 + put_cpu();
21980 +
21981 + /* unknown stack */
21982 + BUG();
21983 +}
21984 +EXPORT_SYMBOL(pax_check_alloca);
21985 +#endif
21986 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21987 index 988c00a..4f673b6 100644
21988 --- a/arch/x86/kernel/e820.c
21989 +++ b/arch/x86/kernel/e820.c
21990 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21991
21992 static void early_panic(char *msg)
21993 {
21994 - early_printk(msg);
21995 - panic(msg);
21996 + early_printk("%s", msg);
21997 + panic("%s", msg);
21998 }
21999
22000 static int userdef __initdata;
22001 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22002 index 01d1c18..8073693 100644
22003 --- a/arch/x86/kernel/early_printk.c
22004 +++ b/arch/x86/kernel/early_printk.c
22005 @@ -7,6 +7,7 @@
22006 #include <linux/pci_regs.h>
22007 #include <linux/pci_ids.h>
22008 #include <linux/errno.h>
22009 +#include <linux/sched.h>
22010 #include <asm/io.h>
22011 #include <asm/processor.h>
22012 #include <asm/fcntl.h>
22013 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22014 index 6491353..a918952 100644
22015 --- a/arch/x86/kernel/entry_32.S
22016 +++ b/arch/x86/kernel/entry_32.S
22017 @@ -177,13 +177,153 @@
22018 /*CFI_REL_OFFSET gs, PT_GS*/
22019 .endm
22020 .macro SET_KERNEL_GS reg
22021 +
22022 +#ifdef CONFIG_CC_STACKPROTECTOR
22023 movl $(__KERNEL_STACK_CANARY), \reg
22024 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22025 + movl $(__USER_DS), \reg
22026 +#else
22027 + xorl \reg, \reg
22028 +#endif
22029 +
22030 movl \reg, %gs
22031 .endm
22032
22033 #endif /* CONFIG_X86_32_LAZY_GS */
22034
22035 -.macro SAVE_ALL
22036 +.macro pax_enter_kernel
22037 +#ifdef CONFIG_PAX_KERNEXEC
22038 + call pax_enter_kernel
22039 +#endif
22040 +.endm
22041 +
22042 +.macro pax_exit_kernel
22043 +#ifdef CONFIG_PAX_KERNEXEC
22044 + call pax_exit_kernel
22045 +#endif
22046 +.endm
22047 +
22048 +#ifdef CONFIG_PAX_KERNEXEC
22049 +ENTRY(pax_enter_kernel)
22050 +#ifdef CONFIG_PARAVIRT
22051 + pushl %eax
22052 + pushl %ecx
22053 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22054 + mov %eax, %esi
22055 +#else
22056 + mov %cr0, %esi
22057 +#endif
22058 + bts $16, %esi
22059 + jnc 1f
22060 + mov %cs, %esi
22061 + cmp $__KERNEL_CS, %esi
22062 + jz 3f
22063 + ljmp $__KERNEL_CS, $3f
22064 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22065 +2:
22066 +#ifdef CONFIG_PARAVIRT
22067 + mov %esi, %eax
22068 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22069 +#else
22070 + mov %esi, %cr0
22071 +#endif
22072 +3:
22073 +#ifdef CONFIG_PARAVIRT
22074 + popl %ecx
22075 + popl %eax
22076 +#endif
22077 + ret
22078 +ENDPROC(pax_enter_kernel)
22079 +
22080 +ENTRY(pax_exit_kernel)
22081 +#ifdef CONFIG_PARAVIRT
22082 + pushl %eax
22083 + pushl %ecx
22084 +#endif
22085 + mov %cs, %esi
22086 + cmp $__KERNEXEC_KERNEL_CS, %esi
22087 + jnz 2f
22088 +#ifdef CONFIG_PARAVIRT
22089 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22090 + mov %eax, %esi
22091 +#else
22092 + mov %cr0, %esi
22093 +#endif
22094 + btr $16, %esi
22095 + ljmp $__KERNEL_CS, $1f
22096 +1:
22097 +#ifdef CONFIG_PARAVIRT
22098 + mov %esi, %eax
22099 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22100 +#else
22101 + mov %esi, %cr0
22102 +#endif
22103 +2:
22104 +#ifdef CONFIG_PARAVIRT
22105 + popl %ecx
22106 + popl %eax
22107 +#endif
22108 + ret
22109 +ENDPROC(pax_exit_kernel)
22110 +#endif
22111 +
22112 + .macro pax_erase_kstack
22113 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22114 + call pax_erase_kstack
22115 +#endif
22116 + .endm
22117 +
22118 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22119 +/*
22120 + * ebp: thread_info
22121 + */
22122 +ENTRY(pax_erase_kstack)
22123 + pushl %edi
22124 + pushl %ecx
22125 + pushl %eax
22126 +
22127 + mov TI_lowest_stack(%ebp), %edi
22128 + mov $-0xBEEF, %eax
22129 + std
22130 +
22131 +1: mov %edi, %ecx
22132 + and $THREAD_SIZE_asm - 1, %ecx
22133 + shr $2, %ecx
22134 + repne scasl
22135 + jecxz 2f
22136 +
22137 + cmp $2*16, %ecx
22138 + jc 2f
22139 +
22140 + mov $2*16, %ecx
22141 + repe scasl
22142 + jecxz 2f
22143 + jne 1b
22144 +
22145 +2: cld
22146 + mov %esp, %ecx
22147 + sub %edi, %ecx
22148 +
22149 + cmp $THREAD_SIZE_asm, %ecx
22150 + jb 3f
22151 + ud2
22152 +3:
22153 +
22154 + shr $2, %ecx
22155 + rep stosl
22156 +
22157 + mov TI_task_thread_sp0(%ebp), %edi
22158 + sub $128, %edi
22159 + mov %edi, TI_lowest_stack(%ebp)
22160 +
22161 + popl %eax
22162 + popl %ecx
22163 + popl %edi
22164 + ret
22165 +ENDPROC(pax_erase_kstack)
22166 +#endif
22167 +
22168 +.macro __SAVE_ALL _DS
22169 cld
22170 PUSH_GS
22171 pushl_cfi %fs
22172 @@ -206,7 +346,7 @@
22173 CFI_REL_OFFSET ecx, 0
22174 pushl_cfi %ebx
22175 CFI_REL_OFFSET ebx, 0
22176 - movl $(__USER_DS), %edx
22177 + movl $\_DS, %edx
22178 movl %edx, %ds
22179 movl %edx, %es
22180 movl $(__KERNEL_PERCPU), %edx
22181 @@ -214,6 +354,15 @@
22182 SET_KERNEL_GS %edx
22183 .endm
22184
22185 +.macro SAVE_ALL
22186 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22187 + __SAVE_ALL __KERNEL_DS
22188 + pax_enter_kernel
22189 +#else
22190 + __SAVE_ALL __USER_DS
22191 +#endif
22192 +.endm
22193 +
22194 .macro RESTORE_INT_REGS
22195 popl_cfi %ebx
22196 CFI_RESTORE ebx
22197 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22198 popfl_cfi
22199 jmp syscall_exit
22200 CFI_ENDPROC
22201 -END(ret_from_fork)
22202 +ENDPROC(ret_from_fork)
22203
22204 ENTRY(ret_from_kernel_thread)
22205 CFI_STARTPROC
22206 @@ -344,7 +493,15 @@ ret_from_intr:
22207 andl $SEGMENT_RPL_MASK, %eax
22208 #endif
22209 cmpl $USER_RPL, %eax
22210 +
22211 +#ifdef CONFIG_PAX_KERNEXEC
22212 + jae resume_userspace
22213 +
22214 + pax_exit_kernel
22215 + jmp resume_kernel
22216 +#else
22217 jb resume_kernel # not returning to v8086 or userspace
22218 +#endif
22219
22220 ENTRY(resume_userspace)
22221 LOCKDEP_SYS_EXIT
22222 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22223 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22224 # int/exception return?
22225 jne work_pending
22226 - jmp restore_all
22227 -END(ret_from_exception)
22228 + jmp restore_all_pax
22229 +ENDPROC(ret_from_exception)
22230
22231 #ifdef CONFIG_PREEMPT
22232 ENTRY(resume_kernel)
22233 @@ -369,7 +526,7 @@ need_resched:
22234 jz restore_all
22235 call preempt_schedule_irq
22236 jmp need_resched
22237 -END(resume_kernel)
22238 +ENDPROC(resume_kernel)
22239 #endif
22240 CFI_ENDPROC
22241 /*
22242 @@ -403,30 +560,45 @@ sysenter_past_esp:
22243 /*CFI_REL_OFFSET cs, 0*/
22244 /*
22245 * Push current_thread_info()->sysenter_return to the stack.
22246 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22247 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22248 */
22249 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22250 + pushl_cfi $0
22251 CFI_REL_OFFSET eip, 0
22252
22253 pushl_cfi %eax
22254 SAVE_ALL
22255 + GET_THREAD_INFO(%ebp)
22256 + movl TI_sysenter_return(%ebp),%ebp
22257 + movl %ebp,PT_EIP(%esp)
22258 ENABLE_INTERRUPTS(CLBR_NONE)
22259
22260 /*
22261 * Load the potential sixth argument from user stack.
22262 * Careful about security.
22263 */
22264 + movl PT_OLDESP(%esp),%ebp
22265 +
22266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22267 + mov PT_OLDSS(%esp),%ds
22268 +1: movl %ds:(%ebp),%ebp
22269 + push %ss
22270 + pop %ds
22271 +#else
22272 cmpl $__PAGE_OFFSET-3,%ebp
22273 jae syscall_fault
22274 ASM_STAC
22275 1: movl (%ebp),%ebp
22276 ASM_CLAC
22277 +#endif
22278 +
22279 movl %ebp,PT_EBP(%esp)
22280 _ASM_EXTABLE(1b,syscall_fault)
22281
22282 GET_THREAD_INFO(%ebp)
22283
22284 +#ifdef CONFIG_PAX_RANDKSTACK
22285 + pax_erase_kstack
22286 +#endif
22287 +
22288 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22289 jnz sysenter_audit
22290 sysenter_do_call:
22291 @@ -442,12 +614,24 @@ sysenter_after_call:
22292 testl $_TIF_ALLWORK_MASK, %ecx
22293 jne sysexit_audit
22294 sysenter_exit:
22295 +
22296 +#ifdef CONFIG_PAX_RANDKSTACK
22297 + pushl_cfi %eax
22298 + movl %esp, %eax
22299 + call pax_randomize_kstack
22300 + popl_cfi %eax
22301 +#endif
22302 +
22303 + pax_erase_kstack
22304 +
22305 /* if something modifies registers it must also disable sysexit */
22306 movl PT_EIP(%esp), %edx
22307 movl PT_OLDESP(%esp), %ecx
22308 xorl %ebp,%ebp
22309 TRACE_IRQS_ON
22310 1: mov PT_FS(%esp), %fs
22311 +2: mov PT_DS(%esp), %ds
22312 +3: mov PT_ES(%esp), %es
22313 PTGS_TO_GS
22314 ENABLE_INTERRUPTS_SYSEXIT
22315
22316 @@ -464,6 +648,9 @@ sysenter_audit:
22317 movl %eax,%edx /* 2nd arg: syscall number */
22318 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22319 call __audit_syscall_entry
22320 +
22321 + pax_erase_kstack
22322 +
22323 pushl_cfi %ebx
22324 movl PT_EAX(%esp),%eax /* reload syscall number */
22325 jmp sysenter_do_call
22326 @@ -489,10 +676,16 @@ sysexit_audit:
22327
22328 CFI_ENDPROC
22329 .pushsection .fixup,"ax"
22330 -2: movl $0,PT_FS(%esp)
22331 +4: movl $0,PT_FS(%esp)
22332 + jmp 1b
22333 +5: movl $0,PT_DS(%esp)
22334 + jmp 1b
22335 +6: movl $0,PT_ES(%esp)
22336 jmp 1b
22337 .popsection
22338 - _ASM_EXTABLE(1b,2b)
22339 + _ASM_EXTABLE(1b,4b)
22340 + _ASM_EXTABLE(2b,5b)
22341 + _ASM_EXTABLE(3b,6b)
22342 PTGS_TO_GS_EX
22343 ENDPROC(ia32_sysenter_target)
22344
22345 @@ -507,6 +700,11 @@ ENTRY(system_call)
22346 pushl_cfi %eax # save orig_eax
22347 SAVE_ALL
22348 GET_THREAD_INFO(%ebp)
22349 +
22350 +#ifdef CONFIG_PAX_RANDKSTACK
22351 + pax_erase_kstack
22352 +#endif
22353 +
22354 # system call tracing in operation / emulation
22355 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22356 jnz syscall_trace_entry
22357 @@ -525,6 +723,15 @@ syscall_exit:
22358 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22359 jne syscall_exit_work
22360
22361 +restore_all_pax:
22362 +
22363 +#ifdef CONFIG_PAX_RANDKSTACK
22364 + movl %esp, %eax
22365 + call pax_randomize_kstack
22366 +#endif
22367 +
22368 + pax_erase_kstack
22369 +
22370 restore_all:
22371 TRACE_IRQS_IRET
22372 restore_all_notrace:
22373 @@ -576,14 +783,34 @@ ldt_ss:
22374 * compensating for the offset by changing to the ESPFIX segment with
22375 * a base address that matches for the difference.
22376 */
22377 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22378 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22379 mov %esp, %edx /* load kernel esp */
22380 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22381 mov %dx, %ax /* eax: new kernel esp */
22382 sub %eax, %edx /* offset (low word is 0) */
22383 +#ifdef CONFIG_SMP
22384 + movl PER_CPU_VAR(cpu_number), %ebx
22385 + shll $PAGE_SHIFT_asm, %ebx
22386 + addl $cpu_gdt_table, %ebx
22387 +#else
22388 + movl $cpu_gdt_table, %ebx
22389 +#endif
22390 shr $16, %edx
22391 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22392 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22393 +
22394 +#ifdef CONFIG_PAX_KERNEXEC
22395 + mov %cr0, %esi
22396 + btr $16, %esi
22397 + mov %esi, %cr0
22398 +#endif
22399 +
22400 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22401 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22402 +
22403 +#ifdef CONFIG_PAX_KERNEXEC
22404 + bts $16, %esi
22405 + mov %esi, %cr0
22406 +#endif
22407 +
22408 pushl_cfi $__ESPFIX_SS
22409 pushl_cfi %eax /* new kernel esp */
22410 /* Disable interrupts, but do not irqtrace this section: we
22411 @@ -612,20 +839,18 @@ work_resched:
22412 movl TI_flags(%ebp), %ecx
22413 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22414 # than syscall tracing?
22415 - jz restore_all
22416 + jz restore_all_pax
22417 testb $_TIF_NEED_RESCHED, %cl
22418 jnz work_resched
22419
22420 work_notifysig: # deal with pending signals and
22421 # notify-resume requests
22422 + movl %esp, %eax
22423 #ifdef CONFIG_VM86
22424 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22425 - movl %esp, %eax
22426 jne work_notifysig_v86 # returning to kernel-space or
22427 # vm86-space
22428 1:
22429 -#else
22430 - movl %esp, %eax
22431 #endif
22432 TRACE_IRQS_ON
22433 ENABLE_INTERRUPTS(CLBR_NONE)
22434 @@ -646,7 +871,7 @@ work_notifysig_v86:
22435 movl %eax, %esp
22436 jmp 1b
22437 #endif
22438 -END(work_pending)
22439 +ENDPROC(work_pending)
22440
22441 # perform syscall exit tracing
22442 ALIGN
22443 @@ -654,11 +879,14 @@ syscall_trace_entry:
22444 movl $-ENOSYS,PT_EAX(%esp)
22445 movl %esp, %eax
22446 call syscall_trace_enter
22447 +
22448 + pax_erase_kstack
22449 +
22450 /* What it returned is what we'll actually use. */
22451 cmpl $(NR_syscalls), %eax
22452 jnae syscall_call
22453 jmp syscall_exit
22454 -END(syscall_trace_entry)
22455 +ENDPROC(syscall_trace_entry)
22456
22457 # perform syscall exit tracing
22458 ALIGN
22459 @@ -671,26 +899,30 @@ syscall_exit_work:
22460 movl %esp, %eax
22461 call syscall_trace_leave
22462 jmp resume_userspace
22463 -END(syscall_exit_work)
22464 +ENDPROC(syscall_exit_work)
22465 CFI_ENDPROC
22466
22467 RING0_INT_FRAME # can't unwind into user space anyway
22468 syscall_fault:
22469 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22470 + push %ss
22471 + pop %ds
22472 +#endif
22473 ASM_CLAC
22474 GET_THREAD_INFO(%ebp)
22475 movl $-EFAULT,PT_EAX(%esp)
22476 jmp resume_userspace
22477 -END(syscall_fault)
22478 +ENDPROC(syscall_fault)
22479
22480 syscall_badsys:
22481 movl $-ENOSYS,PT_EAX(%esp)
22482 jmp syscall_exit
22483 -END(syscall_badsys)
22484 +ENDPROC(syscall_badsys)
22485
22486 sysenter_badsys:
22487 movl $-ENOSYS,PT_EAX(%esp)
22488 jmp sysenter_after_call
22489 -END(syscall_badsys)
22490 +ENDPROC(sysenter_badsys)
22491 CFI_ENDPROC
22492 /*
22493 * End of kprobes section
22494 @@ -706,8 +938,15 @@ END(syscall_badsys)
22495 * normal stack and adjusts ESP with the matching offset.
22496 */
22497 /* fixup the stack */
22498 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22499 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22500 +#ifdef CONFIG_SMP
22501 + movl PER_CPU_VAR(cpu_number), %ebx
22502 + shll $PAGE_SHIFT_asm, %ebx
22503 + addl $cpu_gdt_table, %ebx
22504 +#else
22505 + movl $cpu_gdt_table, %ebx
22506 +#endif
22507 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22508 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22509 shl $16, %eax
22510 addl %esp, %eax /* the adjusted stack pointer */
22511 pushl_cfi $__KERNEL_DS
22512 @@ -760,7 +999,7 @@ vector=vector+1
22513 .endr
22514 2: jmp common_interrupt
22515 .endr
22516 -END(irq_entries_start)
22517 +ENDPROC(irq_entries_start)
22518
22519 .previous
22520 END(interrupt)
22521 @@ -821,7 +1060,7 @@ ENTRY(coprocessor_error)
22522 pushl_cfi $do_coprocessor_error
22523 jmp error_code
22524 CFI_ENDPROC
22525 -END(coprocessor_error)
22526 +ENDPROC(coprocessor_error)
22527
22528 ENTRY(simd_coprocessor_error)
22529 RING0_INT_FRAME
22530 @@ -834,7 +1073,7 @@ ENTRY(simd_coprocessor_error)
22531 .section .altinstructions,"a"
22532 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22533 .previous
22534 -.section .altinstr_replacement,"ax"
22535 +.section .altinstr_replacement,"a"
22536 663: pushl $do_simd_coprocessor_error
22537 664:
22538 .previous
22539 @@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22540 #endif
22541 jmp error_code
22542 CFI_ENDPROC
22543 -END(simd_coprocessor_error)
22544 +ENDPROC(simd_coprocessor_error)
22545
22546 ENTRY(device_not_available)
22547 RING0_INT_FRAME
22548 @@ -852,18 +1091,18 @@ ENTRY(device_not_available)
22549 pushl_cfi $do_device_not_available
22550 jmp error_code
22551 CFI_ENDPROC
22552 -END(device_not_available)
22553 +ENDPROC(device_not_available)
22554
22555 #ifdef CONFIG_PARAVIRT
22556 ENTRY(native_iret)
22557 iret
22558 _ASM_EXTABLE(native_iret, iret_exc)
22559 -END(native_iret)
22560 +ENDPROC(native_iret)
22561
22562 ENTRY(native_irq_enable_sysexit)
22563 sti
22564 sysexit
22565 -END(native_irq_enable_sysexit)
22566 +ENDPROC(native_irq_enable_sysexit)
22567 #endif
22568
22569 ENTRY(overflow)
22570 @@ -873,7 +1112,7 @@ ENTRY(overflow)
22571 pushl_cfi $do_overflow
22572 jmp error_code
22573 CFI_ENDPROC
22574 -END(overflow)
22575 +ENDPROC(overflow)
22576
22577 ENTRY(bounds)
22578 RING0_INT_FRAME
22579 @@ -882,7 +1121,7 @@ ENTRY(bounds)
22580 pushl_cfi $do_bounds
22581 jmp error_code
22582 CFI_ENDPROC
22583 -END(bounds)
22584 +ENDPROC(bounds)
22585
22586 ENTRY(invalid_op)
22587 RING0_INT_FRAME
22588 @@ -891,7 +1130,7 @@ ENTRY(invalid_op)
22589 pushl_cfi $do_invalid_op
22590 jmp error_code
22591 CFI_ENDPROC
22592 -END(invalid_op)
22593 +ENDPROC(invalid_op)
22594
22595 ENTRY(coprocessor_segment_overrun)
22596 RING0_INT_FRAME
22597 @@ -900,7 +1139,7 @@ ENTRY(coprocessor_segment_overrun)
22598 pushl_cfi $do_coprocessor_segment_overrun
22599 jmp error_code
22600 CFI_ENDPROC
22601 -END(coprocessor_segment_overrun)
22602 +ENDPROC(coprocessor_segment_overrun)
22603
22604 ENTRY(invalid_TSS)
22605 RING0_EC_FRAME
22606 @@ -908,7 +1147,7 @@ ENTRY(invalid_TSS)
22607 pushl_cfi $do_invalid_TSS
22608 jmp error_code
22609 CFI_ENDPROC
22610 -END(invalid_TSS)
22611 +ENDPROC(invalid_TSS)
22612
22613 ENTRY(segment_not_present)
22614 RING0_EC_FRAME
22615 @@ -916,7 +1155,7 @@ ENTRY(segment_not_present)
22616 pushl_cfi $do_segment_not_present
22617 jmp error_code
22618 CFI_ENDPROC
22619 -END(segment_not_present)
22620 +ENDPROC(segment_not_present)
22621
22622 ENTRY(stack_segment)
22623 RING0_EC_FRAME
22624 @@ -924,7 +1163,7 @@ ENTRY(stack_segment)
22625 pushl_cfi $do_stack_segment
22626 jmp error_code
22627 CFI_ENDPROC
22628 -END(stack_segment)
22629 +ENDPROC(stack_segment)
22630
22631 ENTRY(alignment_check)
22632 RING0_EC_FRAME
22633 @@ -932,7 +1171,7 @@ ENTRY(alignment_check)
22634 pushl_cfi $do_alignment_check
22635 jmp error_code
22636 CFI_ENDPROC
22637 -END(alignment_check)
22638 +ENDPROC(alignment_check)
22639
22640 ENTRY(divide_error)
22641 RING0_INT_FRAME
22642 @@ -941,7 +1180,7 @@ ENTRY(divide_error)
22643 pushl_cfi $do_divide_error
22644 jmp error_code
22645 CFI_ENDPROC
22646 -END(divide_error)
22647 +ENDPROC(divide_error)
22648
22649 #ifdef CONFIG_X86_MCE
22650 ENTRY(machine_check)
22651 @@ -951,7 +1190,7 @@ ENTRY(machine_check)
22652 pushl_cfi machine_check_vector
22653 jmp error_code
22654 CFI_ENDPROC
22655 -END(machine_check)
22656 +ENDPROC(machine_check)
22657 #endif
22658
22659 ENTRY(spurious_interrupt_bug)
22660 @@ -961,7 +1200,7 @@ ENTRY(spurious_interrupt_bug)
22661 pushl_cfi $do_spurious_interrupt_bug
22662 jmp error_code
22663 CFI_ENDPROC
22664 -END(spurious_interrupt_bug)
22665 +ENDPROC(spurious_interrupt_bug)
22666 /*
22667 * End of kprobes section
22668 */
22669 @@ -1071,7 +1310,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22670
22671 ENTRY(mcount)
22672 ret
22673 -END(mcount)
22674 +ENDPROC(mcount)
22675
22676 ENTRY(ftrace_caller)
22677 cmpl $0, function_trace_stop
22678 @@ -1104,7 +1343,7 @@ ftrace_graph_call:
22679 .globl ftrace_stub
22680 ftrace_stub:
22681 ret
22682 -END(ftrace_caller)
22683 +ENDPROC(ftrace_caller)
22684
22685 ENTRY(ftrace_regs_caller)
22686 pushf /* push flags before compare (in cs location) */
22687 @@ -1208,7 +1447,7 @@ trace:
22688 popl %ecx
22689 popl %eax
22690 jmp ftrace_stub
22691 -END(mcount)
22692 +ENDPROC(mcount)
22693 #endif /* CONFIG_DYNAMIC_FTRACE */
22694 #endif /* CONFIG_FUNCTION_TRACER */
22695
22696 @@ -1226,7 +1465,7 @@ ENTRY(ftrace_graph_caller)
22697 popl %ecx
22698 popl %eax
22699 ret
22700 -END(ftrace_graph_caller)
22701 +ENDPROC(ftrace_graph_caller)
22702
22703 .globl return_to_handler
22704 return_to_handler:
22705 @@ -1292,15 +1531,18 @@ error_code:
22706 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22707 REG_TO_PTGS %ecx
22708 SET_KERNEL_GS %ecx
22709 - movl $(__USER_DS), %ecx
22710 + movl $(__KERNEL_DS), %ecx
22711 movl %ecx, %ds
22712 movl %ecx, %es
22713 +
22714 + pax_enter_kernel
22715 +
22716 TRACE_IRQS_OFF
22717 movl %esp,%eax # pt_regs pointer
22718 call *%edi
22719 jmp ret_from_exception
22720 CFI_ENDPROC
22721 -END(page_fault)
22722 +ENDPROC(page_fault)
22723
22724 /*
22725 * Debug traps and NMI can happen at the one SYSENTER instruction
22726 @@ -1343,7 +1585,7 @@ debug_stack_correct:
22727 call do_debug
22728 jmp ret_from_exception
22729 CFI_ENDPROC
22730 -END(debug)
22731 +ENDPROC(debug)
22732
22733 /*
22734 * NMI is doubly nasty. It can happen _while_ we're handling
22735 @@ -1381,6 +1623,9 @@ nmi_stack_correct:
22736 xorl %edx,%edx # zero error code
22737 movl %esp,%eax # pt_regs pointer
22738 call do_nmi
22739 +
22740 + pax_exit_kernel
22741 +
22742 jmp restore_all_notrace
22743 CFI_ENDPROC
22744
22745 @@ -1417,12 +1662,15 @@ nmi_espfix_stack:
22746 FIXUP_ESPFIX_STACK # %eax == %esp
22747 xorl %edx,%edx # zero error code
22748 call do_nmi
22749 +
22750 + pax_exit_kernel
22751 +
22752 RESTORE_REGS
22753 lss 12+4(%esp), %esp # back to espfix stack
22754 CFI_ADJUST_CFA_OFFSET -24
22755 jmp irq_return
22756 CFI_ENDPROC
22757 -END(nmi)
22758 +ENDPROC(nmi)
22759
22760 ENTRY(int3)
22761 RING0_INT_FRAME
22762 @@ -1435,14 +1683,14 @@ ENTRY(int3)
22763 call do_int3
22764 jmp ret_from_exception
22765 CFI_ENDPROC
22766 -END(int3)
22767 +ENDPROC(int3)
22768
22769 ENTRY(general_protection)
22770 RING0_EC_FRAME
22771 pushl_cfi $do_general_protection
22772 jmp error_code
22773 CFI_ENDPROC
22774 -END(general_protection)
22775 +ENDPROC(general_protection)
22776
22777 #ifdef CONFIG_KVM_GUEST
22778 ENTRY(async_page_fault)
22779 @@ -1451,7 +1699,7 @@ ENTRY(async_page_fault)
22780 pushl_cfi $do_async_page_fault
22781 jmp error_code
22782 CFI_ENDPROC
22783 -END(async_page_fault)
22784 +ENDPROC(async_page_fault)
22785 #endif
22786
22787 /*
22788 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22789 index 1e96c36..3ff710a 100644
22790 --- a/arch/x86/kernel/entry_64.S
22791 +++ b/arch/x86/kernel/entry_64.S
22792 @@ -59,6 +59,8 @@
22793 #include <asm/context_tracking.h>
22794 #include <asm/smap.h>
22795 #include <linux/err.h>
22796 +#include <asm/pgtable.h>
22797 +#include <asm/alternative-asm.h>
22798
22799 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22800 #include <linux/elf-em.h>
22801 @@ -80,8 +82,9 @@
22802 #ifdef CONFIG_DYNAMIC_FTRACE
22803
22804 ENTRY(function_hook)
22805 + pax_force_retaddr
22806 retq
22807 -END(function_hook)
22808 +ENDPROC(function_hook)
22809
22810 /* skip is set if stack has been adjusted */
22811 .macro ftrace_caller_setup skip=0
22812 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22813 #endif
22814
22815 GLOBAL(ftrace_stub)
22816 + pax_force_retaddr
22817 retq
22818 -END(ftrace_caller)
22819 +ENDPROC(ftrace_caller)
22820
22821 ENTRY(ftrace_regs_caller)
22822 /* Save the current flags before compare (in SS location)*/
22823 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22824 popfq
22825 jmp ftrace_stub
22826
22827 -END(ftrace_regs_caller)
22828 +ENDPROC(ftrace_regs_caller)
22829
22830
22831 #else /* ! CONFIG_DYNAMIC_FTRACE */
22832 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22833 #endif
22834
22835 GLOBAL(ftrace_stub)
22836 + pax_force_retaddr
22837 retq
22838
22839 trace:
22840 @@ -225,12 +230,13 @@ trace:
22841 #endif
22842 subq $MCOUNT_INSN_SIZE, %rdi
22843
22844 + pax_force_fptr ftrace_trace_function
22845 call *ftrace_trace_function
22846
22847 MCOUNT_RESTORE_FRAME
22848
22849 jmp ftrace_stub
22850 -END(function_hook)
22851 +ENDPROC(function_hook)
22852 #endif /* CONFIG_DYNAMIC_FTRACE */
22853 #endif /* CONFIG_FUNCTION_TRACER */
22854
22855 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22856
22857 MCOUNT_RESTORE_FRAME
22858
22859 + pax_force_retaddr
22860 retq
22861 -END(ftrace_graph_caller)
22862 +ENDPROC(ftrace_graph_caller)
22863
22864 GLOBAL(return_to_handler)
22865 subq $24, %rsp
22866 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22867 movq 8(%rsp), %rdx
22868 movq (%rsp), %rax
22869 addq $24, %rsp
22870 + pax_force_fptr %rdi
22871 jmp *%rdi
22872 +ENDPROC(return_to_handler)
22873 #endif
22874
22875
22876 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22877 ENDPROC(native_usergs_sysret64)
22878 #endif /* CONFIG_PARAVIRT */
22879
22880 + .macro ljmpq sel, off
22881 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22882 + .byte 0x48; ljmp *1234f(%rip)
22883 + .pushsection .rodata
22884 + .align 16
22885 + 1234: .quad \off; .word \sel
22886 + .popsection
22887 +#else
22888 + pushq $\sel
22889 + pushq $\off
22890 + lretq
22891 +#endif
22892 + .endm
22893 +
22894 + .macro pax_enter_kernel
22895 + pax_set_fptr_mask
22896 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22897 + call pax_enter_kernel
22898 +#endif
22899 + .endm
22900 +
22901 + .macro pax_exit_kernel
22902 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22903 + call pax_exit_kernel
22904 +#endif
22905 +
22906 + .endm
22907 +
22908 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22909 +ENTRY(pax_enter_kernel)
22910 + pushq %rdi
22911 +
22912 +#ifdef CONFIG_PARAVIRT
22913 + PV_SAVE_REGS(CLBR_RDI)
22914 +#endif
22915 +
22916 +#ifdef CONFIG_PAX_KERNEXEC
22917 + GET_CR0_INTO_RDI
22918 + bts $16,%rdi
22919 + jnc 3f
22920 + mov %cs,%edi
22921 + cmp $__KERNEL_CS,%edi
22922 + jnz 2f
22923 +1:
22924 +#endif
22925 +
22926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22927 + 661: jmp 111f
22928 + .pushsection .altinstr_replacement, "a"
22929 + 662: ASM_NOP2
22930 + .popsection
22931 + .pushsection .altinstructions, "a"
22932 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22933 + .popsection
22934 + GET_CR3_INTO_RDI
22935 + cmp $0,%dil
22936 + jnz 112f
22937 + mov $__KERNEL_DS,%edi
22938 + mov %edi,%ss
22939 + jmp 111f
22940 +112: cmp $1,%dil
22941 + jz 113f
22942 + ud2
22943 +113: sub $4097,%rdi
22944 + bts $63,%rdi
22945 + SET_RDI_INTO_CR3
22946 + mov $__UDEREF_KERNEL_DS,%edi
22947 + mov %edi,%ss
22948 +111:
22949 +#endif
22950 +
22951 +#ifdef CONFIG_PARAVIRT
22952 + PV_RESTORE_REGS(CLBR_RDI)
22953 +#endif
22954 +
22955 + popq %rdi
22956 + pax_force_retaddr
22957 + retq
22958 +
22959 +#ifdef CONFIG_PAX_KERNEXEC
22960 +2: ljmpq __KERNEL_CS,1b
22961 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22962 +4: SET_RDI_INTO_CR0
22963 + jmp 1b
22964 +#endif
22965 +ENDPROC(pax_enter_kernel)
22966 +
22967 +ENTRY(pax_exit_kernel)
22968 + pushq %rdi
22969 +
22970 +#ifdef CONFIG_PARAVIRT
22971 + PV_SAVE_REGS(CLBR_RDI)
22972 +#endif
22973 +
22974 +#ifdef CONFIG_PAX_KERNEXEC
22975 + mov %cs,%rdi
22976 + cmp $__KERNEXEC_KERNEL_CS,%edi
22977 + jz 2f
22978 + GET_CR0_INTO_RDI
22979 + bts $16,%rdi
22980 + jnc 4f
22981 +1:
22982 +#endif
22983 +
22984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22985 + 661: jmp 111f
22986 + .pushsection .altinstr_replacement, "a"
22987 + 662: ASM_NOP2
22988 + .popsection
22989 + .pushsection .altinstructions, "a"
22990 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22991 + .popsection
22992 + mov %ss,%edi
22993 + cmp $__UDEREF_KERNEL_DS,%edi
22994 + jnz 111f
22995 + GET_CR3_INTO_RDI
22996 + cmp $0,%dil
22997 + jz 112f
22998 + ud2
22999 +112: add $4097,%rdi
23000 + bts $63,%rdi
23001 + SET_RDI_INTO_CR3
23002 + mov $__KERNEL_DS,%edi
23003 + mov %edi,%ss
23004 +111:
23005 +#endif
23006 +
23007 +#ifdef CONFIG_PARAVIRT
23008 + PV_RESTORE_REGS(CLBR_RDI);
23009 +#endif
23010 +
23011 + popq %rdi
23012 + pax_force_retaddr
23013 + retq
23014 +
23015 +#ifdef CONFIG_PAX_KERNEXEC
23016 +2: GET_CR0_INTO_RDI
23017 + btr $16,%rdi
23018 + jnc 4f
23019 + ljmpq __KERNEL_CS,3f
23020 +3: SET_RDI_INTO_CR0
23021 + jmp 1b
23022 +4: ud2
23023 + jmp 4b
23024 +#endif
23025 +ENDPROC(pax_exit_kernel)
23026 +#endif
23027 +
23028 + .macro pax_enter_kernel_user
23029 + pax_set_fptr_mask
23030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23031 + call pax_enter_kernel_user
23032 +#endif
23033 + .endm
23034 +
23035 + .macro pax_exit_kernel_user
23036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23037 + call pax_exit_kernel_user
23038 +#endif
23039 +#ifdef CONFIG_PAX_RANDKSTACK
23040 + pushq %rax
23041 + pushq %r11
23042 + call pax_randomize_kstack
23043 + popq %r11
23044 + popq %rax
23045 +#endif
23046 + .endm
23047 +
23048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23049 +ENTRY(pax_enter_kernel_user)
23050 + pushq %rdi
23051 + pushq %rbx
23052 +
23053 +#ifdef CONFIG_PARAVIRT
23054 + PV_SAVE_REGS(CLBR_RDI)
23055 +#endif
23056 +
23057 + 661: jmp 111f
23058 + .pushsection .altinstr_replacement, "a"
23059 + 662: ASM_NOP2
23060 + .popsection
23061 + .pushsection .altinstructions, "a"
23062 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23063 + .popsection
23064 + GET_CR3_INTO_RDI
23065 + cmp $1,%dil
23066 + jnz 4f
23067 + sub $4097,%rdi
23068 + bts $63,%rdi
23069 + SET_RDI_INTO_CR3
23070 + jmp 3f
23071 +111:
23072 +
23073 + GET_CR3_INTO_RDI
23074 + mov %rdi,%rbx
23075 + add $__START_KERNEL_map,%rbx
23076 + sub phys_base(%rip),%rbx
23077 +
23078 +#ifdef CONFIG_PARAVIRT
23079 + cmpl $0, pv_info+PARAVIRT_enabled
23080 + jz 1f
23081 + pushq %rdi
23082 + i = 0
23083 + .rept USER_PGD_PTRS
23084 + mov i*8(%rbx),%rsi
23085 + mov $0,%sil
23086 + lea i*8(%rbx),%rdi
23087 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23088 + i = i + 1
23089 + .endr
23090 + popq %rdi
23091 + jmp 2f
23092 +1:
23093 +#endif
23094 +
23095 + i = 0
23096 + .rept USER_PGD_PTRS
23097 + movb $0,i*8(%rbx)
23098 + i = i + 1
23099 + .endr
23100 +
23101 +2: SET_RDI_INTO_CR3
23102 +
23103 +#ifdef CONFIG_PAX_KERNEXEC
23104 + GET_CR0_INTO_RDI
23105 + bts $16,%rdi
23106 + SET_RDI_INTO_CR0
23107 +#endif
23108 +
23109 +3:
23110 +
23111 +#ifdef CONFIG_PARAVIRT
23112 + PV_RESTORE_REGS(CLBR_RDI)
23113 +#endif
23114 +
23115 + popq %rbx
23116 + popq %rdi
23117 + pax_force_retaddr
23118 + retq
23119 +4: ud2
23120 +ENDPROC(pax_enter_kernel_user)
23121 +
23122 +ENTRY(pax_exit_kernel_user)
23123 + pushq %rdi
23124 + pushq %rbx
23125 +
23126 +#ifdef CONFIG_PARAVIRT
23127 + PV_SAVE_REGS(CLBR_RDI)
23128 +#endif
23129 +
23130 + GET_CR3_INTO_RDI
23131 + 661: jmp 1f
23132 + .pushsection .altinstr_replacement, "a"
23133 + 662: ASM_NOP2
23134 + .popsection
23135 + .pushsection .altinstructions, "a"
23136 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23137 + .popsection
23138 + cmp $0,%dil
23139 + jnz 3f
23140 + add $4097,%rdi
23141 + bts $63,%rdi
23142 + SET_RDI_INTO_CR3
23143 + jmp 2f
23144 +1:
23145 +
23146 + mov %rdi,%rbx
23147 +
23148 +#ifdef CONFIG_PAX_KERNEXEC
23149 + GET_CR0_INTO_RDI
23150 + btr $16,%rdi
23151 + jnc 3f
23152 + SET_RDI_INTO_CR0
23153 +#endif
23154 +
23155 + add $__START_KERNEL_map,%rbx
23156 + sub phys_base(%rip),%rbx
23157 +
23158 +#ifdef CONFIG_PARAVIRT
23159 + cmpl $0, pv_info+PARAVIRT_enabled
23160 + jz 1f
23161 + i = 0
23162 + .rept USER_PGD_PTRS
23163 + mov i*8(%rbx),%rsi
23164 + mov $0x67,%sil
23165 + lea i*8(%rbx),%rdi
23166 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23167 + i = i + 1
23168 + .endr
23169 + jmp 2f
23170 +1:
23171 +#endif
23172 +
23173 + i = 0
23174 + .rept USER_PGD_PTRS
23175 + movb $0x67,i*8(%rbx)
23176 + i = i + 1
23177 + .endr
23178 +2:
23179 +
23180 +#ifdef CONFIG_PARAVIRT
23181 + PV_RESTORE_REGS(CLBR_RDI)
23182 +#endif
23183 +
23184 + popq %rbx
23185 + popq %rdi
23186 + pax_force_retaddr
23187 + retq
23188 +3: ud2
23189 +ENDPROC(pax_exit_kernel_user)
23190 +#endif
23191 +
23192 + .macro pax_enter_kernel_nmi
23193 + pax_set_fptr_mask
23194 +
23195 +#ifdef CONFIG_PAX_KERNEXEC
23196 + GET_CR0_INTO_RDI
23197 + bts $16,%rdi
23198 + jc 110f
23199 + SET_RDI_INTO_CR0
23200 + or $2,%ebx
23201 +110:
23202 +#endif
23203 +
23204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23205 + 661: jmp 111f
23206 + .pushsection .altinstr_replacement, "a"
23207 + 662: ASM_NOP2
23208 + .popsection
23209 + .pushsection .altinstructions, "a"
23210 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23211 + .popsection
23212 + GET_CR3_INTO_RDI
23213 + cmp $0,%dil
23214 + jz 111f
23215 + sub $4097,%rdi
23216 + or $4,%ebx
23217 + bts $63,%rdi
23218 + SET_RDI_INTO_CR3
23219 + mov $__UDEREF_KERNEL_DS,%edi
23220 + mov %edi,%ss
23221 +111:
23222 +#endif
23223 + .endm
23224 +
23225 + .macro pax_exit_kernel_nmi
23226 +#ifdef CONFIG_PAX_KERNEXEC
23227 + btr $1,%ebx
23228 + jnc 110f
23229 + GET_CR0_INTO_RDI
23230 + btr $16,%rdi
23231 + SET_RDI_INTO_CR0
23232 +110:
23233 +#endif
23234 +
23235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23236 + btr $2,%ebx
23237 + jnc 111f
23238 + GET_CR3_INTO_RDI
23239 + add $4097,%rdi
23240 + bts $63,%rdi
23241 + SET_RDI_INTO_CR3
23242 + mov $__KERNEL_DS,%edi
23243 + mov %edi,%ss
23244 +111:
23245 +#endif
23246 + .endm
23247 +
23248 + .macro pax_erase_kstack
23249 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23250 + call pax_erase_kstack
23251 +#endif
23252 + .endm
23253 +
23254 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23255 +ENTRY(pax_erase_kstack)
23256 + pushq %rdi
23257 + pushq %rcx
23258 + pushq %rax
23259 + pushq %r11
23260 +
23261 + GET_THREAD_INFO(%r11)
23262 + mov TI_lowest_stack(%r11), %rdi
23263 + mov $-0xBEEF, %rax
23264 + std
23265 +
23266 +1: mov %edi, %ecx
23267 + and $THREAD_SIZE_asm - 1, %ecx
23268 + shr $3, %ecx
23269 + repne scasq
23270 + jecxz 2f
23271 +
23272 + cmp $2*8, %ecx
23273 + jc 2f
23274 +
23275 + mov $2*8, %ecx
23276 + repe scasq
23277 + jecxz 2f
23278 + jne 1b
23279 +
23280 +2: cld
23281 + mov %esp, %ecx
23282 + sub %edi, %ecx
23283 +
23284 + cmp $THREAD_SIZE_asm, %rcx
23285 + jb 3f
23286 + ud2
23287 +3:
23288 +
23289 + shr $3, %ecx
23290 + rep stosq
23291 +
23292 + mov TI_task_thread_sp0(%r11), %rdi
23293 + sub $256, %rdi
23294 + mov %rdi, TI_lowest_stack(%r11)
23295 +
23296 + popq %r11
23297 + popq %rax
23298 + popq %rcx
23299 + popq %rdi
23300 + pax_force_retaddr
23301 + ret
23302 +ENDPROC(pax_erase_kstack)
23303 +#endif
23304
23305 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23306 #ifdef CONFIG_TRACE_IRQFLAGS
23307 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23308 .endm
23309
23310 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23311 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23312 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23313 jnc 1f
23314 TRACE_IRQS_ON_DEBUG
23315 1:
23316 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23317 movq \tmp,R11+\offset(%rsp)
23318 .endm
23319
23320 - .macro FAKE_STACK_FRAME child_rip
23321 - /* push in order ss, rsp, eflags, cs, rip */
23322 - xorl %eax, %eax
23323 - pushq_cfi $__KERNEL_DS /* ss */
23324 - /*CFI_REL_OFFSET ss,0*/
23325 - pushq_cfi %rax /* rsp */
23326 - CFI_REL_OFFSET rsp,0
23327 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23328 - /*CFI_REL_OFFSET rflags,0*/
23329 - pushq_cfi $__KERNEL_CS /* cs */
23330 - /*CFI_REL_OFFSET cs,0*/
23331 - pushq_cfi \child_rip /* rip */
23332 - CFI_REL_OFFSET rip,0
23333 - pushq_cfi %rax /* orig rax */
23334 - .endm
23335 -
23336 - .macro UNFAKE_STACK_FRAME
23337 - addq $8*6, %rsp
23338 - CFI_ADJUST_CFA_OFFSET -(6*8)
23339 - .endm
23340 -
23341 /*
23342 * initial frame state for interrupts (and exceptions without error code)
23343 */
23344 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23345 /* save partial stack frame */
23346 .macro SAVE_ARGS_IRQ
23347 cld
23348 - /* start from rbp in pt_regs and jump over */
23349 - movq_cfi rdi, (RDI-RBP)
23350 - movq_cfi rsi, (RSI-RBP)
23351 - movq_cfi rdx, (RDX-RBP)
23352 - movq_cfi rcx, (RCX-RBP)
23353 - movq_cfi rax, (RAX-RBP)
23354 - movq_cfi r8, (R8-RBP)
23355 - movq_cfi r9, (R9-RBP)
23356 - movq_cfi r10, (R10-RBP)
23357 - movq_cfi r11, (R11-RBP)
23358 + /* start from r15 in pt_regs and jump over */
23359 + movq_cfi rdi, RDI
23360 + movq_cfi rsi, RSI
23361 + movq_cfi rdx, RDX
23362 + movq_cfi rcx, RCX
23363 + movq_cfi rax, RAX
23364 + movq_cfi r8, R8
23365 + movq_cfi r9, R9
23366 + movq_cfi r10, R10
23367 + movq_cfi r11, R11
23368 + movq_cfi r12, R12
23369
23370 /* Save rbp so that we can unwind from get_irq_regs() */
23371 - movq_cfi rbp, 0
23372 + movq_cfi rbp, RBP
23373
23374 /* Save previous stack value */
23375 movq %rsp, %rsi
23376
23377 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23378 - testl $3, CS-RBP(%rsi)
23379 + movq %rsp,%rdi /* arg1 for handler */
23380 + testb $3, CS(%rsi)
23381 je 1f
23382 SWAPGS
23383 /*
23384 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23385 0x06 /* DW_OP_deref */, \
23386 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23387 0x22 /* DW_OP_plus */
23388 +
23389 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23390 + testb $3, CS(%rdi)
23391 + jnz 1f
23392 + pax_enter_kernel
23393 + jmp 2f
23394 +1: pax_enter_kernel_user
23395 +2:
23396 +#else
23397 + pax_enter_kernel
23398 +#endif
23399 +
23400 /* We entered an interrupt context - irqs are off: */
23401 TRACE_IRQS_OFF
23402 .endm
23403 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23404 js 1f /* negative -> in kernel */
23405 SWAPGS
23406 xorl %ebx,%ebx
23407 -1: ret
23408 +1:
23409 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23410 + testb $3, CS+8(%rsp)
23411 + jnz 1f
23412 + pax_enter_kernel
23413 + jmp 2f
23414 +1: pax_enter_kernel_user
23415 +2:
23416 +#else
23417 + pax_enter_kernel
23418 +#endif
23419 + pax_force_retaddr
23420 + ret
23421 CFI_ENDPROC
23422 -END(save_paranoid)
23423 +ENDPROC(save_paranoid)
23424 +
23425 +ENTRY(save_paranoid_nmi)
23426 + XCPT_FRAME 1 RDI+8
23427 + cld
23428 + movq_cfi rdi, RDI+8
23429 + movq_cfi rsi, RSI+8
23430 + movq_cfi rdx, RDX+8
23431 + movq_cfi rcx, RCX+8
23432 + movq_cfi rax, RAX+8
23433 + movq_cfi r8, R8+8
23434 + movq_cfi r9, R9+8
23435 + movq_cfi r10, R10+8
23436 + movq_cfi r11, R11+8
23437 + movq_cfi rbx, RBX+8
23438 + movq_cfi rbp, RBP+8
23439 + movq_cfi r12, R12+8
23440 + movq_cfi r13, R13+8
23441 + movq_cfi r14, R14+8
23442 + movq_cfi r15, R15+8
23443 + movl $1,%ebx
23444 + movl $MSR_GS_BASE,%ecx
23445 + rdmsr
23446 + testl %edx,%edx
23447 + js 1f /* negative -> in kernel */
23448 + SWAPGS
23449 + xorl %ebx,%ebx
23450 +1: pax_enter_kernel_nmi
23451 + pax_force_retaddr
23452 + ret
23453 + CFI_ENDPROC
23454 +ENDPROC(save_paranoid_nmi)
23455 .popsection
23456
23457 /*
23458 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23459
23460 RESTORE_REST
23461
23462 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23463 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23464 jz 1f
23465
23466 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23467 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23468 jmp ret_from_sys_call # go to the SYSRET fastpath
23469
23470 1:
23471 - subq $REST_SKIP, %rsp # leave space for volatiles
23472 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23473 movq %rbp, %rdi
23474 call *%rbx
23475 movl $0, RAX(%rsp)
23476 RESTORE_REST
23477 jmp int_ret_from_sys_call
23478 CFI_ENDPROC
23479 -END(ret_from_fork)
23480 +ENDPROC(ret_from_fork)
23481
23482 /*
23483 * System call entry. Up to 6 arguments in registers are supported.
23484 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23485 ENTRY(system_call)
23486 CFI_STARTPROC simple
23487 CFI_SIGNAL_FRAME
23488 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23489 + CFI_DEF_CFA rsp,0
23490 CFI_REGISTER rip,rcx
23491 /*CFI_REGISTER rflags,r11*/
23492 SWAPGS_UNSAFE_STACK
23493 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23494
23495 movq %rsp,PER_CPU_VAR(old_rsp)
23496 movq PER_CPU_VAR(kernel_stack),%rsp
23497 + SAVE_ARGS 8*6,0
23498 + pax_enter_kernel_user
23499 +
23500 +#ifdef CONFIG_PAX_RANDKSTACK
23501 + pax_erase_kstack
23502 +#endif
23503 +
23504 /*
23505 * No need to follow this irqs off/on section - it's straight
23506 * and short:
23507 */
23508 ENABLE_INTERRUPTS(CLBR_NONE)
23509 - SAVE_ARGS 8,0
23510 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23511 movq %rcx,RIP-ARGOFFSET(%rsp)
23512 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23513 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23514 + GET_THREAD_INFO(%rcx)
23515 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23516 jnz tracesys
23517 system_call_fastpath:
23518 #if __SYSCALL_MASK == ~0
23519 @@ -639,10 +1112,13 @@ sysret_check:
23520 LOCKDEP_SYS_EXIT
23521 DISABLE_INTERRUPTS(CLBR_NONE)
23522 TRACE_IRQS_OFF
23523 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23524 + GET_THREAD_INFO(%rcx)
23525 + movl TI_flags(%rcx),%edx
23526 andl %edi,%edx
23527 jnz sysret_careful
23528 CFI_REMEMBER_STATE
23529 + pax_exit_kernel_user
23530 + pax_erase_kstack
23531 /*
23532 * sysretq will re-enable interrupts:
23533 */
23534 @@ -701,6 +1177,9 @@ auditsys:
23535 movq %rax,%rsi /* 2nd arg: syscall number */
23536 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23537 call __audit_syscall_entry
23538 +
23539 + pax_erase_kstack
23540 +
23541 LOAD_ARGS 0 /* reload call-clobbered registers */
23542 jmp system_call_fastpath
23543
23544 @@ -722,7 +1201,7 @@ sysret_audit:
23545 /* Do syscall tracing */
23546 tracesys:
23547 #ifdef CONFIG_AUDITSYSCALL
23548 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23549 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23550 jz auditsys
23551 #endif
23552 SAVE_REST
23553 @@ -730,12 +1209,15 @@ tracesys:
23554 FIXUP_TOP_OF_STACK %rdi
23555 movq %rsp,%rdi
23556 call syscall_trace_enter
23557 +
23558 + pax_erase_kstack
23559 +
23560 /*
23561 * Reload arg registers from stack in case ptrace changed them.
23562 * We don't reload %rax because syscall_trace_enter() returned
23563 * the value it wants us to use in the table lookup.
23564 */
23565 - LOAD_ARGS ARGOFFSET, 1
23566 + LOAD_ARGS 1
23567 RESTORE_REST
23568 #if __SYSCALL_MASK == ~0
23569 cmpq $__NR_syscall_max,%rax
23570 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23571 andl %edi,%edx
23572 jnz int_careful
23573 andl $~TS_COMPAT,TI_status(%rcx)
23574 - jmp retint_swapgs
23575 + pax_exit_kernel_user
23576 + pax_erase_kstack
23577 + jmp retint_swapgs_pax
23578
23579 /* Either reschedule or signal or syscall exit tracking needed. */
23580 /* First do a reschedule test. */
23581 @@ -811,7 +1295,7 @@ int_restore_rest:
23582 TRACE_IRQS_OFF
23583 jmp int_with_check
23584 CFI_ENDPROC
23585 -END(system_call)
23586 +ENDPROC(system_call)
23587
23588 .macro FORK_LIKE func
23589 ENTRY(stub_\func)
23590 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23591 DEFAULT_FRAME 0 8 /* offset 8: return address */
23592 call sys_\func
23593 RESTORE_TOP_OF_STACK %r11, 8
23594 - ret $REST_SKIP /* pop extended registers */
23595 + pax_force_retaddr
23596 + ret
23597 CFI_ENDPROC
23598 -END(stub_\func)
23599 +ENDPROC(stub_\func)
23600 .endm
23601
23602 .macro FIXED_FRAME label,func
23603 @@ -836,9 +1321,10 @@ ENTRY(\label)
23604 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23605 call \func
23606 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23607 + pax_force_retaddr
23608 ret
23609 CFI_ENDPROC
23610 -END(\label)
23611 +ENDPROC(\label)
23612 .endm
23613
23614 FORK_LIKE clone
23615 @@ -846,19 +1332,6 @@ END(\label)
23616 FORK_LIKE vfork
23617 FIXED_FRAME stub_iopl, sys_iopl
23618
23619 -ENTRY(ptregscall_common)
23620 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23621 - RESTORE_TOP_OF_STACK %r11, 8
23622 - movq_cfi_restore R15+8, r15
23623 - movq_cfi_restore R14+8, r14
23624 - movq_cfi_restore R13+8, r13
23625 - movq_cfi_restore R12+8, r12
23626 - movq_cfi_restore RBP+8, rbp
23627 - movq_cfi_restore RBX+8, rbx
23628 - ret $REST_SKIP /* pop extended registers */
23629 - CFI_ENDPROC
23630 -END(ptregscall_common)
23631 -
23632 ENTRY(stub_execve)
23633 CFI_STARTPROC
23634 addq $8, %rsp
23635 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23636 RESTORE_REST
23637 jmp int_ret_from_sys_call
23638 CFI_ENDPROC
23639 -END(stub_execve)
23640 +ENDPROC(stub_execve)
23641
23642 /*
23643 * sigreturn is special because it needs to restore all registers on return.
23644 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23645 RESTORE_REST
23646 jmp int_ret_from_sys_call
23647 CFI_ENDPROC
23648 -END(stub_rt_sigreturn)
23649 +ENDPROC(stub_rt_sigreturn)
23650
23651 #ifdef CONFIG_X86_X32_ABI
23652 ENTRY(stub_x32_rt_sigreturn)
23653 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23654 RESTORE_REST
23655 jmp int_ret_from_sys_call
23656 CFI_ENDPROC
23657 -END(stub_x32_rt_sigreturn)
23658 +ENDPROC(stub_x32_rt_sigreturn)
23659
23660 ENTRY(stub_x32_execve)
23661 CFI_STARTPROC
23662 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23663 RESTORE_REST
23664 jmp int_ret_from_sys_call
23665 CFI_ENDPROC
23666 -END(stub_x32_execve)
23667 +ENDPROC(stub_x32_execve)
23668
23669 #endif
23670
23671 @@ -952,7 +1425,7 @@ vector=vector+1
23672 2: jmp common_interrupt
23673 .endr
23674 CFI_ENDPROC
23675 -END(irq_entries_start)
23676 +ENDPROC(irq_entries_start)
23677
23678 .previous
23679 END(interrupt)
23680 @@ -969,8 +1442,8 @@ END(interrupt)
23681 /* 0(%rsp): ~(interrupt number) */
23682 .macro interrupt func
23683 /* reserve pt_regs for scratch regs and rbp */
23684 - subq $ORIG_RAX-RBP, %rsp
23685 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23686 + subq $ORIG_RAX, %rsp
23687 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23688 SAVE_ARGS_IRQ
23689 call \func
23690 .endm
23691 @@ -997,14 +1470,14 @@ ret_from_intr:
23692
23693 /* Restore saved previous stack */
23694 popq %rsi
23695 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23696 - leaq ARGOFFSET-RBP(%rsi), %rsp
23697 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23698 + movq %rsi, %rsp
23699 CFI_DEF_CFA_REGISTER rsp
23700 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23701 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23702
23703 exit_intr:
23704 GET_THREAD_INFO(%rcx)
23705 - testl $3,CS-ARGOFFSET(%rsp)
23706 + testb $3,CS-ARGOFFSET(%rsp)
23707 je retint_kernel
23708
23709 /* Interrupt came from user space */
23710 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23711 * The iretq could re-enable interrupts:
23712 */
23713 DISABLE_INTERRUPTS(CLBR_ANY)
23714 + pax_exit_kernel_user
23715 +retint_swapgs_pax:
23716 TRACE_IRQS_IRETQ
23717 SWAPGS
23718 jmp restore_args
23719
23720 retint_restore_args: /* return to kernel space */
23721 DISABLE_INTERRUPTS(CLBR_ANY)
23722 + pax_exit_kernel
23723 + pax_force_retaddr (RIP-ARGOFFSET)
23724 /*
23725 * The iretq could re-enable interrupts:
23726 */
23727 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23728 #endif
23729
23730 CFI_ENDPROC
23731 -END(common_interrupt)
23732 +ENDPROC(common_interrupt)
23733 /*
23734 * End of kprobes section
23735 */
23736 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23737 interrupt \do_sym
23738 jmp ret_from_intr
23739 CFI_ENDPROC
23740 -END(\sym)
23741 +ENDPROC(\sym)
23742 .endm
23743
23744 #ifdef CONFIG_TRACING
23745 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23746 call \do_sym
23747 jmp error_exit /* %ebx: no swapgs flag */
23748 CFI_ENDPROC
23749 -END(\sym)
23750 +ENDPROC(\sym)
23751 .endm
23752
23753 .macro paranoidzeroentry sym do_sym
23754 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23755 call \do_sym
23756 jmp paranoid_exit /* %ebx: no swapgs flag */
23757 CFI_ENDPROC
23758 -END(\sym)
23759 +ENDPROC(\sym)
23760 .endm
23761
23762 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23763 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23764 .macro paranoidzeroentry_ist sym do_sym ist
23765 ENTRY(\sym)
23766 INTR_FRAME
23767 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23768 TRACE_IRQS_OFF_DEBUG
23769 movq %rsp,%rdi /* pt_regs pointer */
23770 xorl %esi,%esi /* no error code */
23771 +#ifdef CONFIG_SMP
23772 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23773 + lea init_tss(%r13), %r13
23774 +#else
23775 + lea init_tss(%rip), %r13
23776 +#endif
23777 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23778 call \do_sym
23779 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23780 jmp paranoid_exit /* %ebx: no swapgs flag */
23781 CFI_ENDPROC
23782 -END(\sym)
23783 +ENDPROC(\sym)
23784 .endm
23785
23786 .macro errorentry sym do_sym
23787 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23788 call \do_sym
23789 jmp error_exit /* %ebx: no swapgs flag */
23790 CFI_ENDPROC
23791 -END(\sym)
23792 +ENDPROC(\sym)
23793 .endm
23794
23795 #ifdef CONFIG_TRACING
23796 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23797 call \do_sym
23798 jmp paranoid_exit /* %ebx: no swapgs flag */
23799 CFI_ENDPROC
23800 -END(\sym)
23801 +ENDPROC(\sym)
23802 .endm
23803
23804 zeroentry divide_error do_divide_error
23805 @@ -1336,9 +1819,10 @@ gs_change:
23806 2: mfence /* workaround */
23807 SWAPGS
23808 popfq_cfi
23809 + pax_force_retaddr
23810 ret
23811 CFI_ENDPROC
23812 -END(native_load_gs_index)
23813 +ENDPROC(native_load_gs_index)
23814
23815 _ASM_EXTABLE(gs_change,bad_gs)
23816 .section .fixup,"ax"
23817 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23818 CFI_DEF_CFA_REGISTER rsp
23819 CFI_ADJUST_CFA_OFFSET -8
23820 decl PER_CPU_VAR(irq_count)
23821 + pax_force_retaddr
23822 ret
23823 CFI_ENDPROC
23824 -END(do_softirq_own_stack)
23825 +ENDPROC(do_softirq_own_stack)
23826
23827 #ifdef CONFIG_XEN
23828 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23829 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23830 decl PER_CPU_VAR(irq_count)
23831 jmp error_exit
23832 CFI_ENDPROC
23833 -END(xen_do_hypervisor_callback)
23834 +ENDPROC(xen_do_hypervisor_callback)
23835
23836 /*
23837 * Hypervisor uses this for application faults while it executes.
23838 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23839 SAVE_ALL
23840 jmp error_exit
23841 CFI_ENDPROC
23842 -END(xen_failsafe_callback)
23843 +ENDPROC(xen_failsafe_callback)
23844
23845 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23846 xen_hvm_callback_vector xen_evtchn_do_upcall
23847 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23848 DEFAULT_FRAME
23849 DISABLE_INTERRUPTS(CLBR_NONE)
23850 TRACE_IRQS_OFF_DEBUG
23851 - testl %ebx,%ebx /* swapgs needed? */
23852 + testl $1,%ebx /* swapgs needed? */
23853 jnz paranoid_restore
23854 - testl $3,CS(%rsp)
23855 + testb $3,CS(%rsp)
23856 jnz paranoid_userspace
23857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23858 + pax_exit_kernel
23859 + TRACE_IRQS_IRETQ 0
23860 + SWAPGS_UNSAFE_STACK
23861 + RESTORE_ALL 8
23862 + pax_force_retaddr_bts
23863 + jmp irq_return
23864 +#endif
23865 paranoid_swapgs:
23866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23867 + pax_exit_kernel_user
23868 +#else
23869 + pax_exit_kernel
23870 +#endif
23871 TRACE_IRQS_IRETQ 0
23872 SWAPGS_UNSAFE_STACK
23873 RESTORE_ALL 8
23874 jmp irq_return
23875 paranoid_restore:
23876 + pax_exit_kernel
23877 TRACE_IRQS_IRETQ_DEBUG 0
23878 RESTORE_ALL 8
23879 + pax_force_retaddr_bts
23880 jmp irq_return
23881 paranoid_userspace:
23882 GET_THREAD_INFO(%rcx)
23883 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23884 TRACE_IRQS_OFF
23885 jmp paranoid_userspace
23886 CFI_ENDPROC
23887 -END(paranoid_exit)
23888 +ENDPROC(paranoid_exit)
23889
23890 /*
23891 * Exception entry point. This expects an error code/orig_rax on the stack.
23892 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23893 movq_cfi r14, R14+8
23894 movq_cfi r15, R15+8
23895 xorl %ebx,%ebx
23896 - testl $3,CS+8(%rsp)
23897 + testb $3,CS+8(%rsp)
23898 je error_kernelspace
23899 error_swapgs:
23900 SWAPGS
23901 error_sti:
23902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23903 + testb $3, CS+8(%rsp)
23904 + jnz 1f
23905 + pax_enter_kernel
23906 + jmp 2f
23907 +1: pax_enter_kernel_user
23908 +2:
23909 +#else
23910 + pax_enter_kernel
23911 +#endif
23912 TRACE_IRQS_OFF
23913 + pax_force_retaddr
23914 ret
23915
23916 /*
23917 @@ -1616,7 +2127,7 @@ bstep_iret:
23918 movq %rcx,RIP+8(%rsp)
23919 jmp error_swapgs
23920 CFI_ENDPROC
23921 -END(error_entry)
23922 +ENDPROC(error_entry)
23923
23924
23925 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23926 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23927 DISABLE_INTERRUPTS(CLBR_NONE)
23928 TRACE_IRQS_OFF
23929 GET_THREAD_INFO(%rcx)
23930 - testl %eax,%eax
23931 + testl $1,%eax
23932 jne retint_kernel
23933 LOCKDEP_SYS_EXIT_IRQ
23934 movl TI_flags(%rcx),%edx
23935 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23936 jnz retint_careful
23937 jmp retint_swapgs
23938 CFI_ENDPROC
23939 -END(error_exit)
23940 +ENDPROC(error_exit)
23941
23942 /*
23943 * Test if a given stack is an NMI stack or not.
23944 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23945 * If %cs was not the kernel segment, then the NMI triggered in user
23946 * space, which means it is definitely not nested.
23947 */
23948 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23949 + je 1f
23950 cmpl $__KERNEL_CS, 16(%rsp)
23951 jne first_nmi
23952 -
23953 +1:
23954 /*
23955 * Check the special variable on the stack to see if NMIs are
23956 * executing.
23957 @@ -1730,8 +2243,7 @@ nested_nmi:
23958
23959 1:
23960 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23961 - leaq -1*8(%rsp), %rdx
23962 - movq %rdx, %rsp
23963 + subq $8, %rsp
23964 CFI_ADJUST_CFA_OFFSET 1*8
23965 leaq -10*8(%rsp), %rdx
23966 pushq_cfi $__KERNEL_DS
23967 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23968 CFI_RESTORE rdx
23969
23970 /* No need to check faults here */
23971 +# pax_force_retaddr_bts
23972 INTERRUPT_RETURN
23973
23974 CFI_RESTORE_STATE
23975 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23976 subq $ORIG_RAX-R15, %rsp
23977 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23978 /*
23979 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23980 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23981 * as we should not be calling schedule in NMI context.
23982 * Even with normal interrupts enabled. An NMI should not be
23983 * setting NEED_RESCHED or anything that normal interrupts and
23984 * exceptions might do.
23985 */
23986 - call save_paranoid
23987 + call save_paranoid_nmi
23988 DEFAULT_FRAME 0
23989
23990 /*
23991 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23992 * NMI itself takes a page fault, the page fault that was preempted
23993 * will read the information from the NMI page fault and not the
23994 * origin fault. Save it off and restore it if it changes.
23995 - * Use the r12 callee-saved register.
23996 + * Use the r13 callee-saved register.
23997 */
23998 - movq %cr2, %r12
23999 + movq %cr2, %r13
24000
24001 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24002 movq %rsp,%rdi
24003 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
24004
24005 /* Did the NMI take a page fault? Restore cr2 if it did */
24006 movq %cr2, %rcx
24007 - cmpq %rcx, %r12
24008 + cmpq %rcx, %r13
24009 je 1f
24010 - movq %r12, %cr2
24011 + movq %r13, %cr2
24012 1:
24013
24014 - testl %ebx,%ebx /* swapgs needed? */
24015 + testl $1,%ebx /* swapgs needed? */
24016 jnz nmi_restore
24017 nmi_swapgs:
24018 SWAPGS_UNSAFE_STACK
24019 nmi_restore:
24020 + pax_exit_kernel_nmi
24021 /* Pop the extra iret frame at once */
24022 RESTORE_ALL 6*8
24023 + testb $3, 8(%rsp)
24024 + jnz 1f
24025 + pax_force_retaddr_bts
24026 +1:
24027
24028 /* Clear the NMI executing stack variable */
24029 movq $0, 5*8(%rsp)
24030 jmp irq_return
24031 CFI_ENDPROC
24032 -END(nmi)
24033 +ENDPROC(nmi)
24034
24035 ENTRY(ignore_sysret)
24036 CFI_STARTPROC
24037 mov $-ENOSYS,%eax
24038 sysret
24039 CFI_ENDPROC
24040 -END(ignore_sysret)
24041 +ENDPROC(ignore_sysret)
24042
24043 /*
24044 * End of kprobes section
24045 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24046 index 52819e8..b6d1dbd 100644
24047 --- a/arch/x86/kernel/ftrace.c
24048 +++ b/arch/x86/kernel/ftrace.c
24049 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24050 {
24051 unsigned char replaced[MCOUNT_INSN_SIZE];
24052
24053 + ip = ktla_ktva(ip);
24054 +
24055 /*
24056 * Note: Due to modules and __init, code can
24057 * disappear and change, we need to protect against faulting
24058 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24059 unsigned char old[MCOUNT_INSN_SIZE];
24060 int ret;
24061
24062 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24063 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24064
24065 ftrace_update_func = ip;
24066 /* Make sure the breakpoints see the ftrace_update_func update */
24067 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24068 * kernel identity mapping to modify code.
24069 */
24070 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24071 - ip = (unsigned long)__va(__pa_symbol(ip));
24072 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24073
24074 if (probe_kernel_write((void *)ip, val, size))
24075 return -EPERM;
24076 @@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24077 unsigned char replaced[MCOUNT_INSN_SIZE];
24078 unsigned char brk = BREAKPOINT_INSTRUCTION;
24079
24080 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24081 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24082 return -EFAULT;
24083
24084 /* Make sure it is what we expect it to be */
24085 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24086 index 068054f..c248bcd 100644
24087 --- a/arch/x86/kernel/head64.c
24088 +++ b/arch/x86/kernel/head64.c
24089 @@ -67,12 +67,12 @@ again:
24090 pgd = *pgd_p;
24091
24092 /*
24093 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24094 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24095 + * The use of __early_va rather than __va here is critical:
24096 + * __va would point us back into the dynamic
24097 * range and we might end up looping forever...
24098 */
24099 if (pgd)
24100 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24101 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24102 else {
24103 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24104 reset_early_page_tables();
24105 @@ -82,13 +82,13 @@ again:
24106 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24107 for (i = 0; i < PTRS_PER_PUD; i++)
24108 pud_p[i] = 0;
24109 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24110 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24111 }
24112 pud_p += pud_index(address);
24113 pud = *pud_p;
24114
24115 if (pud)
24116 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24117 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24118 else {
24119 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24120 reset_early_page_tables();
24121 @@ -98,7 +98,7 @@ again:
24122 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24123 for (i = 0; i < PTRS_PER_PMD; i++)
24124 pmd_p[i] = 0;
24125 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24126 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24127 }
24128 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24129 pmd_p[pmd_index(address)] = pmd;
24130 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24131 if (console_loglevel == 10)
24132 early_printk("Kernel alive\n");
24133
24134 - clear_page(init_level4_pgt);
24135 /* set init_level4_pgt kernel high mapping*/
24136 init_level4_pgt[511] = early_level4_pgt[511];
24137
24138 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24139 index f36bd42..56ee1534 100644
24140 --- a/arch/x86/kernel/head_32.S
24141 +++ b/arch/x86/kernel/head_32.S
24142 @@ -26,6 +26,12 @@
24143 /* Physical address */
24144 #define pa(X) ((X) - __PAGE_OFFSET)
24145
24146 +#ifdef CONFIG_PAX_KERNEXEC
24147 +#define ta(X) (X)
24148 +#else
24149 +#define ta(X) ((X) - __PAGE_OFFSET)
24150 +#endif
24151 +
24152 /*
24153 * References to members of the new_cpu_data structure.
24154 */
24155 @@ -55,11 +61,7 @@
24156 * and small than max_low_pfn, otherwise will waste some page table entries
24157 */
24158
24159 -#if PTRS_PER_PMD > 1
24160 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24161 -#else
24162 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24163 -#endif
24164 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24165
24166 /* Number of possible pages in the lowmem region */
24167 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24168 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24169 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24170
24171 /*
24172 + * Real beginning of normal "text" segment
24173 + */
24174 +ENTRY(stext)
24175 +ENTRY(_stext)
24176 +
24177 +/*
24178 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24179 * %esi points to the real-mode code as a 32-bit pointer.
24180 * CS and DS must be 4 GB flat segments, but we don't depend on
24181 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24182 * can.
24183 */
24184 __HEAD
24185 +
24186 +#ifdef CONFIG_PAX_KERNEXEC
24187 + jmp startup_32
24188 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24189 +.fill PAGE_SIZE-5,1,0xcc
24190 +#endif
24191 +
24192 ENTRY(startup_32)
24193 movl pa(stack_start),%ecx
24194
24195 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24196 2:
24197 leal -__PAGE_OFFSET(%ecx),%esp
24198
24199 +#ifdef CONFIG_SMP
24200 + movl $pa(cpu_gdt_table),%edi
24201 + movl $__per_cpu_load,%eax
24202 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24203 + rorl $16,%eax
24204 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24205 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24206 + movl $__per_cpu_end - 1,%eax
24207 + subl $__per_cpu_start,%eax
24208 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24209 +#endif
24210 +
24211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24212 + movl $NR_CPUS,%ecx
24213 + movl $pa(cpu_gdt_table),%edi
24214 +1:
24215 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24216 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24217 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24218 + addl $PAGE_SIZE_asm,%edi
24219 + loop 1b
24220 +#endif
24221 +
24222 +#ifdef CONFIG_PAX_KERNEXEC
24223 + movl $pa(boot_gdt),%edi
24224 + movl $__LOAD_PHYSICAL_ADDR,%eax
24225 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24226 + rorl $16,%eax
24227 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24228 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24229 + rorl $16,%eax
24230 +
24231 + ljmp $(__BOOT_CS),$1f
24232 +1:
24233 +
24234 + movl $NR_CPUS,%ecx
24235 + movl $pa(cpu_gdt_table),%edi
24236 + addl $__PAGE_OFFSET,%eax
24237 +1:
24238 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24239 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24240 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24241 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24242 + rorl $16,%eax
24243 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24244 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24245 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24246 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24247 + rorl $16,%eax
24248 + addl $PAGE_SIZE_asm,%edi
24249 + loop 1b
24250 +#endif
24251 +
24252 /*
24253 * Clear BSS first so that there are no surprises...
24254 */
24255 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24256 movl %eax, pa(max_pfn_mapped)
24257
24258 /* Do early initialization of the fixmap area */
24259 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24260 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24261 +#ifdef CONFIG_COMPAT_VDSO
24262 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24263 +#else
24264 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24265 +#endif
24266 #else /* Not PAE */
24267
24268 page_pde_offset = (__PAGE_OFFSET >> 20);
24269 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24270 movl %eax, pa(max_pfn_mapped)
24271
24272 /* Do early initialization of the fixmap area */
24273 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24274 - movl %eax,pa(initial_page_table+0xffc)
24275 +#ifdef CONFIG_COMPAT_VDSO
24276 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24277 +#else
24278 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24279 +#endif
24280 #endif
24281
24282 #ifdef CONFIG_PARAVIRT
24283 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24284 cmpl $num_subarch_entries, %eax
24285 jae bad_subarch
24286
24287 - movl pa(subarch_entries)(,%eax,4), %eax
24288 - subl $__PAGE_OFFSET, %eax
24289 - jmp *%eax
24290 + jmp *pa(subarch_entries)(,%eax,4)
24291
24292 bad_subarch:
24293 WEAK(lguest_entry)
24294 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24295 __INITDATA
24296
24297 subarch_entries:
24298 - .long default_entry /* normal x86/PC */
24299 - .long lguest_entry /* lguest hypervisor */
24300 - .long xen_entry /* Xen hypervisor */
24301 - .long default_entry /* Moorestown MID */
24302 + .long ta(default_entry) /* normal x86/PC */
24303 + .long ta(lguest_entry) /* lguest hypervisor */
24304 + .long ta(xen_entry) /* Xen hypervisor */
24305 + .long ta(default_entry) /* Moorestown MID */
24306 num_subarch_entries = (. - subarch_entries) / 4
24307 .previous
24308 #else
24309 @@ -354,6 +426,7 @@ default_entry:
24310 movl pa(mmu_cr4_features),%eax
24311 movl %eax,%cr4
24312
24313 +#ifdef CONFIG_X86_PAE
24314 testb $X86_CR4_PAE, %al # check if PAE is enabled
24315 jz enable_paging
24316
24317 @@ -382,6 +455,9 @@ default_entry:
24318 /* Make changes effective */
24319 wrmsr
24320
24321 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24322 +#endif
24323 +
24324 enable_paging:
24325
24326 /*
24327 @@ -449,14 +525,20 @@ is486:
24328 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24329 movl %eax,%ss # after changing gdt.
24330
24331 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24332 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24333 movl %eax,%ds
24334 movl %eax,%es
24335
24336 movl $(__KERNEL_PERCPU), %eax
24337 movl %eax,%fs # set this cpu's percpu
24338
24339 +#ifdef CONFIG_CC_STACKPROTECTOR
24340 movl $(__KERNEL_STACK_CANARY),%eax
24341 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24342 + movl $(__USER_DS),%eax
24343 +#else
24344 + xorl %eax,%eax
24345 +#endif
24346 movl %eax,%gs
24347
24348 xorl %eax,%eax # Clear LDT
24349 @@ -512,8 +594,11 @@ setup_once:
24350 * relocation. Manually set base address in stack canary
24351 * segment descriptor.
24352 */
24353 - movl $gdt_page,%eax
24354 + movl $cpu_gdt_table,%eax
24355 movl $stack_canary,%ecx
24356 +#ifdef CONFIG_SMP
24357 + addl $__per_cpu_load,%ecx
24358 +#endif
24359 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24360 shrl $16, %ecx
24361 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24362 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24363 cmpl $2,(%esp) # X86_TRAP_NMI
24364 je is_nmi # Ignore NMI
24365
24366 - cmpl $2,%ss:early_recursion_flag
24367 + cmpl $1,%ss:early_recursion_flag
24368 je hlt_loop
24369 incl %ss:early_recursion_flag
24370
24371 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24372 pushl (20+6*4)(%esp) /* trapno */
24373 pushl $fault_msg
24374 call printk
24375 -#endif
24376 call dump_stack
24377 +#endif
24378 hlt_loop:
24379 hlt
24380 jmp hlt_loop
24381 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24382 /* This is the default interrupt "handler" :-) */
24383 ALIGN
24384 ignore_int:
24385 - cld
24386 #ifdef CONFIG_PRINTK
24387 + cmpl $2,%ss:early_recursion_flag
24388 + je hlt_loop
24389 + incl %ss:early_recursion_flag
24390 + cld
24391 pushl %eax
24392 pushl %ecx
24393 pushl %edx
24394 @@ -617,9 +705,6 @@ ignore_int:
24395 movl $(__KERNEL_DS),%eax
24396 movl %eax,%ds
24397 movl %eax,%es
24398 - cmpl $2,early_recursion_flag
24399 - je hlt_loop
24400 - incl early_recursion_flag
24401 pushl 16(%esp)
24402 pushl 24(%esp)
24403 pushl 32(%esp)
24404 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24405 /*
24406 * BSS section
24407 */
24408 -__PAGE_ALIGNED_BSS
24409 - .align PAGE_SIZE
24410 #ifdef CONFIG_X86_PAE
24411 +.section .initial_pg_pmd,"a",@progbits
24412 initial_pg_pmd:
24413 .fill 1024*KPMDS,4,0
24414 #else
24415 +.section .initial_page_table,"a",@progbits
24416 ENTRY(initial_page_table)
24417 .fill 1024,4,0
24418 #endif
24419 +.section .initial_pg_fixmap,"a",@progbits
24420 initial_pg_fixmap:
24421 .fill 1024,4,0
24422 +.section .empty_zero_page,"a",@progbits
24423 ENTRY(empty_zero_page)
24424 .fill 4096,1,0
24425 +.section .swapper_pg_dir,"a",@progbits
24426 ENTRY(swapper_pg_dir)
24427 +#ifdef CONFIG_X86_PAE
24428 + .fill 4,8,0
24429 +#else
24430 .fill 1024,4,0
24431 +#endif
24432
24433 /*
24434 * This starts the data section.
24435 */
24436 #ifdef CONFIG_X86_PAE
24437 -__PAGE_ALIGNED_DATA
24438 - /* Page-aligned for the benefit of paravirt? */
24439 - .align PAGE_SIZE
24440 +.section .initial_page_table,"a",@progbits
24441 ENTRY(initial_page_table)
24442 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24443 # if KPMDS == 3
24444 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24445 # error "Kernel PMDs should be 1, 2 or 3"
24446 # endif
24447 .align PAGE_SIZE /* needs to be page-sized too */
24448 +
24449 +#ifdef CONFIG_PAX_PER_CPU_PGD
24450 +ENTRY(cpu_pgd)
24451 + .rept 2*NR_CPUS
24452 + .fill 4,8,0
24453 + .endr
24454 +#endif
24455 +
24456 #endif
24457
24458 .data
24459 .balign 4
24460 ENTRY(stack_start)
24461 - .long init_thread_union+THREAD_SIZE
24462 + .long init_thread_union+THREAD_SIZE-8
24463
24464 __INITRODATA
24465 int_msg:
24466 @@ -727,7 +825,7 @@ fault_msg:
24467 * segment size, and 32-bit linear address value:
24468 */
24469
24470 - .data
24471 +.section .rodata,"a",@progbits
24472 .globl boot_gdt_descr
24473 .globl idt_descr
24474
24475 @@ -736,7 +834,7 @@ fault_msg:
24476 .word 0 # 32 bit align gdt_desc.address
24477 boot_gdt_descr:
24478 .word __BOOT_DS+7
24479 - .long boot_gdt - __PAGE_OFFSET
24480 + .long pa(boot_gdt)
24481
24482 .word 0 # 32-bit align idt_desc.address
24483 idt_descr:
24484 @@ -747,7 +845,7 @@ idt_descr:
24485 .word 0 # 32 bit align gdt_desc.address
24486 ENTRY(early_gdt_descr)
24487 .word GDT_ENTRIES*8-1
24488 - .long gdt_page /* Overwritten for secondary CPUs */
24489 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24490
24491 /*
24492 * The boot_gdt must mirror the equivalent in setup.S and is
24493 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24494 .align L1_CACHE_BYTES
24495 ENTRY(boot_gdt)
24496 .fill GDT_ENTRY_BOOT_CS,8,0
24497 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24498 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24499 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24500 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24501 +
24502 + .align PAGE_SIZE_asm
24503 +ENTRY(cpu_gdt_table)
24504 + .rept NR_CPUS
24505 + .quad 0x0000000000000000 /* NULL descriptor */
24506 + .quad 0x0000000000000000 /* 0x0b reserved */
24507 + .quad 0x0000000000000000 /* 0x13 reserved */
24508 + .quad 0x0000000000000000 /* 0x1b reserved */
24509 +
24510 +#ifdef CONFIG_PAX_KERNEXEC
24511 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24512 +#else
24513 + .quad 0x0000000000000000 /* 0x20 unused */
24514 +#endif
24515 +
24516 + .quad 0x0000000000000000 /* 0x28 unused */
24517 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24518 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24519 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24520 + .quad 0x0000000000000000 /* 0x4b reserved */
24521 + .quad 0x0000000000000000 /* 0x53 reserved */
24522 + .quad 0x0000000000000000 /* 0x5b reserved */
24523 +
24524 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24525 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24526 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24527 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24528 +
24529 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24530 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24531 +
24532 + /*
24533 + * Segments used for calling PnP BIOS have byte granularity.
24534 + * The code segments and data segments have fixed 64k limits,
24535 + * the transfer segment sizes are set at run time.
24536 + */
24537 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24538 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24539 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24540 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24541 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24542 +
24543 + /*
24544 + * The APM segments have byte granularity and their bases
24545 + * are set at run time. All have 64k limits.
24546 + */
24547 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24548 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24549 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24550 +
24551 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24552 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24553 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24554 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24555 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24556 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24557 +
24558 + /* Be sure this is zeroed to avoid false validations in Xen */
24559 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24560 + .endr
24561 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24562 index a468c0a..c7dec74 100644
24563 --- a/arch/x86/kernel/head_64.S
24564 +++ b/arch/x86/kernel/head_64.S
24565 @@ -20,6 +20,8 @@
24566 #include <asm/processor-flags.h>
24567 #include <asm/percpu.h>
24568 #include <asm/nops.h>
24569 +#include <asm/cpufeature.h>
24570 +#include <asm/alternative-asm.h>
24571
24572 #ifdef CONFIG_PARAVIRT
24573 #include <asm/asm-offsets.h>
24574 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24575 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24576 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24577 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24578 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24579 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24580 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24581 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24582 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24583 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24584
24585 .text
24586 __HEAD
24587 @@ -89,11 +97,24 @@ startup_64:
24588 * Fixup the physical addresses in the page table
24589 */
24590 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24591 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24592 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24593 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24594 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24595 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24596
24597 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24598 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24599 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24600 +#ifndef CONFIG_XEN
24601 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24602 +#endif
24603 +
24604 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24605 +
24606 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24607 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24608
24609 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24610 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24611
24612 /*
24613 * Set up the identity mapping for the switchover. These
24614 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24615 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24616 1:
24617
24618 - /* Enable PAE mode and PGE */
24619 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24620 + /* Enable PAE mode and PSE/PGE */
24621 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24622 movq %rcx, %cr4
24623
24624 /* Setup early boot stage 4 level pagetables. */
24625 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24626 movl $MSR_EFER, %ecx
24627 rdmsr
24628 btsl $_EFER_SCE, %eax /* Enable System Call */
24629 - btl $20,%edi /* No Execute supported? */
24630 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24631 jnc 1f
24632 btsl $_EFER_NX, %eax
24633 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24634 +#ifndef CONFIG_EFI
24635 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24636 +#endif
24637 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24638 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24639 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24640 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24641 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24642 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24643 1: wrmsr /* Make changes effective */
24644
24645 /* Setup cr0 */
24646 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24647 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24648 * address given in m16:64.
24649 */
24650 + pax_set_fptr_mask
24651 movq initial_code(%rip),%rax
24652 pushq $0 # fake return address to stop unwinder
24653 pushq $__KERNEL_CS # set correct cs
24654 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24655 .quad INIT_PER_CPU_VAR(irq_stack_union)
24656
24657 GLOBAL(stack_start)
24658 - .quad init_thread_union+THREAD_SIZE-8
24659 + .quad init_thread_union+THREAD_SIZE-16
24660 .word 0
24661 __FINITDATA
24662
24663 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24664 call dump_stack
24665 #ifdef CONFIG_KALLSYMS
24666 leaq early_idt_ripmsg(%rip),%rdi
24667 - movq 40(%rsp),%rsi # %rip again
24668 + movq 88(%rsp),%rsi # %rip again
24669 call __print_symbol
24670 #endif
24671 #endif /* EARLY_PRINTK */
24672 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24673 early_recursion_flag:
24674 .long 0
24675
24676 + .section .rodata,"a",@progbits
24677 #ifdef CONFIG_EARLY_PRINTK
24678 early_idt_msg:
24679 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24680 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24681 NEXT_PAGE(early_dynamic_pgts)
24682 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24683
24684 - .data
24685 + .section .rodata,"a",@progbits
24686
24687 -#ifndef CONFIG_XEN
24688 NEXT_PAGE(init_level4_pgt)
24689 - .fill 512,8,0
24690 -#else
24691 -NEXT_PAGE(init_level4_pgt)
24692 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24693 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24694 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24695 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24696 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24697 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24698 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24699 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24700 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24701 .org init_level4_pgt + L4_START_KERNEL*8, 0
24702 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24703 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24704
24705 +#ifdef CONFIG_PAX_PER_CPU_PGD
24706 +NEXT_PAGE(cpu_pgd)
24707 + .rept 2*NR_CPUS
24708 + .fill 512,8,0
24709 + .endr
24710 +#endif
24711 +
24712 NEXT_PAGE(level3_ident_pgt)
24713 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24714 +#ifdef CONFIG_XEN
24715 .fill 511, 8, 0
24716 +#else
24717 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24718 + .fill 510,8,0
24719 +#endif
24720 +
24721 +NEXT_PAGE(level3_vmalloc_start_pgt)
24722 + .fill 512,8,0
24723 +
24724 +NEXT_PAGE(level3_vmalloc_end_pgt)
24725 + .fill 512,8,0
24726 +
24727 +NEXT_PAGE(level3_vmemmap_pgt)
24728 + .fill L3_VMEMMAP_START,8,0
24729 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24730 +
24731 NEXT_PAGE(level2_ident_pgt)
24732 - /* Since I easily can, map the first 1G.
24733 + /* Since I easily can, map the first 2G.
24734 * Don't set NX because code runs from these pages.
24735 */
24736 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24737 -#endif
24738 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24739
24740 NEXT_PAGE(level3_kernel_pgt)
24741 .fill L3_START_KERNEL,8,0
24742 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24743 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24744 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24745
24746 +NEXT_PAGE(level2_vmemmap_pgt)
24747 + .fill 512,8,0
24748 +
24749 NEXT_PAGE(level2_kernel_pgt)
24750 /*
24751 * 512 MB kernel mapping. We spend a full page on this pagetable
24752 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24753 NEXT_PAGE(level2_fixmap_pgt)
24754 .fill 506,8,0
24755 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24756 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24757 - .fill 5,8,0
24758 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24759 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24760 + .fill 4,8,0
24761
24762 NEXT_PAGE(level1_fixmap_pgt)
24763 .fill 512,8,0
24764
24765 +NEXT_PAGE(level1_vsyscall_pgt)
24766 + .fill 512,8,0
24767 +
24768 #undef PMDS
24769
24770 - .data
24771 + .align PAGE_SIZE
24772 +ENTRY(cpu_gdt_table)
24773 + .rept NR_CPUS
24774 + .quad 0x0000000000000000 /* NULL descriptor */
24775 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24776 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24777 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24778 + .quad 0x00cffb000000ffff /* __USER32_CS */
24779 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24780 + .quad 0x00affb000000ffff /* __USER_CS */
24781 +
24782 +#ifdef CONFIG_PAX_KERNEXEC
24783 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24784 +#else
24785 + .quad 0x0 /* unused */
24786 +#endif
24787 +
24788 + .quad 0,0 /* TSS */
24789 + .quad 0,0 /* LDT */
24790 + .quad 0,0,0 /* three TLS descriptors */
24791 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24792 + /* asm/segment.h:GDT_ENTRIES must match this */
24793 +
24794 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24795 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24796 +#else
24797 + .quad 0x0 /* unused */
24798 +#endif
24799 +
24800 + /* zero the remaining page */
24801 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24802 + .endr
24803 +
24804 .align 16
24805 .globl early_gdt_descr
24806 early_gdt_descr:
24807 .word GDT_ENTRIES*8-1
24808 early_gdt_descr_base:
24809 - .quad INIT_PER_CPU_VAR(gdt_page)
24810 + .quad cpu_gdt_table
24811
24812 ENTRY(phys_base)
24813 /* This must match the first entry in level2_kernel_pgt */
24814 .quad 0x0000000000000000
24815
24816 #include "../../x86/xen/xen-head.S"
24817 -
24818 - __PAGE_ALIGNED_BSS
24819 +
24820 + .section .rodata,"a",@progbits
24821 NEXT_PAGE(empty_zero_page)
24822 .skip PAGE_SIZE
24823 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24824 index 05fd74f..c3548b1 100644
24825 --- a/arch/x86/kernel/i386_ksyms_32.c
24826 +++ b/arch/x86/kernel/i386_ksyms_32.c
24827 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24828 EXPORT_SYMBOL(cmpxchg8b_emu);
24829 #endif
24830
24831 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24832 +
24833 /* Networking helper routines. */
24834 EXPORT_SYMBOL(csum_partial_copy_generic);
24835 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24836 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24837
24838 EXPORT_SYMBOL(__get_user_1);
24839 EXPORT_SYMBOL(__get_user_2);
24840 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24841 EXPORT_SYMBOL(___preempt_schedule_context);
24842 #endif
24843 #endif
24844 +
24845 +#ifdef CONFIG_PAX_KERNEXEC
24846 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24847 +#endif
24848 +
24849 +#ifdef CONFIG_PAX_PER_CPU_PGD
24850 +EXPORT_SYMBOL(cpu_pgd);
24851 +#endif
24852 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24853 index d5dd808..b6432cf 100644
24854 --- a/arch/x86/kernel/i387.c
24855 +++ b/arch/x86/kernel/i387.c
24856 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24857 static inline bool interrupted_user_mode(void)
24858 {
24859 struct pt_regs *regs = get_irq_regs();
24860 - return regs && user_mode_vm(regs);
24861 + return regs && user_mode(regs);
24862 }
24863
24864 /*
24865 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24866 index 2e977b5..5f2c273 100644
24867 --- a/arch/x86/kernel/i8259.c
24868 +++ b/arch/x86/kernel/i8259.c
24869 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24870 static void make_8259A_irq(unsigned int irq)
24871 {
24872 disable_irq_nosync(irq);
24873 - io_apic_irqs &= ~(1<<irq);
24874 + io_apic_irqs &= ~(1UL<<irq);
24875 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24876 i8259A_chip.name);
24877 enable_irq(irq);
24878 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24879 "spurious 8259A interrupt: IRQ%d.\n", irq);
24880 spurious_irq_mask |= irqmask;
24881 }
24882 - atomic_inc(&irq_err_count);
24883 + atomic_inc_unchecked(&irq_err_count);
24884 /*
24885 * Theoretically we do not have to handle this IRQ,
24886 * but in Linux this does not cause problems and is
24887 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24888 /* (slave's support for AEOI in flat mode is to be investigated) */
24889 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24890
24891 + pax_open_kernel();
24892 if (auto_eoi)
24893 /*
24894 * In AEOI mode we just have to mask the interrupt
24895 * when acking.
24896 */
24897 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24898 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24899 else
24900 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24901 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24902 + pax_close_kernel();
24903
24904 udelay(100); /* wait for 8259A to initialize */
24905
24906 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24907 index a979b5b..1d6db75 100644
24908 --- a/arch/x86/kernel/io_delay.c
24909 +++ b/arch/x86/kernel/io_delay.c
24910 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24911 * Quirk table for systems that misbehave (lock up, etc.) if port
24912 * 0x80 is used:
24913 */
24914 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24915 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24916 {
24917 .callback = dmi_io_delay_0xed_port,
24918 .ident = "Compaq Presario V6000",
24919 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24920 index 4ddaf66..49d5c18 100644
24921 --- a/arch/x86/kernel/ioport.c
24922 +++ b/arch/x86/kernel/ioport.c
24923 @@ -6,6 +6,7 @@
24924 #include <linux/sched.h>
24925 #include <linux/kernel.h>
24926 #include <linux/capability.h>
24927 +#include <linux/security.h>
24928 #include <linux/errno.h>
24929 #include <linux/types.h>
24930 #include <linux/ioport.h>
24931 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24932 return -EINVAL;
24933 if (turn_on && !capable(CAP_SYS_RAWIO))
24934 return -EPERM;
24935 +#ifdef CONFIG_GRKERNSEC_IO
24936 + if (turn_on && grsec_disable_privio) {
24937 + gr_handle_ioperm();
24938 + return -ENODEV;
24939 + }
24940 +#endif
24941
24942 /*
24943 * If it's the first ioperm() call in this thread's lifetime, set the
24944 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24945 * because the ->io_bitmap_max value must match the bitmap
24946 * contents:
24947 */
24948 - tss = &per_cpu(init_tss, get_cpu());
24949 + tss = init_tss + get_cpu();
24950
24951 if (turn_on)
24952 bitmap_clear(t->io_bitmap_ptr, from, num);
24953 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24954 if (level > old) {
24955 if (!capable(CAP_SYS_RAWIO))
24956 return -EPERM;
24957 +#ifdef CONFIG_GRKERNSEC_IO
24958 + if (grsec_disable_privio) {
24959 + gr_handle_iopl();
24960 + return -ENODEV;
24961 + }
24962 +#endif
24963 }
24964 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24965 t->iopl = level << 12;
24966 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24967 index 11ccfb0..ec1e46f 100644
24968 --- a/arch/x86/kernel/irq.c
24969 +++ b/arch/x86/kernel/irq.c
24970 @@ -22,7 +22,7 @@
24971 #define CREATE_TRACE_POINTS
24972 #include <asm/trace/irq_vectors.h>
24973
24974 -atomic_t irq_err_count;
24975 +atomic_unchecked_t irq_err_count;
24976
24977 /* Function pointer for generic interrupt vector handling */
24978 void (*x86_platform_ipi_callback)(void) = NULL;
24979 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24980 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
24981 seq_printf(p, " Hypervisor callback interrupts\n");
24982 #endif
24983 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24984 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24985 #if defined(CONFIG_X86_IO_APIC)
24986 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24987 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24988 #endif
24989 return 0;
24990 }
24991 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24992
24993 u64 arch_irq_stat(void)
24994 {
24995 - u64 sum = atomic_read(&irq_err_count);
24996 + u64 sum = atomic_read_unchecked(&irq_err_count);
24997 return sum;
24998 }
24999
25000 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25001 index 63ce838..2ea3e06 100644
25002 --- a/arch/x86/kernel/irq_32.c
25003 +++ b/arch/x86/kernel/irq_32.c
25004 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25005
25006 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25007
25008 +extern void gr_handle_kernel_exploit(void);
25009 +
25010 int sysctl_panic_on_stackoverflow __read_mostly;
25011
25012 /* Debugging check for stack overflow: is there less than 1KB free? */
25013 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25014 __asm__ __volatile__("andl %%esp,%0" :
25015 "=r" (sp) : "0" (THREAD_SIZE - 1));
25016
25017 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25018 + return sp < STACK_WARN;
25019 }
25020
25021 static void print_stack_overflow(void)
25022 {
25023 printk(KERN_WARNING "low stack detected by irq handler\n");
25024 dump_stack();
25025 + gr_handle_kernel_exploit();
25026 if (sysctl_panic_on_stackoverflow)
25027 panic("low stack detected by irq handler - check messages\n");
25028 }
25029 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25030 static inline int
25031 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25032 {
25033 - struct irq_stack *curstk, *irqstk;
25034 + struct irq_stack *irqstk;
25035 u32 *isp, *prev_esp, arg1, arg2;
25036
25037 - curstk = (struct irq_stack *) current_stack();
25038 irqstk = __this_cpu_read(hardirq_stack);
25039
25040 /*
25041 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25042 * handler) we can't do that and just have to keep using the
25043 * current stack (which is the irq stack already after all)
25044 */
25045 - if (unlikely(curstk == irqstk))
25046 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25047 return 0;
25048
25049 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25050 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25051
25052 /* Save the next esp at the bottom of the stack */
25053 prev_esp = (u32 *)irqstk;
25054 *prev_esp = current_stack_pointer;
25055
25056 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25057 + __set_fs(MAKE_MM_SEG(0));
25058 +#endif
25059 +
25060 if (unlikely(overflow))
25061 call_on_stack(print_stack_overflow, isp);
25062
25063 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25064 : "0" (irq), "1" (desc), "2" (isp),
25065 "D" (desc->handle_irq)
25066 : "memory", "cc", "ecx");
25067 +
25068 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25069 + __set_fs(current_thread_info()->addr_limit);
25070 +#endif
25071 +
25072 return 1;
25073 }
25074
25075 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25076 */
25077 void irq_ctx_init(int cpu)
25078 {
25079 - struct irq_stack *irqstk;
25080 -
25081 if (per_cpu(hardirq_stack, cpu))
25082 return;
25083
25084 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25085 - THREADINFO_GFP,
25086 - THREAD_SIZE_ORDER));
25087 - per_cpu(hardirq_stack, cpu) = irqstk;
25088 -
25089 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25090 - THREADINFO_GFP,
25091 - THREAD_SIZE_ORDER));
25092 - per_cpu(softirq_stack, cpu) = irqstk;
25093 -
25094 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25095 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25096 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25097 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25098 }
25099
25100 void do_softirq_own_stack(void)
25101 {
25102 - struct thread_info *curstk;
25103 struct irq_stack *irqstk;
25104 u32 *isp, *prev_esp;
25105
25106 - curstk = current_stack();
25107 irqstk = __this_cpu_read(softirq_stack);
25108
25109 /* build the stack frame on the softirq stack */
25110 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25111 prev_esp = (u32 *)irqstk;
25112 *prev_esp = current_stack_pointer;
25113
25114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25115 + __set_fs(MAKE_MM_SEG(0));
25116 +#endif
25117 +
25118 call_on_stack(__do_softirq, isp);
25119 +
25120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25121 + __set_fs(current_thread_info()->addr_limit);
25122 +#endif
25123 +
25124 }
25125
25126 bool handle_irq(unsigned irq, struct pt_regs *regs)
25127 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25128 if (unlikely(!desc))
25129 return false;
25130
25131 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25132 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25133 if (unlikely(overflow))
25134 print_stack_overflow();
25135 desc->handle_irq(irq, desc);
25136 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25137 index 4d1c746..55a22d6 100644
25138 --- a/arch/x86/kernel/irq_64.c
25139 +++ b/arch/x86/kernel/irq_64.c
25140 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25141 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25142 EXPORT_PER_CPU_SYMBOL(irq_regs);
25143
25144 +extern void gr_handle_kernel_exploit(void);
25145 +
25146 int sysctl_panic_on_stackoverflow;
25147
25148 /*
25149 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25150 u64 estack_top, estack_bottom;
25151 u64 curbase = (u64)task_stack_page(current);
25152
25153 - if (user_mode_vm(regs))
25154 + if (user_mode(regs))
25155 return;
25156
25157 if (regs->sp >= curbase + sizeof(struct thread_info) +
25158 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25159 irq_stack_top, irq_stack_bottom,
25160 estack_top, estack_bottom);
25161
25162 + gr_handle_kernel_exploit();
25163 +
25164 if (sysctl_panic_on_stackoverflow)
25165 panic("low stack detected by irq handler - check messages\n");
25166 #endif
25167 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25168 index 26d5a55..a01160a 100644
25169 --- a/arch/x86/kernel/jump_label.c
25170 +++ b/arch/x86/kernel/jump_label.c
25171 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25172 * Jump label is enabled for the first time.
25173 * So we expect a default_nop...
25174 */
25175 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25176 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25177 != 0))
25178 bug_at((void *)entry->code, __LINE__);
25179 } else {
25180 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25181 * ...otherwise expect an ideal_nop. Otherwise
25182 * something went horribly wrong.
25183 */
25184 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25185 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25186 != 0))
25187 bug_at((void *)entry->code, __LINE__);
25188 }
25189 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25190 * are converting the default nop to the ideal nop.
25191 */
25192 if (init) {
25193 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25194 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25195 bug_at((void *)entry->code, __LINE__);
25196 } else {
25197 code.jump = 0xe9;
25198 code.offset = entry->target -
25199 (entry->code + JUMP_LABEL_NOP_SIZE);
25200 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25201 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25202 bug_at((void *)entry->code, __LINE__);
25203 }
25204 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25205 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25206 index 7ec1d5f..5a7d130 100644
25207 --- a/arch/x86/kernel/kgdb.c
25208 +++ b/arch/x86/kernel/kgdb.c
25209 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25210 #ifdef CONFIG_X86_32
25211 switch (regno) {
25212 case GDB_SS:
25213 - if (!user_mode_vm(regs))
25214 + if (!user_mode(regs))
25215 *(unsigned long *)mem = __KERNEL_DS;
25216 break;
25217 case GDB_SP:
25218 - if (!user_mode_vm(regs))
25219 + if (!user_mode(regs))
25220 *(unsigned long *)mem = kernel_stack_pointer(regs);
25221 break;
25222 case GDB_GS:
25223 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25224 bp->attr.bp_addr = breakinfo[breakno].addr;
25225 bp->attr.bp_len = breakinfo[breakno].len;
25226 bp->attr.bp_type = breakinfo[breakno].type;
25227 - info->address = breakinfo[breakno].addr;
25228 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25229 + info->address = ktla_ktva(breakinfo[breakno].addr);
25230 + else
25231 + info->address = breakinfo[breakno].addr;
25232 info->len = breakinfo[breakno].len;
25233 info->type = breakinfo[breakno].type;
25234 val = arch_install_hw_breakpoint(bp);
25235 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25236 case 'k':
25237 /* clear the trace bit */
25238 linux_regs->flags &= ~X86_EFLAGS_TF;
25239 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25240 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25241
25242 /* set the trace bit if we're stepping */
25243 if (remcomInBuffer[0] == 's') {
25244 linux_regs->flags |= X86_EFLAGS_TF;
25245 - atomic_set(&kgdb_cpu_doing_single_step,
25246 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25247 raw_smp_processor_id());
25248 }
25249
25250 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25251
25252 switch (cmd) {
25253 case DIE_DEBUG:
25254 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25255 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25256 if (user_mode(regs))
25257 return single_step_cont(regs, args);
25258 break;
25259 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25260 #endif /* CONFIG_DEBUG_RODATA */
25261
25262 bpt->type = BP_BREAKPOINT;
25263 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25264 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25265 BREAK_INSTR_SIZE);
25266 if (err)
25267 return err;
25268 - err = probe_kernel_write((char *)bpt->bpt_addr,
25269 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25270 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25271 #ifdef CONFIG_DEBUG_RODATA
25272 if (!err)
25273 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25274 return -EBUSY;
25275 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25276 BREAK_INSTR_SIZE);
25277 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25278 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25279 if (err)
25280 return err;
25281 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25282 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25283 if (mutex_is_locked(&text_mutex))
25284 goto knl_write;
25285 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25286 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25287 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25288 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25289 goto knl_write;
25290 return err;
25291 knl_write:
25292 #endif /* CONFIG_DEBUG_RODATA */
25293 - return probe_kernel_write((char *)bpt->bpt_addr,
25294 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25295 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25296 }
25297
25298 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25299 index 61b17dc..784bfe9 100644
25300 --- a/arch/x86/kernel/kprobes/core.c
25301 +++ b/arch/x86/kernel/kprobes/core.c
25302 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25303 s32 raddr;
25304 } __packed *insn;
25305
25306 - insn = (struct __arch_relative_insn *)from;
25307 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25308 +
25309 + pax_open_kernel();
25310 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25311 insn->op = op;
25312 + pax_close_kernel();
25313 }
25314
25315 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25316 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25317 kprobe_opcode_t opcode;
25318 kprobe_opcode_t *orig_opcodes = opcodes;
25319
25320 - if (search_exception_tables((unsigned long)opcodes))
25321 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25322 return 0; /* Page fault may occur on this address. */
25323
25324 retry:
25325 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25326 * for the first byte, we can recover the original instruction
25327 * from it and kp->opcode.
25328 */
25329 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25330 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25331 buf[0] = kp->opcode;
25332 - return (unsigned long)buf;
25333 + return ktva_ktla((unsigned long)buf);
25334 }
25335
25336 /*
25337 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25338 /* Another subsystem puts a breakpoint, failed to recover */
25339 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25340 return 0;
25341 + pax_open_kernel();
25342 memcpy(dest, insn.kaddr, insn.length);
25343 + pax_close_kernel();
25344
25345 #ifdef CONFIG_X86_64
25346 if (insn_rip_relative(&insn)) {
25347 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25348 return 0;
25349 }
25350 disp = (u8 *) dest + insn_offset_displacement(&insn);
25351 + pax_open_kernel();
25352 *(s32 *) disp = (s32) newdisp;
25353 + pax_close_kernel();
25354 }
25355 #endif
25356 return insn.length;
25357 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25358 * nor set current_kprobe, because it doesn't use single
25359 * stepping.
25360 */
25361 - regs->ip = (unsigned long)p->ainsn.insn;
25362 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25363 preempt_enable_no_resched();
25364 return;
25365 }
25366 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25367 regs->flags &= ~X86_EFLAGS_IF;
25368 /* single step inline if the instruction is an int3 */
25369 if (p->opcode == BREAKPOINT_INSTRUCTION)
25370 - regs->ip = (unsigned long)p->addr;
25371 + regs->ip = ktla_ktva((unsigned long)p->addr);
25372 else
25373 - regs->ip = (unsigned long)p->ainsn.insn;
25374 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25375 }
25376
25377 /*
25378 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25379 setup_singlestep(p, regs, kcb, 0);
25380 return 1;
25381 }
25382 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25383 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25384 /*
25385 * The breakpoint instruction was removed right
25386 * after we hit it. Another cpu has removed
25387 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25388 " movq %rax, 152(%rsp)\n"
25389 RESTORE_REGS_STRING
25390 " popfq\n"
25391 +#ifdef KERNEXEC_PLUGIN
25392 + " btsq $63,(%rsp)\n"
25393 +#endif
25394 #else
25395 " pushf\n"
25396 SAVE_REGS_STRING
25397 @@ -779,7 +789,7 @@ static void __kprobes
25398 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25399 {
25400 unsigned long *tos = stack_addr(regs);
25401 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25402 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25403 unsigned long orig_ip = (unsigned long)p->addr;
25404 kprobe_opcode_t *insn = p->ainsn.insn;
25405
25406 @@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25407 struct die_args *args = data;
25408 int ret = NOTIFY_DONE;
25409
25410 - if (args->regs && user_mode_vm(args->regs))
25411 + if (args->regs && user_mode(args->regs))
25412 return ret;
25413
25414 switch (val) {
25415 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25416 index 898160b..758cde8 100644
25417 --- a/arch/x86/kernel/kprobes/opt.c
25418 +++ b/arch/x86/kernel/kprobes/opt.c
25419 @@ -79,6 +79,7 @@ found:
25420 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25421 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25422 {
25423 + pax_open_kernel();
25424 #ifdef CONFIG_X86_64
25425 *addr++ = 0x48;
25426 *addr++ = 0xbf;
25427 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25428 *addr++ = 0xb8;
25429 #endif
25430 *(unsigned long *)addr = val;
25431 + pax_close_kernel();
25432 }
25433
25434 asm (
25435 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25436 * Verify if the address gap is in 2GB range, because this uses
25437 * a relative jump.
25438 */
25439 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25440 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25441 if (abs(rel) > 0x7fffffff)
25442 return -ERANGE;
25443
25444 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25445 op->optinsn.size = ret;
25446
25447 /* Copy arch-dep-instance from template */
25448 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25449 + pax_open_kernel();
25450 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25451 + pax_close_kernel();
25452
25453 /* Set probe information */
25454 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25455
25456 /* Set probe function call */
25457 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25458 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25459
25460 /* Set returning jmp instruction at the tail of out-of-line buffer */
25461 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25462 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25463 (u8 *)op->kp.addr + op->optinsn.size);
25464
25465 flush_icache_range((unsigned long) buf,
25466 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25467 WARN_ON(kprobe_disabled(&op->kp));
25468
25469 /* Backup instructions which will be replaced by jump address */
25470 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25471 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25472 RELATIVE_ADDR_SIZE);
25473
25474 insn_buf[0] = RELATIVEJUMP_OPCODE;
25475 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25476 /* This kprobe is really able to run optimized path. */
25477 op = container_of(p, struct optimized_kprobe, kp);
25478 /* Detour through copied instructions */
25479 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25480 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25481 if (!reenter)
25482 reset_current_kprobe();
25483 preempt_enable_no_resched();
25484 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25485 index c2bedae..25e7ab60 100644
25486 --- a/arch/x86/kernel/ksysfs.c
25487 +++ b/arch/x86/kernel/ksysfs.c
25488 @@ -184,7 +184,7 @@ out:
25489
25490 static struct kobj_attribute type_attr = __ATTR_RO(type);
25491
25492 -static struct bin_attribute data_attr = {
25493 +static bin_attribute_no_const data_attr __read_only = {
25494 .attr = {
25495 .name = "data",
25496 .mode = S_IRUGO,
25497 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25498 index dcbbaa1..81ae763 100644
25499 --- a/arch/x86/kernel/ldt.c
25500 +++ b/arch/x86/kernel/ldt.c
25501 @@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25502 if (reload) {
25503 #ifdef CONFIG_SMP
25504 preempt_disable();
25505 - load_LDT(pc);
25506 + load_LDT_nolock(pc);
25507 if (!cpumask_equal(mm_cpumask(current->mm),
25508 cpumask_of(smp_processor_id())))
25509 smp_call_function(flush_ldt, current->mm, 1);
25510 preempt_enable();
25511 #else
25512 - load_LDT(pc);
25513 + load_LDT_nolock(pc);
25514 #endif
25515 }
25516 if (oldsize) {
25517 @@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25518 return err;
25519
25520 for (i = 0; i < old->size; i++)
25521 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25522 + write_ldt_entry(new->ldt, i, old->ldt + i);
25523 return 0;
25524 }
25525
25526 @@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25527 retval = copy_ldt(&mm->context, &old_mm->context);
25528 mutex_unlock(&old_mm->context.lock);
25529 }
25530 +
25531 + if (tsk == current) {
25532 + mm->context.vdso = 0;
25533 +
25534 +#ifdef CONFIG_X86_32
25535 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25536 + mm->context.user_cs_base = 0UL;
25537 + mm->context.user_cs_limit = ~0UL;
25538 +
25539 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25540 + cpus_clear(mm->context.cpu_user_cs_mask);
25541 +#endif
25542 +
25543 +#endif
25544 +#endif
25545 +
25546 + }
25547 +
25548 return retval;
25549 }
25550
25551 @@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25552 }
25553 }
25554
25555 +#ifdef CONFIG_PAX_SEGMEXEC
25556 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25557 + error = -EINVAL;
25558 + goto out_unlock;
25559 + }
25560 +#endif
25561 +
25562 /*
25563 * On x86-64 we do not support 16-bit segments due to
25564 * IRET leaking the high bits of the kernel stack address.
25565 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25566 index 1667b1d..16492c5 100644
25567 --- a/arch/x86/kernel/machine_kexec_32.c
25568 +++ b/arch/x86/kernel/machine_kexec_32.c
25569 @@ -25,7 +25,7 @@
25570 #include <asm/cacheflush.h>
25571 #include <asm/debugreg.h>
25572
25573 -static void set_idt(void *newidt, __u16 limit)
25574 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25575 {
25576 struct desc_ptr curidt;
25577
25578 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25579 }
25580
25581
25582 -static void set_gdt(void *newgdt, __u16 limit)
25583 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25584 {
25585 struct desc_ptr curgdt;
25586
25587 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25588 }
25589
25590 control_page = page_address(image->control_code_page);
25591 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25592 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25593
25594 relocate_kernel_ptr = control_page;
25595 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25596 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25597 index e69f988..da078ea 100644
25598 --- a/arch/x86/kernel/module.c
25599 +++ b/arch/x86/kernel/module.c
25600 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25601 }
25602 #endif
25603
25604 -void *module_alloc(unsigned long size)
25605 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25606 {
25607 - if (PAGE_ALIGN(size) > MODULES_LEN)
25608 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25609 return NULL;
25610 return __vmalloc_node_range(size, 1,
25611 MODULES_VADDR + get_module_load_offset(),
25612 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25613 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25614 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25615 + prot, NUMA_NO_NODE,
25616 __builtin_return_address(0));
25617 }
25618
25619 +void *module_alloc(unsigned long size)
25620 +{
25621 +
25622 +#ifdef CONFIG_PAX_KERNEXEC
25623 + return __module_alloc(size, PAGE_KERNEL);
25624 +#else
25625 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25626 +#endif
25627 +
25628 +}
25629 +
25630 +#ifdef CONFIG_PAX_KERNEXEC
25631 +#ifdef CONFIG_X86_32
25632 +void *module_alloc_exec(unsigned long size)
25633 +{
25634 + struct vm_struct *area;
25635 +
25636 + if (size == 0)
25637 + return NULL;
25638 +
25639 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25640 +return area ? area->addr : NULL;
25641 +}
25642 +EXPORT_SYMBOL(module_alloc_exec);
25643 +
25644 +void module_free_exec(struct module *mod, void *module_region)
25645 +{
25646 + vunmap(module_region);
25647 +}
25648 +EXPORT_SYMBOL(module_free_exec);
25649 +#else
25650 +void module_free_exec(struct module *mod, void *module_region)
25651 +{
25652 + module_free(mod, module_region);
25653 +}
25654 +EXPORT_SYMBOL(module_free_exec);
25655 +
25656 +void *module_alloc_exec(unsigned long size)
25657 +{
25658 + return __module_alloc(size, PAGE_KERNEL_RX);
25659 +}
25660 +EXPORT_SYMBOL(module_alloc_exec);
25661 +#endif
25662 +#endif
25663 +
25664 #ifdef CONFIG_X86_32
25665 int apply_relocate(Elf32_Shdr *sechdrs,
25666 const char *strtab,
25667 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25668 unsigned int i;
25669 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25670 Elf32_Sym *sym;
25671 - uint32_t *location;
25672 + uint32_t *plocation, location;
25673
25674 DEBUGP("Applying relocate section %u to %u\n",
25675 relsec, sechdrs[relsec].sh_info);
25676 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25677 /* This is where to make the change */
25678 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25679 - + rel[i].r_offset;
25680 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25681 + location = (uint32_t)plocation;
25682 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25683 + plocation = ktla_ktva((void *)plocation);
25684 /* This is the symbol it is referring to. Note that all
25685 undefined symbols have been resolved. */
25686 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25687 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25688 switch (ELF32_R_TYPE(rel[i].r_info)) {
25689 case R_386_32:
25690 /* We add the value into the location given */
25691 - *location += sym->st_value;
25692 + pax_open_kernel();
25693 + *plocation += sym->st_value;
25694 + pax_close_kernel();
25695 break;
25696 case R_386_PC32:
25697 /* Add the value, subtract its position */
25698 - *location += sym->st_value - (uint32_t)location;
25699 + pax_open_kernel();
25700 + *plocation += sym->st_value - location;
25701 + pax_close_kernel();
25702 break;
25703 default:
25704 pr_err("%s: Unknown relocation: %u\n",
25705 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25706 case R_X86_64_NONE:
25707 break;
25708 case R_X86_64_64:
25709 + pax_open_kernel();
25710 *(u64 *)loc = val;
25711 + pax_close_kernel();
25712 break;
25713 case R_X86_64_32:
25714 + pax_open_kernel();
25715 *(u32 *)loc = val;
25716 + pax_close_kernel();
25717 if (val != *(u32 *)loc)
25718 goto overflow;
25719 break;
25720 case R_X86_64_32S:
25721 + pax_open_kernel();
25722 *(s32 *)loc = val;
25723 + pax_close_kernel();
25724 if ((s64)val != *(s32 *)loc)
25725 goto overflow;
25726 break;
25727 case R_X86_64_PC32:
25728 val -= (u64)loc;
25729 + pax_open_kernel();
25730 *(u32 *)loc = val;
25731 + pax_close_kernel();
25732 +
25733 #if 0
25734 if ((s64)val != *(s32 *)loc)
25735 goto overflow;
25736 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25737 index c9603ac..9f88728 100644
25738 --- a/arch/x86/kernel/msr.c
25739 +++ b/arch/x86/kernel/msr.c
25740 @@ -37,6 +37,7 @@
25741 #include <linux/notifier.h>
25742 #include <linux/uaccess.h>
25743 #include <linux/gfp.h>
25744 +#include <linux/grsecurity.h>
25745
25746 #include <asm/processor.h>
25747 #include <asm/msr.h>
25748 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25749 int err = 0;
25750 ssize_t bytes = 0;
25751
25752 +#ifdef CONFIG_GRKERNSEC_KMEM
25753 + gr_handle_msr_write();
25754 + return -EPERM;
25755 +#endif
25756 +
25757 if (count % 8)
25758 return -EINVAL; /* Invalid chunk size */
25759
25760 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25761 err = -EBADF;
25762 break;
25763 }
25764 +#ifdef CONFIG_GRKERNSEC_KMEM
25765 + gr_handle_msr_write();
25766 + return -EPERM;
25767 +#endif
25768 if (copy_from_user(&regs, uregs, sizeof regs)) {
25769 err = -EFAULT;
25770 break;
25771 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25772 return notifier_from_errno(err);
25773 }
25774
25775 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25776 +static struct notifier_block msr_class_cpu_notifier = {
25777 .notifier_call = msr_class_cpu_callback,
25778 };
25779
25780 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25781 index b4872b9..5bf0684 100644
25782 --- a/arch/x86/kernel/nmi.c
25783 +++ b/arch/x86/kernel/nmi.c
25784 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25785
25786 static void nmi_max_handler(struct irq_work *w)
25787 {
25788 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25789 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25790 int remainder_ns, decimal_msecs;
25791 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25792 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25793
25794 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25795 decimal_msecs = remainder_ns / 1000;
25796
25797 printk_ratelimited(KERN_INFO
25798 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25799 - a->handler, whole_msecs, decimal_msecs);
25800 + n->action->handler, whole_msecs, decimal_msecs);
25801 }
25802
25803 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25804 @@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25805 delta = sched_clock() - delta;
25806 trace_nmi_handler(a->handler, (int)delta, thishandled);
25807
25808 - if (delta < nmi_longest_ns || delta < a->max_duration)
25809 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
25810 continue;
25811
25812 - a->max_duration = delta;
25813 - irq_work_queue(&a->irq_work);
25814 + a->work->max_duration = delta;
25815 + irq_work_queue(&a->work->irq_work);
25816 }
25817
25818 rcu_read_unlock();
25819 @@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25820 return handled;
25821 }
25822
25823 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25824 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25825 {
25826 struct nmi_desc *desc = nmi_to_desc(type);
25827 unsigned long flags;
25828 @@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25829 if (!action->handler)
25830 return -EINVAL;
25831
25832 - init_irq_work(&action->irq_work, nmi_max_handler);
25833 + action->work->action = action;
25834 + init_irq_work(&action->work->irq_work, nmi_max_handler);
25835
25836 spin_lock_irqsave(&desc->lock, flags);
25837
25838 @@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25839 * event confuses some handlers (kdump uses this flag)
25840 */
25841 if (action->flags & NMI_FLAG_FIRST)
25842 - list_add_rcu(&action->list, &desc->head);
25843 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25844 else
25845 - list_add_tail_rcu(&action->list, &desc->head);
25846 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25847
25848 spin_unlock_irqrestore(&desc->lock, flags);
25849 return 0;
25850 @@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25851 if (!strcmp(n->name, name)) {
25852 WARN(in_nmi(),
25853 "Trying to free NMI (%s) from NMI context!\n", n->name);
25854 - list_del_rcu(&n->list);
25855 + pax_list_del_rcu((struct list_head *)&n->list);
25856 break;
25857 }
25858 }
25859 @@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25860 dotraplinkage notrace __kprobes void
25861 do_nmi(struct pt_regs *regs, long error_code)
25862 {
25863 +
25864 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25865 + if (!user_mode(regs)) {
25866 + unsigned long cs = regs->cs & 0xFFFF;
25867 + unsigned long ip = ktva_ktla(regs->ip);
25868 +
25869 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25870 + regs->ip = ip;
25871 + }
25872 +#endif
25873 +
25874 nmi_nesting_preprocess(regs);
25875
25876 nmi_enter();
25877 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25878 index 6d9582e..f746287 100644
25879 --- a/arch/x86/kernel/nmi_selftest.c
25880 +++ b/arch/x86/kernel/nmi_selftest.c
25881 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25882 {
25883 /* trap all the unknown NMIs we may generate */
25884 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25885 - __initdata);
25886 + __initconst);
25887 }
25888
25889 static void __init cleanup_nmi_testsuite(void)
25890 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25891 unsigned long timeout;
25892
25893 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25894 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25895 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25896 nmi_fail = FAILURE;
25897 return;
25898 }
25899 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25900 index bbb6c73..24a58ef 100644
25901 --- a/arch/x86/kernel/paravirt-spinlocks.c
25902 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25903 @@ -8,7 +8,7 @@
25904
25905 #include <asm/paravirt.h>
25906
25907 -struct pv_lock_ops pv_lock_ops = {
25908 +struct pv_lock_ops pv_lock_ops __read_only = {
25909 #ifdef CONFIG_SMP
25910 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25911 .unlock_kick = paravirt_nop,
25912 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25913 index 1b10af8..45bfbec 100644
25914 --- a/arch/x86/kernel/paravirt.c
25915 +++ b/arch/x86/kernel/paravirt.c
25916 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25917 {
25918 return x;
25919 }
25920 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25921 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25922 +#endif
25923
25924 void __init default_banner(void)
25925 {
25926 @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25927
25928 if (opfunc == NULL)
25929 /* If there's no function, patch it with a ud2a (BUG) */
25930 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25931 - else if (opfunc == _paravirt_nop)
25932 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25933 + else if (opfunc == (void *)_paravirt_nop)
25934 /* If the operation is a nop, then nop the callsite */
25935 ret = paravirt_patch_nop();
25936
25937 /* identity functions just return their single argument */
25938 - else if (opfunc == _paravirt_ident_32)
25939 + else if (opfunc == (void *)_paravirt_ident_32)
25940 ret = paravirt_patch_ident_32(insnbuf, len);
25941 - else if (opfunc == _paravirt_ident_64)
25942 + else if (opfunc == (void *)_paravirt_ident_64)
25943 ret = paravirt_patch_ident_64(insnbuf, len);
25944 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25945 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25946 + ret = paravirt_patch_ident_64(insnbuf, len);
25947 +#endif
25948
25949 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25950 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25951 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25952 if (insn_len > len || start == NULL)
25953 insn_len = len;
25954 else
25955 - memcpy(insnbuf, start, insn_len);
25956 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25957
25958 return insn_len;
25959 }
25960 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25961 return this_cpu_read(paravirt_lazy_mode);
25962 }
25963
25964 -struct pv_info pv_info = {
25965 +struct pv_info pv_info __read_only = {
25966 .name = "bare hardware",
25967 .paravirt_enabled = 0,
25968 .kernel_rpl = 0,
25969 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25970 #endif
25971 };
25972
25973 -struct pv_init_ops pv_init_ops = {
25974 +struct pv_init_ops pv_init_ops __read_only = {
25975 .patch = native_patch,
25976 };
25977
25978 -struct pv_time_ops pv_time_ops = {
25979 +struct pv_time_ops pv_time_ops __read_only = {
25980 .sched_clock = native_sched_clock,
25981 .steal_clock = native_steal_clock,
25982 };
25983
25984 -__visible struct pv_irq_ops pv_irq_ops = {
25985 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25986 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25987 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25988 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25989 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25990 #endif
25991 };
25992
25993 -__visible struct pv_cpu_ops pv_cpu_ops = {
25994 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25995 .cpuid = native_cpuid,
25996 .get_debugreg = native_get_debugreg,
25997 .set_debugreg = native_set_debugreg,
25998 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25999 .end_context_switch = paravirt_nop,
26000 };
26001
26002 -struct pv_apic_ops pv_apic_ops = {
26003 +struct pv_apic_ops pv_apic_ops __read_only= {
26004 #ifdef CONFIG_X86_LOCAL_APIC
26005 .startup_ipi_hook = paravirt_nop,
26006 #endif
26007 };
26008
26009 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26010 +#ifdef CONFIG_X86_32
26011 +#ifdef CONFIG_X86_PAE
26012 +/* 64-bit pagetable entries */
26013 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26014 +#else
26015 /* 32-bit pagetable entries */
26016 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26017 +#endif
26018 #else
26019 /* 64-bit pagetable entries */
26020 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26021 #endif
26022
26023 -struct pv_mmu_ops pv_mmu_ops = {
26024 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26025
26026 .read_cr2 = native_read_cr2,
26027 .write_cr2 = native_write_cr2,
26028 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26029 .make_pud = PTE_IDENT,
26030
26031 .set_pgd = native_set_pgd,
26032 + .set_pgd_batched = native_set_pgd_batched,
26033 #endif
26034 #endif /* PAGETABLE_LEVELS >= 3 */
26035
26036 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26037 },
26038
26039 .set_fixmap = native_set_fixmap,
26040 +
26041 +#ifdef CONFIG_PAX_KERNEXEC
26042 + .pax_open_kernel = native_pax_open_kernel,
26043 + .pax_close_kernel = native_pax_close_kernel,
26044 +#endif
26045 +
26046 };
26047
26048 EXPORT_SYMBOL_GPL(pv_time_ops);
26049 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26050 index 0497f71..7186c0d 100644
26051 --- a/arch/x86/kernel/pci-calgary_64.c
26052 +++ b/arch/x86/kernel/pci-calgary_64.c
26053 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26054 tce_space = be64_to_cpu(readq(target));
26055 tce_space = tce_space & TAR_SW_BITS;
26056
26057 - tce_space = tce_space & (~specified_table_size);
26058 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26059 info->tce_space = (u64 *)__va(tce_space);
26060 }
26061 }
26062 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26063 index 35ccf75..7a15747 100644
26064 --- a/arch/x86/kernel/pci-iommu_table.c
26065 +++ b/arch/x86/kernel/pci-iommu_table.c
26066 @@ -2,7 +2,7 @@
26067 #include <asm/iommu_table.h>
26068 #include <linux/string.h>
26069 #include <linux/kallsyms.h>
26070 -
26071 +#include <linux/sched.h>
26072
26073 #define DEBUG 1
26074
26075 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26076 index 6c483ba..d10ce2f 100644
26077 --- a/arch/x86/kernel/pci-swiotlb.c
26078 +++ b/arch/x86/kernel/pci-swiotlb.c
26079 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26080 void *vaddr, dma_addr_t dma_addr,
26081 struct dma_attrs *attrs)
26082 {
26083 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26084 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26085 }
26086
26087 static struct dma_map_ops swiotlb_dma_ops = {
26088 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26089 index ca7f0d5..8996469 100644
26090 --- a/arch/x86/kernel/preempt.S
26091 +++ b/arch/x86/kernel/preempt.S
26092 @@ -3,12 +3,14 @@
26093 #include <asm/dwarf2.h>
26094 #include <asm/asm.h>
26095 #include <asm/calling.h>
26096 +#include <asm/alternative-asm.h>
26097
26098 ENTRY(___preempt_schedule)
26099 CFI_STARTPROC
26100 SAVE_ALL
26101 call preempt_schedule
26102 RESTORE_ALL
26103 + pax_force_retaddr
26104 ret
26105 CFI_ENDPROC
26106
26107 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26108 SAVE_ALL
26109 call preempt_schedule_context
26110 RESTORE_ALL
26111 + pax_force_retaddr
26112 ret
26113 CFI_ENDPROC
26114
26115 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26116 index 4505e2a..ae28b0d 100644
26117 --- a/arch/x86/kernel/process.c
26118 +++ b/arch/x86/kernel/process.c
26119 @@ -36,7 +36,8 @@
26120 * section. Since TSS's are completely CPU-local, we want them
26121 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26122 */
26123 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26124 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26125 +EXPORT_SYMBOL(init_tss);
26126
26127 #ifdef CONFIG_X86_64
26128 static DEFINE_PER_CPU(unsigned char, is_idle);
26129 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26130 task_xstate_cachep =
26131 kmem_cache_create("task_xstate", xstate_size,
26132 __alignof__(union thread_xstate),
26133 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26134 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26135 }
26136
26137 /*
26138 @@ -105,7 +106,7 @@ void exit_thread(void)
26139 unsigned long *bp = t->io_bitmap_ptr;
26140
26141 if (bp) {
26142 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26143 + struct tss_struct *tss = init_tss + get_cpu();
26144
26145 t->io_bitmap_ptr = NULL;
26146 clear_thread_flag(TIF_IO_BITMAP);
26147 @@ -125,6 +126,9 @@ void flush_thread(void)
26148 {
26149 struct task_struct *tsk = current;
26150
26151 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26152 + loadsegment(gs, 0);
26153 +#endif
26154 flush_ptrace_hw_breakpoint(tsk);
26155 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26156 drop_init_fpu(tsk);
26157 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26158 void exit_idle(void)
26159 {
26160 /* idle loop has pid 0 */
26161 - if (current->pid)
26162 + if (task_pid_nr(current))
26163 return;
26164 __exit_idle();
26165 }
26166 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26167 return ret;
26168 }
26169 #endif
26170 -void stop_this_cpu(void *dummy)
26171 +__noreturn void stop_this_cpu(void *dummy)
26172 {
26173 local_irq_disable();
26174 /*
26175 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26176 }
26177 early_param("idle", idle_setup);
26178
26179 -unsigned long arch_align_stack(unsigned long sp)
26180 +#ifdef CONFIG_PAX_RANDKSTACK
26181 +void pax_randomize_kstack(struct pt_regs *regs)
26182 {
26183 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26184 - sp -= get_random_int() % 8192;
26185 - return sp & ~0xf;
26186 -}
26187 + struct thread_struct *thread = &current->thread;
26188 + unsigned long time;
26189
26190 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26191 -{
26192 - unsigned long range_end = mm->brk + 0x02000000;
26193 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26194 -}
26195 + if (!randomize_va_space)
26196 + return;
26197 +
26198 + if (v8086_mode(regs))
26199 + return;
26200
26201 + rdtscl(time);
26202 +
26203 + /* P4 seems to return a 0 LSB, ignore it */
26204 +#ifdef CONFIG_MPENTIUM4
26205 + time &= 0x3EUL;
26206 + time <<= 2;
26207 +#elif defined(CONFIG_X86_64)
26208 + time &= 0xFUL;
26209 + time <<= 4;
26210 +#else
26211 + time &= 0x1FUL;
26212 + time <<= 3;
26213 +#endif
26214 +
26215 + thread->sp0 ^= time;
26216 + load_sp0(init_tss + smp_processor_id(), thread);
26217 +
26218 +#ifdef CONFIG_X86_64
26219 + this_cpu_write(kernel_stack, thread->sp0);
26220 +#endif
26221 +}
26222 +#endif
26223 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26224 index 7bc86bb..0ea06e8 100644
26225 --- a/arch/x86/kernel/process_32.c
26226 +++ b/arch/x86/kernel/process_32.c
26227 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26228 unsigned long thread_saved_pc(struct task_struct *tsk)
26229 {
26230 return ((unsigned long *)tsk->thread.sp)[3];
26231 +//XXX return tsk->thread.eip;
26232 }
26233
26234 void __show_regs(struct pt_regs *regs, int all)
26235 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26236 unsigned long sp;
26237 unsigned short ss, gs;
26238
26239 - if (user_mode_vm(regs)) {
26240 + if (user_mode(regs)) {
26241 sp = regs->sp;
26242 ss = regs->ss & 0xffff;
26243 - gs = get_user_gs(regs);
26244 } else {
26245 sp = kernel_stack_pointer(regs);
26246 savesegment(ss, ss);
26247 - savesegment(gs, gs);
26248 }
26249 + gs = get_user_gs(regs);
26250
26251 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26252 (u16)regs->cs, regs->ip, regs->flags,
26253 - smp_processor_id());
26254 + raw_smp_processor_id());
26255 print_symbol("EIP is at %s\n", regs->ip);
26256
26257 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26258 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26259 int copy_thread(unsigned long clone_flags, unsigned long sp,
26260 unsigned long arg, struct task_struct *p)
26261 {
26262 - struct pt_regs *childregs = task_pt_regs(p);
26263 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26264 struct task_struct *tsk;
26265 int err;
26266
26267 p->thread.sp = (unsigned long) childregs;
26268 p->thread.sp0 = (unsigned long) (childregs+1);
26269 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26270
26271 if (unlikely(p->flags & PF_KTHREAD)) {
26272 /* kernel thread */
26273 memset(childregs, 0, sizeof(struct pt_regs));
26274 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26275 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26276 - childregs->ds = __USER_DS;
26277 - childregs->es = __USER_DS;
26278 + savesegment(gs, childregs->gs);
26279 + childregs->ds = __KERNEL_DS;
26280 + childregs->es = __KERNEL_DS;
26281 childregs->fs = __KERNEL_PERCPU;
26282 childregs->bx = sp; /* function */
26283 childregs->bp = arg;
26284 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26285 struct thread_struct *prev = &prev_p->thread,
26286 *next = &next_p->thread;
26287 int cpu = smp_processor_id();
26288 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26289 + struct tss_struct *tss = init_tss + cpu;
26290 fpu_switch_t fpu;
26291
26292 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26293 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26294 */
26295 lazy_save_gs(prev->gs);
26296
26297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26298 + __set_fs(task_thread_info(next_p)->addr_limit);
26299 +#endif
26300 +
26301 /*
26302 * Load the per-thread Thread-Local Storage descriptor.
26303 */
26304 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26305 */
26306 arch_end_context_switch(next_p);
26307
26308 - this_cpu_write(kernel_stack,
26309 - (unsigned long)task_stack_page(next_p) +
26310 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26311 + this_cpu_write(current_task, next_p);
26312 + this_cpu_write(current_tinfo, &next_p->tinfo);
26313 + this_cpu_write(kernel_stack, next->sp0);
26314
26315 /*
26316 * Restore %gs if needed (which is common)
26317 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26318
26319 switch_fpu_finish(next_p, fpu);
26320
26321 - this_cpu_write(current_task, next_p);
26322 -
26323 return prev_p;
26324 }
26325
26326 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26327 } while (count++ < 16);
26328 return 0;
26329 }
26330 -
26331 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26332 index 898d077..4c458ff 100644
26333 --- a/arch/x86/kernel/process_64.c
26334 +++ b/arch/x86/kernel/process_64.c
26335 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26336 struct pt_regs *childregs;
26337 struct task_struct *me = current;
26338
26339 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26340 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26341 childregs = task_pt_regs(p);
26342 p->thread.sp = (unsigned long) childregs;
26343 p->thread.usersp = me->thread.usersp;
26344 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26345 set_tsk_thread_flag(p, TIF_FORK);
26346 p->thread.fpu_counter = 0;
26347 p->thread.io_bitmap_ptr = NULL;
26348 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26349 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26350 savesegment(es, p->thread.es);
26351 savesegment(ds, p->thread.ds);
26352 + savesegment(ss, p->thread.ss);
26353 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26354 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26355
26356 if (unlikely(p->flags & PF_KTHREAD)) {
26357 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26358 struct thread_struct *prev = &prev_p->thread;
26359 struct thread_struct *next = &next_p->thread;
26360 int cpu = smp_processor_id();
26361 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26362 + struct tss_struct *tss = init_tss + cpu;
26363 unsigned fsindex, gsindex;
26364 fpu_switch_t fpu;
26365
26366 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26367 if (unlikely(next->ds | prev->ds))
26368 loadsegment(ds, next->ds);
26369
26370 + savesegment(ss, prev->ss);
26371 + if (unlikely(next->ss != prev->ss))
26372 + loadsegment(ss, next->ss);
26373
26374 /* We must save %fs and %gs before load_TLS() because
26375 * %fs and %gs may be cleared by load_TLS().
26376 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26377 prev->usersp = this_cpu_read(old_rsp);
26378 this_cpu_write(old_rsp, next->usersp);
26379 this_cpu_write(current_task, next_p);
26380 + this_cpu_write(current_tinfo, &next_p->tinfo);
26381
26382 /*
26383 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26384 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26385 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26386 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26387
26388 - this_cpu_write(kernel_stack,
26389 - (unsigned long)task_stack_page(next_p) +
26390 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26391 + this_cpu_write(kernel_stack, next->sp0);
26392
26393 /*
26394 * Now maybe reload the debug registers and handle I/O bitmaps
26395 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26396 if (!p || p == current || p->state == TASK_RUNNING)
26397 return 0;
26398 stack = (unsigned long)task_stack_page(p);
26399 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26400 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26401 return 0;
26402 fp = *(u64 *)(p->thread.sp);
26403 do {
26404 - if (fp < (unsigned long)stack ||
26405 - fp >= (unsigned long)stack+THREAD_SIZE)
26406 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26407 return 0;
26408 ip = *(u64 *)(fp+8);
26409 if (!in_sched_functions(ip))
26410 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26411 index 678c0ad..d309ccb 100644
26412 --- a/arch/x86/kernel/ptrace.c
26413 +++ b/arch/x86/kernel/ptrace.c
26414 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26415 unsigned long sp = (unsigned long)&regs->sp;
26416 u32 *prev_esp;
26417
26418 - if (context == (sp & ~(THREAD_SIZE - 1)))
26419 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26420 return sp;
26421
26422 - prev_esp = (u32 *)(context);
26423 + prev_esp = *(u32 **)(context);
26424 if (prev_esp)
26425 return (unsigned long)prev_esp;
26426
26427 @@ -588,7 +588,7 @@ static void ptrace_triggered(struct perf_event *bp,
26428 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26429 {
26430 int i;
26431 - int dr7 = 0;
26432 + unsigned long dr7 = 0;
26433 struct arch_hw_breakpoint *info;
26434
26435 for (i = 0; i < HBP_NUM; i++) {
26436 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
26437 unsigned long addr, unsigned long data)
26438 {
26439 int ret;
26440 - unsigned long __user *datap = (unsigned long __user *)data;
26441 + unsigned long __user *datap = (__force unsigned long __user *)data;
26442
26443 switch (request) {
26444 /* read the word at location addr in the USER area. */
26445 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
26446 if ((int) addr < 0)
26447 return -EIO;
26448 ret = do_get_thread_area(child, addr,
26449 - (struct user_desc __user *)data);
26450 + (__force struct user_desc __user *) data);
26451 break;
26452
26453 case PTRACE_SET_THREAD_AREA:
26454 if ((int) addr < 0)
26455 return -EIO;
26456 ret = do_set_thread_area(child, addr,
26457 - (struct user_desc __user *)data, 0);
26458 + (__force struct user_desc __user *) data, 0);
26459 break;
26460 #endif
26461
26462 @@ -1292,7 +1292,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26463
26464 #ifdef CONFIG_X86_64
26465
26466 -static struct user_regset x86_64_regsets[] __read_mostly = {
26467 +static user_regset_no_const x86_64_regsets[] __read_only = {
26468 [REGSET_GENERAL] = {
26469 .core_note_type = NT_PRSTATUS,
26470 .n = sizeof(struct user_regs_struct) / sizeof(long),
26471 @@ -1333,7 +1333,7 @@ static const struct user_regset_view user_x86_64_view = {
26472 #endif /* CONFIG_X86_64 */
26473
26474 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26475 -static struct user_regset x86_32_regsets[] __read_mostly = {
26476 +static user_regset_no_const x86_32_regsets[] __read_only = {
26477 [REGSET_GENERAL] = {
26478 .core_note_type = NT_PRSTATUS,
26479 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26480 @@ -1386,7 +1386,7 @@ static const struct user_regset_view user_x86_32_view = {
26481 */
26482 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26483
26484 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26485 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26486 {
26487 #ifdef CONFIG_X86_64
26488 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26489 @@ -1421,7 +1421,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26490 memset(info, 0, sizeof(*info));
26491 info->si_signo = SIGTRAP;
26492 info->si_code = si_code;
26493 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26494 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26495 }
26496
26497 void user_single_step_siginfo(struct task_struct *tsk,
26498 @@ -1450,6 +1450,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26499 # define IS_IA32 0
26500 #endif
26501
26502 +#ifdef CONFIG_GRKERNSEC_SETXID
26503 +extern void gr_delayed_cred_worker(void);
26504 +#endif
26505 +
26506 /*
26507 * We must return the syscall number to actually look up in the table.
26508 * This can be -1L to skip running any syscall at all.
26509 @@ -1460,6 +1464,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26510
26511 user_exit();
26512
26513 +#ifdef CONFIG_GRKERNSEC_SETXID
26514 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26515 + gr_delayed_cred_worker();
26516 +#endif
26517 +
26518 /*
26519 * If we stepped into a sysenter/syscall insn, it trapped in
26520 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26521 @@ -1515,6 +1524,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26522 */
26523 user_exit();
26524
26525 +#ifdef CONFIG_GRKERNSEC_SETXID
26526 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26527 + gr_delayed_cred_worker();
26528 +#endif
26529 +
26530 audit_syscall_exit(regs);
26531
26532 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26533 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26534 index 2f355d2..e75ed0a 100644
26535 --- a/arch/x86/kernel/pvclock.c
26536 +++ b/arch/x86/kernel/pvclock.c
26537 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26538 reset_hung_task_detector();
26539 }
26540
26541 -static atomic64_t last_value = ATOMIC64_INIT(0);
26542 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26543
26544 void pvclock_resume(void)
26545 {
26546 - atomic64_set(&last_value, 0);
26547 + atomic64_set_unchecked(&last_value, 0);
26548 }
26549
26550 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26551 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26552 * updating at the same time, and one of them could be slightly behind,
26553 * making the assumption that last_value always go forward fail to hold.
26554 */
26555 - last = atomic64_read(&last_value);
26556 + last = atomic64_read_unchecked(&last_value);
26557 do {
26558 if (ret < last)
26559 return last;
26560 - last = atomic64_cmpxchg(&last_value, last, ret);
26561 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26562 } while (unlikely(last != ret));
26563
26564 return ret;
26565 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26566 index 52b1157..c6e67c4 100644
26567 --- a/arch/x86/kernel/reboot.c
26568 +++ b/arch/x86/kernel/reboot.c
26569 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26570
26571 void __noreturn machine_real_restart(unsigned int type)
26572 {
26573 +
26574 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26575 + struct desc_struct *gdt;
26576 +#endif
26577 +
26578 local_irq_disable();
26579
26580 /*
26581 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26582
26583 /* Jump to the identity-mapped low memory code */
26584 #ifdef CONFIG_X86_32
26585 - asm volatile("jmpl *%0" : :
26586 +
26587 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26588 + gdt = get_cpu_gdt_table(smp_processor_id());
26589 + pax_open_kernel();
26590 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26591 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26592 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26593 + loadsegment(ds, __KERNEL_DS);
26594 + loadsegment(es, __KERNEL_DS);
26595 + loadsegment(ss, __KERNEL_DS);
26596 +#endif
26597 +#ifdef CONFIG_PAX_KERNEXEC
26598 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26599 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26600 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26601 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26602 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26603 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26604 +#endif
26605 + pax_close_kernel();
26606 +#endif
26607 +
26608 + asm volatile("ljmpl *%0" : :
26609 "rm" (real_mode_header->machine_real_restart_asm),
26610 "a" (type));
26611 #else
26612 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26613 * This means that this function can never return, it can misbehave
26614 * by not rebooting properly and hanging.
26615 */
26616 -static void native_machine_emergency_restart(void)
26617 +static void __noreturn native_machine_emergency_restart(void)
26618 {
26619 int i;
26620 int attempt = 0;
26621 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26622 #endif
26623 }
26624
26625 -static void __machine_emergency_restart(int emergency)
26626 +static void __noreturn __machine_emergency_restart(int emergency)
26627 {
26628 reboot_emergency = emergency;
26629 machine_ops.emergency_restart();
26630 }
26631
26632 -static void native_machine_restart(char *__unused)
26633 +static void __noreturn native_machine_restart(char *__unused)
26634 {
26635 pr_notice("machine restart\n");
26636
26637 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26638 __machine_emergency_restart(0);
26639 }
26640
26641 -static void native_machine_halt(void)
26642 +static void __noreturn native_machine_halt(void)
26643 {
26644 /* Stop other cpus and apics */
26645 machine_shutdown();
26646 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
26647 stop_this_cpu(NULL);
26648 }
26649
26650 -static void native_machine_power_off(void)
26651 +static void __noreturn native_machine_power_off(void)
26652 {
26653 if (pm_power_off) {
26654 if (!reboot_force)
26655 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26656 }
26657 /* A fallback in case there is no PM info available */
26658 tboot_shutdown(TB_SHUTDOWN_HALT);
26659 + unreachable();
26660 }
26661
26662 -struct machine_ops machine_ops = {
26663 +struct machine_ops machine_ops __read_only = {
26664 .power_off = native_machine_power_off,
26665 .shutdown = native_machine_shutdown,
26666 .emergency_restart = native_machine_emergency_restart,
26667 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26668 index c8e41e9..64049ef 100644
26669 --- a/arch/x86/kernel/reboot_fixups_32.c
26670 +++ b/arch/x86/kernel/reboot_fixups_32.c
26671 @@ -57,7 +57,7 @@ struct device_fixup {
26672 unsigned int vendor;
26673 unsigned int device;
26674 void (*reboot_fixup)(struct pci_dev *);
26675 -};
26676 +} __do_const;
26677
26678 /*
26679 * PCI ids solely used for fixups_table go here
26680 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26681 index 3fd2c69..a444264 100644
26682 --- a/arch/x86/kernel/relocate_kernel_64.S
26683 +++ b/arch/x86/kernel/relocate_kernel_64.S
26684 @@ -96,8 +96,7 @@ relocate_kernel:
26685
26686 /* jump to identity mapped page */
26687 addq $(identity_mapped - relocate_kernel), %r8
26688 - pushq %r8
26689 - ret
26690 + jmp *%r8
26691
26692 identity_mapped:
26693 /* set return address to 0 if not preserving context */
26694 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26695 index 09c76d2..7f33fc2 100644
26696 --- a/arch/x86/kernel/setup.c
26697 +++ b/arch/x86/kernel/setup.c
26698 @@ -110,6 +110,7 @@
26699 #include <asm/mce.h>
26700 #include <asm/alternative.h>
26701 #include <asm/prom.h>
26702 +#include <asm/boot.h>
26703
26704 /*
26705 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26706 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26707 #endif
26708
26709
26710 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26711 -__visible unsigned long mmu_cr4_features;
26712 +#ifdef CONFIG_X86_64
26713 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26714 +#elif defined(CONFIG_X86_PAE)
26715 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26716 #else
26717 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26718 +__visible unsigned long mmu_cr4_features __read_only;
26719 #endif
26720
26721 +void set_in_cr4(unsigned long mask)
26722 +{
26723 + unsigned long cr4 = read_cr4();
26724 +
26725 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26726 + return;
26727 +
26728 + pax_open_kernel();
26729 + mmu_cr4_features |= mask;
26730 + pax_close_kernel();
26731 +
26732 + if (trampoline_cr4_features)
26733 + *trampoline_cr4_features = mmu_cr4_features;
26734 + cr4 |= mask;
26735 + write_cr4(cr4);
26736 +}
26737 +EXPORT_SYMBOL(set_in_cr4);
26738 +
26739 +void clear_in_cr4(unsigned long mask)
26740 +{
26741 + unsigned long cr4 = read_cr4();
26742 +
26743 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26744 + return;
26745 +
26746 + pax_open_kernel();
26747 + mmu_cr4_features &= ~mask;
26748 + pax_close_kernel();
26749 +
26750 + if (trampoline_cr4_features)
26751 + *trampoline_cr4_features = mmu_cr4_features;
26752 + cr4 &= ~mask;
26753 + write_cr4(cr4);
26754 +}
26755 +EXPORT_SYMBOL(clear_in_cr4);
26756 +
26757 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26758 int bootloader_type, bootloader_version;
26759
26760 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26761 * area (640->1Mb) as ram even though it is not.
26762 * take them out.
26763 */
26764 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26765 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26766
26767 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26768 }
26769 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26770 /* called before trim_bios_range() to spare extra sanitize */
26771 static void __init e820_add_kernel_range(void)
26772 {
26773 - u64 start = __pa_symbol(_text);
26774 + u64 start = __pa_symbol(ktla_ktva(_text));
26775 u64 size = __pa_symbol(_end) - start;
26776
26777 /*
26778 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26779
26780 void __init setup_arch(char **cmdline_p)
26781 {
26782 +#ifdef CONFIG_X86_32
26783 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26784 +#else
26785 memblock_reserve(__pa_symbol(_text),
26786 (unsigned long)__bss_stop - (unsigned long)_text);
26787 +#endif
26788
26789 early_reserve_initrd();
26790
26791 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26792
26793 if (!boot_params.hdr.root_flags)
26794 root_mountflags &= ~MS_RDONLY;
26795 - init_mm.start_code = (unsigned long) _text;
26796 - init_mm.end_code = (unsigned long) _etext;
26797 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26798 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26799 init_mm.end_data = (unsigned long) _edata;
26800 init_mm.brk = _brk_end;
26801
26802 - code_resource.start = __pa_symbol(_text);
26803 - code_resource.end = __pa_symbol(_etext)-1;
26804 - data_resource.start = __pa_symbol(_etext);
26805 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26806 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26807 + data_resource.start = __pa_symbol(_sdata);
26808 data_resource.end = __pa_symbol(_edata)-1;
26809 bss_resource.start = __pa_symbol(__bss_start);
26810 bss_resource.end = __pa_symbol(__bss_stop)-1;
26811 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26812 index 5cdff03..80fa283 100644
26813 --- a/arch/x86/kernel/setup_percpu.c
26814 +++ b/arch/x86/kernel/setup_percpu.c
26815 @@ -21,19 +21,17 @@
26816 #include <asm/cpu.h>
26817 #include <asm/stackprotector.h>
26818
26819 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26820 +#ifdef CONFIG_SMP
26821 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26822 EXPORT_PER_CPU_SYMBOL(cpu_number);
26823 +#endif
26824
26825 -#ifdef CONFIG_X86_64
26826 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26827 -#else
26828 -#define BOOT_PERCPU_OFFSET 0
26829 -#endif
26830
26831 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26832 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26833
26834 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26835 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26836 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26837 };
26838 EXPORT_SYMBOL(__per_cpu_offset);
26839 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26840 {
26841 #ifdef CONFIG_NEED_MULTIPLE_NODES
26842 pg_data_t *last = NULL;
26843 - unsigned int cpu;
26844 + int cpu;
26845
26846 for_each_possible_cpu(cpu) {
26847 int node = early_cpu_to_node(cpu);
26848 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26849 {
26850 #ifdef CONFIG_X86_32
26851 struct desc_struct gdt;
26852 + unsigned long base = per_cpu_offset(cpu);
26853
26854 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26855 - 0x2 | DESCTYPE_S, 0x8);
26856 - gdt.s = 1;
26857 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26858 + 0x83 | DESCTYPE_S, 0xC);
26859 write_gdt_entry(get_cpu_gdt_table(cpu),
26860 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26861 #endif
26862 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26863 /* alrighty, percpu areas up and running */
26864 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26865 for_each_possible_cpu(cpu) {
26866 +#ifdef CONFIG_CC_STACKPROTECTOR
26867 +#ifdef CONFIG_X86_32
26868 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26869 +#endif
26870 +#endif
26871 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26872 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26873 per_cpu(cpu_number, cpu) = cpu;
26874 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26875 */
26876 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26877 #endif
26878 +#ifdef CONFIG_CC_STACKPROTECTOR
26879 +#ifdef CONFIG_X86_32
26880 + if (!cpu)
26881 + per_cpu(stack_canary.canary, cpu) = canary;
26882 +#endif
26883 +#endif
26884 /*
26885 * Up to this point, the boot CPU has been using .init.data
26886 * area. Reload any changed state for the boot CPU.
26887 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26888 index 9e5de68..16c53cb 100644
26889 --- a/arch/x86/kernel/signal.c
26890 +++ b/arch/x86/kernel/signal.c
26891 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26892 * Align the stack pointer according to the i386 ABI,
26893 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26894 */
26895 - sp = ((sp + 4) & -16ul) - 4;
26896 + sp = ((sp - 12) & -16ul) - 4;
26897 #else /* !CONFIG_X86_32 */
26898 sp = round_down(sp, 16) - 8;
26899 #endif
26900 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26901 }
26902
26903 if (current->mm->context.vdso)
26904 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26905 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26906 else
26907 - restorer = &frame->retcode;
26908 + restorer = (void __user *)&frame->retcode;
26909 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26910 restorer = ksig->ka.sa.sa_restorer;
26911
26912 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26913 * reasons and because gdb uses it as a signature to notice
26914 * signal handler stack frames.
26915 */
26916 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26917 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26918
26919 if (err)
26920 return -EFAULT;
26921 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26922 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26923
26924 /* Set up to return from userspace. */
26925 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26926 + if (current->mm->context.vdso)
26927 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26928 + else
26929 + restorer = (void __user *)&frame->retcode;
26930 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26931 restorer = ksig->ka.sa.sa_restorer;
26932 put_user_ex(restorer, &frame->pretcode);
26933 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26934 * reasons and because gdb uses it as a signature to notice
26935 * signal handler stack frames.
26936 */
26937 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26938 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26939 } put_user_catch(err);
26940
26941 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26942 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26943 {
26944 int usig = signr_convert(ksig->sig);
26945 sigset_t *set = sigmask_to_save();
26946 - compat_sigset_t *cset = (compat_sigset_t *) set;
26947 + sigset_t sigcopy;
26948 + compat_sigset_t *cset;
26949 +
26950 + sigcopy = *set;
26951 +
26952 + cset = (compat_sigset_t *) &sigcopy;
26953
26954 /* Set up the stack frame */
26955 if (is_ia32_frame()) {
26956 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26957 } else if (is_x32_frame()) {
26958 return x32_setup_rt_frame(ksig, cset, regs);
26959 } else {
26960 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26961 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26962 }
26963 }
26964
26965 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26966 index be8e1bd..a3d93fa 100644
26967 --- a/arch/x86/kernel/smp.c
26968 +++ b/arch/x86/kernel/smp.c
26969 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26970
26971 __setup("nonmi_ipi", nonmi_ipi_setup);
26972
26973 -struct smp_ops smp_ops = {
26974 +struct smp_ops smp_ops __read_only = {
26975 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26976 .smp_prepare_cpus = native_smp_prepare_cpus,
26977 .smp_cpus_done = native_smp_cpus_done,
26978 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26979 index ae2fd975..c0c8d10 100644
26980 --- a/arch/x86/kernel/smpboot.c
26981 +++ b/arch/x86/kernel/smpboot.c
26982 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
26983
26984 enable_start_cpu0 = 0;
26985
26986 -#ifdef CONFIG_X86_32
26987 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
26988 + barrier();
26989 +
26990 /* switch away from the initial page table */
26991 +#ifdef CONFIG_PAX_PER_CPU_PGD
26992 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26993 +#else
26994 load_cr3(swapper_pg_dir);
26995 +#endif
26996 __flush_tlb_all();
26997 -#endif
26998
26999 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27000 - barrier();
27001 /*
27002 * Check TSC synchronization with the BP:
27003 */
27004 @@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27005 alternatives_enable_smp();
27006
27007 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27008 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27009 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27010 per_cpu(current_task, cpu) = idle;
27011 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27012
27013 #ifdef CONFIG_X86_32
27014 /* Stack for startup_32 can be just as for start_secondary onwards */
27015 @@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27016 clear_tsk_thread_flag(idle, TIF_FORK);
27017 initial_gs = per_cpu_offset(cpu);
27018 #endif
27019 - per_cpu(kernel_stack, cpu) =
27020 - (unsigned long)task_stack_page(idle) -
27021 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27022 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27023 + pax_open_kernel();
27024 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27025 + pax_close_kernel();
27026 initial_code = (unsigned long)start_secondary;
27027 stack_start = idle->thread.sp;
27028
27029 @@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27030 /* the FPU context is blank, nobody can own it */
27031 __cpu_disable_lazy_restore(cpu);
27032
27033 +#ifdef CONFIG_PAX_PER_CPU_PGD
27034 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27035 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27036 + KERNEL_PGD_PTRS);
27037 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27038 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27039 + KERNEL_PGD_PTRS);
27040 +#endif
27041 +
27042 err = do_boot_cpu(apicid, cpu, tidle);
27043 if (err) {
27044 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27045 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27046 index 9b4d51d..5d28b58 100644
27047 --- a/arch/x86/kernel/step.c
27048 +++ b/arch/x86/kernel/step.c
27049 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27050 struct desc_struct *desc;
27051 unsigned long base;
27052
27053 - seg &= ~7UL;
27054 + seg >>= 3;
27055
27056 mutex_lock(&child->mm->context.lock);
27057 - if (unlikely((seg >> 3) >= child->mm->context.size))
27058 + if (unlikely(seg >= child->mm->context.size))
27059 addr = -1L; /* bogus selector, access would fault */
27060 else {
27061 desc = child->mm->context.ldt + seg;
27062 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27063 addr += base;
27064 }
27065 mutex_unlock(&child->mm->context.lock);
27066 - }
27067 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27068 + addr = ktla_ktva(addr);
27069
27070 return addr;
27071 }
27072 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27073 unsigned char opcode[15];
27074 unsigned long addr = convert_ip_to_linear(child, regs);
27075
27076 + if (addr == -EINVAL)
27077 + return 0;
27078 +
27079 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27080 for (i = 0; i < copied; i++) {
27081 switch (opcode[i]) {
27082 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27083 new file mode 100644
27084 index 0000000..5877189
27085 --- /dev/null
27086 +++ b/arch/x86/kernel/sys_i386_32.c
27087 @@ -0,0 +1,189 @@
27088 +/*
27089 + * This file contains various random system calls that
27090 + * have a non-standard calling sequence on the Linux/i386
27091 + * platform.
27092 + */
27093 +
27094 +#include <linux/errno.h>
27095 +#include <linux/sched.h>
27096 +#include <linux/mm.h>
27097 +#include <linux/fs.h>
27098 +#include <linux/smp.h>
27099 +#include <linux/sem.h>
27100 +#include <linux/msg.h>
27101 +#include <linux/shm.h>
27102 +#include <linux/stat.h>
27103 +#include <linux/syscalls.h>
27104 +#include <linux/mman.h>
27105 +#include <linux/file.h>
27106 +#include <linux/utsname.h>
27107 +#include <linux/ipc.h>
27108 +#include <linux/elf.h>
27109 +
27110 +#include <linux/uaccess.h>
27111 +#include <linux/unistd.h>
27112 +
27113 +#include <asm/syscalls.h>
27114 +
27115 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27116 +{
27117 + unsigned long pax_task_size = TASK_SIZE;
27118 +
27119 +#ifdef CONFIG_PAX_SEGMEXEC
27120 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27121 + pax_task_size = SEGMEXEC_TASK_SIZE;
27122 +#endif
27123 +
27124 + if (flags & MAP_FIXED)
27125 + if (len > pax_task_size || addr > pax_task_size - len)
27126 + return -EINVAL;
27127 +
27128 + return 0;
27129 +}
27130 +
27131 +/*
27132 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27133 + */
27134 +static unsigned long get_align_mask(void)
27135 +{
27136 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27137 + return 0;
27138 +
27139 + if (!(current->flags & PF_RANDOMIZE))
27140 + return 0;
27141 +
27142 + return va_align.mask;
27143 +}
27144 +
27145 +unsigned long
27146 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27147 + unsigned long len, unsigned long pgoff, unsigned long flags)
27148 +{
27149 + struct mm_struct *mm = current->mm;
27150 + struct vm_area_struct *vma;
27151 + unsigned long pax_task_size = TASK_SIZE;
27152 + struct vm_unmapped_area_info info;
27153 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27154 +
27155 +#ifdef CONFIG_PAX_SEGMEXEC
27156 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27157 + pax_task_size = SEGMEXEC_TASK_SIZE;
27158 +#endif
27159 +
27160 + pax_task_size -= PAGE_SIZE;
27161 +
27162 + if (len > pax_task_size)
27163 + return -ENOMEM;
27164 +
27165 + if (flags & MAP_FIXED)
27166 + return addr;
27167 +
27168 +#ifdef CONFIG_PAX_RANDMMAP
27169 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27170 +#endif
27171 +
27172 + if (addr) {
27173 + addr = PAGE_ALIGN(addr);
27174 + if (pax_task_size - len >= addr) {
27175 + vma = find_vma(mm, addr);
27176 + if (check_heap_stack_gap(vma, addr, len, offset))
27177 + return addr;
27178 + }
27179 + }
27180 +
27181 + info.flags = 0;
27182 + info.length = len;
27183 + info.align_mask = filp ? get_align_mask() : 0;
27184 + info.align_offset = pgoff << PAGE_SHIFT;
27185 + info.threadstack_offset = offset;
27186 +
27187 +#ifdef CONFIG_PAX_PAGEEXEC
27188 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27189 + info.low_limit = 0x00110000UL;
27190 + info.high_limit = mm->start_code;
27191 +
27192 +#ifdef CONFIG_PAX_RANDMMAP
27193 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27194 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27195 +#endif
27196 +
27197 + if (info.low_limit < info.high_limit) {
27198 + addr = vm_unmapped_area(&info);
27199 + if (!IS_ERR_VALUE(addr))
27200 + return addr;
27201 + }
27202 + } else
27203 +#endif
27204 +
27205 + info.low_limit = mm->mmap_base;
27206 + info.high_limit = pax_task_size;
27207 +
27208 + return vm_unmapped_area(&info);
27209 +}
27210 +
27211 +unsigned long
27212 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27213 + const unsigned long len, const unsigned long pgoff,
27214 + const unsigned long flags)
27215 +{
27216 + struct vm_area_struct *vma;
27217 + struct mm_struct *mm = current->mm;
27218 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27219 + struct vm_unmapped_area_info info;
27220 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27221 +
27222 +#ifdef CONFIG_PAX_SEGMEXEC
27223 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27224 + pax_task_size = SEGMEXEC_TASK_SIZE;
27225 +#endif
27226 +
27227 + pax_task_size -= PAGE_SIZE;
27228 +
27229 + /* requested length too big for entire address space */
27230 + if (len > pax_task_size)
27231 + return -ENOMEM;
27232 +
27233 + if (flags & MAP_FIXED)
27234 + return addr;
27235 +
27236 +#ifdef CONFIG_PAX_PAGEEXEC
27237 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27238 + goto bottomup;
27239 +#endif
27240 +
27241 +#ifdef CONFIG_PAX_RANDMMAP
27242 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27243 +#endif
27244 +
27245 + /* requesting a specific address */
27246 + if (addr) {
27247 + addr = PAGE_ALIGN(addr);
27248 + if (pax_task_size - len >= addr) {
27249 + vma = find_vma(mm, addr);
27250 + if (check_heap_stack_gap(vma, addr, len, offset))
27251 + return addr;
27252 + }
27253 + }
27254 +
27255 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27256 + info.length = len;
27257 + info.low_limit = PAGE_SIZE;
27258 + info.high_limit = mm->mmap_base;
27259 + info.align_mask = filp ? get_align_mask() : 0;
27260 + info.align_offset = pgoff << PAGE_SHIFT;
27261 + info.threadstack_offset = offset;
27262 +
27263 + addr = vm_unmapped_area(&info);
27264 + if (!(addr & ~PAGE_MASK))
27265 + return addr;
27266 + VM_BUG_ON(addr != -ENOMEM);
27267 +
27268 +bottomup:
27269 + /*
27270 + * A failed mmap() very likely causes application failure,
27271 + * so fall back to the bottom-up function here. This scenario
27272 + * can happen with large stack limits and large mmap()
27273 + * allocations.
27274 + */
27275 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27276 +}
27277 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27278 index 30277e2..5664a29 100644
27279 --- a/arch/x86/kernel/sys_x86_64.c
27280 +++ b/arch/x86/kernel/sys_x86_64.c
27281 @@ -81,8 +81,8 @@ out:
27282 return error;
27283 }
27284
27285 -static void find_start_end(unsigned long flags, unsigned long *begin,
27286 - unsigned long *end)
27287 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27288 + unsigned long *begin, unsigned long *end)
27289 {
27290 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27291 unsigned long new_begin;
27292 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27293 *begin = new_begin;
27294 }
27295 } else {
27296 - *begin = current->mm->mmap_legacy_base;
27297 + *begin = mm->mmap_legacy_base;
27298 *end = TASK_SIZE;
27299 }
27300 }
27301 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27302 struct vm_area_struct *vma;
27303 struct vm_unmapped_area_info info;
27304 unsigned long begin, end;
27305 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27306
27307 if (flags & MAP_FIXED)
27308 return addr;
27309
27310 - find_start_end(flags, &begin, &end);
27311 + find_start_end(mm, flags, &begin, &end);
27312
27313 if (len > end)
27314 return -ENOMEM;
27315
27316 +#ifdef CONFIG_PAX_RANDMMAP
27317 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27318 +#endif
27319 +
27320 if (addr) {
27321 addr = PAGE_ALIGN(addr);
27322 vma = find_vma(mm, addr);
27323 - if (end - len >= addr &&
27324 - (!vma || addr + len <= vma->vm_start))
27325 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27326 return addr;
27327 }
27328
27329 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27330 info.high_limit = end;
27331 info.align_mask = filp ? get_align_mask() : 0;
27332 info.align_offset = pgoff << PAGE_SHIFT;
27333 + info.threadstack_offset = offset;
27334 return vm_unmapped_area(&info);
27335 }
27336
27337 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27338 struct mm_struct *mm = current->mm;
27339 unsigned long addr = addr0;
27340 struct vm_unmapped_area_info info;
27341 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27342
27343 /* requested length too big for entire address space */
27344 if (len > TASK_SIZE)
27345 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27346 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27347 goto bottomup;
27348
27349 +#ifdef CONFIG_PAX_RANDMMAP
27350 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27351 +#endif
27352 +
27353 /* requesting a specific address */
27354 if (addr) {
27355 addr = PAGE_ALIGN(addr);
27356 vma = find_vma(mm, addr);
27357 - if (TASK_SIZE - len >= addr &&
27358 - (!vma || addr + len <= vma->vm_start))
27359 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27360 return addr;
27361 }
27362
27363 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27364 info.high_limit = mm->mmap_base;
27365 info.align_mask = filp ? get_align_mask() : 0;
27366 info.align_offset = pgoff << PAGE_SHIFT;
27367 + info.threadstack_offset = offset;
27368 addr = vm_unmapped_area(&info);
27369 if (!(addr & ~PAGE_MASK))
27370 return addr;
27371 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27372 index 91a4496..bb87552 100644
27373 --- a/arch/x86/kernel/tboot.c
27374 +++ b/arch/x86/kernel/tboot.c
27375 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27376
27377 void tboot_shutdown(u32 shutdown_type)
27378 {
27379 - void (*shutdown)(void);
27380 + void (* __noreturn shutdown)(void);
27381
27382 if (!tboot_enabled())
27383 return;
27384 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27385
27386 switch_to_tboot_pt();
27387
27388 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27389 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27390 shutdown();
27391
27392 /* should not reach here */
27393 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27394 return -ENODEV;
27395 }
27396
27397 -static atomic_t ap_wfs_count;
27398 +static atomic_unchecked_t ap_wfs_count;
27399
27400 static int tboot_wait_for_aps(int num_aps)
27401 {
27402 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27403 {
27404 switch (action) {
27405 case CPU_DYING:
27406 - atomic_inc(&ap_wfs_count);
27407 + atomic_inc_unchecked(&ap_wfs_count);
27408 if (num_online_cpus() == 1)
27409 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27410 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27411 return NOTIFY_BAD;
27412 break;
27413 }
27414 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27415
27416 tboot_create_trampoline();
27417
27418 - atomic_set(&ap_wfs_count, 0);
27419 + atomic_set_unchecked(&ap_wfs_count, 0);
27420 register_hotcpu_notifier(&tboot_cpu_notifier);
27421
27422 #ifdef CONFIG_DEBUG_FS
27423 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27424 index bf7ef5c..59d0ac9 100644
27425 --- a/arch/x86/kernel/time.c
27426 +++ b/arch/x86/kernel/time.c
27427 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27428 {
27429 unsigned long pc = instruction_pointer(regs);
27430
27431 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27432 + if (!user_mode(regs) && in_lock_functions(pc)) {
27433 #ifdef CONFIG_FRAME_POINTER
27434 - return *(unsigned long *)(regs->bp + sizeof(long));
27435 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27436 #else
27437 unsigned long *sp =
27438 (unsigned long *)kernel_stack_pointer(regs);
27439 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27440 * or above a saved flags. Eflags has bits 22-31 zero,
27441 * kernel addresses don't.
27442 */
27443 +
27444 +#ifdef CONFIG_PAX_KERNEXEC
27445 + return ktla_ktva(sp[0]);
27446 +#else
27447 if (sp[0] >> 22)
27448 return sp[0];
27449 if (sp[1] >> 22)
27450 return sp[1];
27451 #endif
27452 +
27453 +#endif
27454 }
27455 return pc;
27456 }
27457 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27458 index f7fec09..9991981 100644
27459 --- a/arch/x86/kernel/tls.c
27460 +++ b/arch/x86/kernel/tls.c
27461 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27462 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27463 return -EINVAL;
27464
27465 +#ifdef CONFIG_PAX_SEGMEXEC
27466 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27467 + return -EINVAL;
27468 +#endif
27469 +
27470 set_tls_desc(p, idx, &info, 1);
27471
27472 return 0;
27473 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27474
27475 if (kbuf)
27476 info = kbuf;
27477 - else if (__copy_from_user(infobuf, ubuf, count))
27478 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27479 return -EFAULT;
27480 else
27481 info = infobuf;
27482 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27483 index 1c113db..287b42e 100644
27484 --- a/arch/x86/kernel/tracepoint.c
27485 +++ b/arch/x86/kernel/tracepoint.c
27486 @@ -9,11 +9,11 @@
27487 #include <linux/atomic.h>
27488
27489 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27490 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27491 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27492 (unsigned long) trace_idt_table };
27493
27494 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27495 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27496 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27497
27498 static int trace_irq_vector_refcount;
27499 static DEFINE_MUTEX(irq_vector_mutex);
27500 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27501 index f73b5d4..0adcc9a 100644
27502 --- a/arch/x86/kernel/traps.c
27503 +++ b/arch/x86/kernel/traps.c
27504 @@ -66,7 +66,7 @@
27505 #include <asm/proto.h>
27506
27507 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27508 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27509 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27510 #else
27511 #include <asm/processor-flags.h>
27512 #include <asm/setup.h>
27513 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27514 #endif
27515
27516 /* Must be page-aligned because the real IDT is used in a fixmap. */
27517 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27518 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27519
27520 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27521 EXPORT_SYMBOL_GPL(used_vectors);
27522 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27523 }
27524
27525 static int __kprobes
27526 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27527 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27528 struct pt_regs *regs, long error_code)
27529 {
27530 #ifdef CONFIG_X86_32
27531 - if (regs->flags & X86_VM_MASK) {
27532 + if (v8086_mode(regs)) {
27533 /*
27534 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27535 * On nmi (interrupt 2), do_trap should not be called.
27536 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27537 return -1;
27538 }
27539 #endif
27540 - if (!user_mode(regs)) {
27541 + if (!user_mode_novm(regs)) {
27542 if (!fixup_exception(regs)) {
27543 tsk->thread.error_code = error_code;
27544 tsk->thread.trap_nr = trapnr;
27545 +
27546 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27547 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27548 + str = "PAX: suspicious stack segment fault";
27549 +#endif
27550 +
27551 die(str, regs, error_code);
27552 }
27553 +
27554 +#ifdef CONFIG_PAX_REFCOUNT
27555 + if (trapnr == X86_TRAP_OF)
27556 + pax_report_refcount_overflow(regs);
27557 +#endif
27558 +
27559 return 0;
27560 }
27561
27562 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27563 }
27564
27565 static void __kprobes
27566 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27567 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27568 long error_code, siginfo_t *info)
27569 {
27570 struct task_struct *tsk = current;
27571 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27572 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27573 printk_ratelimit()) {
27574 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27575 - tsk->comm, tsk->pid, str,
27576 + tsk->comm, task_pid_nr(tsk), str,
27577 regs->ip, regs->sp, error_code);
27578 print_vma_addr(" in ", regs->ip);
27579 pr_cont("\n");
27580 @@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27581 tsk->thread.error_code = error_code;
27582 tsk->thread.trap_nr = X86_TRAP_DF;
27583
27584 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27585 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27586 + die("grsec: kernel stack overflow detected", regs, error_code);
27587 +#endif
27588 +
27589 #ifdef CONFIG_DOUBLEFAULT
27590 df_debug(regs, error_code);
27591 #endif
27592 @@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27593 conditional_sti(regs);
27594
27595 #ifdef CONFIG_X86_32
27596 - if (regs->flags & X86_VM_MASK) {
27597 + if (v8086_mode(regs)) {
27598 local_irq_enable();
27599 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27600 goto exit;
27601 @@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27602 #endif
27603
27604 tsk = current;
27605 - if (!user_mode(regs)) {
27606 + if (!user_mode_novm(regs)) {
27607 if (fixup_exception(regs))
27608 goto exit;
27609
27610 tsk->thread.error_code = error_code;
27611 tsk->thread.trap_nr = X86_TRAP_GP;
27612 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27613 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27614 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27615 +
27616 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27617 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27618 + die("PAX: suspicious general protection fault", regs, error_code);
27619 + else
27620 +#endif
27621 +
27622 die("general protection fault", regs, error_code);
27623 + }
27624 goto exit;
27625 }
27626
27627 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27628 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27629 + struct mm_struct *mm = tsk->mm;
27630 + unsigned long limit;
27631 +
27632 + down_write(&mm->mmap_sem);
27633 + limit = mm->context.user_cs_limit;
27634 + if (limit < TASK_SIZE) {
27635 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27636 + up_write(&mm->mmap_sem);
27637 + return;
27638 + }
27639 + up_write(&mm->mmap_sem);
27640 + }
27641 +#endif
27642 +
27643 tsk->thread.error_code = error_code;
27644 tsk->thread.trap_nr = X86_TRAP_GP;
27645
27646 @@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27647 /* It's safe to allow irq's after DR6 has been saved */
27648 preempt_conditional_sti(regs);
27649
27650 - if (regs->flags & X86_VM_MASK) {
27651 + if (v8086_mode(regs)) {
27652 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27653 X86_TRAP_DB);
27654 preempt_conditional_cli(regs);
27655 @@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27656 * We already checked v86 mode above, so we can check for kernel mode
27657 * by just checking the CPL of CS.
27658 */
27659 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27660 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27661 tsk->thread.debugreg6 &= ~DR_STEP;
27662 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27663 regs->flags &= ~X86_EFLAGS_TF;
27664 @@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27665 return;
27666 conditional_sti(regs);
27667
27668 - if (!user_mode_vm(regs))
27669 + if (!user_mode(regs))
27670 {
27671 if (!fixup_exception(regs)) {
27672 task->thread.error_code = error_code;
27673 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27674 index 57e5ce1..20b0040 100644
27675 --- a/arch/x86/kernel/tsc.c
27676 +++ b/arch/x86/kernel/tsc.c
27677 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27678 */
27679 smp_wmb();
27680
27681 - ACCESS_ONCE(c2n->head) = data;
27682 + ACCESS_ONCE_RW(c2n->head) = data;
27683 }
27684
27685 /*
27686 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27687 index 2ed8459..7cf329f 100644
27688 --- a/arch/x86/kernel/uprobes.c
27689 +++ b/arch/x86/kernel/uprobes.c
27690 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27691 int ret = NOTIFY_DONE;
27692
27693 /* We are only interested in userspace traps */
27694 - if (regs && !user_mode_vm(regs))
27695 + if (regs && !user_mode(regs))
27696 return NOTIFY_DONE;
27697
27698 switch (val) {
27699 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27700
27701 if (ncopied != rasize) {
27702 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27703 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27704 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27705
27706 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27707 }
27708 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27709 index b9242ba..50c5edd 100644
27710 --- a/arch/x86/kernel/verify_cpu.S
27711 +++ b/arch/x86/kernel/verify_cpu.S
27712 @@ -20,6 +20,7 @@
27713 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27714 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27715 * arch/x86/kernel/head_32.S: processor startup
27716 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27717 *
27718 * verify_cpu, returns the status of longmode and SSE in register %eax.
27719 * 0: Success 1: Failure
27720 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27721 index e8edcf5..27f9344 100644
27722 --- a/arch/x86/kernel/vm86_32.c
27723 +++ b/arch/x86/kernel/vm86_32.c
27724 @@ -44,6 +44,7 @@
27725 #include <linux/ptrace.h>
27726 #include <linux/audit.h>
27727 #include <linux/stddef.h>
27728 +#include <linux/grsecurity.h>
27729
27730 #include <asm/uaccess.h>
27731 #include <asm/io.h>
27732 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27733 do_exit(SIGSEGV);
27734 }
27735
27736 - tss = &per_cpu(init_tss, get_cpu());
27737 + tss = init_tss + get_cpu();
27738 current->thread.sp0 = current->thread.saved_sp0;
27739 current->thread.sysenter_cs = __KERNEL_CS;
27740 load_sp0(tss, &current->thread);
27741 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27742
27743 if (tsk->thread.saved_sp0)
27744 return -EPERM;
27745 +
27746 +#ifdef CONFIG_GRKERNSEC_VM86
27747 + if (!capable(CAP_SYS_RAWIO)) {
27748 + gr_handle_vm86();
27749 + return -EPERM;
27750 + }
27751 +#endif
27752 +
27753 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27754 offsetof(struct kernel_vm86_struct, vm86plus) -
27755 sizeof(info.regs));
27756 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27757 int tmp;
27758 struct vm86plus_struct __user *v86;
27759
27760 +#ifdef CONFIG_GRKERNSEC_VM86
27761 + if (!capable(CAP_SYS_RAWIO)) {
27762 + gr_handle_vm86();
27763 + return -EPERM;
27764 + }
27765 +#endif
27766 +
27767 tsk = current;
27768 switch (cmd) {
27769 case VM86_REQUEST_IRQ:
27770 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27771 tsk->thread.saved_fs = info->regs32->fs;
27772 tsk->thread.saved_gs = get_user_gs(info->regs32);
27773
27774 - tss = &per_cpu(init_tss, get_cpu());
27775 + tss = init_tss + get_cpu();
27776 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27777 if (cpu_has_sep)
27778 tsk->thread.sysenter_cs = 0;
27779 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27780 goto cannot_handle;
27781 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27782 goto cannot_handle;
27783 - intr_ptr = (unsigned long __user *) (i << 2);
27784 + intr_ptr = (__force unsigned long __user *) (i << 2);
27785 if (get_user(segoffs, intr_ptr))
27786 goto cannot_handle;
27787 if ((segoffs >> 16) == BIOSSEG)
27788 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27789 index 49edf2d..c0d1362 100644
27790 --- a/arch/x86/kernel/vmlinux.lds.S
27791 +++ b/arch/x86/kernel/vmlinux.lds.S
27792 @@ -26,6 +26,13 @@
27793 #include <asm/page_types.h>
27794 #include <asm/cache.h>
27795 #include <asm/boot.h>
27796 +#include <asm/segment.h>
27797 +
27798 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27799 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27800 +#else
27801 +#define __KERNEL_TEXT_OFFSET 0
27802 +#endif
27803
27804 #undef i386 /* in case the preprocessor is a 32bit one */
27805
27806 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27807
27808 PHDRS {
27809 text PT_LOAD FLAGS(5); /* R_E */
27810 +#ifdef CONFIG_X86_32
27811 + module PT_LOAD FLAGS(5); /* R_E */
27812 +#endif
27813 +#ifdef CONFIG_XEN
27814 + rodata PT_LOAD FLAGS(5); /* R_E */
27815 +#else
27816 + rodata PT_LOAD FLAGS(4); /* R__ */
27817 +#endif
27818 data PT_LOAD FLAGS(6); /* RW_ */
27819 -#ifdef CONFIG_X86_64
27820 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27821 #ifdef CONFIG_SMP
27822 percpu PT_LOAD FLAGS(6); /* RW_ */
27823 #endif
27824 + text.init PT_LOAD FLAGS(5); /* R_E */
27825 + text.exit PT_LOAD FLAGS(5); /* R_E */
27826 init PT_LOAD FLAGS(7); /* RWE */
27827 -#endif
27828 note PT_NOTE FLAGS(0); /* ___ */
27829 }
27830
27831 SECTIONS
27832 {
27833 #ifdef CONFIG_X86_32
27834 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27835 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27836 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27837 #else
27838 - . = __START_KERNEL;
27839 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27840 + . = __START_KERNEL;
27841 #endif
27842
27843 /* Text and read-only data */
27844 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27845 - _text = .;
27846 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27847 /* bootstrapping code */
27848 +#ifdef CONFIG_X86_32
27849 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27850 +#else
27851 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27852 +#endif
27853 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27854 + _text = .;
27855 HEAD_TEXT
27856 . = ALIGN(8);
27857 _stext = .;
27858 @@ -104,13 +124,47 @@ SECTIONS
27859 IRQENTRY_TEXT
27860 *(.fixup)
27861 *(.gnu.warning)
27862 - /* End of text section */
27863 - _etext = .;
27864 } :text = 0x9090
27865
27866 - NOTES :text :note
27867 + . += __KERNEL_TEXT_OFFSET;
27868
27869 - EXCEPTION_TABLE(16) :text = 0x9090
27870 +#ifdef CONFIG_X86_32
27871 + . = ALIGN(PAGE_SIZE);
27872 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27873 +
27874 +#ifdef CONFIG_PAX_KERNEXEC
27875 + MODULES_EXEC_VADDR = .;
27876 + BYTE(0)
27877 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27878 + . = ALIGN(HPAGE_SIZE) - 1;
27879 + MODULES_EXEC_END = .;
27880 +#endif
27881 +
27882 + } :module
27883 +#endif
27884 +
27885 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27886 + /* End of text section */
27887 + BYTE(0)
27888 + _etext = . - __KERNEL_TEXT_OFFSET;
27889 + }
27890 +
27891 +#ifdef CONFIG_X86_32
27892 + . = ALIGN(PAGE_SIZE);
27893 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27894 + . = ALIGN(PAGE_SIZE);
27895 + *(.empty_zero_page)
27896 + *(.initial_pg_fixmap)
27897 + *(.initial_pg_pmd)
27898 + *(.initial_page_table)
27899 + *(.swapper_pg_dir)
27900 + } :rodata
27901 +#endif
27902 +
27903 + . = ALIGN(PAGE_SIZE);
27904 + NOTES :rodata :note
27905 +
27906 + EXCEPTION_TABLE(16) :rodata
27907
27908 #if defined(CONFIG_DEBUG_RODATA)
27909 /* .text should occupy whole number of pages */
27910 @@ -122,16 +176,20 @@ SECTIONS
27911
27912 /* Data */
27913 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27914 +
27915 +#ifdef CONFIG_PAX_KERNEXEC
27916 + . = ALIGN(HPAGE_SIZE);
27917 +#else
27918 + . = ALIGN(PAGE_SIZE);
27919 +#endif
27920 +
27921 /* Start of data section */
27922 _sdata = .;
27923
27924 /* init_task */
27925 INIT_TASK_DATA(THREAD_SIZE)
27926
27927 -#ifdef CONFIG_X86_32
27928 - /* 32 bit has nosave before _edata */
27929 NOSAVE_DATA
27930 -#endif
27931
27932 PAGE_ALIGNED_DATA(PAGE_SIZE)
27933
27934 @@ -174,12 +232,19 @@ SECTIONS
27935 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27936
27937 /* Init code and data - will be freed after init */
27938 - . = ALIGN(PAGE_SIZE);
27939 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27940 + BYTE(0)
27941 +
27942 +#ifdef CONFIG_PAX_KERNEXEC
27943 + . = ALIGN(HPAGE_SIZE);
27944 +#else
27945 + . = ALIGN(PAGE_SIZE);
27946 +#endif
27947 +
27948 __init_begin = .; /* paired with __init_end */
27949 - }
27950 + } :init.begin
27951
27952 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27953 +#ifdef CONFIG_SMP
27954 /*
27955 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27956 * output PHDR, so the next output section - .init.text - should
27957 @@ -188,12 +253,27 @@ SECTIONS
27958 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27959 #endif
27960
27961 - INIT_TEXT_SECTION(PAGE_SIZE)
27962 -#ifdef CONFIG_X86_64
27963 - :init
27964 -#endif
27965 + . = ALIGN(PAGE_SIZE);
27966 + init_begin = .;
27967 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27968 + VMLINUX_SYMBOL(_sinittext) = .;
27969 + INIT_TEXT
27970 + VMLINUX_SYMBOL(_einittext) = .;
27971 + . = ALIGN(PAGE_SIZE);
27972 + } :text.init
27973
27974 - INIT_DATA_SECTION(16)
27975 + /*
27976 + * .exit.text is discard at runtime, not link time, to deal with
27977 + * references from .altinstructions and .eh_frame
27978 + */
27979 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27980 + EXIT_TEXT
27981 + . = ALIGN(16);
27982 + } :text.exit
27983 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27984 +
27985 + . = ALIGN(PAGE_SIZE);
27986 + INIT_DATA_SECTION(16) :init
27987
27988 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27989 __x86_cpu_dev_start = .;
27990 @@ -264,19 +344,12 @@ SECTIONS
27991 }
27992
27993 . = ALIGN(8);
27994 - /*
27995 - * .exit.text is discard at runtime, not link time, to deal with
27996 - * references from .altinstructions and .eh_frame
27997 - */
27998 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27999 - EXIT_TEXT
28000 - }
28001
28002 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28003 EXIT_DATA
28004 }
28005
28006 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28007 +#ifndef CONFIG_SMP
28008 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28009 #endif
28010
28011 @@ -295,16 +368,10 @@ SECTIONS
28012 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28013 __smp_locks = .;
28014 *(.smp_locks)
28015 - . = ALIGN(PAGE_SIZE);
28016 __smp_locks_end = .;
28017 + . = ALIGN(PAGE_SIZE);
28018 }
28019
28020 -#ifdef CONFIG_X86_64
28021 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28022 - NOSAVE_DATA
28023 - }
28024 -#endif
28025 -
28026 /* BSS */
28027 . = ALIGN(PAGE_SIZE);
28028 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28029 @@ -320,6 +387,7 @@ SECTIONS
28030 __brk_base = .;
28031 . += 64 * 1024; /* 64k alignment slop space */
28032 *(.brk_reservation) /* areas brk users have reserved */
28033 + . = ALIGN(HPAGE_SIZE);
28034 __brk_limit = .;
28035 }
28036
28037 @@ -346,13 +414,12 @@ SECTIONS
28038 * for the boot processor.
28039 */
28040 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28041 -INIT_PER_CPU(gdt_page);
28042 INIT_PER_CPU(irq_stack_union);
28043
28044 /*
28045 * Build-time check on the image size:
28046 */
28047 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28048 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28049 "kernel image bigger than KERNEL_IMAGE_SIZE");
28050
28051 #ifdef CONFIG_SMP
28052 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28053 index 8b3b3eb..9395aa9 100644
28054 --- a/arch/x86/kernel/vsyscall_64.c
28055 +++ b/arch/x86/kernel/vsyscall_64.c
28056 @@ -54,15 +54,13 @@
28057
28058 DEFINE_VVAR(int, vgetcpu_mode);
28059
28060 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28061 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28062
28063 static int __init vsyscall_setup(char *str)
28064 {
28065 if (str) {
28066 if (!strcmp("emulate", str))
28067 vsyscall_mode = EMULATE;
28068 - else if (!strcmp("native", str))
28069 - vsyscall_mode = NATIVE;
28070 else if (!strcmp("none", str))
28071 vsyscall_mode = NONE;
28072 else
28073 @@ -279,8 +277,7 @@ do_ret:
28074 return true;
28075
28076 sigsegv:
28077 - force_sig(SIGSEGV, current);
28078 - return true;
28079 + do_group_exit(SIGKILL);
28080 }
28081
28082 /*
28083 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28084 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28085 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28086
28087 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28088 - vsyscall_mode == NATIVE
28089 - ? PAGE_KERNEL_VSYSCALL
28090 - : PAGE_KERNEL_VVAR);
28091 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28092 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28093 (unsigned long)VSYSCALL_START);
28094
28095 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28096 index 04068192..4d75aa6 100644
28097 --- a/arch/x86/kernel/x8664_ksyms_64.c
28098 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28099 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28100 EXPORT_SYMBOL(copy_user_generic_unrolled);
28101 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28102 EXPORT_SYMBOL(__copy_user_nocache);
28103 -EXPORT_SYMBOL(_copy_from_user);
28104 -EXPORT_SYMBOL(_copy_to_user);
28105
28106 EXPORT_SYMBOL(copy_page);
28107 EXPORT_SYMBOL(clear_page);
28108 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28109 EXPORT_SYMBOL(___preempt_schedule_context);
28110 #endif
28111 #endif
28112 +
28113 +#ifdef CONFIG_PAX_PER_CPU_PGD
28114 +EXPORT_SYMBOL(cpu_pgd);
28115 +#endif
28116 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28117 index e48b674..a451dd9 100644
28118 --- a/arch/x86/kernel/x86_init.c
28119 +++ b/arch/x86/kernel/x86_init.c
28120 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28121 static void default_nmi_init(void) { };
28122 static int default_i8042_detect(void) { return 1; };
28123
28124 -struct x86_platform_ops x86_platform = {
28125 +struct x86_platform_ops x86_platform __read_only = {
28126 .calibrate_tsc = native_calibrate_tsc,
28127 .get_wallclock = mach_get_cmos_time,
28128 .set_wallclock = mach_set_rtc_mmss,
28129 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28130 EXPORT_SYMBOL_GPL(x86_platform);
28131
28132 #if defined(CONFIG_PCI_MSI)
28133 -struct x86_msi_ops x86_msi = {
28134 +struct x86_msi_ops x86_msi __read_only = {
28135 .setup_msi_irqs = native_setup_msi_irqs,
28136 .compose_msi_msg = native_compose_msi_msg,
28137 .teardown_msi_irq = native_teardown_msi_irq,
28138 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28139 }
28140 #endif
28141
28142 -struct x86_io_apic_ops x86_io_apic_ops = {
28143 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28144 .init = native_io_apic_init_mappings,
28145 .read = native_io_apic_read,
28146 .write = native_io_apic_write,
28147 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28148 index a4b451c..8dfe1ad 100644
28149 --- a/arch/x86/kernel/xsave.c
28150 +++ b/arch/x86/kernel/xsave.c
28151 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28152
28153 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28154 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28155 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28156 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28157
28158 if (!use_xsave())
28159 return err;
28160
28161 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28162 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28163
28164 /*
28165 * Read the xstate_bv which we copied (directly from the cpu or
28166 * from the state in task struct) to the user buffers.
28167 */
28168 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28169 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28170
28171 /*
28172 * For legacy compatible, we always set FP/SSE bits in the bit
28173 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28174 */
28175 xstate_bv |= XSTATE_FPSSE;
28176
28177 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28178 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28179
28180 return err;
28181 }
28182 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28183 {
28184 int err;
28185
28186 + buf = (struct xsave_struct __user *)____m(buf);
28187 if (use_xsave())
28188 err = xsave_user(buf);
28189 else if (use_fxsr())
28190 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28191 */
28192 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28193 {
28194 + buf = (void __user *)____m(buf);
28195 if (use_xsave()) {
28196 if ((unsigned long)buf % 64 || fx_only) {
28197 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28198 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28199 index f47a104..5ce59a8 100644
28200 --- a/arch/x86/kvm/cpuid.c
28201 +++ b/arch/x86/kvm/cpuid.c
28202 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28203 struct kvm_cpuid2 *cpuid,
28204 struct kvm_cpuid_entry2 __user *entries)
28205 {
28206 - int r;
28207 + int r, i;
28208
28209 r = -E2BIG;
28210 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28211 goto out;
28212 r = -EFAULT;
28213 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28214 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28215 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28216 goto out;
28217 + for (i = 0; i < cpuid->nent; ++i) {
28218 + struct kvm_cpuid_entry2 cpuid_entry;
28219 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28220 + goto out;
28221 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28222 + }
28223 vcpu->arch.cpuid_nent = cpuid->nent;
28224 kvm_apic_set_version(vcpu);
28225 kvm_x86_ops->cpuid_update(vcpu);
28226 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28227 struct kvm_cpuid2 *cpuid,
28228 struct kvm_cpuid_entry2 __user *entries)
28229 {
28230 - int r;
28231 + int r, i;
28232
28233 r = -E2BIG;
28234 if (cpuid->nent < vcpu->arch.cpuid_nent)
28235 goto out;
28236 r = -EFAULT;
28237 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28238 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28239 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28240 goto out;
28241 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28242 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28243 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28244 + goto out;
28245 + }
28246 return 0;
28247
28248 out:
28249 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28250 index 0069118..c28ec0a 100644
28251 --- a/arch/x86/kvm/lapic.c
28252 +++ b/arch/x86/kvm/lapic.c
28253 @@ -55,7 +55,7 @@
28254 #define APIC_BUS_CYCLE_NS 1
28255
28256 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28257 -#define apic_debug(fmt, arg...)
28258 +#define apic_debug(fmt, arg...) do {} while (0)
28259
28260 #define APIC_LVT_NUM 6
28261 /* 14 is the version for Xeon and Pentium 8.4.8*/
28262 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28263 index 123efd3..ad7726e 100644
28264 --- a/arch/x86/kvm/paging_tmpl.h
28265 +++ b/arch/x86/kvm/paging_tmpl.h
28266 @@ -331,7 +331,7 @@ retry_walk:
28267 if (unlikely(kvm_is_error_hva(host_addr)))
28268 goto error;
28269
28270 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28271 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28272 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28273 goto error;
28274 walker->ptep_user[walker->level - 1] = ptep_user;
28275 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28276 index 7f4f9c2..67b1db0 100644
28277 --- a/arch/x86/kvm/svm.c
28278 +++ b/arch/x86/kvm/svm.c
28279 @@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28280 int cpu = raw_smp_processor_id();
28281
28282 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28283 +
28284 + pax_open_kernel();
28285 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28286 + pax_close_kernel();
28287 +
28288 load_TR_desc();
28289 }
28290
28291 @@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28292 #endif
28293 #endif
28294
28295 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28296 + __set_fs(current_thread_info()->addr_limit);
28297 +#endif
28298 +
28299 reload_tss(vcpu);
28300
28301 local_irq_disable();
28302 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28303 index 138ceff..2e584f0 100644
28304 --- a/arch/x86/kvm/vmx.c
28305 +++ b/arch/x86/kvm/vmx.c
28306 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28307 #endif
28308 }
28309
28310 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28311 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28312 {
28313 vmcs_writel(field, vmcs_readl(field) & ~mask);
28314 }
28315
28316 -static void vmcs_set_bits(unsigned long field, u32 mask)
28317 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28318 {
28319 vmcs_writel(field, vmcs_readl(field) | mask);
28320 }
28321 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28322 struct desc_struct *descs;
28323
28324 descs = (void *)gdt->address;
28325 +
28326 + pax_open_kernel();
28327 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28328 + pax_close_kernel();
28329 +
28330 load_TR_desc();
28331 }
28332
28333 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28334 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28335 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28336
28337 +#ifdef CONFIG_PAX_PER_CPU_PGD
28338 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28339 +#endif
28340 +
28341 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28342 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28343 vmx->loaded_vmcs->cpu = cpu;
28344 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28345 * reads and returns guest's timestamp counter "register"
28346 * guest_tsc = host_tsc + tsc_offset -- 21.3
28347 */
28348 -static u64 guest_read_tsc(void)
28349 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28350 {
28351 u64 host_tsc, tsc_offset;
28352
28353 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28354 if (!cpu_has_vmx_flexpriority())
28355 flexpriority_enabled = 0;
28356
28357 - if (!cpu_has_vmx_tpr_shadow())
28358 - kvm_x86_ops->update_cr8_intercept = NULL;
28359 + if (!cpu_has_vmx_tpr_shadow()) {
28360 + pax_open_kernel();
28361 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28362 + pax_close_kernel();
28363 + }
28364
28365 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28366 kvm_disable_largepages();
28367 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28368 if (!cpu_has_vmx_apicv())
28369 enable_apicv = 0;
28370
28371 + pax_open_kernel();
28372 if (enable_apicv)
28373 - kvm_x86_ops->update_cr8_intercept = NULL;
28374 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28375 else {
28376 - kvm_x86_ops->hwapic_irr_update = NULL;
28377 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28378 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28379 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28380 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28381 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28382 }
28383 + pax_close_kernel();
28384
28385 if (nested)
28386 nested_vmx_setup_ctls_msrs();
28387 @@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28388
28389 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28390 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28391 +
28392 +#ifndef CONFIG_PAX_PER_CPU_PGD
28393 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28394 +#endif
28395
28396 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28397 #ifdef CONFIG_X86_64
28398 @@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28399 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28400 vmx->host_idt_base = dt.address;
28401
28402 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28403 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28404
28405 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28406 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28407 @@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28408 "jmp 2f \n\t"
28409 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28410 "2: "
28411 +
28412 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28413 + "ljmp %[cs],$3f\n\t"
28414 + "3: "
28415 +#endif
28416 +
28417 /* Save guest registers, load host registers, keep flags */
28418 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28419 "pop %0 \n\t"
28420 @@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28421 #endif
28422 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28423 [wordsize]"i"(sizeof(ulong))
28424 +
28425 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28426 + ,[cs]"i"(__KERNEL_CS)
28427 +#endif
28428 +
28429 : "cc", "memory"
28430 #ifdef CONFIG_X86_64
28431 , "rax", "rbx", "rdi", "rsi"
28432 @@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28433 if (debugctlmsr)
28434 update_debugctlmsr(debugctlmsr);
28435
28436 -#ifndef CONFIG_X86_64
28437 +#ifdef CONFIG_X86_32
28438 /*
28439 * The sysexit path does not restore ds/es, so we must set them to
28440 * a reasonable value ourselves.
28441 @@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28442 * may be executed in interrupt context, which saves and restore segments
28443 * around it, nullifying its effect.
28444 */
28445 - loadsegment(ds, __USER_DS);
28446 - loadsegment(es, __USER_DS);
28447 + loadsegment(ds, __KERNEL_DS);
28448 + loadsegment(es, __KERNEL_DS);
28449 + loadsegment(ss, __KERNEL_DS);
28450 +
28451 +#ifdef CONFIG_PAX_KERNEXEC
28452 + loadsegment(fs, __KERNEL_PERCPU);
28453 +#endif
28454 +
28455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28456 + __set_fs(current_thread_info()->addr_limit);
28457 +#endif
28458 +
28459 #endif
28460
28461 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28462 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28463 index 20316c6..9b3dddc 100644
28464 --- a/arch/x86/kvm/x86.c
28465 +++ b/arch/x86/kvm/x86.c
28466 @@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28467 {
28468 struct kvm *kvm = vcpu->kvm;
28469 int lm = is_long_mode(vcpu);
28470 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28471 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28472 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28473 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28474 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28475 : kvm->arch.xen_hvm_config.blob_size_32;
28476 u32 page_num = data & ~PAGE_MASK;
28477 @@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28478 if (n < msr_list.nmsrs)
28479 goto out;
28480 r = -EFAULT;
28481 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28482 + goto out;
28483 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28484 num_msrs_to_save * sizeof(u32)))
28485 goto out;
28486 @@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28487 };
28488 #endif
28489
28490 -int kvm_arch_init(void *opaque)
28491 +int kvm_arch_init(const void *opaque)
28492 {
28493 int r;
28494 struct kvm_x86_ops *ops = opaque;
28495 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28496 index aae9413..d11e829 100644
28497 --- a/arch/x86/lguest/boot.c
28498 +++ b/arch/x86/lguest/boot.c
28499 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28500 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28501 * Launcher to reboot us.
28502 */
28503 -static void lguest_restart(char *reason)
28504 +static __noreturn void lguest_restart(char *reason)
28505 {
28506 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28507 + BUG();
28508 }
28509
28510 /*G:050
28511 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28512 index 00933d5..3a64af9 100644
28513 --- a/arch/x86/lib/atomic64_386_32.S
28514 +++ b/arch/x86/lib/atomic64_386_32.S
28515 @@ -48,6 +48,10 @@ BEGIN(read)
28516 movl (v), %eax
28517 movl 4(v), %edx
28518 RET_ENDP
28519 +BEGIN(read_unchecked)
28520 + movl (v), %eax
28521 + movl 4(v), %edx
28522 +RET_ENDP
28523 #undef v
28524
28525 #define v %esi
28526 @@ -55,6 +59,10 @@ BEGIN(set)
28527 movl %ebx, (v)
28528 movl %ecx, 4(v)
28529 RET_ENDP
28530 +BEGIN(set_unchecked)
28531 + movl %ebx, (v)
28532 + movl %ecx, 4(v)
28533 +RET_ENDP
28534 #undef v
28535
28536 #define v %esi
28537 @@ -70,6 +78,20 @@ RET_ENDP
28538 BEGIN(add)
28539 addl %eax, (v)
28540 adcl %edx, 4(v)
28541 +
28542 +#ifdef CONFIG_PAX_REFCOUNT
28543 + jno 0f
28544 + subl %eax, (v)
28545 + sbbl %edx, 4(v)
28546 + int $4
28547 +0:
28548 + _ASM_EXTABLE(0b, 0b)
28549 +#endif
28550 +
28551 +RET_ENDP
28552 +BEGIN(add_unchecked)
28553 + addl %eax, (v)
28554 + adcl %edx, 4(v)
28555 RET_ENDP
28556 #undef v
28557
28558 @@ -77,6 +99,24 @@ RET_ENDP
28559 BEGIN(add_return)
28560 addl (v), %eax
28561 adcl 4(v), %edx
28562 +
28563 +#ifdef CONFIG_PAX_REFCOUNT
28564 + into
28565 +1234:
28566 + _ASM_EXTABLE(1234b, 2f)
28567 +#endif
28568 +
28569 + movl %eax, (v)
28570 + movl %edx, 4(v)
28571 +
28572 +#ifdef CONFIG_PAX_REFCOUNT
28573 +2:
28574 +#endif
28575 +
28576 +RET_ENDP
28577 +BEGIN(add_return_unchecked)
28578 + addl (v), %eax
28579 + adcl 4(v), %edx
28580 movl %eax, (v)
28581 movl %edx, 4(v)
28582 RET_ENDP
28583 @@ -86,6 +126,20 @@ RET_ENDP
28584 BEGIN(sub)
28585 subl %eax, (v)
28586 sbbl %edx, 4(v)
28587 +
28588 +#ifdef CONFIG_PAX_REFCOUNT
28589 + jno 0f
28590 + addl %eax, (v)
28591 + adcl %edx, 4(v)
28592 + int $4
28593 +0:
28594 + _ASM_EXTABLE(0b, 0b)
28595 +#endif
28596 +
28597 +RET_ENDP
28598 +BEGIN(sub_unchecked)
28599 + subl %eax, (v)
28600 + sbbl %edx, 4(v)
28601 RET_ENDP
28602 #undef v
28603
28604 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28605 sbbl $0, %edx
28606 addl (v), %eax
28607 adcl 4(v), %edx
28608 +
28609 +#ifdef CONFIG_PAX_REFCOUNT
28610 + into
28611 +1234:
28612 + _ASM_EXTABLE(1234b, 2f)
28613 +#endif
28614 +
28615 + movl %eax, (v)
28616 + movl %edx, 4(v)
28617 +
28618 +#ifdef CONFIG_PAX_REFCOUNT
28619 +2:
28620 +#endif
28621 +
28622 +RET_ENDP
28623 +BEGIN(sub_return_unchecked)
28624 + negl %edx
28625 + negl %eax
28626 + sbbl $0, %edx
28627 + addl (v), %eax
28628 + adcl 4(v), %edx
28629 movl %eax, (v)
28630 movl %edx, 4(v)
28631 RET_ENDP
28632 @@ -105,6 +180,20 @@ RET_ENDP
28633 BEGIN(inc)
28634 addl $1, (v)
28635 adcl $0, 4(v)
28636 +
28637 +#ifdef CONFIG_PAX_REFCOUNT
28638 + jno 0f
28639 + subl $1, (v)
28640 + sbbl $0, 4(v)
28641 + int $4
28642 +0:
28643 + _ASM_EXTABLE(0b, 0b)
28644 +#endif
28645 +
28646 +RET_ENDP
28647 +BEGIN(inc_unchecked)
28648 + addl $1, (v)
28649 + adcl $0, 4(v)
28650 RET_ENDP
28651 #undef v
28652
28653 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28654 movl 4(v), %edx
28655 addl $1, %eax
28656 adcl $0, %edx
28657 +
28658 +#ifdef CONFIG_PAX_REFCOUNT
28659 + into
28660 +1234:
28661 + _ASM_EXTABLE(1234b, 2f)
28662 +#endif
28663 +
28664 + movl %eax, (v)
28665 + movl %edx, 4(v)
28666 +
28667 +#ifdef CONFIG_PAX_REFCOUNT
28668 +2:
28669 +#endif
28670 +
28671 +RET_ENDP
28672 +BEGIN(inc_return_unchecked)
28673 + movl (v), %eax
28674 + movl 4(v), %edx
28675 + addl $1, %eax
28676 + adcl $0, %edx
28677 movl %eax, (v)
28678 movl %edx, 4(v)
28679 RET_ENDP
28680 @@ -123,6 +232,20 @@ RET_ENDP
28681 BEGIN(dec)
28682 subl $1, (v)
28683 sbbl $0, 4(v)
28684 +
28685 +#ifdef CONFIG_PAX_REFCOUNT
28686 + jno 0f
28687 + addl $1, (v)
28688 + adcl $0, 4(v)
28689 + int $4
28690 +0:
28691 + _ASM_EXTABLE(0b, 0b)
28692 +#endif
28693 +
28694 +RET_ENDP
28695 +BEGIN(dec_unchecked)
28696 + subl $1, (v)
28697 + sbbl $0, 4(v)
28698 RET_ENDP
28699 #undef v
28700
28701 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28702 movl 4(v), %edx
28703 subl $1, %eax
28704 sbbl $0, %edx
28705 +
28706 +#ifdef CONFIG_PAX_REFCOUNT
28707 + into
28708 +1234:
28709 + _ASM_EXTABLE(1234b, 2f)
28710 +#endif
28711 +
28712 + movl %eax, (v)
28713 + movl %edx, 4(v)
28714 +
28715 +#ifdef CONFIG_PAX_REFCOUNT
28716 +2:
28717 +#endif
28718 +
28719 +RET_ENDP
28720 +BEGIN(dec_return_unchecked)
28721 + movl (v), %eax
28722 + movl 4(v), %edx
28723 + subl $1, %eax
28724 + sbbl $0, %edx
28725 movl %eax, (v)
28726 movl %edx, 4(v)
28727 RET_ENDP
28728 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28729 adcl %edx, %edi
28730 addl (v), %eax
28731 adcl 4(v), %edx
28732 +
28733 +#ifdef CONFIG_PAX_REFCOUNT
28734 + into
28735 +1234:
28736 + _ASM_EXTABLE(1234b, 2f)
28737 +#endif
28738 +
28739 cmpl %eax, %ecx
28740 je 3f
28741 1:
28742 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28743 1:
28744 addl $1, %eax
28745 adcl $0, %edx
28746 +
28747 +#ifdef CONFIG_PAX_REFCOUNT
28748 + into
28749 +1234:
28750 + _ASM_EXTABLE(1234b, 2f)
28751 +#endif
28752 +
28753 movl %eax, (v)
28754 movl %edx, 4(v)
28755 movl $1, %eax
28756 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28757 movl 4(v), %edx
28758 subl $1, %eax
28759 sbbl $0, %edx
28760 +
28761 +#ifdef CONFIG_PAX_REFCOUNT
28762 + into
28763 +1234:
28764 + _ASM_EXTABLE(1234b, 1f)
28765 +#endif
28766 +
28767 js 1f
28768 movl %eax, (v)
28769 movl %edx, 4(v)
28770 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28771 index f5cc9eb..51fa319 100644
28772 --- a/arch/x86/lib/atomic64_cx8_32.S
28773 +++ b/arch/x86/lib/atomic64_cx8_32.S
28774 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28775 CFI_STARTPROC
28776
28777 read64 %ecx
28778 + pax_force_retaddr
28779 ret
28780 CFI_ENDPROC
28781 ENDPROC(atomic64_read_cx8)
28782
28783 +ENTRY(atomic64_read_unchecked_cx8)
28784 + CFI_STARTPROC
28785 +
28786 + read64 %ecx
28787 + pax_force_retaddr
28788 + ret
28789 + CFI_ENDPROC
28790 +ENDPROC(atomic64_read_unchecked_cx8)
28791 +
28792 ENTRY(atomic64_set_cx8)
28793 CFI_STARTPROC
28794
28795 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28796 cmpxchg8b (%esi)
28797 jne 1b
28798
28799 + pax_force_retaddr
28800 ret
28801 CFI_ENDPROC
28802 ENDPROC(atomic64_set_cx8)
28803
28804 +ENTRY(atomic64_set_unchecked_cx8)
28805 + CFI_STARTPROC
28806 +
28807 +1:
28808 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28809 + * are atomic on 586 and newer */
28810 + cmpxchg8b (%esi)
28811 + jne 1b
28812 +
28813 + pax_force_retaddr
28814 + ret
28815 + CFI_ENDPROC
28816 +ENDPROC(atomic64_set_unchecked_cx8)
28817 +
28818 ENTRY(atomic64_xchg_cx8)
28819 CFI_STARTPROC
28820
28821 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28822 cmpxchg8b (%esi)
28823 jne 1b
28824
28825 + pax_force_retaddr
28826 ret
28827 CFI_ENDPROC
28828 ENDPROC(atomic64_xchg_cx8)
28829
28830 -.macro addsub_return func ins insc
28831 -ENTRY(atomic64_\func\()_return_cx8)
28832 +.macro addsub_return func ins insc unchecked=""
28833 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28834 CFI_STARTPROC
28835 SAVE ebp
28836 SAVE ebx
28837 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28838 movl %edx, %ecx
28839 \ins\()l %esi, %ebx
28840 \insc\()l %edi, %ecx
28841 +
28842 +.ifb \unchecked
28843 +#ifdef CONFIG_PAX_REFCOUNT
28844 + into
28845 +2:
28846 + _ASM_EXTABLE(2b, 3f)
28847 +#endif
28848 +.endif
28849 +
28850 LOCK_PREFIX
28851 cmpxchg8b (%ebp)
28852 jne 1b
28853 -
28854 -10:
28855 movl %ebx, %eax
28856 movl %ecx, %edx
28857 +
28858 +.ifb \unchecked
28859 +#ifdef CONFIG_PAX_REFCOUNT
28860 +3:
28861 +#endif
28862 +.endif
28863 +
28864 RESTORE edi
28865 RESTORE esi
28866 RESTORE ebx
28867 RESTORE ebp
28868 + pax_force_retaddr
28869 ret
28870 CFI_ENDPROC
28871 -ENDPROC(atomic64_\func\()_return_cx8)
28872 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28873 .endm
28874
28875 addsub_return add add adc
28876 addsub_return sub sub sbb
28877 +addsub_return add add adc _unchecked
28878 +addsub_return sub sub sbb _unchecked
28879
28880 -.macro incdec_return func ins insc
28881 -ENTRY(atomic64_\func\()_return_cx8)
28882 +.macro incdec_return func ins insc unchecked=""
28883 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28884 CFI_STARTPROC
28885 SAVE ebx
28886
28887 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28888 movl %edx, %ecx
28889 \ins\()l $1, %ebx
28890 \insc\()l $0, %ecx
28891 +
28892 +.ifb \unchecked
28893 +#ifdef CONFIG_PAX_REFCOUNT
28894 + into
28895 +2:
28896 + _ASM_EXTABLE(2b, 3f)
28897 +#endif
28898 +.endif
28899 +
28900 LOCK_PREFIX
28901 cmpxchg8b (%esi)
28902 jne 1b
28903
28904 -10:
28905 movl %ebx, %eax
28906 movl %ecx, %edx
28907 +
28908 +.ifb \unchecked
28909 +#ifdef CONFIG_PAX_REFCOUNT
28910 +3:
28911 +#endif
28912 +.endif
28913 +
28914 RESTORE ebx
28915 + pax_force_retaddr
28916 ret
28917 CFI_ENDPROC
28918 -ENDPROC(atomic64_\func\()_return_cx8)
28919 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28920 .endm
28921
28922 incdec_return inc add adc
28923 incdec_return dec sub sbb
28924 +incdec_return inc add adc _unchecked
28925 +incdec_return dec sub sbb _unchecked
28926
28927 ENTRY(atomic64_dec_if_positive_cx8)
28928 CFI_STARTPROC
28929 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28930 movl %edx, %ecx
28931 subl $1, %ebx
28932 sbb $0, %ecx
28933 +
28934 +#ifdef CONFIG_PAX_REFCOUNT
28935 + into
28936 +1234:
28937 + _ASM_EXTABLE(1234b, 2f)
28938 +#endif
28939 +
28940 js 2f
28941 LOCK_PREFIX
28942 cmpxchg8b (%esi)
28943 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28944 movl %ebx, %eax
28945 movl %ecx, %edx
28946 RESTORE ebx
28947 + pax_force_retaddr
28948 ret
28949 CFI_ENDPROC
28950 ENDPROC(atomic64_dec_if_positive_cx8)
28951 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28952 movl %edx, %ecx
28953 addl %ebp, %ebx
28954 adcl %edi, %ecx
28955 +
28956 +#ifdef CONFIG_PAX_REFCOUNT
28957 + into
28958 +1234:
28959 + _ASM_EXTABLE(1234b, 3f)
28960 +#endif
28961 +
28962 LOCK_PREFIX
28963 cmpxchg8b (%esi)
28964 jne 1b
28965 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28966 CFI_ADJUST_CFA_OFFSET -8
28967 RESTORE ebx
28968 RESTORE ebp
28969 + pax_force_retaddr
28970 ret
28971 4:
28972 cmpl %edx, 4(%esp)
28973 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28974 xorl %ecx, %ecx
28975 addl $1, %ebx
28976 adcl %edx, %ecx
28977 +
28978 +#ifdef CONFIG_PAX_REFCOUNT
28979 + into
28980 +1234:
28981 + _ASM_EXTABLE(1234b, 3f)
28982 +#endif
28983 +
28984 LOCK_PREFIX
28985 cmpxchg8b (%esi)
28986 jne 1b
28987 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28988 movl $1, %eax
28989 3:
28990 RESTORE ebx
28991 + pax_force_retaddr
28992 ret
28993 CFI_ENDPROC
28994 ENDPROC(atomic64_inc_not_zero_cx8)
28995 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28996 index e78b8ee..7e173a8 100644
28997 --- a/arch/x86/lib/checksum_32.S
28998 +++ b/arch/x86/lib/checksum_32.S
28999 @@ -29,7 +29,8 @@
29000 #include <asm/dwarf2.h>
29001 #include <asm/errno.h>
29002 #include <asm/asm.h>
29003 -
29004 +#include <asm/segment.h>
29005 +
29006 /*
29007 * computes a partial checksum, e.g. for TCP/UDP fragments
29008 */
29009 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29010
29011 #define ARGBASE 16
29012 #define FP 12
29013 -
29014 -ENTRY(csum_partial_copy_generic)
29015 +
29016 +ENTRY(csum_partial_copy_generic_to_user)
29017 CFI_STARTPROC
29018 +
29019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29020 + pushl_cfi %gs
29021 + popl_cfi %es
29022 + jmp csum_partial_copy_generic
29023 +#endif
29024 +
29025 +ENTRY(csum_partial_copy_generic_from_user)
29026 +
29027 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29028 + pushl_cfi %gs
29029 + popl_cfi %ds
29030 +#endif
29031 +
29032 +ENTRY(csum_partial_copy_generic)
29033 subl $4,%esp
29034 CFI_ADJUST_CFA_OFFSET 4
29035 pushl_cfi %edi
29036 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29037 jmp 4f
29038 SRC(1: movw (%esi), %bx )
29039 addl $2, %esi
29040 -DST( movw %bx, (%edi) )
29041 +DST( movw %bx, %es:(%edi) )
29042 addl $2, %edi
29043 addw %bx, %ax
29044 adcl $0, %eax
29045 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29046 SRC(1: movl (%esi), %ebx )
29047 SRC( movl 4(%esi), %edx )
29048 adcl %ebx, %eax
29049 -DST( movl %ebx, (%edi) )
29050 +DST( movl %ebx, %es:(%edi) )
29051 adcl %edx, %eax
29052 -DST( movl %edx, 4(%edi) )
29053 +DST( movl %edx, %es:4(%edi) )
29054
29055 SRC( movl 8(%esi), %ebx )
29056 SRC( movl 12(%esi), %edx )
29057 adcl %ebx, %eax
29058 -DST( movl %ebx, 8(%edi) )
29059 +DST( movl %ebx, %es:8(%edi) )
29060 adcl %edx, %eax
29061 -DST( movl %edx, 12(%edi) )
29062 +DST( movl %edx, %es:12(%edi) )
29063
29064 SRC( movl 16(%esi), %ebx )
29065 SRC( movl 20(%esi), %edx )
29066 adcl %ebx, %eax
29067 -DST( movl %ebx, 16(%edi) )
29068 +DST( movl %ebx, %es:16(%edi) )
29069 adcl %edx, %eax
29070 -DST( movl %edx, 20(%edi) )
29071 +DST( movl %edx, %es:20(%edi) )
29072
29073 SRC( movl 24(%esi), %ebx )
29074 SRC( movl 28(%esi), %edx )
29075 adcl %ebx, %eax
29076 -DST( movl %ebx, 24(%edi) )
29077 +DST( movl %ebx, %es:24(%edi) )
29078 adcl %edx, %eax
29079 -DST( movl %edx, 28(%edi) )
29080 +DST( movl %edx, %es:28(%edi) )
29081
29082 lea 32(%esi), %esi
29083 lea 32(%edi), %edi
29084 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29085 shrl $2, %edx # This clears CF
29086 SRC(3: movl (%esi), %ebx )
29087 adcl %ebx, %eax
29088 -DST( movl %ebx, (%edi) )
29089 +DST( movl %ebx, %es:(%edi) )
29090 lea 4(%esi), %esi
29091 lea 4(%edi), %edi
29092 dec %edx
29093 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29094 jb 5f
29095 SRC( movw (%esi), %cx )
29096 leal 2(%esi), %esi
29097 -DST( movw %cx, (%edi) )
29098 +DST( movw %cx, %es:(%edi) )
29099 leal 2(%edi), %edi
29100 je 6f
29101 shll $16,%ecx
29102 SRC(5: movb (%esi), %cl )
29103 -DST( movb %cl, (%edi) )
29104 +DST( movb %cl, %es:(%edi) )
29105 6: addl %ecx, %eax
29106 adcl $0, %eax
29107 7:
29108 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29109
29110 6001:
29111 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29112 - movl $-EFAULT, (%ebx)
29113 + movl $-EFAULT, %ss:(%ebx)
29114
29115 # zero the complete destination - computing the rest
29116 # is too much work
29117 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29118
29119 6002:
29120 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29121 - movl $-EFAULT,(%ebx)
29122 + movl $-EFAULT,%ss:(%ebx)
29123 jmp 5000b
29124
29125 .previous
29126
29127 + pushl_cfi %ss
29128 + popl_cfi %ds
29129 + pushl_cfi %ss
29130 + popl_cfi %es
29131 popl_cfi %ebx
29132 CFI_RESTORE ebx
29133 popl_cfi %esi
29134 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29135 popl_cfi %ecx # equivalent to addl $4,%esp
29136 ret
29137 CFI_ENDPROC
29138 -ENDPROC(csum_partial_copy_generic)
29139 +ENDPROC(csum_partial_copy_generic_to_user)
29140
29141 #else
29142
29143 /* Version for PentiumII/PPro */
29144
29145 #define ROUND1(x) \
29146 + nop; nop; nop; \
29147 SRC(movl x(%esi), %ebx ) ; \
29148 addl %ebx, %eax ; \
29149 - DST(movl %ebx, x(%edi) ) ;
29150 + DST(movl %ebx, %es:x(%edi)) ;
29151
29152 #define ROUND(x) \
29153 + nop; nop; nop; \
29154 SRC(movl x(%esi), %ebx ) ; \
29155 adcl %ebx, %eax ; \
29156 - DST(movl %ebx, x(%edi) ) ;
29157 + DST(movl %ebx, %es:x(%edi)) ;
29158
29159 #define ARGBASE 12
29160 -
29161 -ENTRY(csum_partial_copy_generic)
29162 +
29163 +ENTRY(csum_partial_copy_generic_to_user)
29164 CFI_STARTPROC
29165 +
29166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29167 + pushl_cfi %gs
29168 + popl_cfi %es
29169 + jmp csum_partial_copy_generic
29170 +#endif
29171 +
29172 +ENTRY(csum_partial_copy_generic_from_user)
29173 +
29174 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29175 + pushl_cfi %gs
29176 + popl_cfi %ds
29177 +#endif
29178 +
29179 +ENTRY(csum_partial_copy_generic)
29180 pushl_cfi %ebx
29181 CFI_REL_OFFSET ebx, 0
29182 pushl_cfi %edi
29183 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29184 subl %ebx, %edi
29185 lea -1(%esi),%edx
29186 andl $-32,%edx
29187 - lea 3f(%ebx,%ebx), %ebx
29188 + lea 3f(%ebx,%ebx,2), %ebx
29189 testl %esi, %esi
29190 jmp *%ebx
29191 1: addl $64,%esi
29192 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29193 jb 5f
29194 SRC( movw (%esi), %dx )
29195 leal 2(%esi), %esi
29196 -DST( movw %dx, (%edi) )
29197 +DST( movw %dx, %es:(%edi) )
29198 leal 2(%edi), %edi
29199 je 6f
29200 shll $16,%edx
29201 5:
29202 SRC( movb (%esi), %dl )
29203 -DST( movb %dl, (%edi) )
29204 +DST( movb %dl, %es:(%edi) )
29205 6: addl %edx, %eax
29206 adcl $0, %eax
29207 7:
29208 .section .fixup, "ax"
29209 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29210 - movl $-EFAULT, (%ebx)
29211 + movl $-EFAULT, %ss:(%ebx)
29212 # zero the complete destination (computing the rest is too much work)
29213 movl ARGBASE+8(%esp),%edi # dst
29214 movl ARGBASE+12(%esp),%ecx # len
29215 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29216 rep; stosb
29217 jmp 7b
29218 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29219 - movl $-EFAULT, (%ebx)
29220 + movl $-EFAULT, %ss:(%ebx)
29221 jmp 7b
29222 .previous
29223
29224 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29225 + pushl_cfi %ss
29226 + popl_cfi %ds
29227 + pushl_cfi %ss
29228 + popl_cfi %es
29229 +#endif
29230 +
29231 popl_cfi %esi
29232 CFI_RESTORE esi
29233 popl_cfi %edi
29234 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29235 CFI_RESTORE ebx
29236 ret
29237 CFI_ENDPROC
29238 -ENDPROC(csum_partial_copy_generic)
29239 +ENDPROC(csum_partial_copy_generic_to_user)
29240
29241 #undef ROUND
29242 #undef ROUND1
29243 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29244 index f2145cf..cea889d 100644
29245 --- a/arch/x86/lib/clear_page_64.S
29246 +++ b/arch/x86/lib/clear_page_64.S
29247 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29248 movl $4096/8,%ecx
29249 xorl %eax,%eax
29250 rep stosq
29251 + pax_force_retaddr
29252 ret
29253 CFI_ENDPROC
29254 ENDPROC(clear_page_c)
29255 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29256 movl $4096,%ecx
29257 xorl %eax,%eax
29258 rep stosb
29259 + pax_force_retaddr
29260 ret
29261 CFI_ENDPROC
29262 ENDPROC(clear_page_c_e)
29263 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29264 leaq 64(%rdi),%rdi
29265 jnz .Lloop
29266 nop
29267 + pax_force_retaddr
29268 ret
29269 CFI_ENDPROC
29270 .Lclear_page_end:
29271 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29272
29273 #include <asm/cpufeature.h>
29274
29275 - .section .altinstr_replacement,"ax"
29276 + .section .altinstr_replacement,"a"
29277 1: .byte 0xeb /* jmp <disp8> */
29278 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29279 2: .byte 0xeb /* jmp <disp8> */
29280 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29281 index 1e572c5..2a162cd 100644
29282 --- a/arch/x86/lib/cmpxchg16b_emu.S
29283 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29284 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29285
29286 popf
29287 mov $1, %al
29288 + pax_force_retaddr
29289 ret
29290
29291 not_same:
29292 popf
29293 xor %al,%al
29294 + pax_force_retaddr
29295 ret
29296
29297 CFI_ENDPROC
29298 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29299 index 176cca6..e0d658e 100644
29300 --- a/arch/x86/lib/copy_page_64.S
29301 +++ b/arch/x86/lib/copy_page_64.S
29302 @@ -9,6 +9,7 @@ copy_page_rep:
29303 CFI_STARTPROC
29304 movl $4096/8, %ecx
29305 rep movsq
29306 + pax_force_retaddr
29307 ret
29308 CFI_ENDPROC
29309 ENDPROC(copy_page_rep)
29310 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29311 CFI_ADJUST_CFA_OFFSET 2*8
29312 movq %rbx, (%rsp)
29313 CFI_REL_OFFSET rbx, 0
29314 - movq %r12, 1*8(%rsp)
29315 - CFI_REL_OFFSET r12, 1*8
29316 + movq %r13, 1*8(%rsp)
29317 + CFI_REL_OFFSET r13, 1*8
29318
29319 movl $(4096/64)-5, %ecx
29320 .p2align 4
29321 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29322 movq 0x8*4(%rsi), %r9
29323 movq 0x8*5(%rsi), %r10
29324 movq 0x8*6(%rsi), %r11
29325 - movq 0x8*7(%rsi), %r12
29326 + movq 0x8*7(%rsi), %r13
29327
29328 prefetcht0 5*64(%rsi)
29329
29330 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29331 movq %r9, 0x8*4(%rdi)
29332 movq %r10, 0x8*5(%rdi)
29333 movq %r11, 0x8*6(%rdi)
29334 - movq %r12, 0x8*7(%rdi)
29335 + movq %r13, 0x8*7(%rdi)
29336
29337 leaq 64 (%rsi), %rsi
29338 leaq 64 (%rdi), %rdi
29339 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29340 movq 0x8*4(%rsi), %r9
29341 movq 0x8*5(%rsi), %r10
29342 movq 0x8*6(%rsi), %r11
29343 - movq 0x8*7(%rsi), %r12
29344 + movq 0x8*7(%rsi), %r13
29345
29346 movq %rax, 0x8*0(%rdi)
29347 movq %rbx, 0x8*1(%rdi)
29348 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29349 movq %r9, 0x8*4(%rdi)
29350 movq %r10, 0x8*5(%rdi)
29351 movq %r11, 0x8*6(%rdi)
29352 - movq %r12, 0x8*7(%rdi)
29353 + movq %r13, 0x8*7(%rdi)
29354
29355 leaq 64(%rdi), %rdi
29356 leaq 64(%rsi), %rsi
29357 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29358
29359 movq (%rsp), %rbx
29360 CFI_RESTORE rbx
29361 - movq 1*8(%rsp), %r12
29362 - CFI_RESTORE r12
29363 + movq 1*8(%rsp), %r13
29364 + CFI_RESTORE r13
29365 addq $2*8, %rsp
29366 CFI_ADJUST_CFA_OFFSET -2*8
29367 + pax_force_retaddr
29368 ret
29369 .Lcopy_page_end:
29370 CFI_ENDPROC
29371 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29372
29373 #include <asm/cpufeature.h>
29374
29375 - .section .altinstr_replacement,"ax"
29376 + .section .altinstr_replacement,"a"
29377 1: .byte 0xeb /* jmp <disp8> */
29378 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29379 2:
29380 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29381 index dee945d..a84067b 100644
29382 --- a/arch/x86/lib/copy_user_64.S
29383 +++ b/arch/x86/lib/copy_user_64.S
29384 @@ -18,31 +18,7 @@
29385 #include <asm/alternative-asm.h>
29386 #include <asm/asm.h>
29387 #include <asm/smap.h>
29388 -
29389 -/*
29390 - * By placing feature2 after feature1 in altinstructions section, we logically
29391 - * implement:
29392 - * If CPU has feature2, jmp to alt2 is used
29393 - * else if CPU has feature1, jmp to alt1 is used
29394 - * else jmp to orig is used.
29395 - */
29396 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29397 -0:
29398 - .byte 0xe9 /* 32bit jump */
29399 - .long \orig-1f /* by default jump to orig */
29400 -1:
29401 - .section .altinstr_replacement,"ax"
29402 -2: .byte 0xe9 /* near jump with 32bit immediate */
29403 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29404 -3: .byte 0xe9 /* near jump with 32bit immediate */
29405 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29406 - .previous
29407 -
29408 - .section .altinstructions,"a"
29409 - altinstruction_entry 0b,2b,\feature1,5,5
29410 - altinstruction_entry 0b,3b,\feature2,5,5
29411 - .previous
29412 - .endm
29413 +#include <asm/pgtable.h>
29414
29415 .macro ALIGN_DESTINATION
29416 #ifdef FIX_ALIGNMENT
29417 @@ -70,52 +46,6 @@
29418 #endif
29419 .endm
29420
29421 -/* Standard copy_to_user with segment limit checking */
29422 -ENTRY(_copy_to_user)
29423 - CFI_STARTPROC
29424 - GET_THREAD_INFO(%rax)
29425 - movq %rdi,%rcx
29426 - addq %rdx,%rcx
29427 - jc bad_to_user
29428 - cmpq TI_addr_limit(%rax),%rcx
29429 - ja bad_to_user
29430 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29431 - copy_user_generic_unrolled,copy_user_generic_string, \
29432 - copy_user_enhanced_fast_string
29433 - CFI_ENDPROC
29434 -ENDPROC(_copy_to_user)
29435 -
29436 -/* Standard copy_from_user with segment limit checking */
29437 -ENTRY(_copy_from_user)
29438 - CFI_STARTPROC
29439 - GET_THREAD_INFO(%rax)
29440 - movq %rsi,%rcx
29441 - addq %rdx,%rcx
29442 - jc bad_from_user
29443 - cmpq TI_addr_limit(%rax),%rcx
29444 - ja bad_from_user
29445 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29446 - copy_user_generic_unrolled,copy_user_generic_string, \
29447 - copy_user_enhanced_fast_string
29448 - CFI_ENDPROC
29449 -ENDPROC(_copy_from_user)
29450 -
29451 - .section .fixup,"ax"
29452 - /* must zero dest */
29453 -ENTRY(bad_from_user)
29454 -bad_from_user:
29455 - CFI_STARTPROC
29456 - movl %edx,%ecx
29457 - xorl %eax,%eax
29458 - rep
29459 - stosb
29460 -bad_to_user:
29461 - movl %edx,%eax
29462 - ret
29463 - CFI_ENDPROC
29464 -ENDPROC(bad_from_user)
29465 - .previous
29466 -
29467 /*
29468 * copy_user_generic_unrolled - memory copy with exception handling.
29469 * This version is for CPUs like P4 that don't have efficient micro
29470 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29471 */
29472 ENTRY(copy_user_generic_unrolled)
29473 CFI_STARTPROC
29474 + ASM_PAX_OPEN_USERLAND
29475 ASM_STAC
29476 cmpl $8,%edx
29477 jb 20f /* less then 8 bytes, go to byte copy loop */
29478 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29479 jnz 21b
29480 23: xor %eax,%eax
29481 ASM_CLAC
29482 + ASM_PAX_CLOSE_USERLAND
29483 + pax_force_retaddr
29484 ret
29485
29486 .section .fixup,"ax"
29487 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29488 */
29489 ENTRY(copy_user_generic_string)
29490 CFI_STARTPROC
29491 + ASM_PAX_OPEN_USERLAND
29492 ASM_STAC
29493 cmpl $8,%edx
29494 jb 2f /* less than 8 bytes, go to byte copy loop */
29495 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29496 movsb
29497 xorl %eax,%eax
29498 ASM_CLAC
29499 + ASM_PAX_CLOSE_USERLAND
29500 + pax_force_retaddr
29501 ret
29502
29503 .section .fixup,"ax"
29504 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29505 */
29506 ENTRY(copy_user_enhanced_fast_string)
29507 CFI_STARTPROC
29508 + ASM_PAX_OPEN_USERLAND
29509 ASM_STAC
29510 movl %edx,%ecx
29511 1: rep
29512 movsb
29513 xorl %eax,%eax
29514 ASM_CLAC
29515 + ASM_PAX_CLOSE_USERLAND
29516 + pax_force_retaddr
29517 ret
29518
29519 .section .fixup,"ax"
29520 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29521 index 6a4f43c..c70fb52 100644
29522 --- a/arch/x86/lib/copy_user_nocache_64.S
29523 +++ b/arch/x86/lib/copy_user_nocache_64.S
29524 @@ -8,6 +8,7 @@
29525
29526 #include <linux/linkage.h>
29527 #include <asm/dwarf2.h>
29528 +#include <asm/alternative-asm.h>
29529
29530 #define FIX_ALIGNMENT 1
29531
29532 @@ -16,6 +17,7 @@
29533 #include <asm/thread_info.h>
29534 #include <asm/asm.h>
29535 #include <asm/smap.h>
29536 +#include <asm/pgtable.h>
29537
29538 .macro ALIGN_DESTINATION
29539 #ifdef FIX_ALIGNMENT
29540 @@ -49,6 +51,16 @@
29541 */
29542 ENTRY(__copy_user_nocache)
29543 CFI_STARTPROC
29544 +
29545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29546 + mov pax_user_shadow_base,%rcx
29547 + cmp %rcx,%rsi
29548 + jae 1f
29549 + add %rcx,%rsi
29550 +1:
29551 +#endif
29552 +
29553 + ASM_PAX_OPEN_USERLAND
29554 ASM_STAC
29555 cmpl $8,%edx
29556 jb 20f /* less then 8 bytes, go to byte copy loop */
29557 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29558 jnz 21b
29559 23: xorl %eax,%eax
29560 ASM_CLAC
29561 + ASM_PAX_CLOSE_USERLAND
29562 sfence
29563 + pax_force_retaddr
29564 ret
29565
29566 .section .fixup,"ax"
29567 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29568 index 2419d5f..fe52d0e 100644
29569 --- a/arch/x86/lib/csum-copy_64.S
29570 +++ b/arch/x86/lib/csum-copy_64.S
29571 @@ -9,6 +9,7 @@
29572 #include <asm/dwarf2.h>
29573 #include <asm/errno.h>
29574 #include <asm/asm.h>
29575 +#include <asm/alternative-asm.h>
29576
29577 /*
29578 * Checksum copy with exception handling.
29579 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29580 CFI_ADJUST_CFA_OFFSET 7*8
29581 movq %rbx, 2*8(%rsp)
29582 CFI_REL_OFFSET rbx, 2*8
29583 - movq %r12, 3*8(%rsp)
29584 - CFI_REL_OFFSET r12, 3*8
29585 + movq %r15, 3*8(%rsp)
29586 + CFI_REL_OFFSET r15, 3*8
29587 movq %r14, 4*8(%rsp)
29588 CFI_REL_OFFSET r14, 4*8
29589 movq %r13, 5*8(%rsp)
29590 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29591 movl %edx, %ecx
29592
29593 xorl %r9d, %r9d
29594 - movq %rcx, %r12
29595 + movq %rcx, %r15
29596
29597 - shrq $6, %r12
29598 + shrq $6, %r15
29599 jz .Lhandle_tail /* < 64 */
29600
29601 clc
29602
29603 /* main loop. clear in 64 byte blocks */
29604 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29605 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29606 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29607 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29608 .p2align 4
29609 .Lloop:
29610 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29611 adcq %r14, %rax
29612 adcq %r13, %rax
29613
29614 - decl %r12d
29615 + decl %r15d
29616
29617 dest
29618 movq %rbx, (%rsi)
29619 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29620 .Lende:
29621 movq 2*8(%rsp), %rbx
29622 CFI_RESTORE rbx
29623 - movq 3*8(%rsp), %r12
29624 - CFI_RESTORE r12
29625 + movq 3*8(%rsp), %r15
29626 + CFI_RESTORE r15
29627 movq 4*8(%rsp), %r14
29628 CFI_RESTORE r14
29629 movq 5*8(%rsp), %r13
29630 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29631 CFI_RESTORE rbp
29632 addq $7*8, %rsp
29633 CFI_ADJUST_CFA_OFFSET -7*8
29634 + pax_force_retaddr
29635 ret
29636 CFI_RESTORE_STATE
29637
29638 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29639 index 7609e0e..b449b98 100644
29640 --- a/arch/x86/lib/csum-wrappers_64.c
29641 +++ b/arch/x86/lib/csum-wrappers_64.c
29642 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29643 len -= 2;
29644 }
29645 }
29646 + pax_open_userland();
29647 stac();
29648 - isum = csum_partial_copy_generic((__force const void *)src,
29649 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29650 dst, len, isum, errp, NULL);
29651 clac();
29652 + pax_close_userland();
29653 if (unlikely(*errp))
29654 goto out_err;
29655
29656 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29657 }
29658
29659 *errp = 0;
29660 + pax_open_userland();
29661 stac();
29662 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29663 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29664 len, isum, NULL, errp);
29665 clac();
29666 + pax_close_userland();
29667 return ret;
29668 }
29669 EXPORT_SYMBOL(csum_partial_copy_to_user);
29670 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29671 index a451235..1daa956 100644
29672 --- a/arch/x86/lib/getuser.S
29673 +++ b/arch/x86/lib/getuser.S
29674 @@ -33,17 +33,40 @@
29675 #include <asm/thread_info.h>
29676 #include <asm/asm.h>
29677 #include <asm/smap.h>
29678 +#include <asm/segment.h>
29679 +#include <asm/pgtable.h>
29680 +#include <asm/alternative-asm.h>
29681 +
29682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29683 +#define __copyuser_seg gs;
29684 +#else
29685 +#define __copyuser_seg
29686 +#endif
29687
29688 .text
29689 ENTRY(__get_user_1)
29690 CFI_STARTPROC
29691 +
29692 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29693 GET_THREAD_INFO(%_ASM_DX)
29694 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29695 jae bad_get_user
29696 ASM_STAC
29697 -1: movzbl (%_ASM_AX),%edx
29698 +
29699 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29700 + mov pax_user_shadow_base,%_ASM_DX
29701 + cmp %_ASM_DX,%_ASM_AX
29702 + jae 1234f
29703 + add %_ASM_DX,%_ASM_AX
29704 +1234:
29705 +#endif
29706 +
29707 +#endif
29708 +
29709 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29710 xor %eax,%eax
29711 ASM_CLAC
29712 + pax_force_retaddr
29713 ret
29714 CFI_ENDPROC
29715 ENDPROC(__get_user_1)
29716 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29717 ENTRY(__get_user_2)
29718 CFI_STARTPROC
29719 add $1,%_ASM_AX
29720 +
29721 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29722 jc bad_get_user
29723 GET_THREAD_INFO(%_ASM_DX)
29724 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29725 jae bad_get_user
29726 ASM_STAC
29727 -2: movzwl -1(%_ASM_AX),%edx
29728 +
29729 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29730 + mov pax_user_shadow_base,%_ASM_DX
29731 + cmp %_ASM_DX,%_ASM_AX
29732 + jae 1234f
29733 + add %_ASM_DX,%_ASM_AX
29734 +1234:
29735 +#endif
29736 +
29737 +#endif
29738 +
29739 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29740 xor %eax,%eax
29741 ASM_CLAC
29742 + pax_force_retaddr
29743 ret
29744 CFI_ENDPROC
29745 ENDPROC(__get_user_2)
29746 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29747 ENTRY(__get_user_4)
29748 CFI_STARTPROC
29749 add $3,%_ASM_AX
29750 +
29751 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29752 jc bad_get_user
29753 GET_THREAD_INFO(%_ASM_DX)
29754 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29755 jae bad_get_user
29756 ASM_STAC
29757 -3: movl -3(%_ASM_AX),%edx
29758 +
29759 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29760 + mov pax_user_shadow_base,%_ASM_DX
29761 + cmp %_ASM_DX,%_ASM_AX
29762 + jae 1234f
29763 + add %_ASM_DX,%_ASM_AX
29764 +1234:
29765 +#endif
29766 +
29767 +#endif
29768 +
29769 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29770 xor %eax,%eax
29771 ASM_CLAC
29772 + pax_force_retaddr
29773 ret
29774 CFI_ENDPROC
29775 ENDPROC(__get_user_4)
29776 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29777 GET_THREAD_INFO(%_ASM_DX)
29778 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29779 jae bad_get_user
29780 +
29781 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29782 + mov pax_user_shadow_base,%_ASM_DX
29783 + cmp %_ASM_DX,%_ASM_AX
29784 + jae 1234f
29785 + add %_ASM_DX,%_ASM_AX
29786 +1234:
29787 +#endif
29788 +
29789 ASM_STAC
29790 4: movq -7(%_ASM_AX),%rdx
29791 xor %eax,%eax
29792 ASM_CLAC
29793 + pax_force_retaddr
29794 ret
29795 #else
29796 add $7,%_ASM_AX
29797 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29798 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29799 jae bad_get_user_8
29800 ASM_STAC
29801 -4: movl -7(%_ASM_AX),%edx
29802 -5: movl -3(%_ASM_AX),%ecx
29803 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29804 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29805 xor %eax,%eax
29806 ASM_CLAC
29807 + pax_force_retaddr
29808 ret
29809 #endif
29810 CFI_ENDPROC
29811 @@ -113,6 +175,7 @@ bad_get_user:
29812 xor %edx,%edx
29813 mov $(-EFAULT),%_ASM_AX
29814 ASM_CLAC
29815 + pax_force_retaddr
29816 ret
29817 CFI_ENDPROC
29818 END(bad_get_user)
29819 @@ -124,6 +187,7 @@ bad_get_user_8:
29820 xor %ecx,%ecx
29821 mov $(-EFAULT),%_ASM_AX
29822 ASM_CLAC
29823 + pax_force_retaddr
29824 ret
29825 CFI_ENDPROC
29826 END(bad_get_user_8)
29827 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29828 index 54fcffe..7be149e 100644
29829 --- a/arch/x86/lib/insn.c
29830 +++ b/arch/x86/lib/insn.c
29831 @@ -20,8 +20,10 @@
29832
29833 #ifdef __KERNEL__
29834 #include <linux/string.h>
29835 +#include <asm/pgtable_types.h>
29836 #else
29837 #include <string.h>
29838 +#define ktla_ktva(addr) addr
29839 #endif
29840 #include <asm/inat.h>
29841 #include <asm/insn.h>
29842 @@ -53,8 +55,8 @@
29843 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29844 {
29845 memset(insn, 0, sizeof(*insn));
29846 - insn->kaddr = kaddr;
29847 - insn->next_byte = kaddr;
29848 + insn->kaddr = ktla_ktva(kaddr);
29849 + insn->next_byte = ktla_ktva(kaddr);
29850 insn->x86_64 = x86_64 ? 1 : 0;
29851 insn->opnd_bytes = 4;
29852 if (x86_64)
29853 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29854 index 05a95e7..326f2fa 100644
29855 --- a/arch/x86/lib/iomap_copy_64.S
29856 +++ b/arch/x86/lib/iomap_copy_64.S
29857 @@ -17,6 +17,7 @@
29858
29859 #include <linux/linkage.h>
29860 #include <asm/dwarf2.h>
29861 +#include <asm/alternative-asm.h>
29862
29863 /*
29864 * override generic version in lib/iomap_copy.c
29865 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29866 CFI_STARTPROC
29867 movl %edx,%ecx
29868 rep movsd
29869 + pax_force_retaddr
29870 ret
29871 CFI_ENDPROC
29872 ENDPROC(__iowrite32_copy)
29873 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29874 index 56313a3..0db417e 100644
29875 --- a/arch/x86/lib/memcpy_64.S
29876 +++ b/arch/x86/lib/memcpy_64.S
29877 @@ -24,7 +24,7 @@
29878 * This gets patched over the unrolled variant (below) via the
29879 * alternative instructions framework:
29880 */
29881 - .section .altinstr_replacement, "ax", @progbits
29882 + .section .altinstr_replacement, "a", @progbits
29883 .Lmemcpy_c:
29884 movq %rdi, %rax
29885 movq %rdx, %rcx
29886 @@ -33,6 +33,7 @@
29887 rep movsq
29888 movl %edx, %ecx
29889 rep movsb
29890 + pax_force_retaddr
29891 ret
29892 .Lmemcpy_e:
29893 .previous
29894 @@ -44,11 +45,12 @@
29895 * This gets patched over the unrolled variant (below) via the
29896 * alternative instructions framework:
29897 */
29898 - .section .altinstr_replacement, "ax", @progbits
29899 + .section .altinstr_replacement, "a", @progbits
29900 .Lmemcpy_c_e:
29901 movq %rdi, %rax
29902 movq %rdx, %rcx
29903 rep movsb
29904 + pax_force_retaddr
29905 ret
29906 .Lmemcpy_e_e:
29907 .previous
29908 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29909 movq %r9, 1*8(%rdi)
29910 movq %r10, -2*8(%rdi, %rdx)
29911 movq %r11, -1*8(%rdi, %rdx)
29912 + pax_force_retaddr
29913 retq
29914 .p2align 4
29915 .Lless_16bytes:
29916 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29917 movq -1*8(%rsi, %rdx), %r9
29918 movq %r8, 0*8(%rdi)
29919 movq %r9, -1*8(%rdi, %rdx)
29920 + pax_force_retaddr
29921 retq
29922 .p2align 4
29923 .Lless_8bytes:
29924 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29925 movl -4(%rsi, %rdx), %r8d
29926 movl %ecx, (%rdi)
29927 movl %r8d, -4(%rdi, %rdx)
29928 + pax_force_retaddr
29929 retq
29930 .p2align 4
29931 .Lless_3bytes:
29932 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29933 movb %cl, (%rdi)
29934
29935 .Lend:
29936 + pax_force_retaddr
29937 retq
29938 CFI_ENDPROC
29939 ENDPROC(memcpy)
29940 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29941 index 65268a6..dd1de11 100644
29942 --- a/arch/x86/lib/memmove_64.S
29943 +++ b/arch/x86/lib/memmove_64.S
29944 @@ -202,14 +202,16 @@ ENTRY(memmove)
29945 movb (%rsi), %r11b
29946 movb %r11b, (%rdi)
29947 13:
29948 + pax_force_retaddr
29949 retq
29950 CFI_ENDPROC
29951
29952 - .section .altinstr_replacement,"ax"
29953 + .section .altinstr_replacement,"a"
29954 .Lmemmove_begin_forward_efs:
29955 /* Forward moving data. */
29956 movq %rdx, %rcx
29957 rep movsb
29958 + pax_force_retaddr
29959 retq
29960 .Lmemmove_end_forward_efs:
29961 .previous
29962 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29963 index 2dcb380..2eb79fe 100644
29964 --- a/arch/x86/lib/memset_64.S
29965 +++ b/arch/x86/lib/memset_64.S
29966 @@ -16,7 +16,7 @@
29967 *
29968 * rax original destination
29969 */
29970 - .section .altinstr_replacement, "ax", @progbits
29971 + .section .altinstr_replacement, "a", @progbits
29972 .Lmemset_c:
29973 movq %rdi,%r9
29974 movq %rdx,%rcx
29975 @@ -30,6 +30,7 @@
29976 movl %edx,%ecx
29977 rep stosb
29978 movq %r9,%rax
29979 + pax_force_retaddr
29980 ret
29981 .Lmemset_e:
29982 .previous
29983 @@ -45,13 +46,14 @@
29984 *
29985 * rax original destination
29986 */
29987 - .section .altinstr_replacement, "ax", @progbits
29988 + .section .altinstr_replacement, "a", @progbits
29989 .Lmemset_c_e:
29990 movq %rdi,%r9
29991 movb %sil,%al
29992 movq %rdx,%rcx
29993 rep stosb
29994 movq %r9,%rax
29995 + pax_force_retaddr
29996 ret
29997 .Lmemset_e_e:
29998 .previous
29999 @@ -118,6 +120,7 @@ ENTRY(__memset)
30000
30001 .Lende:
30002 movq %r10,%rax
30003 + pax_force_retaddr
30004 ret
30005
30006 CFI_RESTORE_STATE
30007 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30008 index c9f2d9b..e7fd2c0 100644
30009 --- a/arch/x86/lib/mmx_32.c
30010 +++ b/arch/x86/lib/mmx_32.c
30011 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30012 {
30013 void *p;
30014 int i;
30015 + unsigned long cr0;
30016
30017 if (unlikely(in_interrupt()))
30018 return __memcpy(to, from, len);
30019 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30020 kernel_fpu_begin();
30021
30022 __asm__ __volatile__ (
30023 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30024 - " prefetch 64(%0)\n"
30025 - " prefetch 128(%0)\n"
30026 - " prefetch 192(%0)\n"
30027 - " prefetch 256(%0)\n"
30028 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30029 + " prefetch 64(%1)\n"
30030 + " prefetch 128(%1)\n"
30031 + " prefetch 192(%1)\n"
30032 + " prefetch 256(%1)\n"
30033 "2: \n"
30034 ".section .fixup, \"ax\"\n"
30035 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30036 + "3: \n"
30037 +
30038 +#ifdef CONFIG_PAX_KERNEXEC
30039 + " movl %%cr0, %0\n"
30040 + " movl %0, %%eax\n"
30041 + " andl $0xFFFEFFFF, %%eax\n"
30042 + " movl %%eax, %%cr0\n"
30043 +#endif
30044 +
30045 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30046 +
30047 +#ifdef CONFIG_PAX_KERNEXEC
30048 + " movl %0, %%cr0\n"
30049 +#endif
30050 +
30051 " jmp 2b\n"
30052 ".previous\n"
30053 _ASM_EXTABLE(1b, 3b)
30054 - : : "r" (from));
30055 + : "=&r" (cr0) : "r" (from) : "ax");
30056
30057 for ( ; i > 5; i--) {
30058 __asm__ __volatile__ (
30059 - "1: prefetch 320(%0)\n"
30060 - "2: movq (%0), %%mm0\n"
30061 - " movq 8(%0), %%mm1\n"
30062 - " movq 16(%0), %%mm2\n"
30063 - " movq 24(%0), %%mm3\n"
30064 - " movq %%mm0, (%1)\n"
30065 - " movq %%mm1, 8(%1)\n"
30066 - " movq %%mm2, 16(%1)\n"
30067 - " movq %%mm3, 24(%1)\n"
30068 - " movq 32(%0), %%mm0\n"
30069 - " movq 40(%0), %%mm1\n"
30070 - " movq 48(%0), %%mm2\n"
30071 - " movq 56(%0), %%mm3\n"
30072 - " movq %%mm0, 32(%1)\n"
30073 - " movq %%mm1, 40(%1)\n"
30074 - " movq %%mm2, 48(%1)\n"
30075 - " movq %%mm3, 56(%1)\n"
30076 + "1: prefetch 320(%1)\n"
30077 + "2: movq (%1), %%mm0\n"
30078 + " movq 8(%1), %%mm1\n"
30079 + " movq 16(%1), %%mm2\n"
30080 + " movq 24(%1), %%mm3\n"
30081 + " movq %%mm0, (%2)\n"
30082 + " movq %%mm1, 8(%2)\n"
30083 + " movq %%mm2, 16(%2)\n"
30084 + " movq %%mm3, 24(%2)\n"
30085 + " movq 32(%1), %%mm0\n"
30086 + " movq 40(%1), %%mm1\n"
30087 + " movq 48(%1), %%mm2\n"
30088 + " movq 56(%1), %%mm3\n"
30089 + " movq %%mm0, 32(%2)\n"
30090 + " movq %%mm1, 40(%2)\n"
30091 + " movq %%mm2, 48(%2)\n"
30092 + " movq %%mm3, 56(%2)\n"
30093 ".section .fixup, \"ax\"\n"
30094 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30095 + "3:\n"
30096 +
30097 +#ifdef CONFIG_PAX_KERNEXEC
30098 + " movl %%cr0, %0\n"
30099 + " movl %0, %%eax\n"
30100 + " andl $0xFFFEFFFF, %%eax\n"
30101 + " movl %%eax, %%cr0\n"
30102 +#endif
30103 +
30104 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30105 +
30106 +#ifdef CONFIG_PAX_KERNEXEC
30107 + " movl %0, %%cr0\n"
30108 +#endif
30109 +
30110 " jmp 2b\n"
30111 ".previous\n"
30112 _ASM_EXTABLE(1b, 3b)
30113 - : : "r" (from), "r" (to) : "memory");
30114 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30115
30116 from += 64;
30117 to += 64;
30118 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30119 static void fast_copy_page(void *to, void *from)
30120 {
30121 int i;
30122 + unsigned long cr0;
30123
30124 kernel_fpu_begin();
30125
30126 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30127 * but that is for later. -AV
30128 */
30129 __asm__ __volatile__(
30130 - "1: prefetch (%0)\n"
30131 - " prefetch 64(%0)\n"
30132 - " prefetch 128(%0)\n"
30133 - " prefetch 192(%0)\n"
30134 - " prefetch 256(%0)\n"
30135 + "1: prefetch (%1)\n"
30136 + " prefetch 64(%1)\n"
30137 + " prefetch 128(%1)\n"
30138 + " prefetch 192(%1)\n"
30139 + " prefetch 256(%1)\n"
30140 "2: \n"
30141 ".section .fixup, \"ax\"\n"
30142 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30143 + "3: \n"
30144 +
30145 +#ifdef CONFIG_PAX_KERNEXEC
30146 + " movl %%cr0, %0\n"
30147 + " movl %0, %%eax\n"
30148 + " andl $0xFFFEFFFF, %%eax\n"
30149 + " movl %%eax, %%cr0\n"
30150 +#endif
30151 +
30152 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30153 +
30154 +#ifdef CONFIG_PAX_KERNEXEC
30155 + " movl %0, %%cr0\n"
30156 +#endif
30157 +
30158 " jmp 2b\n"
30159 ".previous\n"
30160 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30161 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30162
30163 for (i = 0; i < (4096-320)/64; i++) {
30164 __asm__ __volatile__ (
30165 - "1: prefetch 320(%0)\n"
30166 - "2: movq (%0), %%mm0\n"
30167 - " movntq %%mm0, (%1)\n"
30168 - " movq 8(%0), %%mm1\n"
30169 - " movntq %%mm1, 8(%1)\n"
30170 - " movq 16(%0), %%mm2\n"
30171 - " movntq %%mm2, 16(%1)\n"
30172 - " movq 24(%0), %%mm3\n"
30173 - " movntq %%mm3, 24(%1)\n"
30174 - " movq 32(%0), %%mm4\n"
30175 - " movntq %%mm4, 32(%1)\n"
30176 - " movq 40(%0), %%mm5\n"
30177 - " movntq %%mm5, 40(%1)\n"
30178 - " movq 48(%0), %%mm6\n"
30179 - " movntq %%mm6, 48(%1)\n"
30180 - " movq 56(%0), %%mm7\n"
30181 - " movntq %%mm7, 56(%1)\n"
30182 + "1: prefetch 320(%1)\n"
30183 + "2: movq (%1), %%mm0\n"
30184 + " movntq %%mm0, (%2)\n"
30185 + " movq 8(%1), %%mm1\n"
30186 + " movntq %%mm1, 8(%2)\n"
30187 + " movq 16(%1), %%mm2\n"
30188 + " movntq %%mm2, 16(%2)\n"
30189 + " movq 24(%1), %%mm3\n"
30190 + " movntq %%mm3, 24(%2)\n"
30191 + " movq 32(%1), %%mm4\n"
30192 + " movntq %%mm4, 32(%2)\n"
30193 + " movq 40(%1), %%mm5\n"
30194 + " movntq %%mm5, 40(%2)\n"
30195 + " movq 48(%1), %%mm6\n"
30196 + " movntq %%mm6, 48(%2)\n"
30197 + " movq 56(%1), %%mm7\n"
30198 + " movntq %%mm7, 56(%2)\n"
30199 ".section .fixup, \"ax\"\n"
30200 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30201 + "3:\n"
30202 +
30203 +#ifdef CONFIG_PAX_KERNEXEC
30204 + " movl %%cr0, %0\n"
30205 + " movl %0, %%eax\n"
30206 + " andl $0xFFFEFFFF, %%eax\n"
30207 + " movl %%eax, %%cr0\n"
30208 +#endif
30209 +
30210 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30211 +
30212 +#ifdef CONFIG_PAX_KERNEXEC
30213 + " movl %0, %%cr0\n"
30214 +#endif
30215 +
30216 " jmp 2b\n"
30217 ".previous\n"
30218 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30219 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30220
30221 from += 64;
30222 to += 64;
30223 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30224 static void fast_copy_page(void *to, void *from)
30225 {
30226 int i;
30227 + unsigned long cr0;
30228
30229 kernel_fpu_begin();
30230
30231 __asm__ __volatile__ (
30232 - "1: prefetch (%0)\n"
30233 - " prefetch 64(%0)\n"
30234 - " prefetch 128(%0)\n"
30235 - " prefetch 192(%0)\n"
30236 - " prefetch 256(%0)\n"
30237 + "1: prefetch (%1)\n"
30238 + " prefetch 64(%1)\n"
30239 + " prefetch 128(%1)\n"
30240 + " prefetch 192(%1)\n"
30241 + " prefetch 256(%1)\n"
30242 "2: \n"
30243 ".section .fixup, \"ax\"\n"
30244 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30245 + "3: \n"
30246 +
30247 +#ifdef CONFIG_PAX_KERNEXEC
30248 + " movl %%cr0, %0\n"
30249 + " movl %0, %%eax\n"
30250 + " andl $0xFFFEFFFF, %%eax\n"
30251 + " movl %%eax, %%cr0\n"
30252 +#endif
30253 +
30254 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30255 +
30256 +#ifdef CONFIG_PAX_KERNEXEC
30257 + " movl %0, %%cr0\n"
30258 +#endif
30259 +
30260 " jmp 2b\n"
30261 ".previous\n"
30262 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30263 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30264
30265 for (i = 0; i < 4096/64; i++) {
30266 __asm__ __volatile__ (
30267 - "1: prefetch 320(%0)\n"
30268 - "2: movq (%0), %%mm0\n"
30269 - " movq 8(%0), %%mm1\n"
30270 - " movq 16(%0), %%mm2\n"
30271 - " movq 24(%0), %%mm3\n"
30272 - " movq %%mm0, (%1)\n"
30273 - " movq %%mm1, 8(%1)\n"
30274 - " movq %%mm2, 16(%1)\n"
30275 - " movq %%mm3, 24(%1)\n"
30276 - " movq 32(%0), %%mm0\n"
30277 - " movq 40(%0), %%mm1\n"
30278 - " movq 48(%0), %%mm2\n"
30279 - " movq 56(%0), %%mm3\n"
30280 - " movq %%mm0, 32(%1)\n"
30281 - " movq %%mm1, 40(%1)\n"
30282 - " movq %%mm2, 48(%1)\n"
30283 - " movq %%mm3, 56(%1)\n"
30284 + "1: prefetch 320(%1)\n"
30285 + "2: movq (%1), %%mm0\n"
30286 + " movq 8(%1), %%mm1\n"
30287 + " movq 16(%1), %%mm2\n"
30288 + " movq 24(%1), %%mm3\n"
30289 + " movq %%mm0, (%2)\n"
30290 + " movq %%mm1, 8(%2)\n"
30291 + " movq %%mm2, 16(%2)\n"
30292 + " movq %%mm3, 24(%2)\n"
30293 + " movq 32(%1), %%mm0\n"
30294 + " movq 40(%1), %%mm1\n"
30295 + " movq 48(%1), %%mm2\n"
30296 + " movq 56(%1), %%mm3\n"
30297 + " movq %%mm0, 32(%2)\n"
30298 + " movq %%mm1, 40(%2)\n"
30299 + " movq %%mm2, 48(%2)\n"
30300 + " movq %%mm3, 56(%2)\n"
30301 ".section .fixup, \"ax\"\n"
30302 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30303 + "3:\n"
30304 +
30305 +#ifdef CONFIG_PAX_KERNEXEC
30306 + " movl %%cr0, %0\n"
30307 + " movl %0, %%eax\n"
30308 + " andl $0xFFFEFFFF, %%eax\n"
30309 + " movl %%eax, %%cr0\n"
30310 +#endif
30311 +
30312 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30313 +
30314 +#ifdef CONFIG_PAX_KERNEXEC
30315 + " movl %0, %%cr0\n"
30316 +#endif
30317 +
30318 " jmp 2b\n"
30319 ".previous\n"
30320 _ASM_EXTABLE(1b, 3b)
30321 - : : "r" (from), "r" (to) : "memory");
30322 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30323
30324 from += 64;
30325 to += 64;
30326 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30327 index f6d13ee..d789440 100644
30328 --- a/arch/x86/lib/msr-reg.S
30329 +++ b/arch/x86/lib/msr-reg.S
30330 @@ -3,6 +3,7 @@
30331 #include <asm/dwarf2.h>
30332 #include <asm/asm.h>
30333 #include <asm/msr.h>
30334 +#include <asm/alternative-asm.h>
30335
30336 #ifdef CONFIG_X86_64
30337 /*
30338 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30339 movl %edi, 28(%r10)
30340 popq_cfi %rbp
30341 popq_cfi %rbx
30342 + pax_force_retaddr
30343 ret
30344 3:
30345 CFI_RESTORE_STATE
30346 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30347 index fc6ba17..d4d989d 100644
30348 --- a/arch/x86/lib/putuser.S
30349 +++ b/arch/x86/lib/putuser.S
30350 @@ -16,7 +16,9 @@
30351 #include <asm/errno.h>
30352 #include <asm/asm.h>
30353 #include <asm/smap.h>
30354 -
30355 +#include <asm/segment.h>
30356 +#include <asm/pgtable.h>
30357 +#include <asm/alternative-asm.h>
30358
30359 /*
30360 * __put_user_X
30361 @@ -30,57 +32,125 @@
30362 * as they get called from within inline assembly.
30363 */
30364
30365 -#define ENTER CFI_STARTPROC ; \
30366 - GET_THREAD_INFO(%_ASM_BX)
30367 -#define EXIT ASM_CLAC ; \
30368 - ret ; \
30369 +#define ENTER CFI_STARTPROC
30370 +#define EXIT ASM_CLAC ; \
30371 + pax_force_retaddr ; \
30372 + ret ; \
30373 CFI_ENDPROC
30374
30375 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30376 +#define _DEST %_ASM_CX,%_ASM_BX
30377 +#else
30378 +#define _DEST %_ASM_CX
30379 +#endif
30380 +
30381 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30382 +#define __copyuser_seg gs;
30383 +#else
30384 +#define __copyuser_seg
30385 +#endif
30386 +
30387 .text
30388 ENTRY(__put_user_1)
30389 ENTER
30390 +
30391 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30392 + GET_THREAD_INFO(%_ASM_BX)
30393 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30394 jae bad_put_user
30395 ASM_STAC
30396 -1: movb %al,(%_ASM_CX)
30397 +
30398 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30399 + mov pax_user_shadow_base,%_ASM_BX
30400 + cmp %_ASM_BX,%_ASM_CX
30401 + jb 1234f
30402 + xor %ebx,%ebx
30403 +1234:
30404 +#endif
30405 +
30406 +#endif
30407 +
30408 +1: __copyuser_seg movb %al,(_DEST)
30409 xor %eax,%eax
30410 EXIT
30411 ENDPROC(__put_user_1)
30412
30413 ENTRY(__put_user_2)
30414 ENTER
30415 +
30416 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30417 + GET_THREAD_INFO(%_ASM_BX)
30418 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30419 sub $1,%_ASM_BX
30420 cmp %_ASM_BX,%_ASM_CX
30421 jae bad_put_user
30422 ASM_STAC
30423 -2: movw %ax,(%_ASM_CX)
30424 +
30425 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30426 + mov pax_user_shadow_base,%_ASM_BX
30427 + cmp %_ASM_BX,%_ASM_CX
30428 + jb 1234f
30429 + xor %ebx,%ebx
30430 +1234:
30431 +#endif
30432 +
30433 +#endif
30434 +
30435 +2: __copyuser_seg movw %ax,(_DEST)
30436 xor %eax,%eax
30437 EXIT
30438 ENDPROC(__put_user_2)
30439
30440 ENTRY(__put_user_4)
30441 ENTER
30442 +
30443 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30444 + GET_THREAD_INFO(%_ASM_BX)
30445 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30446 sub $3,%_ASM_BX
30447 cmp %_ASM_BX,%_ASM_CX
30448 jae bad_put_user
30449 ASM_STAC
30450 -3: movl %eax,(%_ASM_CX)
30451 +
30452 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30453 + mov pax_user_shadow_base,%_ASM_BX
30454 + cmp %_ASM_BX,%_ASM_CX
30455 + jb 1234f
30456 + xor %ebx,%ebx
30457 +1234:
30458 +#endif
30459 +
30460 +#endif
30461 +
30462 +3: __copyuser_seg movl %eax,(_DEST)
30463 xor %eax,%eax
30464 EXIT
30465 ENDPROC(__put_user_4)
30466
30467 ENTRY(__put_user_8)
30468 ENTER
30469 +
30470 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30471 + GET_THREAD_INFO(%_ASM_BX)
30472 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30473 sub $7,%_ASM_BX
30474 cmp %_ASM_BX,%_ASM_CX
30475 jae bad_put_user
30476 ASM_STAC
30477 -4: mov %_ASM_AX,(%_ASM_CX)
30478 +
30479 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30480 + mov pax_user_shadow_base,%_ASM_BX
30481 + cmp %_ASM_BX,%_ASM_CX
30482 + jb 1234f
30483 + xor %ebx,%ebx
30484 +1234:
30485 +#endif
30486 +
30487 +#endif
30488 +
30489 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30490 #ifdef CONFIG_X86_32
30491 -5: movl %edx,4(%_ASM_CX)
30492 +5: __copyuser_seg movl %edx,4(_DEST)
30493 #endif
30494 xor %eax,%eax
30495 EXIT
30496 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30497 index 1cad221..de671ee 100644
30498 --- a/arch/x86/lib/rwlock.S
30499 +++ b/arch/x86/lib/rwlock.S
30500 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30501 FRAME
30502 0: LOCK_PREFIX
30503 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30504 +
30505 +#ifdef CONFIG_PAX_REFCOUNT
30506 + jno 1234f
30507 + LOCK_PREFIX
30508 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30509 + int $4
30510 +1234:
30511 + _ASM_EXTABLE(1234b, 1234b)
30512 +#endif
30513 +
30514 1: rep; nop
30515 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30516 jne 1b
30517 LOCK_PREFIX
30518 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30519 +
30520 +#ifdef CONFIG_PAX_REFCOUNT
30521 + jno 1234f
30522 + LOCK_PREFIX
30523 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30524 + int $4
30525 +1234:
30526 + _ASM_EXTABLE(1234b, 1234b)
30527 +#endif
30528 +
30529 jnz 0b
30530 ENDFRAME
30531 + pax_force_retaddr
30532 ret
30533 CFI_ENDPROC
30534 END(__write_lock_failed)
30535 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30536 FRAME
30537 0: LOCK_PREFIX
30538 READ_LOCK_SIZE(inc) (%__lock_ptr)
30539 +
30540 +#ifdef CONFIG_PAX_REFCOUNT
30541 + jno 1234f
30542 + LOCK_PREFIX
30543 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30544 + int $4
30545 +1234:
30546 + _ASM_EXTABLE(1234b, 1234b)
30547 +#endif
30548 +
30549 1: rep; nop
30550 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30551 js 1b
30552 LOCK_PREFIX
30553 READ_LOCK_SIZE(dec) (%__lock_ptr)
30554 +
30555 +#ifdef CONFIG_PAX_REFCOUNT
30556 + jno 1234f
30557 + LOCK_PREFIX
30558 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30559 + int $4
30560 +1234:
30561 + _ASM_EXTABLE(1234b, 1234b)
30562 +#endif
30563 +
30564 js 0b
30565 ENDFRAME
30566 + pax_force_retaddr
30567 ret
30568 CFI_ENDPROC
30569 END(__read_lock_failed)
30570 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30571 index 5dff5f0..cadebf4 100644
30572 --- a/arch/x86/lib/rwsem.S
30573 +++ b/arch/x86/lib/rwsem.S
30574 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30575 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30576 CFI_RESTORE __ASM_REG(dx)
30577 restore_common_regs
30578 + pax_force_retaddr
30579 ret
30580 CFI_ENDPROC
30581 ENDPROC(call_rwsem_down_read_failed)
30582 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30583 movq %rax,%rdi
30584 call rwsem_down_write_failed
30585 restore_common_regs
30586 + pax_force_retaddr
30587 ret
30588 CFI_ENDPROC
30589 ENDPROC(call_rwsem_down_write_failed)
30590 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30591 movq %rax,%rdi
30592 call rwsem_wake
30593 restore_common_regs
30594 -1: ret
30595 +1: pax_force_retaddr
30596 + ret
30597 CFI_ENDPROC
30598 ENDPROC(call_rwsem_wake)
30599
30600 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30601 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30602 CFI_RESTORE __ASM_REG(dx)
30603 restore_common_regs
30604 + pax_force_retaddr
30605 ret
30606 CFI_ENDPROC
30607 ENDPROC(call_rwsem_downgrade_wake)
30608 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30609 index a63efd6..8149fbe 100644
30610 --- a/arch/x86/lib/thunk_64.S
30611 +++ b/arch/x86/lib/thunk_64.S
30612 @@ -8,6 +8,7 @@
30613 #include <linux/linkage.h>
30614 #include <asm/dwarf2.h>
30615 #include <asm/calling.h>
30616 +#include <asm/alternative-asm.h>
30617
30618 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30619 .macro THUNK name, func, put_ret_addr_in_rdi=0
30620 @@ -15,11 +16,11 @@
30621 \name:
30622 CFI_STARTPROC
30623
30624 - /* this one pushes 9 elems, the next one would be %rIP */
30625 - SAVE_ARGS
30626 + /* this one pushes 15+1 elems, the next one would be %rIP */
30627 + SAVE_ARGS 8
30628
30629 .if \put_ret_addr_in_rdi
30630 - movq_cfi_restore 9*8, rdi
30631 + movq_cfi_restore RIP, rdi
30632 .endif
30633
30634 call \func
30635 @@ -38,8 +39,9 @@
30636
30637 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30638 CFI_STARTPROC
30639 - SAVE_ARGS
30640 + SAVE_ARGS 8
30641 restore:
30642 - RESTORE_ARGS
30643 + RESTORE_ARGS 1,8
30644 + pax_force_retaddr
30645 ret
30646 CFI_ENDPROC
30647 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30648 index e2f5e21..4b22130 100644
30649 --- a/arch/x86/lib/usercopy_32.c
30650 +++ b/arch/x86/lib/usercopy_32.c
30651 @@ -42,11 +42,13 @@ do { \
30652 int __d0; \
30653 might_fault(); \
30654 __asm__ __volatile__( \
30655 + __COPYUSER_SET_ES \
30656 ASM_STAC "\n" \
30657 "0: rep; stosl\n" \
30658 " movl %2,%0\n" \
30659 "1: rep; stosb\n" \
30660 "2: " ASM_CLAC "\n" \
30661 + __COPYUSER_RESTORE_ES \
30662 ".section .fixup,\"ax\"\n" \
30663 "3: lea 0(%2,%0,4),%0\n" \
30664 " jmp 2b\n" \
30665 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30666
30667 #ifdef CONFIG_X86_INTEL_USERCOPY
30668 static unsigned long
30669 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30670 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30671 {
30672 int d0, d1;
30673 __asm__ __volatile__(
30674 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30675 " .align 2,0x90\n"
30676 "3: movl 0(%4), %%eax\n"
30677 "4: movl 4(%4), %%edx\n"
30678 - "5: movl %%eax, 0(%3)\n"
30679 - "6: movl %%edx, 4(%3)\n"
30680 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30681 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30682 "7: movl 8(%4), %%eax\n"
30683 "8: movl 12(%4),%%edx\n"
30684 - "9: movl %%eax, 8(%3)\n"
30685 - "10: movl %%edx, 12(%3)\n"
30686 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30687 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30688 "11: movl 16(%4), %%eax\n"
30689 "12: movl 20(%4), %%edx\n"
30690 - "13: movl %%eax, 16(%3)\n"
30691 - "14: movl %%edx, 20(%3)\n"
30692 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30693 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30694 "15: movl 24(%4), %%eax\n"
30695 "16: movl 28(%4), %%edx\n"
30696 - "17: movl %%eax, 24(%3)\n"
30697 - "18: movl %%edx, 28(%3)\n"
30698 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30699 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30700 "19: movl 32(%4), %%eax\n"
30701 "20: movl 36(%4), %%edx\n"
30702 - "21: movl %%eax, 32(%3)\n"
30703 - "22: movl %%edx, 36(%3)\n"
30704 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30705 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30706 "23: movl 40(%4), %%eax\n"
30707 "24: movl 44(%4), %%edx\n"
30708 - "25: movl %%eax, 40(%3)\n"
30709 - "26: movl %%edx, 44(%3)\n"
30710 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30711 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30712 "27: movl 48(%4), %%eax\n"
30713 "28: movl 52(%4), %%edx\n"
30714 - "29: movl %%eax, 48(%3)\n"
30715 - "30: movl %%edx, 52(%3)\n"
30716 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30717 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30718 "31: movl 56(%4), %%eax\n"
30719 "32: movl 60(%4), %%edx\n"
30720 - "33: movl %%eax, 56(%3)\n"
30721 - "34: movl %%edx, 60(%3)\n"
30722 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30723 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30724 " addl $-64, %0\n"
30725 " addl $64, %4\n"
30726 " addl $64, %3\n"
30727 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30728 " shrl $2, %0\n"
30729 " andl $3, %%eax\n"
30730 " cld\n"
30731 + __COPYUSER_SET_ES
30732 "99: rep; movsl\n"
30733 "36: movl %%eax, %0\n"
30734 "37: rep; movsb\n"
30735 "100:\n"
30736 + __COPYUSER_RESTORE_ES
30737 + ".section .fixup,\"ax\"\n"
30738 + "101: lea 0(%%eax,%0,4),%0\n"
30739 + " jmp 100b\n"
30740 + ".previous\n"
30741 + _ASM_EXTABLE(1b,100b)
30742 + _ASM_EXTABLE(2b,100b)
30743 + _ASM_EXTABLE(3b,100b)
30744 + _ASM_EXTABLE(4b,100b)
30745 + _ASM_EXTABLE(5b,100b)
30746 + _ASM_EXTABLE(6b,100b)
30747 + _ASM_EXTABLE(7b,100b)
30748 + _ASM_EXTABLE(8b,100b)
30749 + _ASM_EXTABLE(9b,100b)
30750 + _ASM_EXTABLE(10b,100b)
30751 + _ASM_EXTABLE(11b,100b)
30752 + _ASM_EXTABLE(12b,100b)
30753 + _ASM_EXTABLE(13b,100b)
30754 + _ASM_EXTABLE(14b,100b)
30755 + _ASM_EXTABLE(15b,100b)
30756 + _ASM_EXTABLE(16b,100b)
30757 + _ASM_EXTABLE(17b,100b)
30758 + _ASM_EXTABLE(18b,100b)
30759 + _ASM_EXTABLE(19b,100b)
30760 + _ASM_EXTABLE(20b,100b)
30761 + _ASM_EXTABLE(21b,100b)
30762 + _ASM_EXTABLE(22b,100b)
30763 + _ASM_EXTABLE(23b,100b)
30764 + _ASM_EXTABLE(24b,100b)
30765 + _ASM_EXTABLE(25b,100b)
30766 + _ASM_EXTABLE(26b,100b)
30767 + _ASM_EXTABLE(27b,100b)
30768 + _ASM_EXTABLE(28b,100b)
30769 + _ASM_EXTABLE(29b,100b)
30770 + _ASM_EXTABLE(30b,100b)
30771 + _ASM_EXTABLE(31b,100b)
30772 + _ASM_EXTABLE(32b,100b)
30773 + _ASM_EXTABLE(33b,100b)
30774 + _ASM_EXTABLE(34b,100b)
30775 + _ASM_EXTABLE(35b,100b)
30776 + _ASM_EXTABLE(36b,100b)
30777 + _ASM_EXTABLE(37b,100b)
30778 + _ASM_EXTABLE(99b,101b)
30779 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30780 + : "1"(to), "2"(from), "0"(size)
30781 + : "eax", "edx", "memory");
30782 + return size;
30783 +}
30784 +
30785 +static unsigned long
30786 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30787 +{
30788 + int d0, d1;
30789 + __asm__ __volatile__(
30790 + " .align 2,0x90\n"
30791 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30792 + " cmpl $67, %0\n"
30793 + " jbe 3f\n"
30794 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30795 + " .align 2,0x90\n"
30796 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30797 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30798 + "5: movl %%eax, 0(%3)\n"
30799 + "6: movl %%edx, 4(%3)\n"
30800 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30801 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30802 + "9: movl %%eax, 8(%3)\n"
30803 + "10: movl %%edx, 12(%3)\n"
30804 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30805 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30806 + "13: movl %%eax, 16(%3)\n"
30807 + "14: movl %%edx, 20(%3)\n"
30808 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30809 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30810 + "17: movl %%eax, 24(%3)\n"
30811 + "18: movl %%edx, 28(%3)\n"
30812 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30813 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30814 + "21: movl %%eax, 32(%3)\n"
30815 + "22: movl %%edx, 36(%3)\n"
30816 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30817 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30818 + "25: movl %%eax, 40(%3)\n"
30819 + "26: movl %%edx, 44(%3)\n"
30820 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30821 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30822 + "29: movl %%eax, 48(%3)\n"
30823 + "30: movl %%edx, 52(%3)\n"
30824 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30825 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30826 + "33: movl %%eax, 56(%3)\n"
30827 + "34: movl %%edx, 60(%3)\n"
30828 + " addl $-64, %0\n"
30829 + " addl $64, %4\n"
30830 + " addl $64, %3\n"
30831 + " cmpl $63, %0\n"
30832 + " ja 1b\n"
30833 + "35: movl %0, %%eax\n"
30834 + " shrl $2, %0\n"
30835 + " andl $3, %%eax\n"
30836 + " cld\n"
30837 + "99: rep; "__copyuser_seg" movsl\n"
30838 + "36: movl %%eax, %0\n"
30839 + "37: rep; "__copyuser_seg" movsb\n"
30840 + "100:\n"
30841 ".section .fixup,\"ax\"\n"
30842 "101: lea 0(%%eax,%0,4),%0\n"
30843 " jmp 100b\n"
30844 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30845 int d0, d1;
30846 __asm__ __volatile__(
30847 " .align 2,0x90\n"
30848 - "0: movl 32(%4), %%eax\n"
30849 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30850 " cmpl $67, %0\n"
30851 " jbe 2f\n"
30852 - "1: movl 64(%4), %%eax\n"
30853 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30854 " .align 2,0x90\n"
30855 - "2: movl 0(%4), %%eax\n"
30856 - "21: movl 4(%4), %%edx\n"
30857 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30858 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30859 " movl %%eax, 0(%3)\n"
30860 " movl %%edx, 4(%3)\n"
30861 - "3: movl 8(%4), %%eax\n"
30862 - "31: movl 12(%4),%%edx\n"
30863 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30864 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30865 " movl %%eax, 8(%3)\n"
30866 " movl %%edx, 12(%3)\n"
30867 - "4: movl 16(%4), %%eax\n"
30868 - "41: movl 20(%4), %%edx\n"
30869 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30870 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30871 " movl %%eax, 16(%3)\n"
30872 " movl %%edx, 20(%3)\n"
30873 - "10: movl 24(%4), %%eax\n"
30874 - "51: movl 28(%4), %%edx\n"
30875 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30876 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30877 " movl %%eax, 24(%3)\n"
30878 " movl %%edx, 28(%3)\n"
30879 - "11: movl 32(%4), %%eax\n"
30880 - "61: movl 36(%4), %%edx\n"
30881 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30882 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30883 " movl %%eax, 32(%3)\n"
30884 " movl %%edx, 36(%3)\n"
30885 - "12: movl 40(%4), %%eax\n"
30886 - "71: movl 44(%4), %%edx\n"
30887 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30888 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30889 " movl %%eax, 40(%3)\n"
30890 " movl %%edx, 44(%3)\n"
30891 - "13: movl 48(%4), %%eax\n"
30892 - "81: movl 52(%4), %%edx\n"
30893 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30894 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30895 " movl %%eax, 48(%3)\n"
30896 " movl %%edx, 52(%3)\n"
30897 - "14: movl 56(%4), %%eax\n"
30898 - "91: movl 60(%4), %%edx\n"
30899 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30900 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30901 " movl %%eax, 56(%3)\n"
30902 " movl %%edx, 60(%3)\n"
30903 " addl $-64, %0\n"
30904 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30905 " shrl $2, %0\n"
30906 " andl $3, %%eax\n"
30907 " cld\n"
30908 - "6: rep; movsl\n"
30909 + "6: rep; "__copyuser_seg" movsl\n"
30910 " movl %%eax,%0\n"
30911 - "7: rep; movsb\n"
30912 + "7: rep; "__copyuser_seg" movsb\n"
30913 "8:\n"
30914 ".section .fixup,\"ax\"\n"
30915 "9: lea 0(%%eax,%0,4),%0\n"
30916 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30917
30918 __asm__ __volatile__(
30919 " .align 2,0x90\n"
30920 - "0: movl 32(%4), %%eax\n"
30921 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30922 " cmpl $67, %0\n"
30923 " jbe 2f\n"
30924 - "1: movl 64(%4), %%eax\n"
30925 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30926 " .align 2,0x90\n"
30927 - "2: movl 0(%4), %%eax\n"
30928 - "21: movl 4(%4), %%edx\n"
30929 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30930 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30931 " movnti %%eax, 0(%3)\n"
30932 " movnti %%edx, 4(%3)\n"
30933 - "3: movl 8(%4), %%eax\n"
30934 - "31: movl 12(%4),%%edx\n"
30935 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30936 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30937 " movnti %%eax, 8(%3)\n"
30938 " movnti %%edx, 12(%3)\n"
30939 - "4: movl 16(%4), %%eax\n"
30940 - "41: movl 20(%4), %%edx\n"
30941 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30942 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30943 " movnti %%eax, 16(%3)\n"
30944 " movnti %%edx, 20(%3)\n"
30945 - "10: movl 24(%4), %%eax\n"
30946 - "51: movl 28(%4), %%edx\n"
30947 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30948 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30949 " movnti %%eax, 24(%3)\n"
30950 " movnti %%edx, 28(%3)\n"
30951 - "11: movl 32(%4), %%eax\n"
30952 - "61: movl 36(%4), %%edx\n"
30953 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30954 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30955 " movnti %%eax, 32(%3)\n"
30956 " movnti %%edx, 36(%3)\n"
30957 - "12: movl 40(%4), %%eax\n"
30958 - "71: movl 44(%4), %%edx\n"
30959 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30960 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30961 " movnti %%eax, 40(%3)\n"
30962 " movnti %%edx, 44(%3)\n"
30963 - "13: movl 48(%4), %%eax\n"
30964 - "81: movl 52(%4), %%edx\n"
30965 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30966 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30967 " movnti %%eax, 48(%3)\n"
30968 " movnti %%edx, 52(%3)\n"
30969 - "14: movl 56(%4), %%eax\n"
30970 - "91: movl 60(%4), %%edx\n"
30971 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30972 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30973 " movnti %%eax, 56(%3)\n"
30974 " movnti %%edx, 60(%3)\n"
30975 " addl $-64, %0\n"
30976 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30977 " shrl $2, %0\n"
30978 " andl $3, %%eax\n"
30979 " cld\n"
30980 - "6: rep; movsl\n"
30981 + "6: rep; "__copyuser_seg" movsl\n"
30982 " movl %%eax,%0\n"
30983 - "7: rep; movsb\n"
30984 + "7: rep; "__copyuser_seg" movsb\n"
30985 "8:\n"
30986 ".section .fixup,\"ax\"\n"
30987 "9: lea 0(%%eax,%0,4),%0\n"
30988 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30989
30990 __asm__ __volatile__(
30991 " .align 2,0x90\n"
30992 - "0: movl 32(%4), %%eax\n"
30993 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30994 " cmpl $67, %0\n"
30995 " jbe 2f\n"
30996 - "1: movl 64(%4), %%eax\n"
30997 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30998 " .align 2,0x90\n"
30999 - "2: movl 0(%4), %%eax\n"
31000 - "21: movl 4(%4), %%edx\n"
31001 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31002 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31003 " movnti %%eax, 0(%3)\n"
31004 " movnti %%edx, 4(%3)\n"
31005 - "3: movl 8(%4), %%eax\n"
31006 - "31: movl 12(%4),%%edx\n"
31007 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31008 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31009 " movnti %%eax, 8(%3)\n"
31010 " movnti %%edx, 12(%3)\n"
31011 - "4: movl 16(%4), %%eax\n"
31012 - "41: movl 20(%4), %%edx\n"
31013 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31014 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31015 " movnti %%eax, 16(%3)\n"
31016 " movnti %%edx, 20(%3)\n"
31017 - "10: movl 24(%4), %%eax\n"
31018 - "51: movl 28(%4), %%edx\n"
31019 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31020 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31021 " movnti %%eax, 24(%3)\n"
31022 " movnti %%edx, 28(%3)\n"
31023 - "11: movl 32(%4), %%eax\n"
31024 - "61: movl 36(%4), %%edx\n"
31025 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31026 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31027 " movnti %%eax, 32(%3)\n"
31028 " movnti %%edx, 36(%3)\n"
31029 - "12: movl 40(%4), %%eax\n"
31030 - "71: movl 44(%4), %%edx\n"
31031 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31032 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31033 " movnti %%eax, 40(%3)\n"
31034 " movnti %%edx, 44(%3)\n"
31035 - "13: movl 48(%4), %%eax\n"
31036 - "81: movl 52(%4), %%edx\n"
31037 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31038 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31039 " movnti %%eax, 48(%3)\n"
31040 " movnti %%edx, 52(%3)\n"
31041 - "14: movl 56(%4), %%eax\n"
31042 - "91: movl 60(%4), %%edx\n"
31043 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31044 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31045 " movnti %%eax, 56(%3)\n"
31046 " movnti %%edx, 60(%3)\n"
31047 " addl $-64, %0\n"
31048 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31049 " shrl $2, %0\n"
31050 " andl $3, %%eax\n"
31051 " cld\n"
31052 - "6: rep; movsl\n"
31053 + "6: rep; "__copyuser_seg" movsl\n"
31054 " movl %%eax,%0\n"
31055 - "7: rep; movsb\n"
31056 + "7: rep; "__copyuser_seg" movsb\n"
31057 "8:\n"
31058 ".section .fixup,\"ax\"\n"
31059 "9: lea 0(%%eax,%0,4),%0\n"
31060 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31061 */
31062 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31063 unsigned long size);
31064 -unsigned long __copy_user_intel(void __user *to, const void *from,
31065 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31066 + unsigned long size);
31067 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31068 unsigned long size);
31069 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31070 const void __user *from, unsigned long size);
31071 #endif /* CONFIG_X86_INTEL_USERCOPY */
31072
31073 /* Generic arbitrary sized copy. */
31074 -#define __copy_user(to, from, size) \
31075 +#define __copy_user(to, from, size, prefix, set, restore) \
31076 do { \
31077 int __d0, __d1, __d2; \
31078 __asm__ __volatile__( \
31079 + set \
31080 " cmp $7,%0\n" \
31081 " jbe 1f\n" \
31082 " movl %1,%0\n" \
31083 " negl %0\n" \
31084 " andl $7,%0\n" \
31085 " subl %0,%3\n" \
31086 - "4: rep; movsb\n" \
31087 + "4: rep; "prefix"movsb\n" \
31088 " movl %3,%0\n" \
31089 " shrl $2,%0\n" \
31090 " andl $3,%3\n" \
31091 " .align 2,0x90\n" \
31092 - "0: rep; movsl\n" \
31093 + "0: rep; "prefix"movsl\n" \
31094 " movl %3,%0\n" \
31095 - "1: rep; movsb\n" \
31096 + "1: rep; "prefix"movsb\n" \
31097 "2:\n" \
31098 + restore \
31099 ".section .fixup,\"ax\"\n" \
31100 "5: addl %3,%0\n" \
31101 " jmp 2b\n" \
31102 @@ -538,14 +650,14 @@ do { \
31103 " negl %0\n" \
31104 " andl $7,%0\n" \
31105 " subl %0,%3\n" \
31106 - "4: rep; movsb\n" \
31107 + "4: rep; "__copyuser_seg"movsb\n" \
31108 " movl %3,%0\n" \
31109 " shrl $2,%0\n" \
31110 " andl $3,%3\n" \
31111 " .align 2,0x90\n" \
31112 - "0: rep; movsl\n" \
31113 + "0: rep; "__copyuser_seg"movsl\n" \
31114 " movl %3,%0\n" \
31115 - "1: rep; movsb\n" \
31116 + "1: rep; "__copyuser_seg"movsb\n" \
31117 "2:\n" \
31118 ".section .fixup,\"ax\"\n" \
31119 "5: addl %3,%0\n" \
31120 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31121 {
31122 stac();
31123 if (movsl_is_ok(to, from, n))
31124 - __copy_user(to, from, n);
31125 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31126 else
31127 - n = __copy_user_intel(to, from, n);
31128 + n = __generic_copy_to_user_intel(to, from, n);
31129 clac();
31130 return n;
31131 }
31132 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31133 {
31134 stac();
31135 if (movsl_is_ok(to, from, n))
31136 - __copy_user(to, from, n);
31137 + __copy_user(to, from, n, __copyuser_seg, "", "");
31138 else
31139 - n = __copy_user_intel((void __user *)to,
31140 - (const void *)from, n);
31141 + n = __generic_copy_from_user_intel(to, from, n);
31142 clac();
31143 return n;
31144 }
31145 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31146 if (n > 64 && cpu_has_xmm2)
31147 n = __copy_user_intel_nocache(to, from, n);
31148 else
31149 - __copy_user(to, from, n);
31150 + __copy_user(to, from, n, __copyuser_seg, "", "");
31151 #else
31152 - __copy_user(to, from, n);
31153 + __copy_user(to, from, n, __copyuser_seg, "", "");
31154 #endif
31155 clac();
31156 return n;
31157 }
31158 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31159
31160 -/**
31161 - * copy_to_user: - Copy a block of data into user space.
31162 - * @to: Destination address, in user space.
31163 - * @from: Source address, in kernel space.
31164 - * @n: Number of bytes to copy.
31165 - *
31166 - * Context: User context only. This function may sleep.
31167 - *
31168 - * Copy data from kernel space to user space.
31169 - *
31170 - * Returns number of bytes that could not be copied.
31171 - * On success, this will be zero.
31172 - */
31173 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31174 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31175 +void __set_fs(mm_segment_t x)
31176 {
31177 - if (access_ok(VERIFY_WRITE, to, n))
31178 - n = __copy_to_user(to, from, n);
31179 - return n;
31180 + switch (x.seg) {
31181 + case 0:
31182 + loadsegment(gs, 0);
31183 + break;
31184 + case TASK_SIZE_MAX:
31185 + loadsegment(gs, __USER_DS);
31186 + break;
31187 + case -1UL:
31188 + loadsegment(gs, __KERNEL_DS);
31189 + break;
31190 + default:
31191 + BUG();
31192 + }
31193 }
31194 -EXPORT_SYMBOL(_copy_to_user);
31195 +EXPORT_SYMBOL(__set_fs);
31196
31197 -/**
31198 - * copy_from_user: - Copy a block of data from user space.
31199 - * @to: Destination address, in kernel space.
31200 - * @from: Source address, in user space.
31201 - * @n: Number of bytes to copy.
31202 - *
31203 - * Context: User context only. This function may sleep.
31204 - *
31205 - * Copy data from user space to kernel space.
31206 - *
31207 - * Returns number of bytes that could not be copied.
31208 - * On success, this will be zero.
31209 - *
31210 - * If some data could not be copied, this function will pad the copied
31211 - * data to the requested size using zero bytes.
31212 - */
31213 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31214 +void set_fs(mm_segment_t x)
31215 {
31216 - if (access_ok(VERIFY_READ, from, n))
31217 - n = __copy_from_user(to, from, n);
31218 - else
31219 - memset(to, 0, n);
31220 - return n;
31221 + current_thread_info()->addr_limit = x;
31222 + __set_fs(x);
31223 }
31224 -EXPORT_SYMBOL(_copy_from_user);
31225 +EXPORT_SYMBOL(set_fs);
31226 +#endif
31227 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31228 index c905e89..01ab928 100644
31229 --- a/arch/x86/lib/usercopy_64.c
31230 +++ b/arch/x86/lib/usercopy_64.c
31231 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31232 might_fault();
31233 /* no memory constraint because it doesn't change any memory gcc knows
31234 about */
31235 + pax_open_userland();
31236 stac();
31237 asm volatile(
31238 " testq %[size8],%[size8]\n"
31239 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31240 _ASM_EXTABLE(0b,3b)
31241 _ASM_EXTABLE(1b,2b)
31242 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31243 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31244 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31245 [zero] "r" (0UL), [eight] "r" (8UL));
31246 clac();
31247 + pax_close_userland();
31248 return size;
31249 }
31250 EXPORT_SYMBOL(__clear_user);
31251 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31252 }
31253 EXPORT_SYMBOL(clear_user);
31254
31255 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31256 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31257 {
31258 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31259 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31260 - }
31261 - return len;
31262 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31263 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31264 + return len;
31265 }
31266 EXPORT_SYMBOL(copy_in_user);
31267
31268 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31269 * it is not necessary to optimize tail handling.
31270 */
31271 __visible unsigned long
31272 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31273 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31274 {
31275 char c;
31276 unsigned zero_len;
31277
31278 + clac();
31279 + pax_close_userland();
31280 for (; len; --len, to++) {
31281 if (__get_user_nocheck(c, from++, sizeof(char)))
31282 break;
31283 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31284 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31285 if (__put_user_nocheck(c, to++, sizeof(char)))
31286 break;
31287 - clac();
31288 return len;
31289 }
31290 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31291 index 6a19ad9..1c48f9a 100644
31292 --- a/arch/x86/mm/Makefile
31293 +++ b/arch/x86/mm/Makefile
31294 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31295 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31296
31297 obj-$(CONFIG_MEMTEST) += memtest.o
31298 +
31299 +quote:="
31300 +obj-$(CONFIG_X86_64) += uderef_64.o
31301 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31302 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31303 index 903ec1e..c4166b2 100644
31304 --- a/arch/x86/mm/extable.c
31305 +++ b/arch/x86/mm/extable.c
31306 @@ -6,12 +6,24 @@
31307 static inline unsigned long
31308 ex_insn_addr(const struct exception_table_entry *x)
31309 {
31310 - return (unsigned long)&x->insn + x->insn;
31311 + unsigned long reloc = 0;
31312 +
31313 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31314 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31315 +#endif
31316 +
31317 + return (unsigned long)&x->insn + x->insn + reloc;
31318 }
31319 static inline unsigned long
31320 ex_fixup_addr(const struct exception_table_entry *x)
31321 {
31322 - return (unsigned long)&x->fixup + x->fixup;
31323 + unsigned long reloc = 0;
31324 +
31325 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31326 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31327 +#endif
31328 +
31329 + return (unsigned long)&x->fixup + x->fixup + reloc;
31330 }
31331
31332 int fixup_exception(struct pt_regs *regs)
31333 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31334 unsigned long new_ip;
31335
31336 #ifdef CONFIG_PNPBIOS
31337 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31338 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31339 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31340 extern u32 pnp_bios_is_utter_crap;
31341 pnp_bios_is_utter_crap = 1;
31342 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31343 i += 4;
31344 p->fixup -= i;
31345 i += 4;
31346 +
31347 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31348 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31349 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31350 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31351 +#endif
31352 +
31353 }
31354 }
31355
31356 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31357 index 8e57229..31cce89 100644
31358 --- a/arch/x86/mm/fault.c
31359 +++ b/arch/x86/mm/fault.c
31360 @@ -14,11 +14,18 @@
31361 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31362 #include <linux/prefetch.h> /* prefetchw */
31363 #include <linux/context_tracking.h> /* exception_enter(), ... */
31364 +#include <linux/unistd.h>
31365 +#include <linux/compiler.h>
31366
31367 #include <asm/traps.h> /* dotraplinkage, ... */
31368 #include <asm/pgalloc.h> /* pgd_*(), ... */
31369 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31370 #include <asm/fixmap.h> /* VSYSCALL_START */
31371 +#include <asm/tlbflush.h>
31372 +
31373 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31374 +#include <asm/stacktrace.h>
31375 +#endif
31376
31377 #define CREATE_TRACE_POINTS
31378 #include <asm/trace/exceptions.h>
31379 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31380 int ret = 0;
31381
31382 /* kprobe_running() needs smp_processor_id() */
31383 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31384 + if (kprobes_built_in() && !user_mode(regs)) {
31385 preempt_disable();
31386 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31387 ret = 1;
31388 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31389 return !instr_lo || (instr_lo>>1) == 1;
31390 case 0x00:
31391 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31392 - if (probe_kernel_address(instr, opcode))
31393 + if (user_mode(regs)) {
31394 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31395 + return 0;
31396 + } else if (probe_kernel_address(instr, opcode))
31397 return 0;
31398
31399 *prefetch = (instr_lo == 0xF) &&
31400 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31401 while (instr < max_instr) {
31402 unsigned char opcode;
31403
31404 - if (probe_kernel_address(instr, opcode))
31405 + if (user_mode(regs)) {
31406 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31407 + break;
31408 + } else if (probe_kernel_address(instr, opcode))
31409 break;
31410
31411 instr++;
31412 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31413 force_sig_info(si_signo, &info, tsk);
31414 }
31415
31416 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31417 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31418 +#endif
31419 +
31420 +#ifdef CONFIG_PAX_EMUTRAMP
31421 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31422 +#endif
31423 +
31424 +#ifdef CONFIG_PAX_PAGEEXEC
31425 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31426 +{
31427 + pgd_t *pgd;
31428 + pud_t *pud;
31429 + pmd_t *pmd;
31430 +
31431 + pgd = pgd_offset(mm, address);
31432 + if (!pgd_present(*pgd))
31433 + return NULL;
31434 + pud = pud_offset(pgd, address);
31435 + if (!pud_present(*pud))
31436 + return NULL;
31437 + pmd = pmd_offset(pud, address);
31438 + if (!pmd_present(*pmd))
31439 + return NULL;
31440 + return pmd;
31441 +}
31442 +#endif
31443 +
31444 DEFINE_SPINLOCK(pgd_lock);
31445 LIST_HEAD(pgd_list);
31446
31447 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31448 for (address = VMALLOC_START & PMD_MASK;
31449 address >= TASK_SIZE && address < FIXADDR_TOP;
31450 address += PMD_SIZE) {
31451 +
31452 +#ifdef CONFIG_PAX_PER_CPU_PGD
31453 + unsigned long cpu;
31454 +#else
31455 struct page *page;
31456 +#endif
31457
31458 spin_lock(&pgd_lock);
31459 +
31460 +#ifdef CONFIG_PAX_PER_CPU_PGD
31461 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31462 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31463 + pmd_t *ret;
31464 +
31465 + ret = vmalloc_sync_one(pgd, address);
31466 + if (!ret)
31467 + break;
31468 + pgd = get_cpu_pgd(cpu, kernel);
31469 +#else
31470 list_for_each_entry(page, &pgd_list, lru) {
31471 + pgd_t *pgd;
31472 spinlock_t *pgt_lock;
31473 pmd_t *ret;
31474
31475 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31476 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31477
31478 spin_lock(pgt_lock);
31479 - ret = vmalloc_sync_one(page_address(page), address);
31480 + pgd = page_address(page);
31481 +#endif
31482 +
31483 + ret = vmalloc_sync_one(pgd, address);
31484 +
31485 +#ifndef CONFIG_PAX_PER_CPU_PGD
31486 spin_unlock(pgt_lock);
31487 +#endif
31488
31489 if (!ret)
31490 break;
31491 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31492 * an interrupt in the middle of a task switch..
31493 */
31494 pgd_paddr = read_cr3();
31495 +
31496 +#ifdef CONFIG_PAX_PER_CPU_PGD
31497 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31498 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31499 +#endif
31500 +
31501 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31502 if (!pmd_k)
31503 return -1;
31504 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31505 * happen within a race in page table update. In the later
31506 * case just flush:
31507 */
31508 - pgd = pgd_offset(current->active_mm, address);
31509 +
31510 pgd_ref = pgd_offset_k(address);
31511 if (pgd_none(*pgd_ref))
31512 return -1;
31513
31514 +#ifdef CONFIG_PAX_PER_CPU_PGD
31515 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31516 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31517 + if (pgd_none(*pgd)) {
31518 + set_pgd(pgd, *pgd_ref);
31519 + arch_flush_lazy_mmu_mode();
31520 + } else {
31521 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31522 + }
31523 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31524 +#else
31525 + pgd = pgd_offset(current->active_mm, address);
31526 +#endif
31527 +
31528 if (pgd_none(*pgd)) {
31529 set_pgd(pgd, *pgd_ref);
31530 arch_flush_lazy_mmu_mode();
31531 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31532 static int is_errata100(struct pt_regs *regs, unsigned long address)
31533 {
31534 #ifdef CONFIG_X86_64
31535 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31536 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31537 return 1;
31538 #endif
31539 return 0;
31540 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31541 }
31542
31543 static const char nx_warning[] = KERN_CRIT
31544 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31545 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31546
31547 static void
31548 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31549 @@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31550 if (!oops_may_print())
31551 return;
31552
31553 - if (error_code & PF_INSTR) {
31554 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31555 unsigned int level;
31556 pgd_t *pgd;
31557 pte_t *pte;
31558 @@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31559 pte = lookup_address_in_pgd(pgd, address, &level);
31560
31561 if (pte && pte_present(*pte) && !pte_exec(*pte))
31562 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31563 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31564 }
31565
31566 +#ifdef CONFIG_PAX_KERNEXEC
31567 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31568 + if (current->signal->curr_ip)
31569 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31570 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31571 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31572 + else
31573 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31574 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31575 + }
31576 +#endif
31577 +
31578 printk(KERN_ALERT "BUG: unable to handle kernel ");
31579 if (address < PAGE_SIZE)
31580 printk(KERN_CONT "NULL pointer dereference");
31581 @@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31582 return;
31583 }
31584 #endif
31585 +
31586 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31587 + if (pax_is_fetch_fault(regs, error_code, address)) {
31588 +
31589 +#ifdef CONFIG_PAX_EMUTRAMP
31590 + switch (pax_handle_fetch_fault(regs)) {
31591 + case 2:
31592 + return;
31593 + }
31594 +#endif
31595 +
31596 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31597 + do_group_exit(SIGKILL);
31598 + }
31599 +#endif
31600 +
31601 /* Kernel addresses are always protection faults: */
31602 if (address >= TASK_SIZE)
31603 error_code |= PF_PROT;
31604 @@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31605 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31606 printk(KERN_ERR
31607 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31608 - tsk->comm, tsk->pid, address);
31609 + tsk->comm, task_pid_nr(tsk), address);
31610 code = BUS_MCEERR_AR;
31611 }
31612 #endif
31613 @@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31614 return 1;
31615 }
31616
31617 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31618 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31619 +{
31620 + pte_t *pte;
31621 + pmd_t *pmd;
31622 + spinlock_t *ptl;
31623 + unsigned char pte_mask;
31624 +
31625 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31626 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31627 + return 0;
31628 +
31629 + /* PaX: it's our fault, let's handle it if we can */
31630 +
31631 + /* PaX: take a look at read faults before acquiring any locks */
31632 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31633 + /* instruction fetch attempt from a protected page in user mode */
31634 + up_read(&mm->mmap_sem);
31635 +
31636 +#ifdef CONFIG_PAX_EMUTRAMP
31637 + switch (pax_handle_fetch_fault(regs)) {
31638 + case 2:
31639 + return 1;
31640 + }
31641 +#endif
31642 +
31643 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31644 + do_group_exit(SIGKILL);
31645 + }
31646 +
31647 + pmd = pax_get_pmd(mm, address);
31648 + if (unlikely(!pmd))
31649 + return 0;
31650 +
31651 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31652 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31653 + pte_unmap_unlock(pte, ptl);
31654 + return 0;
31655 + }
31656 +
31657 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31658 + /* write attempt to a protected page in user mode */
31659 + pte_unmap_unlock(pte, ptl);
31660 + return 0;
31661 + }
31662 +
31663 +#ifdef CONFIG_SMP
31664 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31665 +#else
31666 + if (likely(address > get_limit(regs->cs)))
31667 +#endif
31668 + {
31669 + set_pte(pte, pte_mkread(*pte));
31670 + __flush_tlb_one(address);
31671 + pte_unmap_unlock(pte, ptl);
31672 + up_read(&mm->mmap_sem);
31673 + return 1;
31674 + }
31675 +
31676 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31677 +
31678 + /*
31679 + * PaX: fill DTLB with user rights and retry
31680 + */
31681 + __asm__ __volatile__ (
31682 + "orb %2,(%1)\n"
31683 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31684 +/*
31685 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31686 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31687 + * page fault when examined during a TLB load attempt. this is true not only
31688 + * for PTEs holding a non-present entry but also present entries that will
31689 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31690 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31691 + * for our target pages since their PTEs are simply not in the TLBs at all.
31692 +
31693 + * the best thing in omitting it is that we gain around 15-20% speed in the
31694 + * fast path of the page fault handler and can get rid of tracing since we
31695 + * can no longer flush unintended entries.
31696 + */
31697 + "invlpg (%0)\n"
31698 +#endif
31699 + __copyuser_seg"testb $0,(%0)\n"
31700 + "xorb %3,(%1)\n"
31701 + :
31702 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31703 + : "memory", "cc");
31704 + pte_unmap_unlock(pte, ptl);
31705 + up_read(&mm->mmap_sem);
31706 + return 1;
31707 +}
31708 +#endif
31709 +
31710 /*
31711 * Handle a spurious fault caused by a stale TLB entry.
31712 *
31713 @@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31714 static inline int
31715 access_error(unsigned long error_code, struct vm_area_struct *vma)
31716 {
31717 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31718 + return 1;
31719 +
31720 if (error_code & PF_WRITE) {
31721 /* write, present and write, not present: */
31722 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31723 @@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31724 if (error_code & PF_USER)
31725 return false;
31726
31727 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31728 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31729 return false;
31730
31731 return true;
31732 @@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31733 tsk = current;
31734 mm = tsk->mm;
31735
31736 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31737 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31738 + if (!search_exception_tables(regs->ip)) {
31739 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31740 + bad_area_nosemaphore(regs, error_code, address);
31741 + return;
31742 + }
31743 + if (address < pax_user_shadow_base) {
31744 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31745 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31746 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31747 + } else
31748 + address -= pax_user_shadow_base;
31749 + }
31750 +#endif
31751 +
31752 /*
31753 * Detect and handle instructions that would cause a page fault for
31754 * both a tracked kernel page and a userspace page.
31755 @@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31756 * User-mode registers count as a user access even for any
31757 * potential system fault or CPU buglet:
31758 */
31759 - if (user_mode_vm(regs)) {
31760 + if (user_mode(regs)) {
31761 local_irq_enable();
31762 error_code |= PF_USER;
31763 flags |= FAULT_FLAG_USER;
31764 @@ -1167,6 +1391,11 @@ retry:
31765 might_sleep();
31766 }
31767
31768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31769 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31770 + return;
31771 +#endif
31772 +
31773 vma = find_vma(mm, address);
31774 if (unlikely(!vma)) {
31775 bad_area(regs, error_code, address);
31776 @@ -1178,18 +1407,24 @@ retry:
31777 bad_area(regs, error_code, address);
31778 return;
31779 }
31780 - if (error_code & PF_USER) {
31781 - /*
31782 - * Accessing the stack below %sp is always a bug.
31783 - * The large cushion allows instructions like enter
31784 - * and pusha to work. ("enter $65535, $31" pushes
31785 - * 32 pointers and then decrements %sp by 65535.)
31786 - */
31787 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31788 - bad_area(regs, error_code, address);
31789 - return;
31790 - }
31791 + /*
31792 + * Accessing the stack below %sp is always a bug.
31793 + * The large cushion allows instructions like enter
31794 + * and pusha to work. ("enter $65535, $31" pushes
31795 + * 32 pointers and then decrements %sp by 65535.)
31796 + */
31797 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31798 + bad_area(regs, error_code, address);
31799 + return;
31800 }
31801 +
31802 +#ifdef CONFIG_PAX_SEGMEXEC
31803 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31804 + bad_area(regs, error_code, address);
31805 + return;
31806 + }
31807 +#endif
31808 +
31809 if (unlikely(expand_stack(vma, address))) {
31810 bad_area(regs, error_code, address);
31811 return;
31812 @@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31813 exception_exit(prev_state);
31814 }
31815 #endif /* CONFIG_TRACING */
31816 +
31817 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31818 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31819 +{
31820 + struct mm_struct *mm = current->mm;
31821 + unsigned long ip = regs->ip;
31822 +
31823 + if (v8086_mode(regs))
31824 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31825 +
31826 +#ifdef CONFIG_PAX_PAGEEXEC
31827 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31828 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31829 + return true;
31830 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31831 + return true;
31832 + return false;
31833 + }
31834 +#endif
31835 +
31836 +#ifdef CONFIG_PAX_SEGMEXEC
31837 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31838 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31839 + return true;
31840 + return false;
31841 + }
31842 +#endif
31843 +
31844 + return false;
31845 +}
31846 +#endif
31847 +
31848 +#ifdef CONFIG_PAX_EMUTRAMP
31849 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31850 +{
31851 + int err;
31852 +
31853 + do { /* PaX: libffi trampoline emulation */
31854 + unsigned char mov, jmp;
31855 + unsigned int addr1, addr2;
31856 +
31857 +#ifdef CONFIG_X86_64
31858 + if ((regs->ip + 9) >> 32)
31859 + break;
31860 +#endif
31861 +
31862 + err = get_user(mov, (unsigned char __user *)regs->ip);
31863 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31864 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31865 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31866 +
31867 + if (err)
31868 + break;
31869 +
31870 + if (mov == 0xB8 && jmp == 0xE9) {
31871 + regs->ax = addr1;
31872 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31873 + return 2;
31874 + }
31875 + } while (0);
31876 +
31877 + do { /* PaX: gcc trampoline emulation #1 */
31878 + unsigned char mov1, mov2;
31879 + unsigned short jmp;
31880 + unsigned int addr1, addr2;
31881 +
31882 +#ifdef CONFIG_X86_64
31883 + if ((regs->ip + 11) >> 32)
31884 + break;
31885 +#endif
31886 +
31887 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31888 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31889 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31890 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31891 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31892 +
31893 + if (err)
31894 + break;
31895 +
31896 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31897 + regs->cx = addr1;
31898 + regs->ax = addr2;
31899 + regs->ip = addr2;
31900 + return 2;
31901 + }
31902 + } while (0);
31903 +
31904 + do { /* PaX: gcc trampoline emulation #2 */
31905 + unsigned char mov, jmp;
31906 + unsigned int addr1, addr2;
31907 +
31908 +#ifdef CONFIG_X86_64
31909 + if ((regs->ip + 9) >> 32)
31910 + break;
31911 +#endif
31912 +
31913 + err = get_user(mov, (unsigned char __user *)regs->ip);
31914 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31915 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31916 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31917 +
31918 + if (err)
31919 + break;
31920 +
31921 + if (mov == 0xB9 && jmp == 0xE9) {
31922 + regs->cx = addr1;
31923 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31924 + return 2;
31925 + }
31926 + } while (0);
31927 +
31928 + return 1; /* PaX in action */
31929 +}
31930 +
31931 +#ifdef CONFIG_X86_64
31932 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31933 +{
31934 + int err;
31935 +
31936 + do { /* PaX: libffi trampoline emulation */
31937 + unsigned short mov1, mov2, jmp1;
31938 + unsigned char stcclc, jmp2;
31939 + unsigned long addr1, addr2;
31940 +
31941 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31942 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31943 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31944 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31945 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31946 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31947 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31948 +
31949 + if (err)
31950 + break;
31951 +
31952 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31953 + regs->r11 = addr1;
31954 + regs->r10 = addr2;
31955 + if (stcclc == 0xF8)
31956 + regs->flags &= ~X86_EFLAGS_CF;
31957 + else
31958 + regs->flags |= X86_EFLAGS_CF;
31959 + regs->ip = addr1;
31960 + return 2;
31961 + }
31962 + } while (0);
31963 +
31964 + do { /* PaX: gcc trampoline emulation #1 */
31965 + unsigned short mov1, mov2, jmp1;
31966 + unsigned char jmp2;
31967 + unsigned int addr1;
31968 + unsigned long addr2;
31969 +
31970 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31971 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31972 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31973 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31974 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31975 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31976 +
31977 + if (err)
31978 + break;
31979 +
31980 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31981 + regs->r11 = addr1;
31982 + regs->r10 = addr2;
31983 + regs->ip = addr1;
31984 + return 2;
31985 + }
31986 + } while (0);
31987 +
31988 + do { /* PaX: gcc trampoline emulation #2 */
31989 + unsigned short mov1, mov2, jmp1;
31990 + unsigned char jmp2;
31991 + unsigned long addr1, addr2;
31992 +
31993 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31994 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31995 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31996 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31997 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31998 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31999 +
32000 + if (err)
32001 + break;
32002 +
32003 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32004 + regs->r11 = addr1;
32005 + regs->r10 = addr2;
32006 + regs->ip = addr1;
32007 + return 2;
32008 + }
32009 + } while (0);
32010 +
32011 + return 1; /* PaX in action */
32012 +}
32013 +#endif
32014 +
32015 +/*
32016 + * PaX: decide what to do with offenders (regs->ip = fault address)
32017 + *
32018 + * returns 1 when task should be killed
32019 + * 2 when gcc trampoline was detected
32020 + */
32021 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32022 +{
32023 + if (v8086_mode(regs))
32024 + return 1;
32025 +
32026 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32027 + return 1;
32028 +
32029 +#ifdef CONFIG_X86_32
32030 + return pax_handle_fetch_fault_32(regs);
32031 +#else
32032 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32033 + return pax_handle_fetch_fault_32(regs);
32034 + else
32035 + return pax_handle_fetch_fault_64(regs);
32036 +#endif
32037 +}
32038 +#endif
32039 +
32040 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32041 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32042 +{
32043 + long i;
32044 +
32045 + printk(KERN_ERR "PAX: bytes at PC: ");
32046 + for (i = 0; i < 20; i++) {
32047 + unsigned char c;
32048 + if (get_user(c, (unsigned char __force_user *)pc+i))
32049 + printk(KERN_CONT "?? ");
32050 + else
32051 + printk(KERN_CONT "%02x ", c);
32052 + }
32053 + printk("\n");
32054 +
32055 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32056 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32057 + unsigned long c;
32058 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32059 +#ifdef CONFIG_X86_32
32060 + printk(KERN_CONT "???????? ");
32061 +#else
32062 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32063 + printk(KERN_CONT "???????? ???????? ");
32064 + else
32065 + printk(KERN_CONT "???????????????? ");
32066 +#endif
32067 + } else {
32068 +#ifdef CONFIG_X86_64
32069 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32070 + printk(KERN_CONT "%08x ", (unsigned int)c);
32071 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32072 + } else
32073 +#endif
32074 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32075 + }
32076 + }
32077 + printk("\n");
32078 +}
32079 +#endif
32080 +
32081 +/**
32082 + * probe_kernel_write(): safely attempt to write to a location
32083 + * @dst: address to write to
32084 + * @src: pointer to the data that shall be written
32085 + * @size: size of the data chunk
32086 + *
32087 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32088 + * happens, handle that and return -EFAULT.
32089 + */
32090 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32091 +{
32092 + long ret;
32093 + mm_segment_t old_fs = get_fs();
32094 +
32095 + set_fs(KERNEL_DS);
32096 + pagefault_disable();
32097 + pax_open_kernel();
32098 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32099 + pax_close_kernel();
32100 + pagefault_enable();
32101 + set_fs(old_fs);
32102 +
32103 + return ret ? -EFAULT : 0;
32104 +}
32105 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32106 index 207d9aef..69030980 100644
32107 --- a/arch/x86/mm/gup.c
32108 +++ b/arch/x86/mm/gup.c
32109 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32110 addr = start;
32111 len = (unsigned long) nr_pages << PAGE_SHIFT;
32112 end = start + len;
32113 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32114 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32115 (void __user *)start, len)))
32116 return 0;
32117
32118 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32119 goto slow_irqon;
32120 #endif
32121
32122 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32123 + (void __user *)start, len)))
32124 + return 0;
32125 +
32126 /*
32127 * XXX: batch / limit 'nr', to avoid large irq off latency
32128 * needs some instrumenting to determine the common sizes used by
32129 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32130 index 4500142..53a363c 100644
32131 --- a/arch/x86/mm/highmem_32.c
32132 +++ b/arch/x86/mm/highmem_32.c
32133 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32134 idx = type + KM_TYPE_NR*smp_processor_id();
32135 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32136 BUG_ON(!pte_none(*(kmap_pte-idx)));
32137 +
32138 + pax_open_kernel();
32139 set_pte(kmap_pte-idx, mk_pte(page, prot));
32140 + pax_close_kernel();
32141 +
32142 arch_flush_lazy_mmu_mode();
32143
32144 return (void *)vaddr;
32145 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32146 index 8b977eb..4732c33 100644
32147 --- a/arch/x86/mm/hugetlbpage.c
32148 +++ b/arch/x86/mm/hugetlbpage.c
32149 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32150 #ifdef CONFIG_HUGETLB_PAGE
32151 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32152 unsigned long addr, unsigned long len,
32153 - unsigned long pgoff, unsigned long flags)
32154 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32155 {
32156 struct hstate *h = hstate_file(file);
32157 struct vm_unmapped_area_info info;
32158 -
32159 +
32160 info.flags = 0;
32161 info.length = len;
32162 info.low_limit = current->mm->mmap_legacy_base;
32163 info.high_limit = TASK_SIZE;
32164 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32165 info.align_offset = 0;
32166 + info.threadstack_offset = offset;
32167 return vm_unmapped_area(&info);
32168 }
32169
32170 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32171 unsigned long addr0, unsigned long len,
32172 - unsigned long pgoff, unsigned long flags)
32173 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32174 {
32175 struct hstate *h = hstate_file(file);
32176 struct vm_unmapped_area_info info;
32177 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32178 info.high_limit = current->mm->mmap_base;
32179 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32180 info.align_offset = 0;
32181 + info.threadstack_offset = offset;
32182 addr = vm_unmapped_area(&info);
32183
32184 /*
32185 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32186 VM_BUG_ON(addr != -ENOMEM);
32187 info.flags = 0;
32188 info.low_limit = TASK_UNMAPPED_BASE;
32189 +
32190 +#ifdef CONFIG_PAX_RANDMMAP
32191 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32192 + info.low_limit += current->mm->delta_mmap;
32193 +#endif
32194 +
32195 info.high_limit = TASK_SIZE;
32196 addr = vm_unmapped_area(&info);
32197 }
32198 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32199 struct hstate *h = hstate_file(file);
32200 struct mm_struct *mm = current->mm;
32201 struct vm_area_struct *vma;
32202 + unsigned long pax_task_size = TASK_SIZE;
32203 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32204
32205 if (len & ~huge_page_mask(h))
32206 return -EINVAL;
32207 - if (len > TASK_SIZE)
32208 +
32209 +#ifdef CONFIG_PAX_SEGMEXEC
32210 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32211 + pax_task_size = SEGMEXEC_TASK_SIZE;
32212 +#endif
32213 +
32214 + pax_task_size -= PAGE_SIZE;
32215 +
32216 + if (len > pax_task_size)
32217 return -ENOMEM;
32218
32219 if (flags & MAP_FIXED) {
32220 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32221 return addr;
32222 }
32223
32224 +#ifdef CONFIG_PAX_RANDMMAP
32225 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32226 +#endif
32227 +
32228 if (addr) {
32229 addr = ALIGN(addr, huge_page_size(h));
32230 vma = find_vma(mm, addr);
32231 - if (TASK_SIZE - len >= addr &&
32232 - (!vma || addr + len <= vma->vm_start))
32233 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32234 return addr;
32235 }
32236 if (mm->get_unmapped_area == arch_get_unmapped_area)
32237 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32238 - pgoff, flags);
32239 + pgoff, flags, offset);
32240 else
32241 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32242 - pgoff, flags);
32243 + pgoff, flags, offset);
32244 }
32245 #endif /* CONFIG_HUGETLB_PAGE */
32246
32247 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32248 index f971306..e83e0f6 100644
32249 --- a/arch/x86/mm/init.c
32250 +++ b/arch/x86/mm/init.c
32251 @@ -4,6 +4,7 @@
32252 #include <linux/swap.h>
32253 #include <linux/memblock.h>
32254 #include <linux/bootmem.h> /* for max_low_pfn */
32255 +#include <linux/tboot.h>
32256
32257 #include <asm/cacheflush.h>
32258 #include <asm/e820.h>
32259 @@ -17,6 +18,8 @@
32260 #include <asm/proto.h>
32261 #include <asm/dma.h> /* for MAX_DMA_PFN */
32262 #include <asm/microcode.h>
32263 +#include <asm/desc.h>
32264 +#include <asm/bios_ebda.h>
32265
32266 #include "mm_internal.h"
32267
32268 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32269 early_ioremap_page_table_range_init();
32270 #endif
32271
32272 +#ifdef CONFIG_PAX_PER_CPU_PGD
32273 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32274 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32275 + KERNEL_PGD_PTRS);
32276 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32277 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32278 + KERNEL_PGD_PTRS);
32279 + load_cr3(get_cpu_pgd(0, kernel));
32280 +#else
32281 load_cr3(swapper_pg_dir);
32282 +#endif
32283 +
32284 __flush_tlb_all();
32285
32286 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32287 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32288 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32289 * mmio resources as well as potential bios/acpi data regions.
32290 */
32291 +
32292 +#ifdef CONFIG_GRKERNSEC_KMEM
32293 +static unsigned int ebda_start __read_only;
32294 +static unsigned int ebda_end __read_only;
32295 +#endif
32296 +
32297 int devmem_is_allowed(unsigned long pagenr)
32298 {
32299 - if (pagenr < 256)
32300 +#ifdef CONFIG_GRKERNSEC_KMEM
32301 + /* allow BDA */
32302 + if (!pagenr)
32303 return 1;
32304 + /* allow EBDA */
32305 + if (pagenr >= ebda_start && pagenr < ebda_end)
32306 + return 1;
32307 + /* if tboot is in use, allow access to its hardcoded serial log range */
32308 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32309 + return 1;
32310 +#else
32311 + if (!pagenr)
32312 + return 1;
32313 +#ifdef CONFIG_VM86
32314 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32315 + return 1;
32316 +#endif
32317 +#endif
32318 +
32319 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32320 + return 1;
32321 +#ifdef CONFIG_GRKERNSEC_KMEM
32322 + /* throw out everything else below 1MB */
32323 + if (pagenr <= 256)
32324 + return 0;
32325 +#endif
32326 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32327 return 0;
32328 if (!page_is_ram(pagenr))
32329 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32330 #endif
32331 }
32332
32333 +#ifdef CONFIG_GRKERNSEC_KMEM
32334 +static inline void gr_init_ebda(void)
32335 +{
32336 + unsigned int ebda_addr;
32337 + unsigned int ebda_size = 0;
32338 +
32339 + ebda_addr = get_bios_ebda();
32340 + if (ebda_addr) {
32341 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32342 + ebda_size <<= 10;
32343 + }
32344 + if (ebda_addr && ebda_size) {
32345 + ebda_start = ebda_addr >> PAGE_SHIFT;
32346 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32347 + } else {
32348 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32349 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32350 + }
32351 +}
32352 +#else
32353 +static inline void gr_init_ebda(void) { }
32354 +#endif
32355 +
32356 void free_initmem(void)
32357 {
32358 +#ifdef CONFIG_PAX_KERNEXEC
32359 +#ifdef CONFIG_X86_32
32360 + /* PaX: limit KERNEL_CS to actual size */
32361 + unsigned long addr, limit;
32362 + struct desc_struct d;
32363 + int cpu;
32364 +#else
32365 + pgd_t *pgd;
32366 + pud_t *pud;
32367 + pmd_t *pmd;
32368 + unsigned long addr, end;
32369 +#endif
32370 +#endif
32371 +
32372 + gr_init_ebda();
32373 +
32374 +#ifdef CONFIG_PAX_KERNEXEC
32375 +#ifdef CONFIG_X86_32
32376 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32377 + limit = (limit - 1UL) >> PAGE_SHIFT;
32378 +
32379 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32380 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32381 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32382 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32383 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32384 + }
32385 +
32386 + /* PaX: make KERNEL_CS read-only */
32387 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32388 + if (!paravirt_enabled())
32389 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32390 +/*
32391 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32392 + pgd = pgd_offset_k(addr);
32393 + pud = pud_offset(pgd, addr);
32394 + pmd = pmd_offset(pud, addr);
32395 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32396 + }
32397 +*/
32398 +#ifdef CONFIG_X86_PAE
32399 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32400 +/*
32401 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32402 + pgd = pgd_offset_k(addr);
32403 + pud = pud_offset(pgd, addr);
32404 + pmd = pmd_offset(pud, addr);
32405 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32406 + }
32407 +*/
32408 +#endif
32409 +
32410 +#ifdef CONFIG_MODULES
32411 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32412 +#endif
32413 +
32414 +#else
32415 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32416 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32417 + pgd = pgd_offset_k(addr);
32418 + pud = pud_offset(pgd, addr);
32419 + pmd = pmd_offset(pud, addr);
32420 + if (!pmd_present(*pmd))
32421 + continue;
32422 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32423 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32424 + else
32425 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32426 + }
32427 +
32428 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32429 + end = addr + KERNEL_IMAGE_SIZE;
32430 + for (; addr < end; addr += PMD_SIZE) {
32431 + pgd = pgd_offset_k(addr);
32432 + pud = pud_offset(pgd, addr);
32433 + pmd = pmd_offset(pud, addr);
32434 + if (!pmd_present(*pmd))
32435 + continue;
32436 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32437 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32438 + }
32439 +#endif
32440 +
32441 + flush_tlb_all();
32442 +#endif
32443 +
32444 free_init_pages("unused kernel",
32445 (unsigned long)(&__init_begin),
32446 (unsigned long)(&__init_end));
32447 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32448 index e395048..cd38278 100644
32449 --- a/arch/x86/mm/init_32.c
32450 +++ b/arch/x86/mm/init_32.c
32451 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32452 bool __read_mostly __vmalloc_start_set = false;
32453
32454 /*
32455 - * Creates a middle page table and puts a pointer to it in the
32456 - * given global directory entry. This only returns the gd entry
32457 - * in non-PAE compilation mode, since the middle layer is folded.
32458 - */
32459 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32460 -{
32461 - pud_t *pud;
32462 - pmd_t *pmd_table;
32463 -
32464 -#ifdef CONFIG_X86_PAE
32465 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32466 - pmd_table = (pmd_t *)alloc_low_page();
32467 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32468 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32469 - pud = pud_offset(pgd, 0);
32470 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32471 -
32472 - return pmd_table;
32473 - }
32474 -#endif
32475 - pud = pud_offset(pgd, 0);
32476 - pmd_table = pmd_offset(pud, 0);
32477 -
32478 - return pmd_table;
32479 -}
32480 -
32481 -/*
32482 * Create a page table and place a pointer to it in a middle page
32483 * directory entry:
32484 */
32485 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32486 pte_t *page_table = (pte_t *)alloc_low_page();
32487
32488 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32489 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32490 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32491 +#else
32492 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32493 +#endif
32494 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32495 }
32496
32497 return pte_offset_kernel(pmd, 0);
32498 }
32499
32500 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32501 +{
32502 + pud_t *pud;
32503 + pmd_t *pmd_table;
32504 +
32505 + pud = pud_offset(pgd, 0);
32506 + pmd_table = pmd_offset(pud, 0);
32507 +
32508 + return pmd_table;
32509 +}
32510 +
32511 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32512 {
32513 int pgd_idx = pgd_index(vaddr);
32514 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32515 int pgd_idx, pmd_idx;
32516 unsigned long vaddr;
32517 pgd_t *pgd;
32518 + pud_t *pud;
32519 pmd_t *pmd;
32520 pte_t *pte = NULL;
32521 unsigned long count = page_table_range_init_count(start, end);
32522 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32523 pgd = pgd_base + pgd_idx;
32524
32525 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32526 - pmd = one_md_table_init(pgd);
32527 - pmd = pmd + pmd_index(vaddr);
32528 + pud = pud_offset(pgd, vaddr);
32529 + pmd = pmd_offset(pud, vaddr);
32530 +
32531 +#ifdef CONFIG_X86_PAE
32532 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32533 +#endif
32534 +
32535 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32536 pmd++, pmd_idx++) {
32537 pte = page_table_kmap_check(one_page_table_init(pmd),
32538 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32539 }
32540 }
32541
32542 -static inline int is_kernel_text(unsigned long addr)
32543 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32544 {
32545 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32546 - return 1;
32547 - return 0;
32548 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32549 + end <= ktla_ktva((unsigned long)_stext)) &&
32550 + (start >= ktla_ktva((unsigned long)_einittext) ||
32551 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32552 +
32553 +#ifdef CONFIG_ACPI_SLEEP
32554 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32555 +#endif
32556 +
32557 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32558 + return 0;
32559 + return 1;
32560 }
32561
32562 /*
32563 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32564 unsigned long last_map_addr = end;
32565 unsigned long start_pfn, end_pfn;
32566 pgd_t *pgd_base = swapper_pg_dir;
32567 - int pgd_idx, pmd_idx, pte_ofs;
32568 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32569 unsigned long pfn;
32570 pgd_t *pgd;
32571 + pud_t *pud;
32572 pmd_t *pmd;
32573 pte_t *pte;
32574 unsigned pages_2m, pages_4k;
32575 @@ -291,8 +295,13 @@ repeat:
32576 pfn = start_pfn;
32577 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32578 pgd = pgd_base + pgd_idx;
32579 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32580 - pmd = one_md_table_init(pgd);
32581 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32582 + pud = pud_offset(pgd, 0);
32583 + pmd = pmd_offset(pud, 0);
32584 +
32585 +#ifdef CONFIG_X86_PAE
32586 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32587 +#endif
32588
32589 if (pfn >= end_pfn)
32590 continue;
32591 @@ -304,14 +313,13 @@ repeat:
32592 #endif
32593 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32594 pmd++, pmd_idx++) {
32595 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32596 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32597
32598 /*
32599 * Map with big pages if possible, otherwise
32600 * create normal page tables:
32601 */
32602 if (use_pse) {
32603 - unsigned int addr2;
32604 pgprot_t prot = PAGE_KERNEL_LARGE;
32605 /*
32606 * first pass will use the same initial
32607 @@ -322,11 +330,7 @@ repeat:
32608 _PAGE_PSE);
32609
32610 pfn &= PMD_MASK >> PAGE_SHIFT;
32611 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32612 - PAGE_OFFSET + PAGE_SIZE-1;
32613 -
32614 - if (is_kernel_text(addr) ||
32615 - is_kernel_text(addr2))
32616 + if (is_kernel_text(address, address + PMD_SIZE))
32617 prot = PAGE_KERNEL_LARGE_EXEC;
32618
32619 pages_2m++;
32620 @@ -343,7 +347,7 @@ repeat:
32621 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32622 pte += pte_ofs;
32623 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32624 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32625 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32626 pgprot_t prot = PAGE_KERNEL;
32627 /*
32628 * first pass will use the same initial
32629 @@ -351,7 +355,7 @@ repeat:
32630 */
32631 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32632
32633 - if (is_kernel_text(addr))
32634 + if (is_kernel_text(address, address + PAGE_SIZE))
32635 prot = PAGE_KERNEL_EXEC;
32636
32637 pages_4k++;
32638 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32639
32640 pud = pud_offset(pgd, va);
32641 pmd = pmd_offset(pud, va);
32642 - if (!pmd_present(*pmd))
32643 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32644 break;
32645
32646 /* should not be large page here */
32647 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32648
32649 static void __init pagetable_init(void)
32650 {
32651 - pgd_t *pgd_base = swapper_pg_dir;
32652 -
32653 - permanent_kmaps_init(pgd_base);
32654 + permanent_kmaps_init(swapper_pg_dir);
32655 }
32656
32657 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32658 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32659 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32660
32661 /* user-defined highmem size */
32662 @@ -787,10 +789,10 @@ void __init mem_init(void)
32663 ((unsigned long)&__init_end -
32664 (unsigned long)&__init_begin) >> 10,
32665
32666 - (unsigned long)&_etext, (unsigned long)&_edata,
32667 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32668 + (unsigned long)&_sdata, (unsigned long)&_edata,
32669 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32670
32671 - (unsigned long)&_text, (unsigned long)&_etext,
32672 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32673 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32674
32675 /*
32676 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32677 if (!kernel_set_to_readonly)
32678 return;
32679
32680 + start = ktla_ktva(start);
32681 pr_debug("Set kernel text: %lx - %lx for read write\n",
32682 start, start+size);
32683
32684 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32685 if (!kernel_set_to_readonly)
32686 return;
32687
32688 + start = ktla_ktva(start);
32689 pr_debug("Set kernel text: %lx - %lx for read only\n",
32690 start, start+size);
32691
32692 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32693 unsigned long start = PFN_ALIGN(_text);
32694 unsigned long size = PFN_ALIGN(_etext) - start;
32695
32696 + start = ktla_ktva(start);
32697 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32698 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32699 size >> 10);
32700 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32701 index f35c66c..84b95ef 100644
32702 --- a/arch/x86/mm/init_64.c
32703 +++ b/arch/x86/mm/init_64.c
32704 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32705 * around without checking the pgd every time.
32706 */
32707
32708 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32709 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32710 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32711
32712 int force_personality32;
32713 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32714
32715 for (address = start; address <= end; address += PGDIR_SIZE) {
32716 const pgd_t *pgd_ref = pgd_offset_k(address);
32717 +
32718 +#ifdef CONFIG_PAX_PER_CPU_PGD
32719 + unsigned long cpu;
32720 +#else
32721 struct page *page;
32722 +#endif
32723
32724 if (pgd_none(*pgd_ref))
32725 continue;
32726
32727 spin_lock(&pgd_lock);
32728 +
32729 +#ifdef CONFIG_PAX_PER_CPU_PGD
32730 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32731 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32732 +
32733 + if (pgd_none(*pgd))
32734 + set_pgd(pgd, *pgd_ref);
32735 + else
32736 + BUG_ON(pgd_page_vaddr(*pgd)
32737 + != pgd_page_vaddr(*pgd_ref));
32738 + pgd = pgd_offset_cpu(cpu, kernel, address);
32739 +#else
32740 list_for_each_entry(page, &pgd_list, lru) {
32741 pgd_t *pgd;
32742 spinlock_t *pgt_lock;
32743 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32744 /* the pgt_lock only for Xen */
32745 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32746 spin_lock(pgt_lock);
32747 +#endif
32748
32749 if (pgd_none(*pgd))
32750 set_pgd(pgd, *pgd_ref);
32751 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32752 BUG_ON(pgd_page_vaddr(*pgd)
32753 != pgd_page_vaddr(*pgd_ref));
32754
32755 +#ifndef CONFIG_PAX_PER_CPU_PGD
32756 spin_unlock(pgt_lock);
32757 +#endif
32758 +
32759 }
32760 spin_unlock(&pgd_lock);
32761 }
32762 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32763 {
32764 if (pgd_none(*pgd)) {
32765 pud_t *pud = (pud_t *)spp_getpage();
32766 - pgd_populate(&init_mm, pgd, pud);
32767 + pgd_populate_kernel(&init_mm, pgd, pud);
32768 if (pud != pud_offset(pgd, 0))
32769 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32770 pud, pud_offset(pgd, 0));
32771 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32772 {
32773 if (pud_none(*pud)) {
32774 pmd_t *pmd = (pmd_t *) spp_getpage();
32775 - pud_populate(&init_mm, pud, pmd);
32776 + pud_populate_kernel(&init_mm, pud, pmd);
32777 if (pmd != pmd_offset(pud, 0))
32778 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32779 pmd, pmd_offset(pud, 0));
32780 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32781 pmd = fill_pmd(pud, vaddr);
32782 pte = fill_pte(pmd, vaddr);
32783
32784 + pax_open_kernel();
32785 set_pte(pte, new_pte);
32786 + pax_close_kernel();
32787
32788 /*
32789 * It's enough to flush this one mapping.
32790 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32791 pgd = pgd_offset_k((unsigned long)__va(phys));
32792 if (pgd_none(*pgd)) {
32793 pud = (pud_t *) spp_getpage();
32794 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32795 - _PAGE_USER));
32796 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32797 }
32798 pud = pud_offset(pgd, (unsigned long)__va(phys));
32799 if (pud_none(*pud)) {
32800 pmd = (pmd_t *) spp_getpage();
32801 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32802 - _PAGE_USER));
32803 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32804 }
32805 pmd = pmd_offset(pud, phys);
32806 BUG_ON(!pmd_none(*pmd));
32807 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32808 prot);
32809
32810 spin_lock(&init_mm.page_table_lock);
32811 - pud_populate(&init_mm, pud, pmd);
32812 + pud_populate_kernel(&init_mm, pud, pmd);
32813 spin_unlock(&init_mm.page_table_lock);
32814 }
32815 __flush_tlb_all();
32816 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32817 page_size_mask);
32818
32819 spin_lock(&init_mm.page_table_lock);
32820 - pgd_populate(&init_mm, pgd, pud);
32821 + pgd_populate_kernel(&init_mm, pgd, pud);
32822 spin_unlock(&init_mm.page_table_lock);
32823 pgd_changed = true;
32824 }
32825 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32826 static struct vm_area_struct gate_vma = {
32827 .vm_start = VSYSCALL_START,
32828 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32829 - .vm_page_prot = PAGE_READONLY_EXEC,
32830 - .vm_flags = VM_READ | VM_EXEC
32831 + .vm_page_prot = PAGE_READONLY,
32832 + .vm_flags = VM_READ
32833 };
32834
32835 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32836 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32837
32838 const char *arch_vma_name(struct vm_area_struct *vma)
32839 {
32840 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32841 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32842 return "[vdso]";
32843 if (vma == &gate_vma)
32844 return "[vsyscall]";
32845 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32846 index 7b179b4..6bd17777 100644
32847 --- a/arch/x86/mm/iomap_32.c
32848 +++ b/arch/x86/mm/iomap_32.c
32849 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32850 type = kmap_atomic_idx_push();
32851 idx = type + KM_TYPE_NR * smp_processor_id();
32852 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32853 +
32854 + pax_open_kernel();
32855 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32856 + pax_close_kernel();
32857 +
32858 arch_flush_lazy_mmu_mode();
32859
32860 return (void *)vaddr;
32861 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32862 index 597ac15..49841be 100644
32863 --- a/arch/x86/mm/ioremap.c
32864 +++ b/arch/x86/mm/ioremap.c
32865 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32866 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32867 int is_ram = page_is_ram(pfn);
32868
32869 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32870 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32871 return NULL;
32872 WARN_ON_ONCE(is_ram);
32873 }
32874 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32875 *
32876 * Caller must ensure there is only one unmapping for the same pointer.
32877 */
32878 -void iounmap(volatile void __iomem *addr)
32879 +void iounmap(const volatile void __iomem *addr)
32880 {
32881 struct vm_struct *p, *o;
32882
32883 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32884
32885 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32886 if (page_is_ram(start >> PAGE_SHIFT))
32887 +#ifdef CONFIG_HIGHMEM
32888 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32889 +#endif
32890 return __va(phys);
32891
32892 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32893 @@ -322,13 +325,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32894 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32895 {
32896 if (page_is_ram(phys >> PAGE_SHIFT))
32897 +#ifdef CONFIG_HIGHMEM
32898 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32899 +#endif
32900 return;
32901
32902 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32903 return;
32904 }
32905
32906 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32907 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32908
32909 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32910 {
32911 @@ -358,8 +364,7 @@ void __init early_ioremap_init(void)
32912 early_ioremap_setup();
32913
32914 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32915 - memset(bm_pte, 0, sizeof(bm_pte));
32916 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32917 + pmd_populate_user(&init_mm, pmd, bm_pte);
32918
32919 /*
32920 * The boot-ioremap range spans multiple pmds, for which
32921 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32922 index dd89a13..d77bdcc 100644
32923 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32924 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32925 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32926 * memory (e.g. tracked pages)? For now, we need this to avoid
32927 * invoking kmemcheck for PnP BIOS calls.
32928 */
32929 - if (regs->flags & X86_VM_MASK)
32930 + if (v8086_mode(regs))
32931 return false;
32932 - if (regs->cs != __KERNEL_CS)
32933 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32934 return false;
32935
32936 pte = kmemcheck_pte_lookup(address);
32937 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32938 index 25e7e13..1964579 100644
32939 --- a/arch/x86/mm/mmap.c
32940 +++ b/arch/x86/mm/mmap.c
32941 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32942 * Leave an at least ~128 MB hole with possible stack randomization.
32943 */
32944 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32945 -#define MAX_GAP (TASK_SIZE/6*5)
32946 +#define MAX_GAP (pax_task_size/6*5)
32947
32948 static int mmap_is_legacy(void)
32949 {
32950 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32951 return rnd << PAGE_SHIFT;
32952 }
32953
32954 -static unsigned long mmap_base(void)
32955 +static unsigned long mmap_base(struct mm_struct *mm)
32956 {
32957 unsigned long gap = rlimit(RLIMIT_STACK);
32958 + unsigned long pax_task_size = TASK_SIZE;
32959 +
32960 +#ifdef CONFIG_PAX_SEGMEXEC
32961 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32962 + pax_task_size = SEGMEXEC_TASK_SIZE;
32963 +#endif
32964
32965 if (gap < MIN_GAP)
32966 gap = MIN_GAP;
32967 else if (gap > MAX_GAP)
32968 gap = MAX_GAP;
32969
32970 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32971 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32972 }
32973
32974 /*
32975 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32976 * does, but not when emulating X86_32
32977 */
32978 -static unsigned long mmap_legacy_base(void)
32979 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32980 {
32981 - if (mmap_is_ia32())
32982 + if (mmap_is_ia32()) {
32983 +
32984 +#ifdef CONFIG_PAX_SEGMEXEC
32985 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32986 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32987 + else
32988 +#endif
32989 +
32990 return TASK_UNMAPPED_BASE;
32991 - else
32992 + } else
32993 return TASK_UNMAPPED_BASE + mmap_rnd();
32994 }
32995
32996 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32997 */
32998 void arch_pick_mmap_layout(struct mm_struct *mm)
32999 {
33000 - mm->mmap_legacy_base = mmap_legacy_base();
33001 - mm->mmap_base = mmap_base();
33002 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33003 + mm->mmap_base = mmap_base(mm);
33004 +
33005 +#ifdef CONFIG_PAX_RANDMMAP
33006 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33007 + mm->mmap_legacy_base += mm->delta_mmap;
33008 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33009 + }
33010 +#endif
33011
33012 if (mmap_is_legacy()) {
33013 mm->mmap_base = mm->mmap_legacy_base;
33014 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33015 index 0057a7a..95c7edd 100644
33016 --- a/arch/x86/mm/mmio-mod.c
33017 +++ b/arch/x86/mm/mmio-mod.c
33018 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33019 break;
33020 default:
33021 {
33022 - unsigned char *ip = (unsigned char *)instptr;
33023 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33024 my_trace->opcode = MMIO_UNKNOWN_OP;
33025 my_trace->width = 0;
33026 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33027 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33028 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33029 void __iomem *addr)
33030 {
33031 - static atomic_t next_id;
33032 + static atomic_unchecked_t next_id;
33033 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33034 /* These are page-unaligned. */
33035 struct mmiotrace_map map = {
33036 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33037 .private = trace
33038 },
33039 .phys = offset,
33040 - .id = atomic_inc_return(&next_id)
33041 + .id = atomic_inc_return_unchecked(&next_id)
33042 };
33043 map.map_id = trace->id;
33044
33045 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33046 ioremap_trace_core(offset, size, addr);
33047 }
33048
33049 -static void iounmap_trace_core(volatile void __iomem *addr)
33050 +static void iounmap_trace_core(const volatile void __iomem *addr)
33051 {
33052 struct mmiotrace_map map = {
33053 .phys = 0,
33054 @@ -328,7 +328,7 @@ not_enabled:
33055 }
33056 }
33057
33058 -void mmiotrace_iounmap(volatile void __iomem *addr)
33059 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33060 {
33061 might_sleep();
33062 if (is_enabled()) /* recheck and proper locking in *_core() */
33063 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33064 index 1d045f9..3a00249 100644
33065 --- a/arch/x86/mm/numa.c
33066 +++ b/arch/x86/mm/numa.c
33067 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33068 return true;
33069 }
33070
33071 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33072 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33073 {
33074 unsigned long uninitialized_var(pfn_align);
33075 int i, nid;
33076 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33077 index 461bc82..4e091a3 100644
33078 --- a/arch/x86/mm/pageattr-test.c
33079 +++ b/arch/x86/mm/pageattr-test.c
33080 @@ -35,7 +35,7 @@ enum {
33081
33082 static int pte_testbit(pte_t pte)
33083 {
33084 - return pte_flags(pte) & _PAGE_UNUSED1;
33085 + return pte_flags(pte) & _PAGE_CPA_TEST;
33086 }
33087
33088 struct split_state {
33089 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33090 index ae242a7..1c7998f 100644
33091 --- a/arch/x86/mm/pageattr.c
33092 +++ b/arch/x86/mm/pageattr.c
33093 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33094 */
33095 #ifdef CONFIG_PCI_BIOS
33096 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33097 - pgprot_val(forbidden) |= _PAGE_NX;
33098 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33099 #endif
33100
33101 /*
33102 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33103 * Does not cover __inittext since that is gone later on. On
33104 * 64bit we do not enforce !NX on the low mapping
33105 */
33106 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33107 - pgprot_val(forbidden) |= _PAGE_NX;
33108 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33109 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33110
33111 +#ifdef CONFIG_DEBUG_RODATA
33112 /*
33113 * The .rodata section needs to be read-only. Using the pfn
33114 * catches all aliases.
33115 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33116 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33117 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33118 pgprot_val(forbidden) |= _PAGE_RW;
33119 +#endif
33120
33121 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33122 /*
33123 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33124 }
33125 #endif
33126
33127 +#ifdef CONFIG_PAX_KERNEXEC
33128 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33129 + pgprot_val(forbidden) |= _PAGE_RW;
33130 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33131 + }
33132 +#endif
33133 +
33134 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33135
33136 return prot;
33137 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33138 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33139 {
33140 /* change init_mm */
33141 + pax_open_kernel();
33142 set_pte_atomic(kpte, pte);
33143 +
33144 #ifdef CONFIG_X86_32
33145 if (!SHARED_KERNEL_PMD) {
33146 +
33147 +#ifdef CONFIG_PAX_PER_CPU_PGD
33148 + unsigned long cpu;
33149 +#else
33150 struct page *page;
33151 +#endif
33152
33153 +#ifdef CONFIG_PAX_PER_CPU_PGD
33154 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33155 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33156 +#else
33157 list_for_each_entry(page, &pgd_list, lru) {
33158 - pgd_t *pgd;
33159 + pgd_t *pgd = (pgd_t *)page_address(page);
33160 +#endif
33161 +
33162 pud_t *pud;
33163 pmd_t *pmd;
33164
33165 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33166 + pgd += pgd_index(address);
33167 pud = pud_offset(pgd, address);
33168 pmd = pmd_offset(pud, address);
33169 set_pte_atomic((pte_t *)pmd, pte);
33170 }
33171 }
33172 #endif
33173 + pax_close_kernel();
33174 }
33175
33176 static int
33177 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33178 index 6574388..87e9bef 100644
33179 --- a/arch/x86/mm/pat.c
33180 +++ b/arch/x86/mm/pat.c
33181 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33182
33183 if (!entry) {
33184 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33185 - current->comm, current->pid, start, end - 1);
33186 + current->comm, task_pid_nr(current), start, end - 1);
33187 return -EINVAL;
33188 }
33189
33190 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33191
33192 while (cursor < to) {
33193 if (!devmem_is_allowed(pfn)) {
33194 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33195 - current->comm, from, to - 1);
33196 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33197 + current->comm, from, to - 1, cursor);
33198 return 0;
33199 }
33200 cursor += PAGE_SIZE;
33201 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33202 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33203 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33204 "for [mem %#010Lx-%#010Lx]\n",
33205 - current->comm, current->pid,
33206 + current->comm, task_pid_nr(current),
33207 cattr_name(flags),
33208 base, (unsigned long long)(base + size-1));
33209 return -EINVAL;
33210 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33211 flags = lookup_memtype(paddr);
33212 if (want_flags != flags) {
33213 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33214 - current->comm, current->pid,
33215 + current->comm, task_pid_nr(current),
33216 cattr_name(want_flags),
33217 (unsigned long long)paddr,
33218 (unsigned long long)(paddr + size - 1),
33219 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33220 free_memtype(paddr, paddr + size);
33221 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33222 " for [mem %#010Lx-%#010Lx], got %s\n",
33223 - current->comm, current->pid,
33224 + current->comm, task_pid_nr(current),
33225 cattr_name(want_flags),
33226 (unsigned long long)paddr,
33227 (unsigned long long)(paddr + size - 1),
33228 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33229 index 415f6c4..d319983 100644
33230 --- a/arch/x86/mm/pat_rbtree.c
33231 +++ b/arch/x86/mm/pat_rbtree.c
33232 @@ -160,7 +160,7 @@ success:
33233
33234 failure:
33235 printk(KERN_INFO "%s:%d conflicting memory types "
33236 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33237 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33238 end, cattr_name(found_type), cattr_name(match->type));
33239 return -EBUSY;
33240 }
33241 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33242 index 9f0614d..92ae64a 100644
33243 --- a/arch/x86/mm/pf_in.c
33244 +++ b/arch/x86/mm/pf_in.c
33245 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33246 int i;
33247 enum reason_type rv = OTHERS;
33248
33249 - p = (unsigned char *)ins_addr;
33250 + p = (unsigned char *)ktla_ktva(ins_addr);
33251 p += skip_prefix(p, &prf);
33252 p += get_opcode(p, &opcode);
33253
33254 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33255 struct prefix_bits prf;
33256 int i;
33257
33258 - p = (unsigned char *)ins_addr;
33259 + p = (unsigned char *)ktla_ktva(ins_addr);
33260 p += skip_prefix(p, &prf);
33261 p += get_opcode(p, &opcode);
33262
33263 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33264 struct prefix_bits prf;
33265 int i;
33266
33267 - p = (unsigned char *)ins_addr;
33268 + p = (unsigned char *)ktla_ktva(ins_addr);
33269 p += skip_prefix(p, &prf);
33270 p += get_opcode(p, &opcode);
33271
33272 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33273 struct prefix_bits prf;
33274 int i;
33275
33276 - p = (unsigned char *)ins_addr;
33277 + p = (unsigned char *)ktla_ktva(ins_addr);
33278 p += skip_prefix(p, &prf);
33279 p += get_opcode(p, &opcode);
33280 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33281 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33282 struct prefix_bits prf;
33283 int i;
33284
33285 - p = (unsigned char *)ins_addr;
33286 + p = (unsigned char *)ktla_ktva(ins_addr);
33287 p += skip_prefix(p, &prf);
33288 p += get_opcode(p, &opcode);
33289 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33290 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33291 index c96314a..433b127 100644
33292 --- a/arch/x86/mm/pgtable.c
33293 +++ b/arch/x86/mm/pgtable.c
33294 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33295 list_del(&page->lru);
33296 }
33297
33298 -#define UNSHARED_PTRS_PER_PGD \
33299 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33300 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33301 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33302
33303 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33304 +{
33305 + unsigned int count = USER_PGD_PTRS;
33306
33307 + if (!pax_user_shadow_base)
33308 + return;
33309 +
33310 + while (count--)
33311 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33312 +}
33313 +#endif
33314 +
33315 +#ifdef CONFIG_PAX_PER_CPU_PGD
33316 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33317 +{
33318 + unsigned int count = USER_PGD_PTRS;
33319 +
33320 + while (count--) {
33321 + pgd_t pgd;
33322 +
33323 +#ifdef CONFIG_X86_64
33324 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33325 +#else
33326 + pgd = *src++;
33327 +#endif
33328 +
33329 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33330 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33331 +#endif
33332 +
33333 + *dst++ = pgd;
33334 + }
33335 +
33336 +}
33337 +#endif
33338 +
33339 +#ifdef CONFIG_X86_64
33340 +#define pxd_t pud_t
33341 +#define pyd_t pgd_t
33342 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33343 +#define pgtable_pxd_page_ctor(page) true
33344 +#define pgtable_pxd_page_dtor(page)
33345 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33346 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33347 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33348 +#define PYD_SIZE PGDIR_SIZE
33349 +#else
33350 +#define pxd_t pmd_t
33351 +#define pyd_t pud_t
33352 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33353 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33354 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33355 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33356 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33357 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33358 +#define PYD_SIZE PUD_SIZE
33359 +#endif
33360 +
33361 +#ifdef CONFIG_PAX_PER_CPU_PGD
33362 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33363 +static inline void pgd_dtor(pgd_t *pgd) {}
33364 +#else
33365 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33366 {
33367 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33368 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33369 pgd_list_del(pgd);
33370 spin_unlock(&pgd_lock);
33371 }
33372 +#endif
33373
33374 /*
33375 * List of all pgd's needed for non-PAE so it can invalidate entries
33376 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33377 * -- nyc
33378 */
33379
33380 -#ifdef CONFIG_X86_PAE
33381 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33382 /*
33383 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33384 * updating the top-level pagetable entries to guarantee the
33385 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33386 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33387 * and initialize the kernel pmds here.
33388 */
33389 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33390 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33391
33392 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33393 {
33394 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33395 */
33396 flush_tlb_mm(mm);
33397 }
33398 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33399 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33400 #else /* !CONFIG_X86_PAE */
33401
33402 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33403 -#define PREALLOCATED_PMDS 0
33404 +#define PREALLOCATED_PXDS 0
33405
33406 #endif /* CONFIG_X86_PAE */
33407
33408 -static void free_pmds(pmd_t *pmds[])
33409 +static void free_pxds(pxd_t *pxds[])
33410 {
33411 int i;
33412
33413 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33414 - if (pmds[i]) {
33415 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33416 - free_page((unsigned long)pmds[i]);
33417 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33418 + if (pxds[i]) {
33419 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33420 + free_page((unsigned long)pxds[i]);
33421 }
33422 }
33423
33424 -static int preallocate_pmds(pmd_t *pmds[])
33425 +static int preallocate_pxds(pxd_t *pxds[])
33426 {
33427 int i;
33428 bool failed = false;
33429
33430 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33431 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33432 - if (!pmd)
33433 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33434 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33435 + if (!pxd)
33436 failed = true;
33437 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33438 - free_page((unsigned long)pmd);
33439 - pmd = NULL;
33440 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33441 + free_page((unsigned long)pxd);
33442 + pxd = NULL;
33443 failed = true;
33444 }
33445 - pmds[i] = pmd;
33446 + pxds[i] = pxd;
33447 }
33448
33449 if (failed) {
33450 - free_pmds(pmds);
33451 + free_pxds(pxds);
33452 return -ENOMEM;
33453 }
33454
33455 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33456 * preallocate which never got a corresponding vma will need to be
33457 * freed manually.
33458 */
33459 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33460 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33461 {
33462 int i;
33463
33464 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33465 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33466 pgd_t pgd = pgdp[i];
33467
33468 if (pgd_val(pgd) != 0) {
33469 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33470 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33471
33472 - pgdp[i] = native_make_pgd(0);
33473 + set_pgd(pgdp + i, native_make_pgd(0));
33474
33475 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33476 - pmd_free(mm, pmd);
33477 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33478 + pxd_free(mm, pxd);
33479 }
33480 }
33481 }
33482
33483 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33484 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33485 {
33486 - pud_t *pud;
33487 + pyd_t *pyd;
33488 int i;
33489
33490 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33491 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33492 return;
33493
33494 - pud = pud_offset(pgd, 0);
33495 -
33496 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33497 - pmd_t *pmd = pmds[i];
33498 +#ifdef CONFIG_X86_64
33499 + pyd = pyd_offset(mm, 0L);
33500 +#else
33501 + pyd = pyd_offset(pgd, 0L);
33502 +#endif
33503
33504 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33505 + pxd_t *pxd = pxds[i];
33506 if (i >= KERNEL_PGD_BOUNDARY)
33507 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33508 - sizeof(pmd_t) * PTRS_PER_PMD);
33509 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33510 + sizeof(pxd_t) * PTRS_PER_PMD);
33511
33512 - pud_populate(mm, pud, pmd);
33513 + pyd_populate(mm, pyd, pxd);
33514 }
33515 }
33516
33517 pgd_t *pgd_alloc(struct mm_struct *mm)
33518 {
33519 pgd_t *pgd;
33520 - pmd_t *pmds[PREALLOCATED_PMDS];
33521 + pxd_t *pxds[PREALLOCATED_PXDS];
33522
33523 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33524
33525 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33526
33527 mm->pgd = pgd;
33528
33529 - if (preallocate_pmds(pmds) != 0)
33530 + if (preallocate_pxds(pxds) != 0)
33531 goto out_free_pgd;
33532
33533 if (paravirt_pgd_alloc(mm) != 0)
33534 - goto out_free_pmds;
33535 + goto out_free_pxds;
33536
33537 /*
33538 * Make sure that pre-populating the pmds is atomic with
33539 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33540 spin_lock(&pgd_lock);
33541
33542 pgd_ctor(mm, pgd);
33543 - pgd_prepopulate_pmd(mm, pgd, pmds);
33544 + pgd_prepopulate_pxd(mm, pgd, pxds);
33545
33546 spin_unlock(&pgd_lock);
33547
33548 return pgd;
33549
33550 -out_free_pmds:
33551 - free_pmds(pmds);
33552 +out_free_pxds:
33553 + free_pxds(pxds);
33554 out_free_pgd:
33555 free_page((unsigned long)pgd);
33556 out:
33557 @@ -313,7 +380,7 @@ out:
33558
33559 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33560 {
33561 - pgd_mop_up_pmds(mm, pgd);
33562 + pgd_mop_up_pxds(mm, pgd);
33563 pgd_dtor(pgd);
33564 paravirt_pgd_free(mm, pgd);
33565 free_page((unsigned long)pgd);
33566 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33567 index 4dd8cf6..f9d143e 100644
33568 --- a/arch/x86/mm/pgtable_32.c
33569 +++ b/arch/x86/mm/pgtable_32.c
33570 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33571 return;
33572 }
33573 pte = pte_offset_kernel(pmd, vaddr);
33574 +
33575 + pax_open_kernel();
33576 if (pte_val(pteval))
33577 set_pte_at(&init_mm, vaddr, pte, pteval);
33578 else
33579 pte_clear(&init_mm, vaddr, pte);
33580 + pax_close_kernel();
33581
33582 /*
33583 * It's enough to flush this one mapping.
33584 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33585 index e666cbb..61788c45 100644
33586 --- a/arch/x86/mm/physaddr.c
33587 +++ b/arch/x86/mm/physaddr.c
33588 @@ -10,7 +10,7 @@
33589 #ifdef CONFIG_X86_64
33590
33591 #ifdef CONFIG_DEBUG_VIRTUAL
33592 -unsigned long __phys_addr(unsigned long x)
33593 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33594 {
33595 unsigned long y = x - __START_KERNEL_map;
33596
33597 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33598 #else
33599
33600 #ifdef CONFIG_DEBUG_VIRTUAL
33601 -unsigned long __phys_addr(unsigned long x)
33602 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33603 {
33604 unsigned long phys_addr = x - PAGE_OFFSET;
33605 /* VMALLOC_* aren't constants */
33606 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33607 index 90555bf..f5f1828 100644
33608 --- a/arch/x86/mm/setup_nx.c
33609 +++ b/arch/x86/mm/setup_nx.c
33610 @@ -5,8 +5,10 @@
33611 #include <asm/pgtable.h>
33612 #include <asm/proto.h>
33613
33614 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33615 static int disable_nx;
33616
33617 +#ifndef CONFIG_PAX_PAGEEXEC
33618 /*
33619 * noexec = on|off
33620 *
33621 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33622 return 0;
33623 }
33624 early_param("noexec", noexec_setup);
33625 +#endif
33626 +
33627 +#endif
33628
33629 void x86_configure_nx(void)
33630 {
33631 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33632 if (cpu_has_nx && !disable_nx)
33633 __supported_pte_mask |= _PAGE_NX;
33634 else
33635 +#endif
33636 __supported_pte_mask &= ~_PAGE_NX;
33637 }
33638
33639 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33640 index dd8dda1..9e9b0f6 100644
33641 --- a/arch/x86/mm/tlb.c
33642 +++ b/arch/x86/mm/tlb.c
33643 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33644 BUG();
33645 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33646 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33647 +
33648 +#ifndef CONFIG_PAX_PER_CPU_PGD
33649 load_cr3(swapper_pg_dir);
33650 +#endif
33651 +
33652 }
33653 }
33654 EXPORT_SYMBOL_GPL(leave_mm);
33655 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33656 new file mode 100644
33657 index 0000000..dace51c
33658 --- /dev/null
33659 +++ b/arch/x86/mm/uderef_64.c
33660 @@ -0,0 +1,37 @@
33661 +#include <linux/mm.h>
33662 +#include <asm/pgtable.h>
33663 +#include <asm/uaccess.h>
33664 +
33665 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33666 +/* PaX: due to the special call convention these functions must
33667 + * - remain leaf functions under all configurations,
33668 + * - never be called directly, only dereferenced from the wrappers.
33669 + */
33670 +void __pax_open_userland(void)
33671 +{
33672 + unsigned int cpu;
33673 +
33674 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33675 + return;
33676 +
33677 + cpu = raw_get_cpu();
33678 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33679 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33680 + raw_put_cpu_no_resched();
33681 +}
33682 +EXPORT_SYMBOL(__pax_open_userland);
33683 +
33684 +void __pax_close_userland(void)
33685 +{
33686 + unsigned int cpu;
33687 +
33688 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33689 + return;
33690 +
33691 + cpu = raw_get_cpu();
33692 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33693 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33694 + raw_put_cpu_no_resched();
33695 +}
33696 +EXPORT_SYMBOL(__pax_close_userland);
33697 +#endif
33698 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33699 index 0149575..f746de8 100644
33700 --- a/arch/x86/net/bpf_jit.S
33701 +++ b/arch/x86/net/bpf_jit.S
33702 @@ -9,6 +9,7 @@
33703 */
33704 #include <linux/linkage.h>
33705 #include <asm/dwarf2.h>
33706 +#include <asm/alternative-asm.h>
33707
33708 /*
33709 * Calling convention :
33710 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33711 jle bpf_slow_path_word
33712 mov (SKBDATA,%rsi),%eax
33713 bswap %eax /* ntohl() */
33714 + pax_force_retaddr
33715 ret
33716
33717 sk_load_half:
33718 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33719 jle bpf_slow_path_half
33720 movzwl (SKBDATA,%rsi),%eax
33721 rol $8,%ax # ntohs()
33722 + pax_force_retaddr
33723 ret
33724
33725 sk_load_byte:
33726 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33727 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33728 jle bpf_slow_path_byte
33729 movzbl (SKBDATA,%rsi),%eax
33730 + pax_force_retaddr
33731 ret
33732
33733 /**
33734 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33735 movzbl (SKBDATA,%rsi),%ebx
33736 and $15,%bl
33737 shl $2,%bl
33738 + pax_force_retaddr
33739 ret
33740
33741 /* rsi contains offset and can be scratched */
33742 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33743 js bpf_error
33744 mov -12(%rbp),%eax
33745 bswap %eax
33746 + pax_force_retaddr
33747 ret
33748
33749 bpf_slow_path_half:
33750 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33751 mov -12(%rbp),%ax
33752 rol $8,%ax
33753 movzwl %ax,%eax
33754 + pax_force_retaddr
33755 ret
33756
33757 bpf_slow_path_byte:
33758 bpf_slow_path_common(1)
33759 js bpf_error
33760 movzbl -12(%rbp),%eax
33761 + pax_force_retaddr
33762 ret
33763
33764 bpf_slow_path_byte_msh:
33765 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33766 and $15,%al
33767 shl $2,%al
33768 xchg %eax,%ebx
33769 + pax_force_retaddr
33770 ret
33771
33772 #define sk_negative_common(SIZE) \
33773 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33774 sk_negative_common(4)
33775 mov (%rax), %eax
33776 bswap %eax
33777 + pax_force_retaddr
33778 ret
33779
33780 bpf_slow_path_half_neg:
33781 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33782 mov (%rax),%ax
33783 rol $8,%ax
33784 movzwl %ax,%eax
33785 + pax_force_retaddr
33786 ret
33787
33788 bpf_slow_path_byte_neg:
33789 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33790 .globl sk_load_byte_negative_offset
33791 sk_negative_common(1)
33792 movzbl (%rax), %eax
33793 + pax_force_retaddr
33794 ret
33795
33796 bpf_slow_path_byte_msh_neg:
33797 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33798 and $15,%al
33799 shl $2,%al
33800 xchg %eax,%ebx
33801 + pax_force_retaddr
33802 ret
33803
33804 bpf_error:
33805 @@ -197,4 +210,5 @@ bpf_error:
33806 xor %eax,%eax
33807 mov -8(%rbp),%rbx
33808 leaveq
33809 + pax_force_retaddr
33810 ret
33811 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33812 index 6d5663a..f1ec380 100644
33813 --- a/arch/x86/net/bpf_jit_comp.c
33814 +++ b/arch/x86/net/bpf_jit_comp.c
33815 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33816 return ptr + len;
33817 }
33818
33819 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33820 +#define MAX_INSTR_CODE_SIZE 96
33821 +#else
33822 +#define MAX_INSTR_CODE_SIZE 64
33823 +#endif
33824 +
33825 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33826
33827 #define EMIT1(b1) EMIT(b1, 1)
33828 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33829 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33830 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33831 +
33832 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33833 +/* original constant will appear in ecx */
33834 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33835 +do { \
33836 + /* mov ecx, randkey */ \
33837 + EMIT1(0xb9); \
33838 + EMIT(_key, 4); \
33839 + /* xor ecx, randkey ^ off */ \
33840 + EMIT2(0x81, 0xf1); \
33841 + EMIT((_key) ^ (_off), 4); \
33842 +} while (0)
33843 +
33844 +#define EMIT1_off32(b1, _off) \
33845 +do { \
33846 + switch (b1) { \
33847 + case 0x05: /* add eax, imm32 */ \
33848 + case 0x2d: /* sub eax, imm32 */ \
33849 + case 0x25: /* and eax, imm32 */ \
33850 + case 0x0d: /* or eax, imm32 */ \
33851 + case 0xb8: /* mov eax, imm32 */ \
33852 + case 0x35: /* xor eax, imm32 */ \
33853 + case 0x3d: /* cmp eax, imm32 */ \
33854 + case 0xa9: /* test eax, imm32 */ \
33855 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33856 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33857 + break; \
33858 + case 0xbb: /* mov ebx, imm32 */ \
33859 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33860 + /* mov ebx, ecx */ \
33861 + EMIT2(0x89, 0xcb); \
33862 + break; \
33863 + case 0xbe: /* mov esi, imm32 */ \
33864 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33865 + /* mov esi, ecx */ \
33866 + EMIT2(0x89, 0xce); \
33867 + break; \
33868 + case 0xe8: /* call rel imm32, always to known funcs */ \
33869 + EMIT1(b1); \
33870 + EMIT(_off, 4); \
33871 + break; \
33872 + case 0xe9: /* jmp rel imm32 */ \
33873 + EMIT1(b1); \
33874 + EMIT(_off, 4); \
33875 + /* prevent fall-through, we're not called if off = 0 */ \
33876 + EMIT(0xcccccccc, 4); \
33877 + EMIT(0xcccccccc, 4); \
33878 + break; \
33879 + default: \
33880 + BUILD_BUG(); \
33881 + } \
33882 +} while (0)
33883 +
33884 +#define EMIT2_off32(b1, b2, _off) \
33885 +do { \
33886 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33887 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33888 + EMIT(randkey, 4); \
33889 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33890 + EMIT((_off) - randkey, 4); \
33891 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33892 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33893 + /* imul eax, ecx */ \
33894 + EMIT3(0x0f, 0xaf, 0xc1); \
33895 + } else { \
33896 + BUILD_BUG(); \
33897 + } \
33898 +} while (0)
33899 +#else
33900 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33901 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33902 +#endif
33903
33904 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33905 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33906 @@ -91,6 +168,24 @@ do { \
33907 #define X86_JBE 0x76
33908 #define X86_JA 0x77
33909
33910 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33911 +#define APPEND_FLOW_VERIFY() \
33912 +do { \
33913 + /* mov ecx, randkey */ \
33914 + EMIT1(0xb9); \
33915 + EMIT(randkey, 4); \
33916 + /* cmp ecx, randkey */ \
33917 + EMIT2(0x81, 0xf9); \
33918 + EMIT(randkey, 4); \
33919 + /* jz after 8 int 3s */ \
33920 + EMIT2(0x74, 0x08); \
33921 + EMIT(0xcccccccc, 4); \
33922 + EMIT(0xcccccccc, 4); \
33923 +} while (0)
33924 +#else
33925 +#define APPEND_FLOW_VERIFY() do { } while (0)
33926 +#endif
33927 +
33928 #define EMIT_COND_JMP(op, offset) \
33929 do { \
33930 if (is_near(offset)) \
33931 @@ -98,6 +193,7 @@ do { \
33932 else { \
33933 EMIT2(0x0f, op + 0x10); \
33934 EMIT(offset, 4); /* jxx .+off32 */ \
33935 + APPEND_FLOW_VERIFY(); \
33936 } \
33937 } while (0)
33938
33939 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33940 return -1;
33941 }
33942
33943 -struct bpf_binary_header {
33944 - unsigned int pages;
33945 - /* Note : for security reasons, bpf code will follow a randomly
33946 - * sized amount of int3 instructions
33947 - */
33948 - u8 image[];
33949 -};
33950 -
33951 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33952 +/* Note : for security reasons, bpf code will follow a randomly
33953 + * sized amount of int3 instructions
33954 + */
33955 +static u8 *bpf_alloc_binary(unsigned int proglen,
33956 u8 **image_ptr)
33957 {
33958 unsigned int sz, hole;
33959 - struct bpf_binary_header *header;
33960 + u8 *header;
33961
33962 /* Most of BPF filters are really small,
33963 * but if some of them fill a page, allow at least
33964 * 128 extra bytes to insert a random section of int3
33965 */
33966 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33967 - header = module_alloc(sz);
33968 + sz = round_up(proglen + 128, PAGE_SIZE);
33969 + header = module_alloc_exec(sz);
33970 if (!header)
33971 return NULL;
33972
33973 + pax_open_kernel();
33974 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33975 + pax_close_kernel();
33976
33977 - header->pages = sz / PAGE_SIZE;
33978 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
33979 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33980
33981 /* insert a random number of int3 instructions before BPF code */
33982 - *image_ptr = &header->image[prandom_u32() % hole];
33983 + *image_ptr = &header[prandom_u32() % hole];
33984 return header;
33985 }
33986
33987 void bpf_jit_compile(struct sk_filter *fp)
33988 {
33989 - u8 temp[64];
33990 + u8 temp[MAX_INSTR_CODE_SIZE];
33991 u8 *prog;
33992 unsigned int proglen, oldproglen = 0;
33993 int ilen, i;
33994 int t_offset, f_offset;
33995 u8 t_op, f_op, seen = 0, pass;
33996 u8 *image = NULL;
33997 - struct bpf_binary_header *header = NULL;
33998 + u8 *header = NULL;
33999 u8 *func;
34000 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34001 unsigned int cleanup_addr; /* epilogue code offset */
34002 unsigned int *addrs;
34003 const struct sock_filter *filter = fp->insns;
34004 int flen = fp->len;
34005 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34006 + unsigned int randkey;
34007 +#endif
34008
34009 if (!bpf_jit_enable)
34010 return;
34011 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34012 return;
34013
34014 /* Before first pass, make a rough estimation of addrs[]
34015 - * each bpf instruction is translated to less than 64 bytes
34016 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34017 */
34018 for (proglen = 0, i = 0; i < flen; i++) {
34019 - proglen += 64;
34020 + proglen += MAX_INSTR_CODE_SIZE;
34021 addrs[i] = proglen;
34022 }
34023 cleanup_addr = proglen; /* epilogue address */
34024 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34025 for (i = 0; i < flen; i++) {
34026 unsigned int K = filter[i].k;
34027
34028 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34029 + randkey = prandom_u32();
34030 +#endif
34031 +
34032 switch (filter[i].code) {
34033 case BPF_S_ALU_ADD_X: /* A += X; */
34034 seen |= SEEN_XREG;
34035 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34036 case BPF_S_ALU_MUL_K: /* A *= K */
34037 if (is_imm8(K))
34038 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34039 - else {
34040 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34041 - EMIT(K, 4);
34042 - }
34043 + else
34044 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34045 break;
34046 case BPF_S_ALU_DIV_X: /* A /= X; */
34047 seen |= SEEN_XREG;
34048 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34049 break;
34050 }
34051 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34052 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34053 + DILUTE_CONST_SEQUENCE(K, randkey);
34054 +#else
34055 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34056 +#endif
34057 EMIT2(0xf7, 0xf1); /* div %ecx */
34058 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34059 break;
34060 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34061 if (K == 1)
34062 break;
34063 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34064 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34065 + DILUTE_CONST_SEQUENCE(K, randkey);
34066 +#else
34067 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34068 +#endif
34069 EMIT2(0xf7, 0xf1); /* div %ecx */
34070 break;
34071 case BPF_S_ALU_AND_X:
34072 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34073 if (is_imm8(K)) {
34074 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34075 } else {
34076 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34077 - EMIT(K, 4);
34078 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34079 }
34080 } else {
34081 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34082 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34083 if (unlikely(proglen + ilen > oldproglen)) {
34084 pr_err("bpb_jit_compile fatal error\n");
34085 kfree(addrs);
34086 - module_free(NULL, header);
34087 + module_free_exec(NULL, image);
34088 return;
34089 }
34090 + pax_open_kernel();
34091 memcpy(image + proglen, temp, ilen);
34092 + pax_close_kernel();
34093 }
34094 proglen += ilen;
34095 addrs[i] = proglen;
34096 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34097
34098 if (image) {
34099 bpf_flush_icache(header, image + proglen);
34100 - set_memory_ro((unsigned long)header, header->pages);
34101 fp->bpf_func = (void *)image;
34102 fp->jited = 1;
34103 }
34104 @@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34105 {
34106 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34107 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34108 - struct bpf_binary_header *header = (void *)addr;
34109
34110 - set_memory_rw(addr, header->pages);
34111 - module_free(NULL, header);
34112 + set_memory_rw(addr, 1);
34113 + module_free_exec(NULL, (void *)addr);
34114 kfree(fp);
34115 }
34116
34117 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34118 index 5d04be5..2beeaa2 100644
34119 --- a/arch/x86/oprofile/backtrace.c
34120 +++ b/arch/x86/oprofile/backtrace.c
34121 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34122 struct stack_frame_ia32 *fp;
34123 unsigned long bytes;
34124
34125 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34126 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34127 if (bytes != 0)
34128 return NULL;
34129
34130 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34131 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34132
34133 oprofile_add_trace(bufhead[0].return_address);
34134
34135 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34136 struct stack_frame bufhead[2];
34137 unsigned long bytes;
34138
34139 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34140 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34141 if (bytes != 0)
34142 return NULL;
34143
34144 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34145 {
34146 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34147
34148 - if (!user_mode_vm(regs)) {
34149 + if (!user_mode(regs)) {
34150 unsigned long stack = kernel_stack_pointer(regs);
34151 if (depth)
34152 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34153 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34154 index 379e8bd..6386e09 100644
34155 --- a/arch/x86/oprofile/nmi_int.c
34156 +++ b/arch/x86/oprofile/nmi_int.c
34157 @@ -23,6 +23,7 @@
34158 #include <asm/nmi.h>
34159 #include <asm/msr.h>
34160 #include <asm/apic.h>
34161 +#include <asm/pgtable.h>
34162
34163 #include "op_counter.h"
34164 #include "op_x86_model.h"
34165 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34166 if (ret)
34167 return ret;
34168
34169 - if (!model->num_virt_counters)
34170 - model->num_virt_counters = model->num_counters;
34171 + if (!model->num_virt_counters) {
34172 + pax_open_kernel();
34173 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34174 + pax_close_kernel();
34175 + }
34176
34177 mux_init(ops);
34178
34179 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34180 index 50d86c0..7985318 100644
34181 --- a/arch/x86/oprofile/op_model_amd.c
34182 +++ b/arch/x86/oprofile/op_model_amd.c
34183 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34184 num_counters = AMD64_NUM_COUNTERS;
34185 }
34186
34187 - op_amd_spec.num_counters = num_counters;
34188 - op_amd_spec.num_controls = num_counters;
34189 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34190 + pax_open_kernel();
34191 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34192 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34193 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34194 + pax_close_kernel();
34195
34196 return 0;
34197 }
34198 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34199 index d90528e..0127e2b 100644
34200 --- a/arch/x86/oprofile/op_model_ppro.c
34201 +++ b/arch/x86/oprofile/op_model_ppro.c
34202 @@ -19,6 +19,7 @@
34203 #include <asm/msr.h>
34204 #include <asm/apic.h>
34205 #include <asm/nmi.h>
34206 +#include <asm/pgtable.h>
34207
34208 #include "op_x86_model.h"
34209 #include "op_counter.h"
34210 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34211
34212 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34213
34214 - op_arch_perfmon_spec.num_counters = num_counters;
34215 - op_arch_perfmon_spec.num_controls = num_counters;
34216 + pax_open_kernel();
34217 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34218 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34219 + pax_close_kernel();
34220 }
34221
34222 static int arch_perfmon_init(struct oprofile_operations *ignore)
34223 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34224 index 71e8a67..6a313bb 100644
34225 --- a/arch/x86/oprofile/op_x86_model.h
34226 +++ b/arch/x86/oprofile/op_x86_model.h
34227 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34228 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34229 struct op_msrs const * const msrs);
34230 #endif
34231 -};
34232 +} __do_const;
34233
34234 struct op_counter_config;
34235
34236 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34237 index 84b9d67..260e5ff 100644
34238 --- a/arch/x86/pci/intel_mid_pci.c
34239 +++ b/arch/x86/pci/intel_mid_pci.c
34240 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34241 pr_info("Intel MID platform detected, using MID PCI ops\n");
34242 pci_mmcfg_late_init();
34243 pcibios_enable_irq = intel_mid_pci_irq_enable;
34244 - pci_root_ops = intel_mid_pci_ops;
34245 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34246 pci_soc_mode = 1;
34247 /* Continue with standard init */
34248 return 1;
34249 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34250 index 84112f5..6334d60 100644
34251 --- a/arch/x86/pci/irq.c
34252 +++ b/arch/x86/pci/irq.c
34253 @@ -50,7 +50,7 @@ struct irq_router {
34254 struct irq_router_handler {
34255 u16 vendor;
34256 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34257 -};
34258 +} __do_const;
34259
34260 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34261 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34262 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34263 return 0;
34264 }
34265
34266 -static __initdata struct irq_router_handler pirq_routers[] = {
34267 +static __initconst const struct irq_router_handler pirq_routers[] = {
34268 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34269 { PCI_VENDOR_ID_AL, ali_router_probe },
34270 { PCI_VENDOR_ID_ITE, ite_router_probe },
34271 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34272 static void __init pirq_find_router(struct irq_router *r)
34273 {
34274 struct irq_routing_table *rt = pirq_table;
34275 - struct irq_router_handler *h;
34276 + const struct irq_router_handler *h;
34277
34278 #ifdef CONFIG_PCI_BIOS
34279 if (!rt->signature) {
34280 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34281 return 0;
34282 }
34283
34284 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34285 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34286 {
34287 .callback = fix_broken_hp_bios_irq9,
34288 .ident = "HP Pavilion N5400 Series Laptop",
34289 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34290 index c77b24a..c979855 100644
34291 --- a/arch/x86/pci/pcbios.c
34292 +++ b/arch/x86/pci/pcbios.c
34293 @@ -79,7 +79,7 @@ union bios32 {
34294 static struct {
34295 unsigned long address;
34296 unsigned short segment;
34297 -} bios32_indirect = { 0, __KERNEL_CS };
34298 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34299
34300 /*
34301 * Returns the entry point for the given service, NULL on error
34302 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34303 unsigned long length; /* %ecx */
34304 unsigned long entry; /* %edx */
34305 unsigned long flags;
34306 + struct desc_struct d, *gdt;
34307
34308 local_irq_save(flags);
34309 - __asm__("lcall *(%%edi); cld"
34310 +
34311 + gdt = get_cpu_gdt_table(smp_processor_id());
34312 +
34313 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34314 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34315 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34316 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34317 +
34318 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34319 : "=a" (return_code),
34320 "=b" (address),
34321 "=c" (length),
34322 "=d" (entry)
34323 : "0" (service),
34324 "1" (0),
34325 - "D" (&bios32_indirect));
34326 + "D" (&bios32_indirect),
34327 + "r"(__PCIBIOS_DS)
34328 + : "memory");
34329 +
34330 + pax_open_kernel();
34331 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34332 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34333 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34334 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34335 + pax_close_kernel();
34336 +
34337 local_irq_restore(flags);
34338
34339 switch (return_code) {
34340 - case 0:
34341 - return address + entry;
34342 - case 0x80: /* Not present */
34343 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34344 - return 0;
34345 - default: /* Shouldn't happen */
34346 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34347 - service, return_code);
34348 + case 0: {
34349 + int cpu;
34350 + unsigned char flags;
34351 +
34352 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34353 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34354 + printk(KERN_WARNING "bios32_service: not valid\n");
34355 return 0;
34356 + }
34357 + address = address + PAGE_OFFSET;
34358 + length += 16UL; /* some BIOSs underreport this... */
34359 + flags = 4;
34360 + if (length >= 64*1024*1024) {
34361 + length >>= PAGE_SHIFT;
34362 + flags |= 8;
34363 + }
34364 +
34365 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34366 + gdt = get_cpu_gdt_table(cpu);
34367 + pack_descriptor(&d, address, length, 0x9b, flags);
34368 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34369 + pack_descriptor(&d, address, length, 0x93, flags);
34370 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34371 + }
34372 + return entry;
34373 + }
34374 + case 0x80: /* Not present */
34375 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34376 + return 0;
34377 + default: /* Shouldn't happen */
34378 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34379 + service, return_code);
34380 + return 0;
34381 }
34382 }
34383
34384 static struct {
34385 unsigned long address;
34386 unsigned short segment;
34387 -} pci_indirect = { 0, __KERNEL_CS };
34388 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34389
34390 -static int pci_bios_present;
34391 +static int pci_bios_present __read_only;
34392
34393 static int check_pcibios(void)
34394 {
34395 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34396 unsigned long flags, pcibios_entry;
34397
34398 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34399 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34400 + pci_indirect.address = pcibios_entry;
34401
34402 local_irq_save(flags);
34403 - __asm__(
34404 - "lcall *(%%edi); cld\n\t"
34405 + __asm__("movw %w6, %%ds\n\t"
34406 + "lcall *%%ss:(%%edi); cld\n\t"
34407 + "push %%ss\n\t"
34408 + "pop %%ds\n\t"
34409 "jc 1f\n\t"
34410 "xor %%ah, %%ah\n"
34411 "1:"
34412 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34413 "=b" (ebx),
34414 "=c" (ecx)
34415 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34416 - "D" (&pci_indirect)
34417 + "D" (&pci_indirect),
34418 + "r" (__PCIBIOS_DS)
34419 : "memory");
34420 local_irq_restore(flags);
34421
34422 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34423
34424 switch (len) {
34425 case 1:
34426 - __asm__("lcall *(%%esi); cld\n\t"
34427 + __asm__("movw %w6, %%ds\n\t"
34428 + "lcall *%%ss:(%%esi); cld\n\t"
34429 + "push %%ss\n\t"
34430 + "pop %%ds\n\t"
34431 "jc 1f\n\t"
34432 "xor %%ah, %%ah\n"
34433 "1:"
34434 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34435 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34436 "b" (bx),
34437 "D" ((long)reg),
34438 - "S" (&pci_indirect));
34439 + "S" (&pci_indirect),
34440 + "r" (__PCIBIOS_DS));
34441 /*
34442 * Zero-extend the result beyond 8 bits, do not trust the
34443 * BIOS having done it:
34444 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34445 *value &= 0xff;
34446 break;
34447 case 2:
34448 - __asm__("lcall *(%%esi); cld\n\t"
34449 + __asm__("movw %w6, %%ds\n\t"
34450 + "lcall *%%ss:(%%esi); cld\n\t"
34451 + "push %%ss\n\t"
34452 + "pop %%ds\n\t"
34453 "jc 1f\n\t"
34454 "xor %%ah, %%ah\n"
34455 "1:"
34456 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34457 : "1" (PCIBIOS_READ_CONFIG_WORD),
34458 "b" (bx),
34459 "D" ((long)reg),
34460 - "S" (&pci_indirect));
34461 + "S" (&pci_indirect),
34462 + "r" (__PCIBIOS_DS));
34463 /*
34464 * Zero-extend the result beyond 16 bits, do not trust the
34465 * BIOS having done it:
34466 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34467 *value &= 0xffff;
34468 break;
34469 case 4:
34470 - __asm__("lcall *(%%esi); cld\n\t"
34471 + __asm__("movw %w6, %%ds\n\t"
34472 + "lcall *%%ss:(%%esi); cld\n\t"
34473 + "push %%ss\n\t"
34474 + "pop %%ds\n\t"
34475 "jc 1f\n\t"
34476 "xor %%ah, %%ah\n"
34477 "1:"
34478 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34479 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34480 "b" (bx),
34481 "D" ((long)reg),
34482 - "S" (&pci_indirect));
34483 + "S" (&pci_indirect),
34484 + "r" (__PCIBIOS_DS));
34485 break;
34486 }
34487
34488 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34489
34490 switch (len) {
34491 case 1:
34492 - __asm__("lcall *(%%esi); cld\n\t"
34493 + __asm__("movw %w6, %%ds\n\t"
34494 + "lcall *%%ss:(%%esi); cld\n\t"
34495 + "push %%ss\n\t"
34496 + "pop %%ds\n\t"
34497 "jc 1f\n\t"
34498 "xor %%ah, %%ah\n"
34499 "1:"
34500 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34501 "c" (value),
34502 "b" (bx),
34503 "D" ((long)reg),
34504 - "S" (&pci_indirect));
34505 + "S" (&pci_indirect),
34506 + "r" (__PCIBIOS_DS));
34507 break;
34508 case 2:
34509 - __asm__("lcall *(%%esi); cld\n\t"
34510 + __asm__("movw %w6, %%ds\n\t"
34511 + "lcall *%%ss:(%%esi); cld\n\t"
34512 + "push %%ss\n\t"
34513 + "pop %%ds\n\t"
34514 "jc 1f\n\t"
34515 "xor %%ah, %%ah\n"
34516 "1:"
34517 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34518 "c" (value),
34519 "b" (bx),
34520 "D" ((long)reg),
34521 - "S" (&pci_indirect));
34522 + "S" (&pci_indirect),
34523 + "r" (__PCIBIOS_DS));
34524 break;
34525 case 4:
34526 - __asm__("lcall *(%%esi); cld\n\t"
34527 + __asm__("movw %w6, %%ds\n\t"
34528 + "lcall *%%ss:(%%esi); cld\n\t"
34529 + "push %%ss\n\t"
34530 + "pop %%ds\n\t"
34531 "jc 1f\n\t"
34532 "xor %%ah, %%ah\n"
34533 "1:"
34534 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34535 "c" (value),
34536 "b" (bx),
34537 "D" ((long)reg),
34538 - "S" (&pci_indirect));
34539 + "S" (&pci_indirect),
34540 + "r" (__PCIBIOS_DS));
34541 break;
34542 }
34543
34544 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34545
34546 DBG("PCI: Fetching IRQ routing table... ");
34547 __asm__("push %%es\n\t"
34548 + "movw %w8, %%ds\n\t"
34549 "push %%ds\n\t"
34550 "pop %%es\n\t"
34551 - "lcall *(%%esi); cld\n\t"
34552 + "lcall *%%ss:(%%esi); cld\n\t"
34553 "pop %%es\n\t"
34554 + "push %%ss\n\t"
34555 + "pop %%ds\n"
34556 "jc 1f\n\t"
34557 "xor %%ah, %%ah\n"
34558 "1:"
34559 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34560 "1" (0),
34561 "D" ((long) &opt),
34562 "S" (&pci_indirect),
34563 - "m" (opt)
34564 + "m" (opt),
34565 + "r" (__PCIBIOS_DS)
34566 : "memory");
34567 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34568 if (ret & 0xff00)
34569 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34570 {
34571 int ret;
34572
34573 - __asm__("lcall *(%%esi); cld\n\t"
34574 + __asm__("movw %w5, %%ds\n\t"
34575 + "lcall *%%ss:(%%esi); cld\n\t"
34576 + "push %%ss\n\t"
34577 + "pop %%ds\n"
34578 "jc 1f\n\t"
34579 "xor %%ah, %%ah\n"
34580 "1:"
34581 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34582 : "0" (PCIBIOS_SET_PCI_HW_INT),
34583 "b" ((dev->bus->number << 8) | dev->devfn),
34584 "c" ((irq << 8) | (pin + 10)),
34585 - "S" (&pci_indirect));
34586 + "S" (&pci_indirect),
34587 + "r" (__PCIBIOS_DS));
34588 return !(ret & 0xff00);
34589 }
34590 EXPORT_SYMBOL(pcibios_set_irq_routing);
34591 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34592 index 9ee3491..872192f 100644
34593 --- a/arch/x86/platform/efi/efi_32.c
34594 +++ b/arch/x86/platform/efi/efi_32.c
34595 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34596 {
34597 struct desc_ptr gdt_descr;
34598
34599 +#ifdef CONFIG_PAX_KERNEXEC
34600 + struct desc_struct d;
34601 +#endif
34602 +
34603 local_irq_save(efi_rt_eflags);
34604
34605 load_cr3(initial_page_table);
34606 __flush_tlb_all();
34607
34608 +#ifdef CONFIG_PAX_KERNEXEC
34609 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34610 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34611 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34612 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34613 +#endif
34614 +
34615 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34616 gdt_descr.size = GDT_SIZE - 1;
34617 load_gdt(&gdt_descr);
34618 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34619 {
34620 struct desc_ptr gdt_descr;
34621
34622 +#ifdef CONFIG_PAX_KERNEXEC
34623 + struct desc_struct d;
34624 +
34625 + memset(&d, 0, sizeof d);
34626 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34627 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34628 +#endif
34629 +
34630 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34631 gdt_descr.size = GDT_SIZE - 1;
34632 load_gdt(&gdt_descr);
34633
34634 +#ifdef CONFIG_PAX_PER_CPU_PGD
34635 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34636 +#else
34637 load_cr3(swapper_pg_dir);
34638 +#endif
34639 +
34640 __flush_tlb_all();
34641
34642 local_irq_restore(efi_rt_eflags);
34643 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34644 index 290d397..3906bcd 100644
34645 --- a/arch/x86/platform/efi/efi_64.c
34646 +++ b/arch/x86/platform/efi/efi_64.c
34647 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34648 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34649 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34650 }
34651 +
34652 +#ifdef CONFIG_PAX_PER_CPU_PGD
34653 + load_cr3(swapper_pg_dir);
34654 +#endif
34655 +
34656 __flush_tlb_all();
34657 }
34658
34659 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34660 for (pgd = 0; pgd < n_pgds; pgd++)
34661 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34662 kfree(save_pgd);
34663 +
34664 +#ifdef CONFIG_PAX_PER_CPU_PGD
34665 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34666 +#endif
34667 +
34668 __flush_tlb_all();
34669 local_irq_restore(efi_flags);
34670 early_code_mapping_set_exec(0);
34671 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34672 index fbe66e6..eae5e38 100644
34673 --- a/arch/x86/platform/efi/efi_stub_32.S
34674 +++ b/arch/x86/platform/efi/efi_stub_32.S
34675 @@ -6,7 +6,9 @@
34676 */
34677
34678 #include <linux/linkage.h>
34679 +#include <linux/init.h>
34680 #include <asm/page_types.h>
34681 +#include <asm/segment.h>
34682
34683 /*
34684 * efi_call_phys(void *, ...) is a function with variable parameters.
34685 @@ -20,7 +22,7 @@
34686 * service functions will comply with gcc calling convention, too.
34687 */
34688
34689 -.text
34690 +__INIT
34691 ENTRY(efi_call_phys)
34692 /*
34693 * 0. The function can only be called in Linux kernel. So CS has been
34694 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34695 * The mapping of lower virtual memory has been created in prelog and
34696 * epilog.
34697 */
34698 - movl $1f, %edx
34699 - subl $__PAGE_OFFSET, %edx
34700 - jmp *%edx
34701 +#ifdef CONFIG_PAX_KERNEXEC
34702 + movl $(__KERNEXEC_EFI_DS), %edx
34703 + mov %edx, %ds
34704 + mov %edx, %es
34705 + mov %edx, %ss
34706 + addl $2f,(1f)
34707 + ljmp *(1f)
34708 +
34709 +__INITDATA
34710 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34711 +.previous
34712 +
34713 +2:
34714 + subl $2b,(1b)
34715 +#else
34716 + jmp 1f-__PAGE_OFFSET
34717 1:
34718 +#endif
34719
34720 /*
34721 * 2. Now on the top of stack is the return
34722 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34723 * parameter 2, ..., param n. To make things easy, we save the return
34724 * address of efi_call_phys in a global variable.
34725 */
34726 - popl %edx
34727 - movl %edx, saved_return_addr
34728 - /* get the function pointer into ECX*/
34729 - popl %ecx
34730 - movl %ecx, efi_rt_function_ptr
34731 - movl $2f, %edx
34732 - subl $__PAGE_OFFSET, %edx
34733 - pushl %edx
34734 + popl (saved_return_addr)
34735 + popl (efi_rt_function_ptr)
34736
34737 /*
34738 * 3. Clear PG bit in %CR0.
34739 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34740 /*
34741 * 5. Call the physical function.
34742 */
34743 - jmp *%ecx
34744 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34745
34746 -2:
34747 /*
34748 * 6. After EFI runtime service returns, control will return to
34749 * following instruction. We'd better readjust stack pointer first.
34750 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34751 movl %cr0, %edx
34752 orl $0x80000000, %edx
34753 movl %edx, %cr0
34754 - jmp 1f
34755 -1:
34756 +
34757 /*
34758 * 8. Now restore the virtual mode from flat mode by
34759 * adding EIP with PAGE_OFFSET.
34760 */
34761 - movl $1f, %edx
34762 - jmp *%edx
34763 +#ifdef CONFIG_PAX_KERNEXEC
34764 + movl $(__KERNEL_DS), %edx
34765 + mov %edx, %ds
34766 + mov %edx, %es
34767 + mov %edx, %ss
34768 + ljmp $(__KERNEL_CS),$1f
34769 +#else
34770 + jmp 1f+__PAGE_OFFSET
34771 +#endif
34772 1:
34773
34774 /*
34775 * 9. Balance the stack. And because EAX contain the return value,
34776 * we'd better not clobber it.
34777 */
34778 - leal efi_rt_function_ptr, %edx
34779 - movl (%edx), %ecx
34780 - pushl %ecx
34781 + pushl (efi_rt_function_ptr)
34782
34783 /*
34784 - * 10. Push the saved return address onto the stack and return.
34785 + * 10. Return to the saved return address.
34786 */
34787 - leal saved_return_addr, %edx
34788 - movl (%edx), %ecx
34789 - pushl %ecx
34790 - ret
34791 + jmpl *(saved_return_addr)
34792 ENDPROC(efi_call_phys)
34793 .previous
34794
34795 -.data
34796 +__INITDATA
34797 saved_return_addr:
34798 .long 0
34799 efi_rt_function_ptr:
34800 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34801 index e0984ef..a062dac 100644
34802 --- a/arch/x86/platform/efi/efi_stub_64.S
34803 +++ b/arch/x86/platform/efi/efi_stub_64.S
34804 @@ -11,6 +11,7 @@
34805 #include <asm/msr.h>
34806 #include <asm/processor-flags.h>
34807 #include <asm/page_types.h>
34808 +#include <asm/alternative-asm.h>
34809
34810 #define SAVE_XMM \
34811 mov %rsp, %rax; \
34812 @@ -81,6 +82,7 @@ ENTRY(efi_call0)
34813 RESTORE_PGT
34814 addq $32, %rsp
34815 RESTORE_XMM
34816 + pax_force_retaddr 0, 1
34817 ret
34818 ENDPROC(efi_call0)
34819
34820 @@ -93,6 +95,7 @@ ENTRY(efi_call1)
34821 RESTORE_PGT
34822 addq $32, %rsp
34823 RESTORE_XMM
34824 + pax_force_retaddr 0, 1
34825 ret
34826 ENDPROC(efi_call1)
34827
34828 @@ -105,6 +108,7 @@ ENTRY(efi_call2)
34829 RESTORE_PGT
34830 addq $32, %rsp
34831 RESTORE_XMM
34832 + pax_force_retaddr 0, 1
34833 ret
34834 ENDPROC(efi_call2)
34835
34836 @@ -118,6 +122,7 @@ ENTRY(efi_call3)
34837 RESTORE_PGT
34838 addq $32, %rsp
34839 RESTORE_XMM
34840 + pax_force_retaddr 0, 1
34841 ret
34842 ENDPROC(efi_call3)
34843
34844 @@ -132,6 +137,7 @@ ENTRY(efi_call4)
34845 RESTORE_PGT
34846 addq $32, %rsp
34847 RESTORE_XMM
34848 + pax_force_retaddr 0, 1
34849 ret
34850 ENDPROC(efi_call4)
34851
34852 @@ -147,6 +153,7 @@ ENTRY(efi_call5)
34853 RESTORE_PGT
34854 addq $48, %rsp
34855 RESTORE_XMM
34856 + pax_force_retaddr 0, 1
34857 ret
34858 ENDPROC(efi_call5)
34859
34860 @@ -165,6 +172,7 @@ ENTRY(efi_call6)
34861 RESTORE_PGT
34862 addq $48, %rsp
34863 RESTORE_XMM
34864 + pax_force_retaddr 0, 1
34865 ret
34866 ENDPROC(efi_call6)
34867
34868 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34869 index 1bbedc4..eb795b5 100644
34870 --- a/arch/x86/platform/intel-mid/intel-mid.c
34871 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34872 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34873 {
34874 };
34875
34876 -static void intel_mid_reboot(void)
34877 +static void __noreturn intel_mid_reboot(void)
34878 {
34879 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34880 + BUG();
34881 }
34882
34883 static unsigned long __init intel_mid_calibrate_tsc(void)
34884 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34885 index d6ee929..3637cb5 100644
34886 --- a/arch/x86/platform/olpc/olpc_dt.c
34887 +++ b/arch/x86/platform/olpc/olpc_dt.c
34888 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34889 return res;
34890 }
34891
34892 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34893 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34894 .nextprop = olpc_dt_nextprop,
34895 .getproplen = olpc_dt_getproplen,
34896 .getproperty = olpc_dt_getproperty,
34897 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34898 index 424f4c9..f2a2988 100644
34899 --- a/arch/x86/power/cpu.c
34900 +++ b/arch/x86/power/cpu.c
34901 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34902 static void fix_processor_context(void)
34903 {
34904 int cpu = smp_processor_id();
34905 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34906 -#ifdef CONFIG_X86_64
34907 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34908 - tss_desc tss;
34909 -#endif
34910 + struct tss_struct *t = init_tss + cpu;
34911 +
34912 set_tss_desc(cpu, t); /*
34913 * This just modifies memory; should not be
34914 * necessary. But... This is necessary, because
34915 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34916 */
34917
34918 #ifdef CONFIG_X86_64
34919 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34920 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34921 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34922 -
34923 syscall_init(); /* This sets MSR_*STAR and related */
34924 #endif
34925 load_TR_desc(); /* This does ltr */
34926 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34927 index bad628a..a102610 100644
34928 --- a/arch/x86/realmode/init.c
34929 +++ b/arch/x86/realmode/init.c
34930 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34931 __va(real_mode_header->trampoline_header);
34932
34933 #ifdef CONFIG_X86_32
34934 - trampoline_header->start = __pa_symbol(startup_32_smp);
34935 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34936 +
34937 +#ifdef CONFIG_PAX_KERNEXEC
34938 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34939 +#endif
34940 +
34941 + trampoline_header->boot_cs = __BOOT_CS;
34942 trampoline_header->gdt_limit = __BOOT_DS + 7;
34943 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34944 #else
34945 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34946 *trampoline_cr4_features = read_cr4();
34947
34948 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34949 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34950 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34951 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34952 #endif
34953 }
34954 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34955 index 3497f14..cc73b92 100644
34956 --- a/arch/x86/realmode/rm/Makefile
34957 +++ b/arch/x86/realmode/rm/Makefile
34958 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34959
34960 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34961 -I$(srctree)/arch/x86/boot
34962 +ifdef CONSTIFY_PLUGIN
34963 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34964 +endif
34965 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34966 GCOV_PROFILE := n
34967 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34968 index a28221d..93c40f1 100644
34969 --- a/arch/x86/realmode/rm/header.S
34970 +++ b/arch/x86/realmode/rm/header.S
34971 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34972 #endif
34973 /* APM/BIOS reboot */
34974 .long pa_machine_real_restart_asm
34975 -#ifdef CONFIG_X86_64
34976 +#ifdef CONFIG_X86_32
34977 + .long __KERNEL_CS
34978 +#else
34979 .long __KERNEL32_CS
34980 #endif
34981 END(real_mode_header)
34982 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34983 index 48ddd76..c26749f 100644
34984 --- a/arch/x86/realmode/rm/trampoline_32.S
34985 +++ b/arch/x86/realmode/rm/trampoline_32.S
34986 @@ -24,6 +24,12 @@
34987 #include <asm/page_types.h>
34988 #include "realmode.h"
34989
34990 +#ifdef CONFIG_PAX_KERNEXEC
34991 +#define ta(X) (X)
34992 +#else
34993 +#define ta(X) (pa_ ## X)
34994 +#endif
34995 +
34996 .text
34997 .code16
34998
34999 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35000
35001 cli # We should be safe anyway
35002
35003 - movl tr_start, %eax # where we need to go
35004 -
35005 movl $0xA5A5A5A5, trampoline_status
35006 # write marker for master knows we're running
35007
35008 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35009 movw $1, %dx # protected mode (PE) bit
35010 lmsw %dx # into protected mode
35011
35012 - ljmpl $__BOOT_CS, $pa_startup_32
35013 + ljmpl *(trampoline_header)
35014
35015 .section ".text32","ax"
35016 .code32
35017 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35018 .balign 8
35019 GLOBAL(trampoline_header)
35020 tr_start: .space 4
35021 - tr_gdt_pad: .space 2
35022 + tr_boot_cs: .space 2
35023 tr_gdt: .space 6
35024 END(trampoline_header)
35025
35026 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35027 index dac7b20..72dbaca 100644
35028 --- a/arch/x86/realmode/rm/trampoline_64.S
35029 +++ b/arch/x86/realmode/rm/trampoline_64.S
35030 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35031 movl %edx, %gs
35032
35033 movl pa_tr_cr4, %eax
35034 + andl $~X86_CR4_PCIDE, %eax
35035 movl %eax, %cr4 # Enable PAE mode
35036
35037 # Setup trampoline 4 level pagetables
35038 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35039 wrmsr
35040
35041 # Enable paging and in turn activate Long Mode
35042 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35043 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35044 movl %eax, %cr0
35045
35046 /*
35047 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35048 index 9e7e147..25a4158 100644
35049 --- a/arch/x86/realmode/rm/wakeup_asm.S
35050 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35051 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35052 lgdtl pmode_gdt
35053
35054 /* This really couldn't... */
35055 - movl pmode_entry, %eax
35056 movl pmode_cr0, %ecx
35057 movl %ecx, %cr0
35058 - ljmpl $__KERNEL_CS, $pa_startup_32
35059 - /* -> jmp *%eax in trampoline_32.S */
35060 +
35061 + ljmpl *pmode_entry
35062 #else
35063 jmp trampoline_start
35064 #endif
35065 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35066 index 604a37e..e49702a 100644
35067 --- a/arch/x86/tools/Makefile
35068 +++ b/arch/x86/tools/Makefile
35069 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35070
35071 $(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
35072
35073 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35074 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35075 hostprogs-y += relocs
35076 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35077 PHONY += relocs
35078 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35079 index bbb1d22..e505211 100644
35080 --- a/arch/x86/tools/relocs.c
35081 +++ b/arch/x86/tools/relocs.c
35082 @@ -1,5 +1,7 @@
35083 /* This is included from relocs_32/64.c */
35084
35085 +#include "../../../include/generated/autoconf.h"
35086 +
35087 #define ElfW(type) _ElfW(ELF_BITS, type)
35088 #define _ElfW(bits, type) __ElfW(bits, type)
35089 #define __ElfW(bits, type) Elf##bits##_##type
35090 @@ -11,6 +13,7 @@
35091 #define Elf_Sym ElfW(Sym)
35092
35093 static Elf_Ehdr ehdr;
35094 +static Elf_Phdr *phdr;
35095
35096 struct relocs {
35097 uint32_t *offset;
35098 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35099 }
35100 }
35101
35102 +static void read_phdrs(FILE *fp)
35103 +{
35104 + unsigned int i;
35105 +
35106 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35107 + if (!phdr) {
35108 + die("Unable to allocate %d program headers\n",
35109 + ehdr.e_phnum);
35110 + }
35111 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35112 + die("Seek to %d failed: %s\n",
35113 + ehdr.e_phoff, strerror(errno));
35114 + }
35115 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35116 + die("Cannot read ELF program headers: %s\n",
35117 + strerror(errno));
35118 + }
35119 + for(i = 0; i < ehdr.e_phnum; i++) {
35120 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35121 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35122 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35123 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35124 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35125 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35126 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35127 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35128 + }
35129 +
35130 +}
35131 +
35132 static void read_shdrs(FILE *fp)
35133 {
35134 - int i;
35135 + unsigned int i;
35136 Elf_Shdr shdr;
35137
35138 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35139 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35140
35141 static void read_strtabs(FILE *fp)
35142 {
35143 - int i;
35144 + unsigned int i;
35145 for (i = 0; i < ehdr.e_shnum; i++) {
35146 struct section *sec = &secs[i];
35147 if (sec->shdr.sh_type != SHT_STRTAB) {
35148 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35149
35150 static void read_symtabs(FILE *fp)
35151 {
35152 - int i,j;
35153 + unsigned int i,j;
35154 for (i = 0; i < ehdr.e_shnum; i++) {
35155 struct section *sec = &secs[i];
35156 if (sec->shdr.sh_type != SHT_SYMTAB) {
35157 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35158 }
35159
35160
35161 -static void read_relocs(FILE *fp)
35162 +static void read_relocs(FILE *fp, int use_real_mode)
35163 {
35164 - int i,j;
35165 + unsigned int i,j;
35166 + uint32_t base;
35167 +
35168 for (i = 0; i < ehdr.e_shnum; i++) {
35169 struct section *sec = &secs[i];
35170 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35171 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35172 die("Cannot read symbol table: %s\n",
35173 strerror(errno));
35174 }
35175 + base = 0;
35176 +
35177 +#ifdef CONFIG_X86_32
35178 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35179 + if (phdr[j].p_type != PT_LOAD )
35180 + continue;
35181 + 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)
35182 + continue;
35183 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35184 + break;
35185 + }
35186 +#endif
35187 +
35188 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35189 Elf_Rel *rel = &sec->reltab[j];
35190 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35191 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35192 rel->r_info = elf_xword_to_cpu(rel->r_info);
35193 #if (SHT_REL_TYPE == SHT_RELA)
35194 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35195 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35196
35197 static void print_absolute_symbols(void)
35198 {
35199 - int i;
35200 + unsigned int i;
35201 const char *format;
35202
35203 if (ELF_BITS == 64)
35204 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35205 for (i = 0; i < ehdr.e_shnum; i++) {
35206 struct section *sec = &secs[i];
35207 char *sym_strtab;
35208 - int j;
35209 + unsigned int j;
35210
35211 if (sec->shdr.sh_type != SHT_SYMTAB) {
35212 continue;
35213 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35214
35215 static void print_absolute_relocs(void)
35216 {
35217 - int i, printed = 0;
35218 + unsigned int i, printed = 0;
35219 const char *format;
35220
35221 if (ELF_BITS == 64)
35222 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35223 struct section *sec_applies, *sec_symtab;
35224 char *sym_strtab;
35225 Elf_Sym *sh_symtab;
35226 - int j;
35227 + unsigned int j;
35228 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35229 continue;
35230 }
35231 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35232 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35233 Elf_Sym *sym, const char *symname))
35234 {
35235 - int i;
35236 + unsigned int i;
35237 /* Walk through the relocations */
35238 for (i = 0; i < ehdr.e_shnum; i++) {
35239 char *sym_strtab;
35240 Elf_Sym *sh_symtab;
35241 struct section *sec_applies, *sec_symtab;
35242 - int j;
35243 + unsigned int j;
35244 struct section *sec = &secs[i];
35245
35246 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35247 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35248 {
35249 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35250 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35251 + char *sym_strtab = sec->link->link->strtab;
35252 +
35253 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35254 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35255 + return 0;
35256 +
35257 +#ifdef CONFIG_PAX_KERNEXEC
35258 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35259 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35260 + return 0;
35261 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35262 + return 0;
35263 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35264 + return 0;
35265 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35266 + return 0;
35267 +#endif
35268
35269 switch (r_type) {
35270 case R_386_NONE:
35271 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35272
35273 static void emit_relocs(int as_text, int use_real_mode)
35274 {
35275 - int i;
35276 + unsigned int i;
35277 int (*write_reloc)(uint32_t, FILE *) = write32;
35278 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35279 const char *symname);
35280 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35281 {
35282 regex_init(use_real_mode);
35283 read_ehdr(fp);
35284 + read_phdrs(fp);
35285 read_shdrs(fp);
35286 read_strtabs(fp);
35287 read_symtabs(fp);
35288 - read_relocs(fp);
35289 + read_relocs(fp, use_real_mode);
35290 if (ELF_BITS == 64)
35291 percpu_init();
35292 if (show_absolute_syms) {
35293 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35294 index f40281e..92728c9 100644
35295 --- a/arch/x86/um/mem_32.c
35296 +++ b/arch/x86/um/mem_32.c
35297 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35298 gate_vma.vm_start = FIXADDR_USER_START;
35299 gate_vma.vm_end = FIXADDR_USER_END;
35300 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35301 - gate_vma.vm_page_prot = __P101;
35302 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35303
35304 return 0;
35305 }
35306 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35307 index 80ffa5b..a33bd15 100644
35308 --- a/arch/x86/um/tls_32.c
35309 +++ b/arch/x86/um/tls_32.c
35310 @@ -260,7 +260,7 @@ out:
35311 if (unlikely(task == current &&
35312 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35313 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35314 - "without flushed TLS.", current->pid);
35315 + "without flushed TLS.", task_pid_nr(current));
35316 }
35317
35318 return 0;
35319 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35320 index c580d12..0a0ba35 100644
35321 --- a/arch/x86/vdso/Makefile
35322 +++ b/arch/x86/vdso/Makefile
35323 @@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35324 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35325 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35326
35327 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35328 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35329 $(LTO_CFLAGS)
35330 GCOV_PROFILE := n
35331
35332 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35333 index 310c5f0..766d0a7 100644
35334 --- a/arch/x86/vdso/vdso32-setup.c
35335 +++ b/arch/x86/vdso/vdso32-setup.c
35336 @@ -29,6 +29,7 @@
35337 #include <asm/fixmap.h>
35338 #include <asm/hpet.h>
35339 #include <asm/vvar.h>
35340 +#include <asm/mman.h>
35341
35342 #ifdef CONFIG_COMPAT_VDSO
35343 #define VDSO_DEFAULT 0
35344 @@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35345 void enable_sep_cpu(void)
35346 {
35347 int cpu = get_cpu();
35348 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35349 + struct tss_struct *tss = init_tss + cpu;
35350
35351 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35352 put_cpu();
35353 @@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35354
35355 down_write(&mm->mmap_sem);
35356
35357 - addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35358 + addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35359 if (IS_ERR_VALUE(addr)) {
35360 ret = addr;
35361 goto up_fail;
35362 @@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35363
35364 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35365
35366 - current->mm->context.vdso = (void *)addr;
35367 + current->mm->context.vdso = addr;
35368
35369 /*
35370 * MAYWRITE to allow gdb to COW and set breakpoints
35371 @@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35372 #endif
35373
35374 current_thread_info()->sysenter_return =
35375 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35376 + (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35377
35378 up_fail:
35379 if (ret)
35380 - current->mm->context.vdso = NULL;
35381 + current->mm->context.vdso = 0;
35382
35383 up_write(&mm->mmap_sem);
35384
35385 @@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35386
35387 const char *arch_vma_name(struct vm_area_struct *vma)
35388 {
35389 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35390 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35391 return "[vdso]";
35392 +
35393 +#ifdef CONFIG_PAX_SEGMEXEC
35394 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35395 + return "[vdso]";
35396 +#endif
35397 +
35398 return NULL;
35399 }
35400
35401 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35402 index 1ad1026..1a08abe 100644
35403 --- a/arch/x86/vdso/vma.c
35404 +++ b/arch/x86/vdso/vma.c
35405 @@ -17,8 +17,6 @@
35406 #include <asm/page.h>
35407
35408 #if defined(CONFIG_X86_64)
35409 -unsigned int __read_mostly vdso_enabled = 1;
35410 -
35411 DECLARE_VDSO_IMAGE(vdso);
35412 extern unsigned short vdso_sync_cpuid;
35413 static unsigned vdso_size;
35414 @@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35415 * unaligned here as a result of stack start randomization.
35416 */
35417 addr = PAGE_ALIGN(addr);
35418 - addr = align_vdso_addr(addr);
35419
35420 return addr;
35421 }
35422 @@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35423 unsigned size)
35424 {
35425 struct mm_struct *mm = current->mm;
35426 - unsigned long addr;
35427 + unsigned long addr = 0;
35428 int ret;
35429
35430 - if (!vdso_enabled)
35431 - return 0;
35432 -
35433 down_write(&mm->mmap_sem);
35434 +
35435 +#ifdef CONFIG_PAX_RANDMMAP
35436 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35437 +#endif
35438 +
35439 addr = vdso_addr(mm->start_stack, size);
35440 + addr = align_vdso_addr(addr);
35441 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35442 if (IS_ERR_VALUE(addr)) {
35443 ret = addr;
35444 goto up_fail;
35445 }
35446
35447 - current->mm->context.vdso = (void *)addr;
35448 + mm->context.vdso = addr;
35449
35450 ret = install_special_mapping(mm, addr, size,
35451 VM_READ|VM_EXEC|
35452 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35453 pages);
35454 - if (ret) {
35455 - current->mm->context.vdso = NULL;
35456 - goto up_fail;
35457 - }
35458 + if (ret)
35459 + mm->context.vdso = 0;
35460
35461 up_fail:
35462 up_write(&mm->mmap_sem);
35463 @@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35464 vdsox32_size);
35465 }
35466 #endif
35467 -
35468 -static __init int vdso_setup(char *s)
35469 -{
35470 - vdso_enabled = simple_strtoul(s, NULL, 0);
35471 - return 0;
35472 -}
35473 -__setup("vdso=", vdso_setup);
35474 #endif
35475 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35476 index e88fda8..76ce7ce 100644
35477 --- a/arch/x86/xen/Kconfig
35478 +++ b/arch/x86/xen/Kconfig
35479 @@ -9,6 +9,7 @@ config XEN
35480 select XEN_HAVE_PVMMU
35481 depends on X86_64 || (X86_32 && X86_PAE)
35482 depends on X86_TSC
35483 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35484 help
35485 This is the Linux Xen port. Enabling this will allow the
35486 kernel to boot in a paravirtualized environment under the
35487 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35488 index c34bfc4..e599673 100644
35489 --- a/arch/x86/xen/enlighten.c
35490 +++ b/arch/x86/xen/enlighten.c
35491 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35492
35493 struct shared_info xen_dummy_shared_info;
35494
35495 -void *xen_initial_gdt;
35496 -
35497 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35498 __read_mostly int xen_have_vector_callback;
35499 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35500 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35501 {
35502 unsigned long va = dtr->address;
35503 unsigned int size = dtr->size + 1;
35504 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35505 - unsigned long frames[pages];
35506 + unsigned long frames[65536 / PAGE_SIZE];
35507 int f;
35508
35509 /*
35510 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35511 {
35512 unsigned long va = dtr->address;
35513 unsigned int size = dtr->size + 1;
35514 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35515 - unsigned long frames[pages];
35516 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35517 int f;
35518
35519 /*
35520 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35521 * 8-byte entries, or 16 4k pages..
35522 */
35523
35524 - BUG_ON(size > 65536);
35525 + BUG_ON(size > GDT_SIZE);
35526 BUG_ON(va & ~PAGE_MASK);
35527
35528 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35529 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35530 return 0;
35531 }
35532
35533 -static void set_xen_basic_apic_ops(void)
35534 +static void __init set_xen_basic_apic_ops(void)
35535 {
35536 apic->read = xen_apic_read;
35537 apic->write = xen_apic_write;
35538 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35539 #endif
35540 };
35541
35542 -static void xen_reboot(int reason)
35543 +static __noreturn void xen_reboot(int reason)
35544 {
35545 struct sched_shutdown r = { .reason = reason };
35546
35547 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35548 - BUG();
35549 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35550 + BUG();
35551 }
35552
35553 -static void xen_restart(char *msg)
35554 +static __noreturn void xen_restart(char *msg)
35555 {
35556 xen_reboot(SHUTDOWN_reboot);
35557 }
35558
35559 -static void xen_emergency_restart(void)
35560 +static __noreturn void xen_emergency_restart(void)
35561 {
35562 xen_reboot(SHUTDOWN_reboot);
35563 }
35564
35565 -static void xen_machine_halt(void)
35566 +static __noreturn void xen_machine_halt(void)
35567 {
35568 xen_reboot(SHUTDOWN_poweroff);
35569 }
35570
35571 -static void xen_machine_power_off(void)
35572 +static __noreturn void xen_machine_power_off(void)
35573 {
35574 if (pm_power_off)
35575 pm_power_off();
35576 @@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35577 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35578
35579 /* Work out if we support NX */
35580 - x86_configure_nx();
35581 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35582 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35583 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35584 + unsigned l, h;
35585 +
35586 + __supported_pte_mask |= _PAGE_NX;
35587 + rdmsr(MSR_EFER, l, h);
35588 + l |= EFER_NX;
35589 + wrmsr(MSR_EFER, l, h);
35590 + }
35591 +#endif
35592
35593 /* Get mfn list */
35594 xen_build_dynamic_phys_to_machine();
35595 @@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35596
35597 machine_ops = xen_machine_ops;
35598
35599 - /*
35600 - * The only reliable way to retain the initial address of the
35601 - * percpu gdt_page is to remember it here, so we can go and
35602 - * mark it RW later, when the initial percpu area is freed.
35603 - */
35604 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35605 -
35606 xen_smp_init();
35607
35608 #ifdef CONFIG_ACPI_NUMA
35609 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35610 index 86e02ea..e3705ca 100644
35611 --- a/arch/x86/xen/mmu.c
35612 +++ b/arch/x86/xen/mmu.c
35613 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35614 return val;
35615 }
35616
35617 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35618 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35619 {
35620 if (val & _PAGE_PRESENT) {
35621 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35622 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35623 /* L3_k[510] -> level2_kernel_pgt
35624 * L3_i[511] -> level2_fixmap_pgt */
35625 convert_pfn_mfn(level3_kernel_pgt);
35626 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35627 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35628 + convert_pfn_mfn(level3_vmemmap_pgt);
35629 }
35630 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35631 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35632 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35633 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35634 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35635 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35636 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35637 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35638 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35639 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35640 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35641 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35642 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35643 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35644
35645 @@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35646 pv_mmu_ops.set_pud = xen_set_pud;
35647 #if PAGETABLE_LEVELS == 4
35648 pv_mmu_ops.set_pgd = xen_set_pgd;
35649 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35650 #endif
35651
35652 /* This will work as long as patching hasn't happened yet
35653 @@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35654 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35655 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35656 .set_pgd = xen_set_pgd_hyper,
35657 + .set_pgd_batched = xen_set_pgd_hyper,
35658
35659 .alloc_pud = xen_alloc_pmd_init,
35660 .release_pud = xen_release_pmd_init,
35661 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35662 index 7005974..54fb05f 100644
35663 --- a/arch/x86/xen/smp.c
35664 +++ b/arch/x86/xen/smp.c
35665 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35666
35667 if (xen_pv_domain()) {
35668 if (!xen_feature(XENFEAT_writable_page_tables))
35669 - /* We've switched to the "real" per-cpu gdt, so make
35670 - * sure the old memory can be recycled. */
35671 - make_lowmem_page_readwrite(xen_initial_gdt);
35672 -
35673 #ifdef CONFIG_X86_32
35674 /*
35675 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35676 * expects __USER_DS
35677 */
35678 - loadsegment(ds, __USER_DS);
35679 - loadsegment(es, __USER_DS);
35680 + loadsegment(ds, __KERNEL_DS);
35681 + loadsegment(es, __KERNEL_DS);
35682 #endif
35683
35684 xen_filter_cpu_maps();
35685 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35686 #ifdef CONFIG_X86_32
35687 /* Note: PVH is not yet supported on x86_32. */
35688 ctxt->user_regs.fs = __KERNEL_PERCPU;
35689 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35690 + savesegment(gs, ctxt->user_regs.gs);
35691 #endif
35692 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35693
35694 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35695 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35696 ctxt->flags = VGCF_IN_KERNEL;
35697 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35698 - ctxt->user_regs.ds = __USER_DS;
35699 - ctxt->user_regs.es = __USER_DS;
35700 + ctxt->user_regs.ds = __KERNEL_DS;
35701 + ctxt->user_regs.es = __KERNEL_DS;
35702 ctxt->user_regs.ss = __KERNEL_DS;
35703
35704 xen_copy_trap_info(ctxt->trap_ctxt);
35705 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35706 int rc;
35707
35708 per_cpu(current_task, cpu) = idle;
35709 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35710 #ifdef CONFIG_X86_32
35711 irq_ctx_init(cpu);
35712 #else
35713 clear_tsk_thread_flag(idle, TIF_FORK);
35714 #endif
35715 - per_cpu(kernel_stack, cpu) =
35716 - (unsigned long)task_stack_page(idle) -
35717 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35718 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35719
35720 xen_setup_runstate_info(cpu);
35721 xen_setup_timer(cpu);
35722 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35723
35724 void __init xen_smp_init(void)
35725 {
35726 - smp_ops = xen_smp_ops;
35727 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35728 xen_fill_possible_map();
35729 }
35730
35731 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35732 index fd92a64..1f72641 100644
35733 --- a/arch/x86/xen/xen-asm_32.S
35734 +++ b/arch/x86/xen/xen-asm_32.S
35735 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35736 pushw %fs
35737 movl $(__KERNEL_PERCPU), %eax
35738 movl %eax, %fs
35739 - movl %fs:xen_vcpu, %eax
35740 + mov PER_CPU_VAR(xen_vcpu), %eax
35741 POP_FS
35742 #else
35743 movl %ss:xen_vcpu, %eax
35744 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35745 index 485b695..fda3e7c 100644
35746 --- a/arch/x86/xen/xen-head.S
35747 +++ b/arch/x86/xen/xen-head.S
35748 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35749 #ifdef CONFIG_X86_32
35750 mov %esi,xen_start_info
35751 mov $init_thread_union+THREAD_SIZE,%esp
35752 +#ifdef CONFIG_SMP
35753 + movl $cpu_gdt_table,%edi
35754 + movl $__per_cpu_load,%eax
35755 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35756 + rorl $16,%eax
35757 + movb %al,__KERNEL_PERCPU + 4(%edi)
35758 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35759 + movl $__per_cpu_end - 1,%eax
35760 + subl $__per_cpu_start,%eax
35761 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35762 +#endif
35763 #else
35764 mov %rsi,xen_start_info
35765 mov $init_thread_union+THREAD_SIZE,%rsp
35766 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35767 index 1cb6f4c..9981524 100644
35768 --- a/arch/x86/xen/xen-ops.h
35769 +++ b/arch/x86/xen/xen-ops.h
35770 @@ -10,8 +10,6 @@
35771 extern const char xen_hypervisor_callback[];
35772 extern const char xen_failsafe_callback[];
35773
35774 -extern void *xen_initial_gdt;
35775 -
35776 struct trap_info;
35777 void xen_copy_trap_info(struct trap_info *traps);
35778
35779 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35780 index 525bd3d..ef888b1 100644
35781 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35782 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35783 @@ -119,9 +119,9 @@
35784 ----------------------------------------------------------------------*/
35785
35786 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35787 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35788 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35789 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35790 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35791
35792 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35793 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35794 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35795 index 2f33760..835e50a 100644
35796 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35797 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35798 @@ -11,6 +11,7 @@
35799 #ifndef _XTENSA_CORE_H
35800 #define _XTENSA_CORE_H
35801
35802 +#include <linux/const.h>
35803
35804 /****************************************************************************
35805 Parameters Useful for Any Code, USER or PRIVILEGED
35806 @@ -112,9 +113,9 @@
35807 ----------------------------------------------------------------------*/
35808
35809 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35810 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35811 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35812 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35813 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35814
35815 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35816 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35817 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35818 index af00795..2bb8105 100644
35819 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35820 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35821 @@ -11,6 +11,7 @@
35822 #ifndef _XTENSA_CORE_CONFIGURATION_H
35823 #define _XTENSA_CORE_CONFIGURATION_H
35824
35825 +#include <linux/const.h>
35826
35827 /****************************************************************************
35828 Parameters Useful for Any Code, USER or PRIVILEGED
35829 @@ -118,9 +119,9 @@
35830 ----------------------------------------------------------------------*/
35831
35832 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35833 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35834 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35835 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35836 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35837
35838 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35839 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35840 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35841 index 1039fb9..d7c0d9a 100644
35842 --- a/block/blk-cgroup.c
35843 +++ b/block/blk-cgroup.c
35844 @@ -825,7 +825,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35845 static struct cgroup_subsys_state *
35846 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35847 {
35848 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35849 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35850 struct blkcg *blkcg;
35851
35852 if (!parent_css) {
35853 @@ -839,7 +839,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35854
35855 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35856 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35857 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35858 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35859 done:
35860 spin_lock_init(&blkcg->lock);
35861 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35862 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35863 index c11d24e..e915d24 100644
35864 --- a/block/blk-iopoll.c
35865 +++ b/block/blk-iopoll.c
35866 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35867 }
35868 EXPORT_SYMBOL(blk_iopoll_complete);
35869
35870 -static void blk_iopoll_softirq(struct softirq_action *h)
35871 +static __latent_entropy void blk_iopoll_softirq(void)
35872 {
35873 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35874 int rearm = 0, budget = blk_iopoll_budget;
35875 diff --git a/block/blk-map.c b/block/blk-map.c
35876 index f7b22bc..ec2ddf4 100644
35877 --- a/block/blk-map.c
35878 +++ b/block/blk-map.c
35879 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35880 if (!len || !kbuf)
35881 return -EINVAL;
35882
35883 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35884 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35885 if (do_copy)
35886 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35887 else
35888 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35889 index 53b1737..08177d2e 100644
35890 --- a/block/blk-softirq.c
35891 +++ b/block/blk-softirq.c
35892 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35893 * Softirq action handler - move entries to local list and loop over them
35894 * while passing them to the queue registered handler.
35895 */
35896 -static void blk_done_softirq(struct softirq_action *h)
35897 +static __latent_entropy void blk_done_softirq(void)
35898 {
35899 struct list_head *cpu_list, local_list;
35900
35901 diff --git a/block/bsg.c b/block/bsg.c
35902 index 420a5a9..23834aa 100644
35903 --- a/block/bsg.c
35904 +++ b/block/bsg.c
35905 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35906 struct sg_io_v4 *hdr, struct bsg_device *bd,
35907 fmode_t has_write_perm)
35908 {
35909 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35910 + unsigned char *cmdptr;
35911 +
35912 if (hdr->request_len > BLK_MAX_CDB) {
35913 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35914 if (!rq->cmd)
35915 return -ENOMEM;
35916 - }
35917 + cmdptr = rq->cmd;
35918 + } else
35919 + cmdptr = tmpcmd;
35920
35921 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35922 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35923 hdr->request_len))
35924 return -EFAULT;
35925
35926 + if (cmdptr != rq->cmd)
35927 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35928 +
35929 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35930 if (blk_verify_command(rq->cmd, has_write_perm))
35931 return -EPERM;
35932 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35933 index fbd5a67..f24fd95 100644
35934 --- a/block/compat_ioctl.c
35935 +++ b/block/compat_ioctl.c
35936 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35937 cgc = compat_alloc_user_space(sizeof(*cgc));
35938 cgc32 = compat_ptr(arg);
35939
35940 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35941 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35942 get_user(data, &cgc32->buffer) ||
35943 put_user(compat_ptr(data), &cgc->buffer) ||
35944 copy_in_user(&cgc->buflen, &cgc32->buflen,
35945 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35946 err |= __get_user(f->spec1, &uf->spec1);
35947 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35948 err |= __get_user(name, &uf->name);
35949 - f->name = compat_ptr(name);
35950 + f->name = (void __force_kernel *)compat_ptr(name);
35951 if (err) {
35952 err = -EFAULT;
35953 goto out;
35954 diff --git a/block/genhd.c b/block/genhd.c
35955 index 791f419..89f21c4 100644
35956 --- a/block/genhd.c
35957 +++ b/block/genhd.c
35958 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35959
35960 /*
35961 * Register device numbers dev..(dev+range-1)
35962 - * range must be nonzero
35963 + * Noop if @range is zero.
35964 * The hash chain is sorted on range, so that subranges can override.
35965 */
35966 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35967 struct kobject *(*probe)(dev_t, int *, void *),
35968 int (*lock)(dev_t, void *), void *data)
35969 {
35970 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35971 + if (range)
35972 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35973 }
35974
35975 EXPORT_SYMBOL(blk_register_region);
35976
35977 +/* undo blk_register_region(), noop if @range is zero */
35978 void blk_unregister_region(dev_t devt, unsigned long range)
35979 {
35980 - kobj_unmap(bdev_map, devt, range);
35981 + if (range)
35982 + kobj_unmap(bdev_map, devt, range);
35983 }
35984
35985 EXPORT_SYMBOL(blk_unregister_region);
35986 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35987 index dc51f46..d5446a8 100644
35988 --- a/block/partitions/efi.c
35989 +++ b/block/partitions/efi.c
35990 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35991 if (!gpt)
35992 return NULL;
35993
35994 + if (!le32_to_cpu(gpt->num_partition_entries))
35995 + return NULL;
35996 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35997 + if (!pte)
35998 + return NULL;
35999 +
36000 count = le32_to_cpu(gpt->num_partition_entries) *
36001 le32_to_cpu(gpt->sizeof_partition_entry);
36002 - if (!count)
36003 - return NULL;
36004 - pte = kmalloc(count, GFP_KERNEL);
36005 - if (!pte)
36006 - return NULL;
36007 -
36008 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36009 (u8 *) pte, count) < count) {
36010 kfree(pte);
36011 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36012 index 2648797..92ed21f 100644
36013 --- a/block/scsi_ioctl.c
36014 +++ b/block/scsi_ioctl.c
36015 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36016 return put_user(0, p);
36017 }
36018
36019 -static int sg_get_timeout(struct request_queue *q)
36020 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36021 {
36022 return jiffies_to_clock_t(q->sg_timeout);
36023 }
36024 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36025 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36026 struct sg_io_hdr *hdr, fmode_t mode)
36027 {
36028 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36029 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36030 + unsigned char *cmdptr;
36031 +
36032 + if (rq->cmd != rq->__cmd)
36033 + cmdptr = rq->cmd;
36034 + else
36035 + cmdptr = tmpcmd;
36036 +
36037 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36038 return -EFAULT;
36039 +
36040 + if (cmdptr != rq->cmd)
36041 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36042 +
36043 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36044 return -EPERM;
36045
36046 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36047 int err;
36048 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36049 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36050 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36051 + unsigned char *cmdptr;
36052
36053 if (!sic)
36054 return -EINVAL;
36055 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36056 */
36057 err = -EFAULT;
36058 rq->cmd_len = cmdlen;
36059 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36060 +
36061 + if (rq->cmd != rq->__cmd)
36062 + cmdptr = rq->cmd;
36063 + else
36064 + cmdptr = tmpcmd;
36065 +
36066 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36067 goto error;
36068
36069 + if (rq->cmd != cmdptr)
36070 + memcpy(rq->cmd, cmdptr, cmdlen);
36071 +
36072 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36073 goto error;
36074
36075 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36076 index 7bdd61b..afec999 100644
36077 --- a/crypto/cryptd.c
36078 +++ b/crypto/cryptd.c
36079 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36080
36081 struct cryptd_blkcipher_request_ctx {
36082 crypto_completion_t complete;
36083 -};
36084 +} __no_const;
36085
36086 struct cryptd_hash_ctx {
36087 struct crypto_shash *child;
36088 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36089
36090 struct cryptd_aead_request_ctx {
36091 crypto_completion_t complete;
36092 -};
36093 +} __no_const;
36094
36095 static void cryptd_queue_worker(struct work_struct *work);
36096
36097 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36098 index 309d345..1632720 100644
36099 --- a/crypto/pcrypt.c
36100 +++ b/crypto/pcrypt.c
36101 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36102 int ret;
36103
36104 pinst->kobj.kset = pcrypt_kset;
36105 - ret = kobject_add(&pinst->kobj, NULL, name);
36106 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36107 if (!ret)
36108 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36109
36110 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36111 index 6921c7f..78e1af7 100644
36112 --- a/drivers/acpi/acpica/hwxfsleep.c
36113 +++ b/drivers/acpi/acpica/hwxfsleep.c
36114 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36115 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36116
36117 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36118 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36119 - acpi_hw_extended_sleep},
36120 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36121 - acpi_hw_extended_wake_prep},
36122 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36123 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36124 + .extended_function = acpi_hw_extended_sleep},
36125 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36126 + .extended_function = acpi_hw_extended_wake_prep},
36127 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36128 + .extended_function = acpi_hw_extended_wake}
36129 };
36130
36131 /*
36132 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36133 index e5bcd91..74f050d 100644
36134 --- a/drivers/acpi/apei/apei-internal.h
36135 +++ b/drivers/acpi/apei/apei-internal.h
36136 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36137 struct apei_exec_ins_type {
36138 u32 flags;
36139 apei_exec_ins_func_t run;
36140 -};
36141 +} __do_const;
36142
36143 struct apei_exec_context {
36144 u32 ip;
36145 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36146 index dab7cb7..f0d2994 100644
36147 --- a/drivers/acpi/apei/ghes.c
36148 +++ b/drivers/acpi/apei/ghes.c
36149 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36150 const struct acpi_hest_generic *generic,
36151 const struct acpi_generic_status *estatus)
36152 {
36153 - static atomic_t seqno;
36154 + static atomic_unchecked_t seqno;
36155 unsigned int curr_seqno;
36156 char pfx_seq[64];
36157
36158 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36159 else
36160 pfx = KERN_ERR;
36161 }
36162 - curr_seqno = atomic_inc_return(&seqno);
36163 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36164 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36165 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36166 pfx_seq, generic->header.source_id);
36167 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36168 index a83e3c6..c3d617f 100644
36169 --- a/drivers/acpi/bgrt.c
36170 +++ b/drivers/acpi/bgrt.c
36171 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36172 if (!bgrt_image)
36173 return -ENODEV;
36174
36175 - bin_attr_image.private = bgrt_image;
36176 - bin_attr_image.size = bgrt_image_size;
36177 + pax_open_kernel();
36178 + *(void **)&bin_attr_image.private = bgrt_image;
36179 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36180 + pax_close_kernel();
36181
36182 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36183 if (!bgrt_kobj)
36184 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36185 index 3d8413d..95f638c 100644
36186 --- a/drivers/acpi/blacklist.c
36187 +++ b/drivers/acpi/blacklist.c
36188 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36189 u32 is_critical_error;
36190 };
36191
36192 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36193 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36194
36195 /*
36196 * POLICY: If *anything* doesn't work, put it on the blacklist.
36197 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36198 return 0;
36199 }
36200
36201 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36202 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36203 {
36204 .callback = dmi_disable_osi_vista,
36205 .ident = "Fujitsu Siemens",
36206 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36207 index c68e724..e863008 100644
36208 --- a/drivers/acpi/custom_method.c
36209 +++ b/drivers/acpi/custom_method.c
36210 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36211 struct acpi_table_header table;
36212 acpi_status status;
36213
36214 +#ifdef CONFIG_GRKERNSEC_KMEM
36215 + return -EPERM;
36216 +#endif
36217 +
36218 if (!(*ppos)) {
36219 /* parse the table header to get the table length */
36220 if (count <= sizeof(struct acpi_table_header))
36221 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36222 index 3dca36d..abaf070 100644
36223 --- a/drivers/acpi/processor_idle.c
36224 +++ b/drivers/acpi/processor_idle.c
36225 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36226 {
36227 int i, count = CPUIDLE_DRIVER_STATE_START;
36228 struct acpi_processor_cx *cx;
36229 - struct cpuidle_state *state;
36230 + cpuidle_state_no_const *state;
36231 struct cpuidle_driver *drv = &acpi_idle_driver;
36232
36233 if (!pr->flags.power_setup_done)
36234 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36235 index 38cb978..352c761 100644
36236 --- a/drivers/acpi/sysfs.c
36237 +++ b/drivers/acpi/sysfs.c
36238 @@ -423,11 +423,11 @@ static u32 num_counters;
36239 static struct attribute **all_attrs;
36240 static u32 acpi_gpe_count;
36241
36242 -static struct attribute_group interrupt_stats_attr_group = {
36243 +static attribute_group_no_const interrupt_stats_attr_group = {
36244 .name = "interrupts",
36245 };
36246
36247 -static struct kobj_attribute *counter_attrs;
36248 +static kobj_attribute_no_const *counter_attrs;
36249
36250 static void delete_gpe_attr_array(void)
36251 {
36252 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36253 index b986145..82bddb8 100644
36254 --- a/drivers/ata/libahci.c
36255 +++ b/drivers/ata/libahci.c
36256 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36257 }
36258 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36259
36260 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36261 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36262 struct ata_taskfile *tf, int is_cmd, u16 flags,
36263 unsigned long timeout_msec)
36264 {
36265 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36266 index 18d97d5..be690af 100644
36267 --- a/drivers/ata/libata-core.c
36268 +++ b/drivers/ata/libata-core.c
36269 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36270 static void ata_dev_xfermask(struct ata_device *dev);
36271 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36272
36273 -atomic_t ata_print_id = ATOMIC_INIT(0);
36274 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36275
36276 struct ata_force_param {
36277 const char *name;
36278 @@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36279 struct ata_port *ap;
36280 unsigned int tag;
36281
36282 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36283 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36284 ap = qc->ap;
36285
36286 qc->flags = 0;
36287 @@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36288 struct ata_port *ap;
36289 struct ata_link *link;
36290
36291 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36292 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36293 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36294 ap = qc->ap;
36295 link = qc->dev->link;
36296 @@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36297 return;
36298
36299 spin_lock(&lock);
36300 + pax_open_kernel();
36301
36302 for (cur = ops->inherits; cur; cur = cur->inherits) {
36303 void **inherit = (void **)cur;
36304 @@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36305 if (IS_ERR(*pp))
36306 *pp = NULL;
36307
36308 - ops->inherits = NULL;
36309 + *(struct ata_port_operations **)&ops->inherits = NULL;
36310
36311 + pax_close_kernel();
36312 spin_unlock(&lock);
36313 }
36314
36315 @@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36316
36317 /* give ports names and add SCSI hosts */
36318 for (i = 0; i < host->n_ports; i++) {
36319 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36320 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36321 host->ports[i]->local_port_no = i + 1;
36322 }
36323
36324 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36325 index ef8567d..8bdbd03 100644
36326 --- a/drivers/ata/libata-scsi.c
36327 +++ b/drivers/ata/libata-scsi.c
36328 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36329
36330 if (rc)
36331 return rc;
36332 - ap->print_id = atomic_inc_return(&ata_print_id);
36333 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36334 return 0;
36335 }
36336 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36337 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36338 index 45b5ab3..98446b8 100644
36339 --- a/drivers/ata/libata.h
36340 +++ b/drivers/ata/libata.h
36341 @@ -53,7 +53,7 @@ enum {
36342 ATA_DNXFER_QUIET = (1 << 31),
36343 };
36344
36345 -extern atomic_t ata_print_id;
36346 +extern atomic_unchecked_t ata_print_id;
36347 extern int atapi_passthru16;
36348 extern int libata_fua;
36349 extern int libata_noacpi;
36350 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36351 index 4edb1a8..84e1658 100644
36352 --- a/drivers/ata/pata_arasan_cf.c
36353 +++ b/drivers/ata/pata_arasan_cf.c
36354 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36355 /* Handle platform specific quirks */
36356 if (quirk) {
36357 if (quirk & CF_BROKEN_PIO) {
36358 - ap->ops->set_piomode = NULL;
36359 + pax_open_kernel();
36360 + *(void **)&ap->ops->set_piomode = NULL;
36361 + pax_close_kernel();
36362 ap->pio_mask = 0;
36363 }
36364 if (quirk & CF_BROKEN_MWDMA)
36365 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36366 index f9b983a..887b9d8 100644
36367 --- a/drivers/atm/adummy.c
36368 +++ b/drivers/atm/adummy.c
36369 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36370 vcc->pop(vcc, skb);
36371 else
36372 dev_kfree_skb_any(skb);
36373 - atomic_inc(&vcc->stats->tx);
36374 + atomic_inc_unchecked(&vcc->stats->tx);
36375
36376 return 0;
36377 }
36378 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36379 index f1a9198..f466a4a 100644
36380 --- a/drivers/atm/ambassador.c
36381 +++ b/drivers/atm/ambassador.c
36382 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36383 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36384
36385 // VC layer stats
36386 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36387 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36388
36389 // free the descriptor
36390 kfree (tx_descr);
36391 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36392 dump_skb ("<<<", vc, skb);
36393
36394 // VC layer stats
36395 - atomic_inc(&atm_vcc->stats->rx);
36396 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36397 __net_timestamp(skb);
36398 // end of our responsibility
36399 atm_vcc->push (atm_vcc, skb);
36400 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36401 } else {
36402 PRINTK (KERN_INFO, "dropped over-size frame");
36403 // should we count this?
36404 - atomic_inc(&atm_vcc->stats->rx_drop);
36405 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36406 }
36407
36408 } else {
36409 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36410 }
36411
36412 if (check_area (skb->data, skb->len)) {
36413 - atomic_inc(&atm_vcc->stats->tx_err);
36414 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36415 return -ENOMEM; // ?
36416 }
36417
36418 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36419 index 0e3f8f9..765a7a5 100644
36420 --- a/drivers/atm/atmtcp.c
36421 +++ b/drivers/atm/atmtcp.c
36422 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36423 if (vcc->pop) vcc->pop(vcc,skb);
36424 else dev_kfree_skb(skb);
36425 if (dev_data) return 0;
36426 - atomic_inc(&vcc->stats->tx_err);
36427 + atomic_inc_unchecked(&vcc->stats->tx_err);
36428 return -ENOLINK;
36429 }
36430 size = skb->len+sizeof(struct atmtcp_hdr);
36431 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36432 if (!new_skb) {
36433 if (vcc->pop) vcc->pop(vcc,skb);
36434 else dev_kfree_skb(skb);
36435 - atomic_inc(&vcc->stats->tx_err);
36436 + atomic_inc_unchecked(&vcc->stats->tx_err);
36437 return -ENOBUFS;
36438 }
36439 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36440 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36441 if (vcc->pop) vcc->pop(vcc,skb);
36442 else dev_kfree_skb(skb);
36443 out_vcc->push(out_vcc,new_skb);
36444 - atomic_inc(&vcc->stats->tx);
36445 - atomic_inc(&out_vcc->stats->rx);
36446 + atomic_inc_unchecked(&vcc->stats->tx);
36447 + atomic_inc_unchecked(&out_vcc->stats->rx);
36448 return 0;
36449 }
36450
36451 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36452 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36453 read_unlock(&vcc_sklist_lock);
36454 if (!out_vcc) {
36455 - atomic_inc(&vcc->stats->tx_err);
36456 + atomic_inc_unchecked(&vcc->stats->tx_err);
36457 goto done;
36458 }
36459 skb_pull(skb,sizeof(struct atmtcp_hdr));
36460 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36461 __net_timestamp(new_skb);
36462 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36463 out_vcc->push(out_vcc,new_skb);
36464 - atomic_inc(&vcc->stats->tx);
36465 - atomic_inc(&out_vcc->stats->rx);
36466 + atomic_inc_unchecked(&vcc->stats->tx);
36467 + atomic_inc_unchecked(&out_vcc->stats->rx);
36468 done:
36469 if (vcc->pop) vcc->pop(vcc,skb);
36470 else dev_kfree_skb(skb);
36471 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36472 index b1955ba..b179940 100644
36473 --- a/drivers/atm/eni.c
36474 +++ b/drivers/atm/eni.c
36475 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36476 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36477 vcc->dev->number);
36478 length = 0;
36479 - atomic_inc(&vcc->stats->rx_err);
36480 + atomic_inc_unchecked(&vcc->stats->rx_err);
36481 }
36482 else {
36483 length = ATM_CELL_SIZE-1; /* no HEC */
36484 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36485 size);
36486 }
36487 eff = length = 0;
36488 - atomic_inc(&vcc->stats->rx_err);
36489 + atomic_inc_unchecked(&vcc->stats->rx_err);
36490 }
36491 else {
36492 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36493 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36494 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36495 vcc->dev->number,vcc->vci,length,size << 2,descr);
36496 length = eff = 0;
36497 - atomic_inc(&vcc->stats->rx_err);
36498 + atomic_inc_unchecked(&vcc->stats->rx_err);
36499 }
36500 }
36501 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36502 @@ -767,7 +767,7 @@ rx_dequeued++;
36503 vcc->push(vcc,skb);
36504 pushed++;
36505 }
36506 - atomic_inc(&vcc->stats->rx);
36507 + atomic_inc_unchecked(&vcc->stats->rx);
36508 }
36509 wake_up(&eni_dev->rx_wait);
36510 }
36511 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36512 PCI_DMA_TODEVICE);
36513 if (vcc->pop) vcc->pop(vcc,skb);
36514 else dev_kfree_skb_irq(skb);
36515 - atomic_inc(&vcc->stats->tx);
36516 + atomic_inc_unchecked(&vcc->stats->tx);
36517 wake_up(&eni_dev->tx_wait);
36518 dma_complete++;
36519 }
36520 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36521 index 82f2ae0..f205c02 100644
36522 --- a/drivers/atm/firestream.c
36523 +++ b/drivers/atm/firestream.c
36524 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36525 }
36526 }
36527
36528 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36529 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36530
36531 fs_dprintk (FS_DEBUG_TXMEM, "i");
36532 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36533 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36534 #endif
36535 skb_put (skb, qe->p1 & 0xffff);
36536 ATM_SKB(skb)->vcc = atm_vcc;
36537 - atomic_inc(&atm_vcc->stats->rx);
36538 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36539 __net_timestamp(skb);
36540 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36541 atm_vcc->push (atm_vcc, skb);
36542 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36543 kfree (pe);
36544 }
36545 if (atm_vcc)
36546 - atomic_inc(&atm_vcc->stats->rx_drop);
36547 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36548 break;
36549 case 0x1f: /* Reassembly abort: no buffers. */
36550 /* Silently increment error counter. */
36551 if (atm_vcc)
36552 - atomic_inc(&atm_vcc->stats->rx_drop);
36553 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36554 break;
36555 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36556 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36557 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36558 index 204814e..cede831 100644
36559 --- a/drivers/atm/fore200e.c
36560 +++ b/drivers/atm/fore200e.c
36561 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36562 #endif
36563 /* check error condition */
36564 if (*entry->status & STATUS_ERROR)
36565 - atomic_inc(&vcc->stats->tx_err);
36566 + atomic_inc_unchecked(&vcc->stats->tx_err);
36567 else
36568 - atomic_inc(&vcc->stats->tx);
36569 + atomic_inc_unchecked(&vcc->stats->tx);
36570 }
36571 }
36572
36573 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36574 if (skb == NULL) {
36575 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36576
36577 - atomic_inc(&vcc->stats->rx_drop);
36578 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36579 return -ENOMEM;
36580 }
36581
36582 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36583
36584 dev_kfree_skb_any(skb);
36585
36586 - atomic_inc(&vcc->stats->rx_drop);
36587 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36588 return -ENOMEM;
36589 }
36590
36591 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36592
36593 vcc->push(vcc, skb);
36594 - atomic_inc(&vcc->stats->rx);
36595 + atomic_inc_unchecked(&vcc->stats->rx);
36596
36597 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36598
36599 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36600 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36601 fore200e->atm_dev->number,
36602 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36603 - atomic_inc(&vcc->stats->rx_err);
36604 + atomic_inc_unchecked(&vcc->stats->rx_err);
36605 }
36606 }
36607
36608 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36609 goto retry_here;
36610 }
36611
36612 - atomic_inc(&vcc->stats->tx_err);
36613 + atomic_inc_unchecked(&vcc->stats->tx_err);
36614
36615 fore200e->tx_sat++;
36616 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36617 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36618 index aa6be26..f70a785 100644
36619 --- a/drivers/atm/he.c
36620 +++ b/drivers/atm/he.c
36621 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36622
36623 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36624 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36625 - atomic_inc(&vcc->stats->rx_drop);
36626 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36627 goto return_host_buffers;
36628 }
36629
36630 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36631 RBRQ_LEN_ERR(he_dev->rbrq_head)
36632 ? "LEN_ERR" : "",
36633 vcc->vpi, vcc->vci);
36634 - atomic_inc(&vcc->stats->rx_err);
36635 + atomic_inc_unchecked(&vcc->stats->rx_err);
36636 goto return_host_buffers;
36637 }
36638
36639 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36640 vcc->push(vcc, skb);
36641 spin_lock(&he_dev->global_lock);
36642
36643 - atomic_inc(&vcc->stats->rx);
36644 + atomic_inc_unchecked(&vcc->stats->rx);
36645
36646 return_host_buffers:
36647 ++pdus_assembled;
36648 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36649 tpd->vcc->pop(tpd->vcc, tpd->skb);
36650 else
36651 dev_kfree_skb_any(tpd->skb);
36652 - atomic_inc(&tpd->vcc->stats->tx_err);
36653 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36654 }
36655 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36656 return;
36657 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36658 vcc->pop(vcc, skb);
36659 else
36660 dev_kfree_skb_any(skb);
36661 - atomic_inc(&vcc->stats->tx_err);
36662 + atomic_inc_unchecked(&vcc->stats->tx_err);
36663 return -EINVAL;
36664 }
36665
36666 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36667 vcc->pop(vcc, skb);
36668 else
36669 dev_kfree_skb_any(skb);
36670 - atomic_inc(&vcc->stats->tx_err);
36671 + atomic_inc_unchecked(&vcc->stats->tx_err);
36672 return -EINVAL;
36673 }
36674 #endif
36675 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36676 vcc->pop(vcc, skb);
36677 else
36678 dev_kfree_skb_any(skb);
36679 - atomic_inc(&vcc->stats->tx_err);
36680 + atomic_inc_unchecked(&vcc->stats->tx_err);
36681 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36682 return -ENOMEM;
36683 }
36684 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36685 vcc->pop(vcc, skb);
36686 else
36687 dev_kfree_skb_any(skb);
36688 - atomic_inc(&vcc->stats->tx_err);
36689 + atomic_inc_unchecked(&vcc->stats->tx_err);
36690 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36691 return -ENOMEM;
36692 }
36693 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36694 __enqueue_tpd(he_dev, tpd, cid);
36695 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36696
36697 - atomic_inc(&vcc->stats->tx);
36698 + atomic_inc_unchecked(&vcc->stats->tx);
36699
36700 return 0;
36701 }
36702 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36703 index 1dc0519..1aadaf7 100644
36704 --- a/drivers/atm/horizon.c
36705 +++ b/drivers/atm/horizon.c
36706 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36707 {
36708 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36709 // VC layer stats
36710 - atomic_inc(&vcc->stats->rx);
36711 + atomic_inc_unchecked(&vcc->stats->rx);
36712 __net_timestamp(skb);
36713 // end of our responsibility
36714 vcc->push (vcc, skb);
36715 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36716 dev->tx_iovec = NULL;
36717
36718 // VC layer stats
36719 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36720 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36721
36722 // free the skb
36723 hrz_kfree_skb (skb);
36724 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36725 index 1bdf104..9dc44b1 100644
36726 --- a/drivers/atm/idt77252.c
36727 +++ b/drivers/atm/idt77252.c
36728 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36729 else
36730 dev_kfree_skb(skb);
36731
36732 - atomic_inc(&vcc->stats->tx);
36733 + atomic_inc_unchecked(&vcc->stats->tx);
36734 }
36735
36736 atomic_dec(&scq->used);
36737 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36738 if ((sb = dev_alloc_skb(64)) == NULL) {
36739 printk("%s: Can't allocate buffers for aal0.\n",
36740 card->name);
36741 - atomic_add(i, &vcc->stats->rx_drop);
36742 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36743 break;
36744 }
36745 if (!atm_charge(vcc, sb->truesize)) {
36746 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36747 card->name);
36748 - atomic_add(i - 1, &vcc->stats->rx_drop);
36749 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36750 dev_kfree_skb(sb);
36751 break;
36752 }
36753 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36754 ATM_SKB(sb)->vcc = vcc;
36755 __net_timestamp(sb);
36756 vcc->push(vcc, sb);
36757 - atomic_inc(&vcc->stats->rx);
36758 + atomic_inc_unchecked(&vcc->stats->rx);
36759
36760 cell += ATM_CELL_PAYLOAD;
36761 }
36762 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36763 "(CDC: %08x)\n",
36764 card->name, len, rpp->len, readl(SAR_REG_CDC));
36765 recycle_rx_pool_skb(card, rpp);
36766 - atomic_inc(&vcc->stats->rx_err);
36767 + atomic_inc_unchecked(&vcc->stats->rx_err);
36768 return;
36769 }
36770 if (stat & SAR_RSQE_CRC) {
36771 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36772 recycle_rx_pool_skb(card, rpp);
36773 - atomic_inc(&vcc->stats->rx_err);
36774 + atomic_inc_unchecked(&vcc->stats->rx_err);
36775 return;
36776 }
36777 if (skb_queue_len(&rpp->queue) > 1) {
36778 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36779 RXPRINTK("%s: Can't alloc RX skb.\n",
36780 card->name);
36781 recycle_rx_pool_skb(card, rpp);
36782 - atomic_inc(&vcc->stats->rx_err);
36783 + atomic_inc_unchecked(&vcc->stats->rx_err);
36784 return;
36785 }
36786 if (!atm_charge(vcc, skb->truesize)) {
36787 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36788 __net_timestamp(skb);
36789
36790 vcc->push(vcc, skb);
36791 - atomic_inc(&vcc->stats->rx);
36792 + atomic_inc_unchecked(&vcc->stats->rx);
36793
36794 return;
36795 }
36796 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36797 __net_timestamp(skb);
36798
36799 vcc->push(vcc, skb);
36800 - atomic_inc(&vcc->stats->rx);
36801 + atomic_inc_unchecked(&vcc->stats->rx);
36802
36803 if (skb->truesize > SAR_FB_SIZE_3)
36804 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36805 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36806 if (vcc->qos.aal != ATM_AAL0) {
36807 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36808 card->name, vpi, vci);
36809 - atomic_inc(&vcc->stats->rx_drop);
36810 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36811 goto drop;
36812 }
36813
36814 if ((sb = dev_alloc_skb(64)) == NULL) {
36815 printk("%s: Can't allocate buffers for AAL0.\n",
36816 card->name);
36817 - atomic_inc(&vcc->stats->rx_err);
36818 + atomic_inc_unchecked(&vcc->stats->rx_err);
36819 goto drop;
36820 }
36821
36822 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36823 ATM_SKB(sb)->vcc = vcc;
36824 __net_timestamp(sb);
36825 vcc->push(vcc, sb);
36826 - atomic_inc(&vcc->stats->rx);
36827 + atomic_inc_unchecked(&vcc->stats->rx);
36828
36829 drop:
36830 skb_pull(queue, 64);
36831 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36832
36833 if (vc == NULL) {
36834 printk("%s: NULL connection in send().\n", card->name);
36835 - atomic_inc(&vcc->stats->tx_err);
36836 + atomic_inc_unchecked(&vcc->stats->tx_err);
36837 dev_kfree_skb(skb);
36838 return -EINVAL;
36839 }
36840 if (!test_bit(VCF_TX, &vc->flags)) {
36841 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36842 - atomic_inc(&vcc->stats->tx_err);
36843 + atomic_inc_unchecked(&vcc->stats->tx_err);
36844 dev_kfree_skb(skb);
36845 return -EINVAL;
36846 }
36847 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36848 break;
36849 default:
36850 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36851 - atomic_inc(&vcc->stats->tx_err);
36852 + atomic_inc_unchecked(&vcc->stats->tx_err);
36853 dev_kfree_skb(skb);
36854 return -EINVAL;
36855 }
36856
36857 if (skb_shinfo(skb)->nr_frags != 0) {
36858 printk("%s: No scatter-gather yet.\n", card->name);
36859 - atomic_inc(&vcc->stats->tx_err);
36860 + atomic_inc_unchecked(&vcc->stats->tx_err);
36861 dev_kfree_skb(skb);
36862 return -EINVAL;
36863 }
36864 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36865
36866 err = queue_skb(card, vc, skb, oam);
36867 if (err) {
36868 - atomic_inc(&vcc->stats->tx_err);
36869 + atomic_inc_unchecked(&vcc->stats->tx_err);
36870 dev_kfree_skb(skb);
36871 return err;
36872 }
36873 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36874 skb = dev_alloc_skb(64);
36875 if (!skb) {
36876 printk("%s: Out of memory in send_oam().\n", card->name);
36877 - atomic_inc(&vcc->stats->tx_err);
36878 + atomic_inc_unchecked(&vcc->stats->tx_err);
36879 return -ENOMEM;
36880 }
36881 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36882 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36883 index 4217f29..88f547a 100644
36884 --- a/drivers/atm/iphase.c
36885 +++ b/drivers/atm/iphase.c
36886 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36887 status = (u_short) (buf_desc_ptr->desc_mode);
36888 if (status & (RX_CER | RX_PTE | RX_OFL))
36889 {
36890 - atomic_inc(&vcc->stats->rx_err);
36891 + atomic_inc_unchecked(&vcc->stats->rx_err);
36892 IF_ERR(printk("IA: bad packet, dropping it");)
36893 if (status & RX_CER) {
36894 IF_ERR(printk(" cause: packet CRC error\n");)
36895 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36896 len = dma_addr - buf_addr;
36897 if (len > iadev->rx_buf_sz) {
36898 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36899 - atomic_inc(&vcc->stats->rx_err);
36900 + atomic_inc_unchecked(&vcc->stats->rx_err);
36901 goto out_free_desc;
36902 }
36903
36904 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36905 ia_vcc = INPH_IA_VCC(vcc);
36906 if (ia_vcc == NULL)
36907 {
36908 - atomic_inc(&vcc->stats->rx_err);
36909 + atomic_inc_unchecked(&vcc->stats->rx_err);
36910 atm_return(vcc, skb->truesize);
36911 dev_kfree_skb_any(skb);
36912 goto INCR_DLE;
36913 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36914 if ((length > iadev->rx_buf_sz) || (length >
36915 (skb->len - sizeof(struct cpcs_trailer))))
36916 {
36917 - atomic_inc(&vcc->stats->rx_err);
36918 + atomic_inc_unchecked(&vcc->stats->rx_err);
36919 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36920 length, skb->len);)
36921 atm_return(vcc, skb->truesize);
36922 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36923
36924 IF_RX(printk("rx_dle_intr: skb push");)
36925 vcc->push(vcc,skb);
36926 - atomic_inc(&vcc->stats->rx);
36927 + atomic_inc_unchecked(&vcc->stats->rx);
36928 iadev->rx_pkt_cnt++;
36929 }
36930 INCR_DLE:
36931 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36932 {
36933 struct k_sonet_stats *stats;
36934 stats = &PRIV(_ia_dev[board])->sonet_stats;
36935 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36936 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36937 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36938 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36939 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36940 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36941 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36942 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36943 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36944 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36945 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36946 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36947 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36948 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36949 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36950 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36951 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36952 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36953 }
36954 ia_cmds.status = 0;
36955 break;
36956 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36957 if ((desc == 0) || (desc > iadev->num_tx_desc))
36958 {
36959 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36960 - atomic_inc(&vcc->stats->tx);
36961 + atomic_inc_unchecked(&vcc->stats->tx);
36962 if (vcc->pop)
36963 vcc->pop(vcc, skb);
36964 else
36965 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36966 ATM_DESC(skb) = vcc->vci;
36967 skb_queue_tail(&iadev->tx_dma_q, skb);
36968
36969 - atomic_inc(&vcc->stats->tx);
36970 + atomic_inc_unchecked(&vcc->stats->tx);
36971 iadev->tx_pkt_cnt++;
36972 /* Increment transaction counter */
36973 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36974
36975 #if 0
36976 /* add flow control logic */
36977 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36978 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36979 if (iavcc->vc_desc_cnt > 10) {
36980 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36981 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36982 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36983 index fa7d701..1e404c7 100644
36984 --- a/drivers/atm/lanai.c
36985 +++ b/drivers/atm/lanai.c
36986 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36987 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36988 lanai_endtx(lanai, lvcc);
36989 lanai_free_skb(lvcc->tx.atmvcc, skb);
36990 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36991 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36992 }
36993
36994 /* Try to fill the buffer - don't call unless there is backlog */
36995 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36996 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36997 __net_timestamp(skb);
36998 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36999 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37000 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37001 out:
37002 lvcc->rx.buf.ptr = end;
37003 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37004 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37005 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37006 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37007 lanai->stats.service_rxnotaal5++;
37008 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37009 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37010 return 0;
37011 }
37012 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37013 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37014 int bytes;
37015 read_unlock(&vcc_sklist_lock);
37016 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37017 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37018 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37019 lvcc->stats.x.aal5.service_trash++;
37020 bytes = (SERVICE_GET_END(s) * 16) -
37021 (((unsigned long) lvcc->rx.buf.ptr) -
37022 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37023 }
37024 if (s & SERVICE_STREAM) {
37025 read_unlock(&vcc_sklist_lock);
37026 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37027 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37028 lvcc->stats.x.aal5.service_stream++;
37029 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37030 "PDU on VCI %d!\n", lanai->number, vci);
37031 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37032 return 0;
37033 }
37034 DPRINTK("got rx crc error on vci %d\n", vci);
37035 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37036 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37037 lvcc->stats.x.aal5.service_rxcrc++;
37038 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37039 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37040 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37041 index 9988ac9..7c52585 100644
37042 --- a/drivers/atm/nicstar.c
37043 +++ b/drivers/atm/nicstar.c
37044 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37045 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37046 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37047 card->index);
37048 - atomic_inc(&vcc->stats->tx_err);
37049 + atomic_inc_unchecked(&vcc->stats->tx_err);
37050 dev_kfree_skb_any(skb);
37051 return -EINVAL;
37052 }
37053 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37054 if (!vc->tx) {
37055 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37056 card->index);
37057 - atomic_inc(&vcc->stats->tx_err);
37058 + atomic_inc_unchecked(&vcc->stats->tx_err);
37059 dev_kfree_skb_any(skb);
37060 return -EINVAL;
37061 }
37062 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37063 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37064 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37065 card->index);
37066 - atomic_inc(&vcc->stats->tx_err);
37067 + atomic_inc_unchecked(&vcc->stats->tx_err);
37068 dev_kfree_skb_any(skb);
37069 return -EINVAL;
37070 }
37071
37072 if (skb_shinfo(skb)->nr_frags != 0) {
37073 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37074 - atomic_inc(&vcc->stats->tx_err);
37075 + atomic_inc_unchecked(&vcc->stats->tx_err);
37076 dev_kfree_skb_any(skb);
37077 return -EINVAL;
37078 }
37079 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37080 }
37081
37082 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37083 - atomic_inc(&vcc->stats->tx_err);
37084 + atomic_inc_unchecked(&vcc->stats->tx_err);
37085 dev_kfree_skb_any(skb);
37086 return -EIO;
37087 }
37088 - atomic_inc(&vcc->stats->tx);
37089 + atomic_inc_unchecked(&vcc->stats->tx);
37090
37091 return 0;
37092 }
37093 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37094 printk
37095 ("nicstar%d: Can't allocate buffers for aal0.\n",
37096 card->index);
37097 - atomic_add(i, &vcc->stats->rx_drop);
37098 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37099 break;
37100 }
37101 if (!atm_charge(vcc, sb->truesize)) {
37102 RXPRINTK
37103 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37104 card->index);
37105 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37106 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37107 dev_kfree_skb_any(sb);
37108 break;
37109 }
37110 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37111 ATM_SKB(sb)->vcc = vcc;
37112 __net_timestamp(sb);
37113 vcc->push(vcc, sb);
37114 - atomic_inc(&vcc->stats->rx);
37115 + atomic_inc_unchecked(&vcc->stats->rx);
37116 cell += ATM_CELL_PAYLOAD;
37117 }
37118
37119 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37120 if (iovb == NULL) {
37121 printk("nicstar%d: Out of iovec buffers.\n",
37122 card->index);
37123 - atomic_inc(&vcc->stats->rx_drop);
37124 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37125 recycle_rx_buf(card, skb);
37126 return;
37127 }
37128 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37129 small or large buffer itself. */
37130 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37131 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37132 - atomic_inc(&vcc->stats->rx_err);
37133 + atomic_inc_unchecked(&vcc->stats->rx_err);
37134 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37135 NS_MAX_IOVECS);
37136 NS_PRV_IOVCNT(iovb) = 0;
37137 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37138 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37139 card->index);
37140 which_list(card, skb);
37141 - atomic_inc(&vcc->stats->rx_err);
37142 + atomic_inc_unchecked(&vcc->stats->rx_err);
37143 recycle_rx_buf(card, skb);
37144 vc->rx_iov = NULL;
37145 recycle_iov_buf(card, iovb);
37146 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37147 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37148 card->index);
37149 which_list(card, skb);
37150 - atomic_inc(&vcc->stats->rx_err);
37151 + atomic_inc_unchecked(&vcc->stats->rx_err);
37152 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37153 NS_PRV_IOVCNT(iovb));
37154 vc->rx_iov = NULL;
37155 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37156 printk(" - PDU size mismatch.\n");
37157 else
37158 printk(".\n");
37159 - atomic_inc(&vcc->stats->rx_err);
37160 + atomic_inc_unchecked(&vcc->stats->rx_err);
37161 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37162 NS_PRV_IOVCNT(iovb));
37163 vc->rx_iov = NULL;
37164 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37165 /* skb points to a small buffer */
37166 if (!atm_charge(vcc, skb->truesize)) {
37167 push_rxbufs(card, skb);
37168 - atomic_inc(&vcc->stats->rx_drop);
37169 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37170 } else {
37171 skb_put(skb, len);
37172 dequeue_sm_buf(card, skb);
37173 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37174 ATM_SKB(skb)->vcc = vcc;
37175 __net_timestamp(skb);
37176 vcc->push(vcc, skb);
37177 - atomic_inc(&vcc->stats->rx);
37178 + atomic_inc_unchecked(&vcc->stats->rx);
37179 }
37180 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37181 struct sk_buff *sb;
37182 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37183 if (len <= NS_SMBUFSIZE) {
37184 if (!atm_charge(vcc, sb->truesize)) {
37185 push_rxbufs(card, sb);
37186 - atomic_inc(&vcc->stats->rx_drop);
37187 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37188 } else {
37189 skb_put(sb, len);
37190 dequeue_sm_buf(card, sb);
37191 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37192 ATM_SKB(sb)->vcc = vcc;
37193 __net_timestamp(sb);
37194 vcc->push(vcc, sb);
37195 - atomic_inc(&vcc->stats->rx);
37196 + atomic_inc_unchecked(&vcc->stats->rx);
37197 }
37198
37199 push_rxbufs(card, skb);
37200 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37201
37202 if (!atm_charge(vcc, skb->truesize)) {
37203 push_rxbufs(card, skb);
37204 - atomic_inc(&vcc->stats->rx_drop);
37205 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37206 } else {
37207 dequeue_lg_buf(card, skb);
37208 #ifdef NS_USE_DESTRUCTORS
37209 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37210 ATM_SKB(skb)->vcc = vcc;
37211 __net_timestamp(skb);
37212 vcc->push(vcc, skb);
37213 - atomic_inc(&vcc->stats->rx);
37214 + atomic_inc_unchecked(&vcc->stats->rx);
37215 }
37216
37217 push_rxbufs(card, sb);
37218 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37219 printk
37220 ("nicstar%d: Out of huge buffers.\n",
37221 card->index);
37222 - atomic_inc(&vcc->stats->rx_drop);
37223 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37224 recycle_iovec_rx_bufs(card,
37225 (struct iovec *)
37226 iovb->data,
37227 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37228 card->hbpool.count++;
37229 } else
37230 dev_kfree_skb_any(hb);
37231 - atomic_inc(&vcc->stats->rx_drop);
37232 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37233 } else {
37234 /* Copy the small buffer to the huge buffer */
37235 sb = (struct sk_buff *)iov->iov_base;
37236 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37237 #endif /* NS_USE_DESTRUCTORS */
37238 __net_timestamp(hb);
37239 vcc->push(vcc, hb);
37240 - atomic_inc(&vcc->stats->rx);
37241 + atomic_inc_unchecked(&vcc->stats->rx);
37242 }
37243 }
37244
37245 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37246 index 943cf0d..37d15d5 100644
37247 --- a/drivers/atm/solos-pci.c
37248 +++ b/drivers/atm/solos-pci.c
37249 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37250 }
37251 atm_charge(vcc, skb->truesize);
37252 vcc->push(vcc, skb);
37253 - atomic_inc(&vcc->stats->rx);
37254 + atomic_inc_unchecked(&vcc->stats->rx);
37255 break;
37256
37257 case PKT_STATUS:
37258 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37259 vcc = SKB_CB(oldskb)->vcc;
37260
37261 if (vcc) {
37262 - atomic_inc(&vcc->stats->tx);
37263 + atomic_inc_unchecked(&vcc->stats->tx);
37264 solos_pop(vcc, oldskb);
37265 } else {
37266 dev_kfree_skb_irq(oldskb);
37267 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37268 index 0215934..ce9f5b1 100644
37269 --- a/drivers/atm/suni.c
37270 +++ b/drivers/atm/suni.c
37271 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37272
37273
37274 #define ADD_LIMITED(s,v) \
37275 - atomic_add((v),&stats->s); \
37276 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37277 + atomic_add_unchecked((v),&stats->s); \
37278 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37279
37280
37281 static void suni_hz(unsigned long from_timer)
37282 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37283 index 5120a96..e2572bd 100644
37284 --- a/drivers/atm/uPD98402.c
37285 +++ b/drivers/atm/uPD98402.c
37286 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37287 struct sonet_stats tmp;
37288 int error = 0;
37289
37290 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37291 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37292 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37293 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37294 if (zero && !error) {
37295 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37296
37297
37298 #define ADD_LIMITED(s,v) \
37299 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37300 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37301 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37302 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37303 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37304 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37305
37306
37307 static void stat_event(struct atm_dev *dev)
37308 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37309 if (reason & uPD98402_INT_PFM) stat_event(dev);
37310 if (reason & uPD98402_INT_PCO) {
37311 (void) GET(PCOCR); /* clear interrupt cause */
37312 - atomic_add(GET(HECCT),
37313 + atomic_add_unchecked(GET(HECCT),
37314 &PRIV(dev)->sonet_stats.uncorr_hcs);
37315 }
37316 if ((reason & uPD98402_INT_RFO) &&
37317 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37318 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37319 uPD98402_INT_LOS),PIMR); /* enable them */
37320 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37321 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37322 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37323 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37324 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37325 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37326 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37327 return 0;
37328 }
37329
37330 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37331 index 969c3c2..9b72956 100644
37332 --- a/drivers/atm/zatm.c
37333 +++ b/drivers/atm/zatm.c
37334 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37335 }
37336 if (!size) {
37337 dev_kfree_skb_irq(skb);
37338 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37339 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37340 continue;
37341 }
37342 if (!atm_charge(vcc,skb->truesize)) {
37343 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37344 skb->len = size;
37345 ATM_SKB(skb)->vcc = vcc;
37346 vcc->push(vcc,skb);
37347 - atomic_inc(&vcc->stats->rx);
37348 + atomic_inc_unchecked(&vcc->stats->rx);
37349 }
37350 zout(pos & 0xffff,MTA(mbx));
37351 #if 0 /* probably a stupid idea */
37352 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37353 skb_queue_head(&zatm_vcc->backlog,skb);
37354 break;
37355 }
37356 - atomic_inc(&vcc->stats->tx);
37357 + atomic_inc_unchecked(&vcc->stats->tx);
37358 wake_up(&zatm_vcc->tx_wait);
37359 }
37360
37361 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37362 index 83e910a..b224a73 100644
37363 --- a/drivers/base/bus.c
37364 +++ b/drivers/base/bus.c
37365 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37366 return -EINVAL;
37367
37368 mutex_lock(&subsys->p->mutex);
37369 - list_add_tail(&sif->node, &subsys->p->interfaces);
37370 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37371 if (sif->add_dev) {
37372 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37373 while ((dev = subsys_dev_iter_next(&iter)))
37374 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37375 subsys = sif->subsys;
37376
37377 mutex_lock(&subsys->p->mutex);
37378 - list_del_init(&sif->node);
37379 + pax_list_del_init((struct list_head *)&sif->node);
37380 if (sif->remove_dev) {
37381 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37382 while ((dev = subsys_dev_iter_next(&iter)))
37383 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37384 index 25798db..15f130e 100644
37385 --- a/drivers/base/devtmpfs.c
37386 +++ b/drivers/base/devtmpfs.c
37387 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37388 if (!thread)
37389 return 0;
37390
37391 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37392 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37393 if (err)
37394 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37395 else
37396 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37397 *err = sys_unshare(CLONE_NEWNS);
37398 if (*err)
37399 goto out;
37400 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37401 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37402 if (*err)
37403 goto out;
37404 - sys_chdir("/.."); /* will traverse into overmounted root */
37405 - sys_chroot(".");
37406 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37407 + sys_chroot((char __force_user *)".");
37408 complete(&setup_done);
37409 while (1) {
37410 spin_lock(&req_lock);
37411 diff --git a/drivers/base/node.c b/drivers/base/node.c
37412 index 8f7ed99..700dd0c 100644
37413 --- a/drivers/base/node.c
37414 +++ b/drivers/base/node.c
37415 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37416 struct node_attr {
37417 struct device_attribute attr;
37418 enum node_states state;
37419 -};
37420 +} __do_const;
37421
37422 static ssize_t show_node_state(struct device *dev,
37423 struct device_attribute *attr, char *buf)
37424 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37425 index ae098a2..0999830 100644
37426 --- a/drivers/base/power/domain.c
37427 +++ b/drivers/base/power/domain.c
37428 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37429
37430 if (dev->power.subsys_data->domain_data) {
37431 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37432 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37433 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37434 if (clear_td)
37435 - gpd_data->td = (struct gpd_timing_data){ 0 };
37436 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37437
37438 if (--gpd_data->refcount == 0) {
37439 dev->power.subsys_data->domain_data = NULL;
37440 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37441 {
37442 struct cpuidle_driver *cpuidle_drv;
37443 struct gpd_cpu_data *cpu_data;
37444 - struct cpuidle_state *idle_state;
37445 + cpuidle_state_no_const *idle_state;
37446 int ret = 0;
37447
37448 if (IS_ERR_OR_NULL(genpd) || state < 0)
37449 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37450 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37451 {
37452 struct gpd_cpu_data *cpu_data;
37453 - struct cpuidle_state *idle_state;
37454 + cpuidle_state_no_const *idle_state;
37455 int ret = 0;
37456
37457 if (IS_ERR_OR_NULL(genpd))
37458 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37459 index 95b181d1..c4f0e19 100644
37460 --- a/drivers/base/power/sysfs.c
37461 +++ b/drivers/base/power/sysfs.c
37462 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37463 return -EIO;
37464 }
37465 }
37466 - return sprintf(buf, p);
37467 + return sprintf(buf, "%s", p);
37468 }
37469
37470 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37471 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37472 index 2d56f41..8830f19 100644
37473 --- a/drivers/base/power/wakeup.c
37474 +++ b/drivers/base/power/wakeup.c
37475 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37476 * They need to be modified together atomically, so it's better to use one
37477 * atomic variable to hold them both.
37478 */
37479 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37480 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37481
37482 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37483 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37484
37485 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37486 {
37487 - unsigned int comb = atomic_read(&combined_event_count);
37488 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37489
37490 *cnt = (comb >> IN_PROGRESS_BITS);
37491 *inpr = comb & MAX_IN_PROGRESS;
37492 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37493 ws->start_prevent_time = ws->last_time;
37494
37495 /* Increment the counter of events in progress. */
37496 - cec = atomic_inc_return(&combined_event_count);
37497 + cec = atomic_inc_return_unchecked(&combined_event_count);
37498
37499 trace_wakeup_source_activate(ws->name, cec);
37500 }
37501 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37502 * Increment the counter of registered wakeup events and decrement the
37503 * couter of wakeup events in progress simultaneously.
37504 */
37505 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37506 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37507 trace_wakeup_source_deactivate(ws->name, cec);
37508
37509 split_counters(&cnt, &inpr);
37510 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37511 index e8d11b6..7b1b36f 100644
37512 --- a/drivers/base/syscore.c
37513 +++ b/drivers/base/syscore.c
37514 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37515 void register_syscore_ops(struct syscore_ops *ops)
37516 {
37517 mutex_lock(&syscore_ops_lock);
37518 - list_add_tail(&ops->node, &syscore_ops_list);
37519 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37520 mutex_unlock(&syscore_ops_lock);
37521 }
37522 EXPORT_SYMBOL_GPL(register_syscore_ops);
37523 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37524 void unregister_syscore_ops(struct syscore_ops *ops)
37525 {
37526 mutex_lock(&syscore_ops_lock);
37527 - list_del(&ops->node);
37528 + pax_list_del((struct list_head *)&ops->node);
37529 mutex_unlock(&syscore_ops_lock);
37530 }
37531 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37532 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37533 index 73894ca..69f64ef 100644
37534 --- a/drivers/block/cciss.c
37535 +++ b/drivers/block/cciss.c
37536 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37537 while (!list_empty(&h->reqQ)) {
37538 c = list_entry(h->reqQ.next, CommandList_struct, list);
37539 /* can't do anything if fifo is full */
37540 - if ((h->access.fifo_full(h))) {
37541 + if ((h->access->fifo_full(h))) {
37542 dev_warn(&h->pdev->dev, "fifo full\n");
37543 break;
37544 }
37545 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37546 h->Qdepth--;
37547
37548 /* Tell the controller execute command */
37549 - h->access.submit_command(h, c);
37550 + h->access->submit_command(h, c);
37551
37552 /* Put job onto the completed Q */
37553 addQ(&h->cmpQ, c);
37554 @@ -3447,17 +3447,17 @@ startio:
37555
37556 static inline unsigned long get_next_completion(ctlr_info_t *h)
37557 {
37558 - return h->access.command_completed(h);
37559 + return h->access->command_completed(h);
37560 }
37561
37562 static inline int interrupt_pending(ctlr_info_t *h)
37563 {
37564 - return h->access.intr_pending(h);
37565 + return h->access->intr_pending(h);
37566 }
37567
37568 static inline long interrupt_not_for_us(ctlr_info_t *h)
37569 {
37570 - return ((h->access.intr_pending(h) == 0) ||
37571 + return ((h->access->intr_pending(h) == 0) ||
37572 (h->interrupts_enabled == 0));
37573 }
37574
37575 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37576 u32 a;
37577
37578 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37579 - return h->access.command_completed(h);
37580 + return h->access->command_completed(h);
37581
37582 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37583 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37584 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37585 trans_support & CFGTBL_Trans_use_short_tags);
37586
37587 /* Change the access methods to the performant access methods */
37588 - h->access = SA5_performant_access;
37589 + h->access = &SA5_performant_access;
37590 h->transMethod = CFGTBL_Trans_Performant;
37591
37592 return;
37593 @@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37594 if (prod_index < 0)
37595 return -ENODEV;
37596 h->product_name = products[prod_index].product_name;
37597 - h->access = *(products[prod_index].access);
37598 + h->access = products[prod_index].access;
37599
37600 if (cciss_board_disabled(h)) {
37601 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37602 @@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37603 }
37604
37605 /* make sure the board interrupts are off */
37606 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37607 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37608 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37609 if (rc)
37610 goto clean2;
37611 @@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37612 * fake ones to scoop up any residual completions.
37613 */
37614 spin_lock_irqsave(&h->lock, flags);
37615 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37616 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37617 spin_unlock_irqrestore(&h->lock, flags);
37618 free_irq(h->intr[h->intr_mode], h);
37619 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37620 @@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37621 dev_info(&h->pdev->dev, "Board READY.\n");
37622 dev_info(&h->pdev->dev,
37623 "Waiting for stale completions to drain.\n");
37624 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37625 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37626 msleep(10000);
37627 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37628 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37629
37630 rc = controller_reset_failed(h->cfgtable);
37631 if (rc)
37632 @@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37633 cciss_scsi_setup(h);
37634
37635 /* Turn the interrupts on so we can service requests */
37636 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37637 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37638
37639 /* Get the firmware version */
37640 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37641 @@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37642 kfree(flush_buf);
37643 if (return_code != IO_OK)
37644 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37645 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37646 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37647 free_irq(h->intr[h->intr_mode], h);
37648 }
37649
37650 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37651 index 7fda30e..2f27946 100644
37652 --- a/drivers/block/cciss.h
37653 +++ b/drivers/block/cciss.h
37654 @@ -101,7 +101,7 @@ struct ctlr_info
37655 /* information about each logical volume */
37656 drive_info_struct *drv[CISS_MAX_LUN];
37657
37658 - struct access_method access;
37659 + struct access_method *access;
37660
37661 /* queue and queue Info */
37662 struct list_head reqQ;
37663 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37664 }
37665
37666 static struct access_method SA5_access = {
37667 - SA5_submit_command,
37668 - SA5_intr_mask,
37669 - SA5_fifo_full,
37670 - SA5_intr_pending,
37671 - SA5_completed,
37672 + .submit_command = SA5_submit_command,
37673 + .set_intr_mask = SA5_intr_mask,
37674 + .fifo_full = SA5_fifo_full,
37675 + .intr_pending = SA5_intr_pending,
37676 + .command_completed = SA5_completed,
37677 };
37678
37679 static struct access_method SA5B_access = {
37680 - SA5_submit_command,
37681 - SA5B_intr_mask,
37682 - SA5_fifo_full,
37683 - SA5B_intr_pending,
37684 - SA5_completed,
37685 + .submit_command = SA5_submit_command,
37686 + .set_intr_mask = SA5B_intr_mask,
37687 + .fifo_full = SA5_fifo_full,
37688 + .intr_pending = SA5B_intr_pending,
37689 + .command_completed = SA5_completed,
37690 };
37691
37692 static struct access_method SA5_performant_access = {
37693 - SA5_submit_command,
37694 - SA5_performant_intr_mask,
37695 - SA5_fifo_full,
37696 - SA5_performant_intr_pending,
37697 - SA5_performant_completed,
37698 + .submit_command = SA5_submit_command,
37699 + .set_intr_mask = SA5_performant_intr_mask,
37700 + .fifo_full = SA5_fifo_full,
37701 + .intr_pending = SA5_performant_intr_pending,
37702 + .command_completed = SA5_performant_completed,
37703 };
37704
37705 struct board_type {
37706 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37707 index 2b94403..fd6ad1f 100644
37708 --- a/drivers/block/cpqarray.c
37709 +++ b/drivers/block/cpqarray.c
37710 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37711 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37712 goto Enomem4;
37713 }
37714 - hba[i]->access.set_intr_mask(hba[i], 0);
37715 + hba[i]->access->set_intr_mask(hba[i], 0);
37716 if (request_irq(hba[i]->intr, do_ida_intr,
37717 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37718 {
37719 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37720 add_timer(&hba[i]->timer);
37721
37722 /* Enable IRQ now that spinlock and rate limit timer are set up */
37723 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37724 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37725
37726 for(j=0; j<NWD; j++) {
37727 struct gendisk *disk = ida_gendisk[i][j];
37728 @@ -694,7 +694,7 @@ DBGINFO(
37729 for(i=0; i<NR_PRODUCTS; i++) {
37730 if (board_id == products[i].board_id) {
37731 c->product_name = products[i].product_name;
37732 - c->access = *(products[i].access);
37733 + c->access = products[i].access;
37734 break;
37735 }
37736 }
37737 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37738 hba[ctlr]->intr = intr;
37739 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37740 hba[ctlr]->product_name = products[j].product_name;
37741 - hba[ctlr]->access = *(products[j].access);
37742 + hba[ctlr]->access = products[j].access;
37743 hba[ctlr]->ctlr = ctlr;
37744 hba[ctlr]->board_id = board_id;
37745 hba[ctlr]->pci_dev = NULL; /* not PCI */
37746 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37747
37748 while((c = h->reqQ) != NULL) {
37749 /* Can't do anything if we're busy */
37750 - if (h->access.fifo_full(h) == 0)
37751 + if (h->access->fifo_full(h) == 0)
37752 return;
37753
37754 /* Get the first entry from the request Q */
37755 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37756 h->Qdepth--;
37757
37758 /* Tell the controller to do our bidding */
37759 - h->access.submit_command(h, c);
37760 + h->access->submit_command(h, c);
37761
37762 /* Get onto the completion Q */
37763 addQ(&h->cmpQ, c);
37764 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37765 unsigned long flags;
37766 __u32 a,a1;
37767
37768 - istat = h->access.intr_pending(h);
37769 + istat = h->access->intr_pending(h);
37770 /* Is this interrupt for us? */
37771 if (istat == 0)
37772 return IRQ_NONE;
37773 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37774 */
37775 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37776 if (istat & FIFO_NOT_EMPTY) {
37777 - while((a = h->access.command_completed(h))) {
37778 + while((a = h->access->command_completed(h))) {
37779 a1 = a; a &= ~3;
37780 if ((c = h->cmpQ) == NULL)
37781 {
37782 @@ -1448,11 +1448,11 @@ static int sendcmd(
37783 /*
37784 * Disable interrupt
37785 */
37786 - info_p->access.set_intr_mask(info_p, 0);
37787 + info_p->access->set_intr_mask(info_p, 0);
37788 /* Make sure there is room in the command FIFO */
37789 /* Actually it should be completely empty at this time. */
37790 for (i = 200000; i > 0; i--) {
37791 - temp = info_p->access.fifo_full(info_p);
37792 + temp = info_p->access->fifo_full(info_p);
37793 if (temp != 0) {
37794 break;
37795 }
37796 @@ -1465,7 +1465,7 @@ DBG(
37797 /*
37798 * Send the cmd
37799 */
37800 - info_p->access.submit_command(info_p, c);
37801 + info_p->access->submit_command(info_p, c);
37802 complete = pollcomplete(ctlr);
37803
37804 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37805 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37806 * we check the new geometry. Then turn interrupts back on when
37807 * we're done.
37808 */
37809 - host->access.set_intr_mask(host, 0);
37810 + host->access->set_intr_mask(host, 0);
37811 getgeometry(ctlr);
37812 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37813 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37814
37815 for(i=0; i<NWD; i++) {
37816 struct gendisk *disk = ida_gendisk[ctlr][i];
37817 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37818 /* Wait (up to 2 seconds) for a command to complete */
37819
37820 for (i = 200000; i > 0; i--) {
37821 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37822 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37823 if (done == 0) {
37824 udelay(10); /* a short fixed delay */
37825 } else
37826 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37827 index be73e9d..7fbf140 100644
37828 --- a/drivers/block/cpqarray.h
37829 +++ b/drivers/block/cpqarray.h
37830 @@ -99,7 +99,7 @@ struct ctlr_info {
37831 drv_info_t drv[NWD];
37832 struct proc_dir_entry *proc;
37833
37834 - struct access_method access;
37835 + struct access_method *access;
37836
37837 cmdlist_t *reqQ;
37838 cmdlist_t *cmpQ;
37839 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37840 index e7093d4..b364085 100644
37841 --- a/drivers/block/drbd/drbd_int.h
37842 +++ b/drivers/block/drbd/drbd_int.h
37843 @@ -331,7 +331,7 @@ struct drbd_epoch {
37844 struct drbd_connection *connection;
37845 struct list_head list;
37846 unsigned int barrier_nr;
37847 - atomic_t epoch_size; /* increased on every request added. */
37848 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37849 atomic_t active; /* increased on every req. added, and dec on every finished. */
37850 unsigned long flags;
37851 };
37852 @@ -787,7 +787,7 @@ struct drbd_device {
37853 unsigned int al_tr_number;
37854 int al_tr_cycle;
37855 wait_queue_head_t seq_wait;
37856 - atomic_t packet_seq;
37857 + atomic_unchecked_t packet_seq;
37858 unsigned int peer_seq;
37859 spinlock_t peer_seq_lock;
37860 unsigned int minor;
37861 @@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37862 char __user *uoptval;
37863 int err;
37864
37865 - uoptval = (char __user __force *)optval;
37866 + uoptval = (char __force_user *)optval;
37867
37868 set_fs(KERNEL_DS);
37869 if (level == SOL_SOCKET)
37870 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37871 index 89c497c..9c736ae 100644
37872 --- a/drivers/block/drbd/drbd_interval.c
37873 +++ b/drivers/block/drbd/drbd_interval.c
37874 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37875 }
37876
37877 static const struct rb_augment_callbacks augment_callbacks = {
37878 - augment_propagate,
37879 - augment_copy,
37880 - augment_rotate,
37881 + .propagate = augment_propagate,
37882 + .copy = augment_copy,
37883 + .rotate = augment_rotate,
37884 };
37885
37886 /**
37887 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37888 index 331e5cc..6d657bce 100644
37889 --- a/drivers/block/drbd/drbd_main.c
37890 +++ b/drivers/block/drbd/drbd_main.c
37891 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37892 p->sector = sector;
37893 p->block_id = block_id;
37894 p->blksize = blksize;
37895 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37896 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37897 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37898 }
37899
37900 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37901 return -EIO;
37902 p->sector = cpu_to_be64(req->i.sector);
37903 p->block_id = (unsigned long)req;
37904 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37905 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37906 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37907 if (device->state.conn >= C_SYNC_SOURCE &&
37908 device->state.conn <= C_PAUSED_SYNC_T)
37909 @@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37910 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37911 struct drbd_resource *resource = connection->resource;
37912
37913 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37914 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37915 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37916 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37917 kfree(connection->current_epoch);
37918
37919 idr_destroy(&connection->peer_devices);
37920 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37921 index 526414b..4eb8184 100644
37922 --- a/drivers/block/drbd/drbd_nl.c
37923 +++ b/drivers/block/drbd/drbd_nl.c
37924 @@ -3505,7 +3505,7 @@ out:
37925
37926 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37927 {
37928 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37929 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37930 struct sk_buff *msg;
37931 struct drbd_genlmsghdr *d_out;
37932 unsigned seq;
37933 @@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37934 return;
37935 }
37936
37937 - seq = atomic_inc_return(&drbd_genl_seq);
37938 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37939 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37940 if (!msg)
37941 goto failed;
37942 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37943 index 68e3992..1aca24a 100644
37944 --- a/drivers/block/drbd/drbd_receiver.c
37945 +++ b/drivers/block/drbd/drbd_receiver.c
37946 @@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37947 struct drbd_device *device = peer_device->device;
37948 int err;
37949
37950 - atomic_set(&device->packet_seq, 0);
37951 + atomic_set_unchecked(&device->packet_seq, 0);
37952 device->peer_seq = 0;
37953
37954 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37955 @@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37956 do {
37957 next_epoch = NULL;
37958
37959 - epoch_size = atomic_read(&epoch->epoch_size);
37960 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37961
37962 switch (ev & ~EV_CLEANUP) {
37963 case EV_PUT:
37964 @@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37965 rv = FE_DESTROYED;
37966 } else {
37967 epoch->flags = 0;
37968 - atomic_set(&epoch->epoch_size, 0);
37969 + atomic_set_unchecked(&epoch->epoch_size, 0);
37970 /* atomic_set(&epoch->active, 0); is already zero */
37971 if (rv == FE_STILL_LIVE)
37972 rv = FE_RECYCLED;
37973 @@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37974 conn_wait_active_ee_empty(connection);
37975 drbd_flush(connection);
37976
37977 - if (atomic_read(&connection->current_epoch->epoch_size)) {
37978 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
37979 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37980 if (epoch)
37981 break;
37982 @@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37983 }
37984
37985 epoch->flags = 0;
37986 - atomic_set(&epoch->epoch_size, 0);
37987 + atomic_set_unchecked(&epoch->epoch_size, 0);
37988 atomic_set(&epoch->active, 0);
37989
37990 spin_lock(&connection->epoch_lock);
37991 - if (atomic_read(&connection->current_epoch->epoch_size)) {
37992 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
37993 list_add(&epoch->list, &connection->current_epoch->list);
37994 connection->current_epoch = epoch;
37995 connection->epochs++;
37996 @@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
37997
37998 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
37999 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38000 - atomic_inc(&connection->current_epoch->epoch_size);
38001 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38002 err2 = drbd_drain_block(peer_device, pi->size);
38003 if (!err)
38004 err = err2;
38005 @@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38006
38007 spin_lock(&connection->epoch_lock);
38008 peer_req->epoch = connection->current_epoch;
38009 - atomic_inc(&peer_req->epoch->epoch_size);
38010 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38011 atomic_inc(&peer_req->epoch->active);
38012 spin_unlock(&connection->epoch_lock);
38013
38014 @@ -4396,7 +4396,7 @@ struct data_cmd {
38015 int expect_payload;
38016 size_t pkt_size;
38017 int (*fn)(struct drbd_connection *, struct packet_info *);
38018 -};
38019 +} __do_const;
38020
38021 static struct data_cmd drbd_cmd_handler[] = {
38022 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38023 @@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38024 if (!list_empty(&connection->current_epoch->list))
38025 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38026 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38027 - atomic_set(&connection->current_epoch->epoch_size, 0);
38028 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38029 connection->send.seen_any_write_yet = false;
38030
38031 drbd_info(connection, "Connection closed\n");
38032 @@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38033 struct asender_cmd {
38034 size_t pkt_size;
38035 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38036 -};
38037 +} __do_const;
38038
38039 static struct asender_cmd asender_tbl[] = {
38040 [P_PING] = { 0, got_Ping },
38041 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38042 index f70a230..9dc90d5 100644
38043 --- a/drivers/block/loop.c
38044 +++ b/drivers/block/loop.c
38045 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38046
38047 file_start_write(file);
38048 set_fs(get_ds());
38049 - bw = file->f_op->write(file, buf, len, &pos);
38050 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38051 set_fs(old_fs);
38052 file_end_write(file);
38053 if (likely(bw == len))
38054 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38055 index 091b9ea..f5428f8 100644
38056 --- a/drivers/block/null_blk.c
38057 +++ b/drivers/block/null_blk.c
38058 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38059 return 0;
38060 }
38061
38062 -static struct blk_mq_ops null_mq_ops = {
38063 - .queue_rq = null_queue_rq,
38064 - .map_queue = blk_mq_map_queue,
38065 +static struct blk_mq_ops null_mq_single_ops = {
38066 + .queue_rq = null_queue_rq,
38067 + .map_queue = blk_mq_map_queue,
38068 .init_hctx = null_init_hctx,
38069 .complete = null_softirq_done_fn,
38070 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
38071 + .free_hctx = blk_mq_free_single_hw_queue,
38072 +};
38073 +
38074 +static struct blk_mq_ops null_mq_per_node_ops = {
38075 + .queue_rq = null_queue_rq,
38076 + .map_queue = blk_mq_map_queue,
38077 + .init_hctx = null_init_hctx,
38078 + .alloc_hctx = null_alloc_hctx,
38079 + .free_hctx = null_free_hctx,
38080 };
38081
38082 static struct blk_mq_reg null_mq_reg = {
38083 - .ops = &null_mq_ops,
38084 + .ops = &null_mq_single_ops,
38085 .queue_depth = 64,
38086 .cmd_size = sizeof(struct nullb_cmd),
38087 .flags = BLK_MQ_F_SHOULD_MERGE,
38088 @@ -521,13 +531,8 @@ static int null_add_dev(void)
38089 null_mq_reg.queue_depth = hw_queue_depth;
38090 null_mq_reg.nr_hw_queues = submit_queues;
38091
38092 - if (use_per_node_hctx) {
38093 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38094 - null_mq_reg.ops->free_hctx = null_free_hctx;
38095 - } else {
38096 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38097 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38098 - }
38099 + if (use_per_node_hctx)
38100 + null_mq_reg.ops = &null_mq_per_node_ops;
38101
38102 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38103 } else if (queue_mode == NULL_Q_BIO) {
38104 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38105 index a2af73d..c0b8f61 100644
38106 --- a/drivers/block/pktcdvd.c
38107 +++ b/drivers/block/pktcdvd.c
38108 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38109
38110 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38111 {
38112 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38113 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38114 }
38115
38116 /*
38117 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38118 return -EROFS;
38119 }
38120 pd->settings.fp = ti.fp;
38121 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38122 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38123
38124 if (ti.nwa_v) {
38125 pd->nwa = be32_to_cpu(ti.next_writable);
38126 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38127 index e5565fb..71be10b4 100644
38128 --- a/drivers/block/smart1,2.h
38129 +++ b/drivers/block/smart1,2.h
38130 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38131 }
38132
38133 static struct access_method smart4_access = {
38134 - smart4_submit_command,
38135 - smart4_intr_mask,
38136 - smart4_fifo_full,
38137 - smart4_intr_pending,
38138 - smart4_completed,
38139 + .submit_command = smart4_submit_command,
38140 + .set_intr_mask = smart4_intr_mask,
38141 + .fifo_full = smart4_fifo_full,
38142 + .intr_pending = smart4_intr_pending,
38143 + .command_completed = smart4_completed,
38144 };
38145
38146 /*
38147 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38148 }
38149
38150 static struct access_method smart2_access = {
38151 - smart2_submit_command,
38152 - smart2_intr_mask,
38153 - smart2_fifo_full,
38154 - smart2_intr_pending,
38155 - smart2_completed,
38156 + .submit_command = smart2_submit_command,
38157 + .set_intr_mask = smart2_intr_mask,
38158 + .fifo_full = smart2_fifo_full,
38159 + .intr_pending = smart2_intr_pending,
38160 + .command_completed = smart2_completed,
38161 };
38162
38163 /*
38164 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38165 }
38166
38167 static struct access_method smart2e_access = {
38168 - smart2e_submit_command,
38169 - smart2e_intr_mask,
38170 - smart2e_fifo_full,
38171 - smart2e_intr_pending,
38172 - smart2e_completed,
38173 + .submit_command = smart2e_submit_command,
38174 + .set_intr_mask = smart2e_intr_mask,
38175 + .fifo_full = smart2e_fifo_full,
38176 + .intr_pending = smart2e_intr_pending,
38177 + .command_completed = smart2e_completed,
38178 };
38179
38180 /*
38181 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38182 }
38183
38184 static struct access_method smart1_access = {
38185 - smart1_submit_command,
38186 - smart1_intr_mask,
38187 - smart1_fifo_full,
38188 - smart1_intr_pending,
38189 - smart1_completed,
38190 + .submit_command = smart1_submit_command,
38191 + .set_intr_mask = smart1_intr_mask,
38192 + .fifo_full = smart1_fifo_full,
38193 + .intr_pending = smart1_intr_pending,
38194 + .command_completed = smart1_completed,
38195 };
38196 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38197 index f038dba..bb74c08 100644
38198 --- a/drivers/bluetooth/btwilink.c
38199 +++ b/drivers/bluetooth/btwilink.c
38200 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38201
38202 static int bt_ti_probe(struct platform_device *pdev)
38203 {
38204 - static struct ti_st *hst;
38205 + struct ti_st *hst;
38206 struct hci_dev *hdev;
38207 int err;
38208
38209 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38210 index 8a3aff7..d7538c2 100644
38211 --- a/drivers/cdrom/cdrom.c
38212 +++ b/drivers/cdrom/cdrom.c
38213 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38214 ENSURE(reset, CDC_RESET);
38215 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38216 cdi->mc_flags = 0;
38217 - cdo->n_minors = 0;
38218 cdi->options = CDO_USE_FFLAGS;
38219
38220 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38221 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38222 else
38223 cdi->cdda_method = CDDA_OLD;
38224
38225 - if (!cdo->generic_packet)
38226 - cdo->generic_packet = cdrom_dummy_generic_packet;
38227 + if (!cdo->generic_packet) {
38228 + pax_open_kernel();
38229 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38230 + pax_close_kernel();
38231 + }
38232
38233 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38234 mutex_lock(&cdrom_mutex);
38235 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38236 if (cdi->exit)
38237 cdi->exit(cdi);
38238
38239 - cdi->ops->n_minors--;
38240 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38241 }
38242
38243 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38244 */
38245 nr = nframes;
38246 do {
38247 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38248 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38249 if (cgc.buffer)
38250 break;
38251
38252 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38253 struct cdrom_device_info *cdi;
38254 int ret;
38255
38256 - ret = scnprintf(info + *pos, max_size - *pos, header);
38257 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38258 if (!ret)
38259 return 1;
38260
38261 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38262 index 51e75ad..39c4c76 100644
38263 --- a/drivers/cdrom/gdrom.c
38264 +++ b/drivers/cdrom/gdrom.c
38265 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38266 .audio_ioctl = gdrom_audio_ioctl,
38267 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38268 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38269 - .n_minors = 1,
38270 };
38271
38272 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38273 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38274 index 6e9f74a..50c7ceae 100644
38275 --- a/drivers/char/Kconfig
38276 +++ b/drivers/char/Kconfig
38277 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38278
38279 config DEVKMEM
38280 bool "/dev/kmem virtual device support"
38281 - default y
38282 + default n
38283 + depends on !GRKERNSEC_KMEM
38284 help
38285 Say Y here if you want to support the /dev/kmem device. The
38286 /dev/kmem device is rarely used, but can be used for certain
38287 @@ -577,6 +578,7 @@ config DEVPORT
38288 bool
38289 depends on !M68K
38290 depends on ISA || PCI
38291 + depends on !GRKERNSEC_KMEM
38292 default y
38293
38294 source "drivers/s390/char/Kconfig"
38295 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38296 index a48e05b..6bac831 100644
38297 --- a/drivers/char/agp/compat_ioctl.c
38298 +++ b/drivers/char/agp/compat_ioctl.c
38299 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38300 return -ENOMEM;
38301 }
38302
38303 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38304 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38305 sizeof(*usegment) * ureserve.seg_count)) {
38306 kfree(usegment);
38307 kfree(ksegment);
38308 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38309 index b297033..fa217ca 100644
38310 --- a/drivers/char/agp/frontend.c
38311 +++ b/drivers/char/agp/frontend.c
38312 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38313 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38314 return -EFAULT;
38315
38316 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38317 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38318 return -EFAULT;
38319
38320 client = agp_find_client_by_pid(reserve.pid);
38321 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38322 if (segment == NULL)
38323 return -ENOMEM;
38324
38325 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38326 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38327 sizeof(struct agp_segment) * reserve.seg_count)) {
38328 kfree(segment);
38329 return -EFAULT;
38330 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38331 index 4f94375..413694e 100644
38332 --- a/drivers/char/genrtc.c
38333 +++ b/drivers/char/genrtc.c
38334 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38335 switch (cmd) {
38336
38337 case RTC_PLL_GET:
38338 + memset(&pll, 0, sizeof(pll));
38339 if (get_rtc_pll(&pll))
38340 return -EINVAL;
38341 else
38342 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38343 index d5d4cd8..22d561d 100644
38344 --- a/drivers/char/hpet.c
38345 +++ b/drivers/char/hpet.c
38346 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38347 }
38348
38349 static int
38350 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38351 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38352 struct hpet_info *info)
38353 {
38354 struct hpet_timer __iomem *timer;
38355 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38356 index 86fe45c..c0ea948 100644
38357 --- a/drivers/char/hw_random/intel-rng.c
38358 +++ b/drivers/char/hw_random/intel-rng.c
38359 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38360
38361 if (no_fwh_detect)
38362 return -ENODEV;
38363 - printk(warning);
38364 + printk("%s", warning);
38365 return -EBUSY;
38366 }
38367
38368 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38369 index e6db938..835e3a2 100644
38370 --- a/drivers/char/ipmi/ipmi_msghandler.c
38371 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38372 @@ -438,7 +438,7 @@ struct ipmi_smi {
38373 struct proc_dir_entry *proc_dir;
38374 char proc_dir_name[10];
38375
38376 - atomic_t stats[IPMI_NUM_STATS];
38377 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38378
38379 /*
38380 * run_to_completion duplicate of smb_info, smi_info
38381 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38382 static DEFINE_MUTEX(smi_watchers_mutex);
38383
38384 #define ipmi_inc_stat(intf, stat) \
38385 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38386 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38387 #define ipmi_get_stat(intf, stat) \
38388 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38389 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38390
38391 static int is_lan_addr(struct ipmi_addr *addr)
38392 {
38393 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38394 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38395 init_waitqueue_head(&intf->waitq);
38396 for (i = 0; i < IPMI_NUM_STATS; i++)
38397 - atomic_set(&intf->stats[i], 0);
38398 + atomic_set_unchecked(&intf->stats[i], 0);
38399
38400 intf->proc_dir = NULL;
38401
38402 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38403 index 1c4bb4f..719e873 100644
38404 --- a/drivers/char/ipmi/ipmi_si_intf.c
38405 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38406 @@ -285,7 +285,7 @@ struct smi_info {
38407 unsigned char slave_addr;
38408
38409 /* Counters and things for the proc filesystem. */
38410 - atomic_t stats[SI_NUM_STATS];
38411 + atomic_unchecked_t stats[SI_NUM_STATS];
38412
38413 struct task_struct *thread;
38414
38415 @@ -294,9 +294,9 @@ struct smi_info {
38416 };
38417
38418 #define smi_inc_stat(smi, stat) \
38419 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38420 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38421 #define smi_get_stat(smi, stat) \
38422 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38423 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38424
38425 #define SI_MAX_PARMS 4
38426
38427 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38428 atomic_set(&new_smi->req_events, 0);
38429 new_smi->run_to_completion = false;
38430 for (i = 0; i < SI_NUM_STATS; i++)
38431 - atomic_set(&new_smi->stats[i], 0);
38432 + atomic_set_unchecked(&new_smi->stats[i], 0);
38433
38434 new_smi->interrupt_disabled = true;
38435 atomic_set(&new_smi->stop_operation, 0);
38436 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38437 index 917403f..dddd899 100644
38438 --- a/drivers/char/mem.c
38439 +++ b/drivers/char/mem.c
38440 @@ -18,6 +18,7 @@
38441 #include <linux/raw.h>
38442 #include <linux/tty.h>
38443 #include <linux/capability.h>
38444 +#include <linux/security.h>
38445 #include <linux/ptrace.h>
38446 #include <linux/device.h>
38447 #include <linux/highmem.h>
38448 @@ -36,6 +37,10 @@
38449
38450 #define DEVPORT_MINOR 4
38451
38452 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38453 +extern const struct file_operations grsec_fops;
38454 +#endif
38455 +
38456 static inline unsigned long size_inside_page(unsigned long start,
38457 unsigned long size)
38458 {
38459 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38460
38461 while (cursor < to) {
38462 if (!devmem_is_allowed(pfn)) {
38463 +#ifdef CONFIG_GRKERNSEC_KMEM
38464 + gr_handle_mem_readwrite(from, to);
38465 +#else
38466 printk(KERN_INFO
38467 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38468 current->comm, from, to);
38469 +#endif
38470 return 0;
38471 }
38472 cursor += PAGE_SIZE;
38473 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38474 }
38475 return 1;
38476 }
38477 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38478 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38479 +{
38480 + return 0;
38481 +}
38482 #else
38483 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38484 {
38485 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38486
38487 while (count > 0) {
38488 unsigned long remaining;
38489 + char *temp;
38490
38491 sz = size_inside_page(p, count);
38492
38493 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38494 if (!ptr)
38495 return -EFAULT;
38496
38497 - remaining = copy_to_user(buf, ptr, sz);
38498 +#ifdef CONFIG_PAX_USERCOPY
38499 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38500 + if (!temp) {
38501 + unxlate_dev_mem_ptr(p, ptr);
38502 + return -ENOMEM;
38503 + }
38504 + memcpy(temp, ptr, sz);
38505 +#else
38506 + temp = ptr;
38507 +#endif
38508 +
38509 + remaining = copy_to_user(buf, temp, sz);
38510 +
38511 +#ifdef CONFIG_PAX_USERCOPY
38512 + kfree(temp);
38513 +#endif
38514 +
38515 unxlate_dev_mem_ptr(p, ptr);
38516 if (remaining)
38517 return -EFAULT;
38518 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38519 size_t count, loff_t *ppos)
38520 {
38521 unsigned long p = *ppos;
38522 - ssize_t low_count, read, sz;
38523 + ssize_t low_count, read, sz, err = 0;
38524 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38525 - int err = 0;
38526
38527 read = 0;
38528 if (p < (unsigned long) high_memory) {
38529 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38530 }
38531 #endif
38532 while (low_count > 0) {
38533 + char *temp;
38534 +
38535 sz = size_inside_page(p, low_count);
38536
38537 /*
38538 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38539 */
38540 kbuf = xlate_dev_kmem_ptr((char *)p);
38541
38542 - if (copy_to_user(buf, kbuf, sz))
38543 +#ifdef CONFIG_PAX_USERCOPY
38544 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38545 + if (!temp)
38546 + return -ENOMEM;
38547 + memcpy(temp, kbuf, sz);
38548 +#else
38549 + temp = kbuf;
38550 +#endif
38551 +
38552 + err = copy_to_user(buf, temp, sz);
38553 +
38554 +#ifdef CONFIG_PAX_USERCOPY
38555 + kfree(temp);
38556 +#endif
38557 +
38558 + if (err)
38559 return -EFAULT;
38560 buf += sz;
38561 p += sz;
38562 @@ -827,6 +874,9 @@ static const struct memdev {
38563 #ifdef CONFIG_PRINTK
38564 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38565 #endif
38566 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38567 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38568 +#endif
38569 };
38570
38571 static int memory_open(struct inode *inode, struct file *filp)
38572 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38573 continue;
38574
38575 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38576 - NULL, devlist[minor].name);
38577 + NULL, "%s", devlist[minor].name);
38578 }
38579
38580 return tty_init();
38581 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38582 index 9df78e2..01ba9ae 100644
38583 --- a/drivers/char/nvram.c
38584 +++ b/drivers/char/nvram.c
38585 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38586
38587 spin_unlock_irq(&rtc_lock);
38588
38589 - if (copy_to_user(buf, contents, tmp - contents))
38590 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38591 return -EFAULT;
38592
38593 *ppos = i;
38594 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38595 index 8320abd..ec48108 100644
38596 --- a/drivers/char/pcmcia/synclink_cs.c
38597 +++ b/drivers/char/pcmcia/synclink_cs.c
38598 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38599
38600 if (debug_level >= DEBUG_LEVEL_INFO)
38601 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38602 - __FILE__, __LINE__, info->device_name, port->count);
38603 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38604
38605 - WARN_ON(!port->count);
38606 + WARN_ON(!atomic_read(&port->count));
38607
38608 if (tty_port_close_start(port, tty, filp) == 0)
38609 goto cleanup;
38610 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38611 cleanup:
38612 if (debug_level >= DEBUG_LEVEL_INFO)
38613 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38614 - tty->driver->name, port->count);
38615 + tty->driver->name, atomic_read(&port->count));
38616 }
38617
38618 /* Wait until the transmitter is empty.
38619 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38620
38621 if (debug_level >= DEBUG_LEVEL_INFO)
38622 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38623 - __FILE__, __LINE__, tty->driver->name, port->count);
38624 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38625
38626 /* If port is closing, signal caller to try again */
38627 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38628 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38629 goto cleanup;
38630 }
38631 spin_lock(&port->lock);
38632 - port->count++;
38633 + atomic_inc(&port->count);
38634 spin_unlock(&port->lock);
38635 spin_unlock_irqrestore(&info->netlock, flags);
38636
38637 - if (port->count == 1) {
38638 + if (atomic_read(&port->count) == 1) {
38639 /* 1st open on this device, init hardware */
38640 retval = startup(info, tty);
38641 if (retval < 0)
38642 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38643 unsigned short new_crctype;
38644
38645 /* return error if TTY interface open */
38646 - if (info->port.count)
38647 + if (atomic_read(&info->port.count))
38648 return -EBUSY;
38649
38650 switch (encoding)
38651 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38652
38653 /* arbitrate between network and tty opens */
38654 spin_lock_irqsave(&info->netlock, flags);
38655 - if (info->port.count != 0 || info->netcount != 0) {
38656 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38657 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38658 spin_unlock_irqrestore(&info->netlock, flags);
38659 return -EBUSY;
38660 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38661 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38662
38663 /* return error if TTY interface open */
38664 - if (info->port.count)
38665 + if (atomic_read(&info->port.count))
38666 return -EBUSY;
38667
38668 if (cmd != SIOCWANDEV)
38669 diff --git a/drivers/char/random.c b/drivers/char/random.c
38670 index 2b6e4cd..43d7ae1 100644
38671 --- a/drivers/char/random.c
38672 +++ b/drivers/char/random.c
38673 @@ -270,10 +270,17 @@
38674 /*
38675 * Configuration information
38676 */
38677 +#ifdef CONFIG_GRKERNSEC_RANDNET
38678 +#define INPUT_POOL_SHIFT 14
38679 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38680 +#define OUTPUT_POOL_SHIFT 12
38681 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38682 +#else
38683 #define INPUT_POOL_SHIFT 12
38684 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38685 #define OUTPUT_POOL_SHIFT 10
38686 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38687 +#endif
38688 #define SEC_XFER_SIZE 512
38689 #define EXTRACT_SIZE 10
38690
38691 @@ -284,9 +291,6 @@
38692 /*
38693 * To allow fractional bits to be tracked, the entropy_count field is
38694 * denominated in units of 1/8th bits.
38695 - *
38696 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38697 - * credit_entropy_bits() needs to be 64 bits wide.
38698 */
38699 #define ENTROPY_SHIFT 3
38700 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38701 @@ -361,12 +365,19 @@ static struct poolinfo {
38702 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38703 int tap1, tap2, tap3, tap4, tap5;
38704 } poolinfo_table[] = {
38705 +#ifdef CONFIG_GRKERNSEC_RANDNET
38706 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38707 + { S(512), 411, 308, 208, 104, 1 },
38708 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38709 + { S(128), 104, 76, 51, 25, 1 },
38710 +#else
38711 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38712 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38713 { S(128), 104, 76, 51, 25, 1 },
38714 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38715 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38716 { S(32), 26, 19, 14, 7, 1 },
38717 +#endif
38718 #if 0
38719 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38720 { S(2048), 1638, 1231, 819, 411, 1 },
38721 @@ -433,9 +444,9 @@ struct entropy_store {
38722 };
38723
38724 static void push_to_pool(struct work_struct *work);
38725 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38726 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38727 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38728 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38729 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38730 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38731
38732 static struct entropy_store input_pool = {
38733 .poolinfo = &poolinfo_table[0],
38734 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38735 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38736 }
38737
38738 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38739 - ACCESS_ONCE(r->add_ptr) = i;
38740 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38741 + ACCESS_ONCE_RW(r->add_ptr) = i;
38742 smp_wmb();
38743
38744 if (out)
38745 @@ -632,7 +643,7 @@ retry:
38746 /* The +2 corresponds to the /4 in the denominator */
38747
38748 do {
38749 - unsigned int anfrac = min(pnfrac, pool_size/2);
38750 + u64 anfrac = min(pnfrac, pool_size/2);
38751 unsigned int add =
38752 ((pool_size - entropy_count)*anfrac*3) >> s;
38753
38754 @@ -1166,7 +1177,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38755
38756 extract_buf(r, tmp);
38757 i = min_t(int, nbytes, EXTRACT_SIZE);
38758 - if (copy_to_user(buf, tmp, i)) {
38759 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38760 ret = -EFAULT;
38761 break;
38762 }
38763 @@ -1555,7 +1566,7 @@ static char sysctl_bootid[16];
38764 static int proc_do_uuid(struct ctl_table *table, int write,
38765 void __user *buffer, size_t *lenp, loff_t *ppos)
38766 {
38767 - struct ctl_table fake_table;
38768 + ctl_table_no_const fake_table;
38769 unsigned char buf[64], tmp_uuid[16], *uuid;
38770
38771 uuid = table->data;
38772 @@ -1585,7 +1596,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38773 static int proc_do_entropy(ctl_table *table, int write,
38774 void __user *buffer, size_t *lenp, loff_t *ppos)
38775 {
38776 - ctl_table fake_table;
38777 + ctl_table_no_const fake_table;
38778 int entropy_count;
38779
38780 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38781 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38782 index 7cc1fe22..b602d6b 100644
38783 --- a/drivers/char/sonypi.c
38784 +++ b/drivers/char/sonypi.c
38785 @@ -54,6 +54,7 @@
38786
38787 #include <asm/uaccess.h>
38788 #include <asm/io.h>
38789 +#include <asm/local.h>
38790
38791 #include <linux/sonypi.h>
38792
38793 @@ -490,7 +491,7 @@ static struct sonypi_device {
38794 spinlock_t fifo_lock;
38795 wait_queue_head_t fifo_proc_list;
38796 struct fasync_struct *fifo_async;
38797 - int open_count;
38798 + local_t open_count;
38799 int model;
38800 struct input_dev *input_jog_dev;
38801 struct input_dev *input_key_dev;
38802 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38803 static int sonypi_misc_release(struct inode *inode, struct file *file)
38804 {
38805 mutex_lock(&sonypi_device.lock);
38806 - sonypi_device.open_count--;
38807 + local_dec(&sonypi_device.open_count);
38808 mutex_unlock(&sonypi_device.lock);
38809 return 0;
38810 }
38811 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38812 {
38813 mutex_lock(&sonypi_device.lock);
38814 /* Flush input queue on first open */
38815 - if (!sonypi_device.open_count)
38816 + if (!local_read(&sonypi_device.open_count))
38817 kfifo_reset(&sonypi_device.fifo);
38818 - sonypi_device.open_count++;
38819 + local_inc(&sonypi_device.open_count);
38820 mutex_unlock(&sonypi_device.lock);
38821
38822 return 0;
38823 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38824 index b9a57fa..5bb9e38 100644
38825 --- a/drivers/char/tpm/tpm_acpi.c
38826 +++ b/drivers/char/tpm/tpm_acpi.c
38827 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38828 virt = acpi_os_map_memory(start, len);
38829 if (!virt) {
38830 kfree(log->bios_event_log);
38831 + log->bios_event_log = NULL;
38832 printk("%s: ERROR - Unable to map memory\n", __func__);
38833 return -EIO;
38834 }
38835
38836 - memcpy_fromio(log->bios_event_log, virt, len);
38837 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38838
38839 acpi_os_unmap_memory(virt, len);
38840 return 0;
38841 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38842 index 59f7cb2..bac8b6d 100644
38843 --- a/drivers/char/tpm/tpm_eventlog.c
38844 +++ b/drivers/char/tpm/tpm_eventlog.c
38845 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38846 event = addr;
38847
38848 if ((event->event_type == 0 && event->event_size == 0) ||
38849 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38850 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38851 return NULL;
38852
38853 return addr;
38854 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38855 return NULL;
38856
38857 if ((event->event_type == 0 && event->event_size == 0) ||
38858 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38859 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38860 return NULL;
38861
38862 (*pos)++;
38863 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38864 int i;
38865
38866 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38867 - seq_putc(m, data[i]);
38868 + if (!seq_putc(m, data[i]))
38869 + return -EFAULT;
38870
38871 return 0;
38872 }
38873 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38874 index 60aafb8..10c08e0 100644
38875 --- a/drivers/char/virtio_console.c
38876 +++ b/drivers/char/virtio_console.c
38877 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38878 if (to_user) {
38879 ssize_t ret;
38880
38881 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38882 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38883 if (ret)
38884 return -EFAULT;
38885 } else {
38886 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38887 if (!port_has_data(port) && !port->host_connected)
38888 return 0;
38889
38890 - return fill_readbuf(port, ubuf, count, true);
38891 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38892 }
38893
38894 static int wait_port_writable(struct port *port, bool nonblock)
38895 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38896 index 57a078e..c17cde8 100644
38897 --- a/drivers/clk/clk-composite.c
38898 +++ b/drivers/clk/clk-composite.c
38899 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38900 struct clk *clk;
38901 struct clk_init_data init;
38902 struct clk_composite *composite;
38903 - struct clk_ops *clk_composite_ops;
38904 + clk_ops_no_const *clk_composite_ops;
38905
38906 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38907 if (!composite) {
38908 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38909 index 501d513..fb0ecf9 100644
38910 --- a/drivers/clk/socfpga/clk-gate.c
38911 +++ b/drivers/clk/socfpga/clk-gate.c
38912 @@ -22,6 +22,7 @@
38913 #include <linux/mfd/syscon.h>
38914 #include <linux/of.h>
38915 #include <linux/regmap.h>
38916 +#include <asm/pgtable.h>
38917
38918 #include "clk.h"
38919
38920 @@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38921 return 0;
38922 }
38923
38924 -static struct clk_ops gateclk_ops = {
38925 +static clk_ops_no_const gateclk_ops __read_only = {
38926 .prepare = socfpga_clk_prepare,
38927 .recalc_rate = socfpga_clk_recalc_rate,
38928 .get_parent = socfpga_clk_get_parent,
38929 @@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38930 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38931 socfpga_clk->hw.bit_idx = clk_gate[1];
38932
38933 - gateclk_ops.enable = clk_gate_ops.enable;
38934 - gateclk_ops.disable = clk_gate_ops.disable;
38935 + pax_open_kernel();
38936 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38937 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38938 + pax_close_kernel();
38939 }
38940
38941 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38942 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38943 index de6da95..a2e72c0 100644
38944 --- a/drivers/clk/socfpga/clk-pll.c
38945 +++ b/drivers/clk/socfpga/clk-pll.c
38946 @@ -21,6 +21,7 @@
38947 #include <linux/io.h>
38948 #include <linux/of.h>
38949 #include <linux/of_address.h>
38950 +#include <asm/pgtable.h>
38951
38952 #include "clk.h"
38953
38954 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38955 CLK_MGR_PLL_CLK_SRC_MASK;
38956 }
38957
38958 -static struct clk_ops clk_pll_ops = {
38959 +static struct clk_ops_no_const clk_pll_ops __read_only = {
38960 .recalc_rate = clk_pll_recalc_rate,
38961 .get_parent = clk_pll_get_parent,
38962 };
38963 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
38964 pll_clk->hw.hw.init = &init;
38965
38966 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38967 - clk_pll_ops.enable = clk_gate_ops.enable;
38968 - clk_pll_ops.disable = clk_gate_ops.disable;
38969 + pax_open_kernel();
38970 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38971 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38972 + pax_close_kernel();
38973
38974 clk = clk_register(NULL, &pll_clk->hw.hw);
38975 if (WARN_ON(IS_ERR(clk))) {
38976 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38977 index 000e4e0..4770351 100644
38978 --- a/drivers/cpufreq/acpi-cpufreq.c
38979 +++ b/drivers/cpufreq/acpi-cpufreq.c
38980 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38981 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38982 per_cpu(acfreq_data, cpu) = data;
38983
38984 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38985 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38986 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38987 + pax_open_kernel();
38988 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38989 + pax_close_kernel();
38990 + }
38991
38992 result = acpi_processor_register_performance(data->acpi_data, cpu);
38993 if (result)
38994 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38995 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38996 break;
38997 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38998 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38999 + pax_open_kernel();
39000 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39001 + pax_close_kernel();
39002 break;
39003 default:
39004 break;
39005 @@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39006 if (!msrs)
39007 return;
39008
39009 - acpi_cpufreq_driver.boost_supported = true;
39010 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39011 + pax_open_kernel();
39012 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39013 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39014 + pax_close_kernel();
39015
39016 cpu_notifier_register_begin();
39017
39018 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39019 index abda660..f1d1de0 100644
39020 --- a/drivers/cpufreq/cpufreq.c
39021 +++ b/drivers/cpufreq/cpufreq.c
39022 @@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39023 }
39024
39025 mutex_lock(&cpufreq_governor_mutex);
39026 - list_del(&governor->governor_list);
39027 + pax_list_del(&governor->governor_list);
39028 mutex_unlock(&cpufreq_governor_mutex);
39029 return;
39030 }
39031 @@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39032 return NOTIFY_OK;
39033 }
39034
39035 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39036 +static struct notifier_block cpufreq_cpu_notifier = {
39037 .notifier_call = cpufreq_cpu_callback,
39038 };
39039
39040 @@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39041 return 0;
39042
39043 write_lock_irqsave(&cpufreq_driver_lock, flags);
39044 - cpufreq_driver->boost_enabled = state;
39045 + pax_open_kernel();
39046 + *(bool *)&cpufreq_driver->boost_enabled = state;
39047 + pax_close_kernel();
39048 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39049
39050 ret = cpufreq_driver->set_boost(state);
39051 if (ret) {
39052 write_lock_irqsave(&cpufreq_driver_lock, flags);
39053 - cpufreq_driver->boost_enabled = !state;
39054 + pax_open_kernel();
39055 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39056 + pax_close_kernel();
39057 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39058
39059 pr_err("%s: Cannot %s BOOST\n",
39060 @@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39061
39062 pr_debug("trying to register driver %s\n", driver_data->name);
39063
39064 - if (driver_data->setpolicy)
39065 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39066 + if (driver_data->setpolicy) {
39067 + pax_open_kernel();
39068 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39069 + pax_close_kernel();
39070 + }
39071
39072 write_lock_irqsave(&cpufreq_driver_lock, flags);
39073 if (cpufreq_driver) {
39074 @@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39075 * Check if driver provides function to enable boost -
39076 * if not, use cpufreq_boost_set_sw as default
39077 */
39078 - if (!cpufreq_driver->set_boost)
39079 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39080 + if (!cpufreq_driver->set_boost) {
39081 + pax_open_kernel();
39082 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39083 + pax_close_kernel();
39084 + }
39085
39086 ret = cpufreq_sysfs_create_file(&boost.attr);
39087 if (ret) {
39088 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39089 index e1c6433..31203ae 100644
39090 --- a/drivers/cpufreq/cpufreq_governor.c
39091 +++ b/drivers/cpufreq/cpufreq_governor.c
39092 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39093 struct dbs_data *dbs_data;
39094 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39095 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39096 - struct od_ops *od_ops = NULL;
39097 + const struct od_ops *od_ops = NULL;
39098 struct od_dbs_tuners *od_tuners = NULL;
39099 struct cs_dbs_tuners *cs_tuners = NULL;
39100 struct cpu_dbs_common_info *cpu_cdbs;
39101 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39102
39103 if ((cdata->governor == GOV_CONSERVATIVE) &&
39104 (!policy->governor->initialized)) {
39105 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39106 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39107
39108 cpufreq_register_notifier(cs_ops->notifier_block,
39109 CPUFREQ_TRANSITION_NOTIFIER);
39110 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39111
39112 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39113 (policy->governor->initialized == 1)) {
39114 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39115 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39116
39117 cpufreq_unregister_notifier(cs_ops->notifier_block,
39118 CPUFREQ_TRANSITION_NOTIFIER);
39119 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39120 index bfb9ae1..e1d3a7e 100644
39121 --- a/drivers/cpufreq/cpufreq_governor.h
39122 +++ b/drivers/cpufreq/cpufreq_governor.h
39123 @@ -205,7 +205,7 @@ struct common_dbs_data {
39124 void (*exit)(struct dbs_data *dbs_data);
39125
39126 /* Governor specific ops, see below */
39127 - void *gov_ops;
39128 + const void *gov_ops;
39129 };
39130
39131 /* Governor Per policy data */
39132 @@ -225,7 +225,7 @@ struct od_ops {
39133 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39134 unsigned int freq_next, unsigned int relation);
39135 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39136 -};
39137 +} __no_const;
39138
39139 struct cs_ops {
39140 struct notifier_block *notifier_block;
39141 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39142 index 18d4091..434be15 100644
39143 --- a/drivers/cpufreq/cpufreq_ondemand.c
39144 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39145 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39146
39147 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39148
39149 -static struct od_ops od_ops = {
39150 +static struct od_ops od_ops __read_only = {
39151 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39152 .powersave_bias_target = generic_powersave_bias_target,
39153 .freq_increase = dbs_freq_increase,
39154 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39155 (struct cpufreq_policy *, unsigned int, unsigned int),
39156 unsigned int powersave_bias)
39157 {
39158 - od_ops.powersave_bias_target = f;
39159 + pax_open_kernel();
39160 + *(void **)&od_ops.powersave_bias_target = f;
39161 + pax_close_kernel();
39162 od_set_powersave_bias(powersave_bias);
39163 }
39164 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39165
39166 void od_unregister_powersave_bias_handler(void)
39167 {
39168 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39169 + pax_open_kernel();
39170 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39171 + pax_close_kernel();
39172 od_set_powersave_bias(0);
39173 }
39174 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39175 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39176 index db2e45b..72c7d37 100644
39177 --- a/drivers/cpufreq/intel_pstate.c
39178 +++ b/drivers/cpufreq/intel_pstate.c
39179 @@ -125,10 +125,10 @@ struct pstate_funcs {
39180 struct cpu_defaults {
39181 struct pstate_adjust_policy pid_policy;
39182 struct pstate_funcs funcs;
39183 -};
39184 +} __do_const;
39185
39186 static struct pstate_adjust_policy pid_params;
39187 -static struct pstate_funcs pstate_funcs;
39188 +static struct pstate_funcs *pstate_funcs;
39189
39190 struct perf_limits {
39191 int no_turbo;
39192 @@ -529,7 +529,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39193
39194 cpu->pstate.current_pstate = pstate;
39195
39196 - pstate_funcs.set(cpu, pstate);
39197 + pstate_funcs->set(cpu, pstate);
39198 }
39199
39200 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39201 @@ -551,12 +551,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39202 {
39203 sprintf(cpu->name, "Intel 2nd generation core");
39204
39205 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39206 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39207 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39208 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39209 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39210 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39211
39212 - if (pstate_funcs.get_vid)
39213 - pstate_funcs.get_vid(cpu);
39214 + if (pstate_funcs->get_vid)
39215 + pstate_funcs->get_vid(cpu);
39216 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39217 }
39218
39219 @@ -841,9 +841,9 @@ static int intel_pstate_msrs_not_valid(void)
39220 rdmsrl(MSR_IA32_APERF, aperf);
39221 rdmsrl(MSR_IA32_MPERF, mperf);
39222
39223 - if (!pstate_funcs.get_max() ||
39224 - !pstate_funcs.get_min() ||
39225 - !pstate_funcs.get_turbo())
39226 + if (!pstate_funcs->get_max() ||
39227 + !pstate_funcs->get_min() ||
39228 + !pstate_funcs->get_turbo())
39229 return -ENODEV;
39230
39231 rdmsrl(MSR_IA32_APERF, tmp);
39232 @@ -857,7 +857,7 @@ static int intel_pstate_msrs_not_valid(void)
39233 return 0;
39234 }
39235
39236 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39237 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39238 {
39239 pid_params.sample_rate_ms = policy->sample_rate_ms;
39240 pid_params.p_gain_pct = policy->p_gain_pct;
39241 @@ -869,11 +869,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39242
39243 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39244 {
39245 - pstate_funcs.get_max = funcs->get_max;
39246 - pstate_funcs.get_min = funcs->get_min;
39247 - pstate_funcs.get_turbo = funcs->get_turbo;
39248 - pstate_funcs.set = funcs->set;
39249 - pstate_funcs.get_vid = funcs->get_vid;
39250 + pstate_funcs = funcs;
39251 }
39252
39253 #if IS_ENABLED(CONFIG_ACPI)
39254 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39255 index 529cfd9..0e28fff 100644
39256 --- a/drivers/cpufreq/p4-clockmod.c
39257 +++ b/drivers/cpufreq/p4-clockmod.c
39258 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39259 case 0x0F: /* Core Duo */
39260 case 0x16: /* Celeron Core */
39261 case 0x1C: /* Atom */
39262 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39263 + pax_open_kernel();
39264 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39265 + pax_close_kernel();
39266 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39267 case 0x0D: /* Pentium M (Dothan) */
39268 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39269 + pax_open_kernel();
39270 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39271 + pax_close_kernel();
39272 /* fall through */
39273 case 0x09: /* Pentium M (Banias) */
39274 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39275 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39276
39277 /* on P-4s, the TSC runs with constant frequency independent whether
39278 * throttling is active or not. */
39279 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39280 + pax_open_kernel();
39281 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39282 + pax_close_kernel();
39283
39284 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39285 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39286 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39287 index 9bb42ba..b01b4a2 100644
39288 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39289 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39290 @@ -18,14 +18,12 @@
39291 #include <asm/head.h>
39292 #include <asm/timer.h>
39293
39294 -static struct cpufreq_driver *cpufreq_us3_driver;
39295 -
39296 struct us3_freq_percpu_info {
39297 struct cpufreq_frequency_table table[4];
39298 };
39299
39300 /* Indexed by cpu number. */
39301 -static struct us3_freq_percpu_info *us3_freq_table;
39302 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39303
39304 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39305 * in the Safari config register.
39306 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39307
39308 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39309 {
39310 - if (cpufreq_us3_driver)
39311 - us3_freq_target(policy, 0);
39312 + us3_freq_target(policy, 0);
39313
39314 return 0;
39315 }
39316
39317 +static int __init us3_freq_init(void);
39318 +static void __exit us3_freq_exit(void);
39319 +
39320 +static struct cpufreq_driver cpufreq_us3_driver = {
39321 + .init = us3_freq_cpu_init,
39322 + .verify = cpufreq_generic_frequency_table_verify,
39323 + .target_index = us3_freq_target,
39324 + .get = us3_freq_get,
39325 + .exit = us3_freq_cpu_exit,
39326 + .name = "UltraSPARC-III",
39327 +
39328 +};
39329 +
39330 static int __init us3_freq_init(void)
39331 {
39332 unsigned long manuf, impl, ver;
39333 - int ret;
39334
39335 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39336 return -ENODEV;
39337 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39338 (impl == CHEETAH_IMPL ||
39339 impl == CHEETAH_PLUS_IMPL ||
39340 impl == JAGUAR_IMPL ||
39341 - impl == PANTHER_IMPL)) {
39342 - struct cpufreq_driver *driver;
39343 -
39344 - ret = -ENOMEM;
39345 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39346 - if (!driver)
39347 - goto err_out;
39348 -
39349 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39350 - GFP_KERNEL);
39351 - if (!us3_freq_table)
39352 - goto err_out;
39353 -
39354 - driver->init = us3_freq_cpu_init;
39355 - driver->verify = cpufreq_generic_frequency_table_verify;
39356 - driver->target_index = us3_freq_target;
39357 - driver->get = us3_freq_get;
39358 - driver->exit = us3_freq_cpu_exit;
39359 - strcpy(driver->name, "UltraSPARC-III");
39360 -
39361 - cpufreq_us3_driver = driver;
39362 - ret = cpufreq_register_driver(driver);
39363 - if (ret)
39364 - goto err_out;
39365 -
39366 - return 0;
39367 -
39368 -err_out:
39369 - if (driver) {
39370 - kfree(driver);
39371 - cpufreq_us3_driver = NULL;
39372 - }
39373 - kfree(us3_freq_table);
39374 - us3_freq_table = NULL;
39375 - return ret;
39376 - }
39377 + impl == PANTHER_IMPL))
39378 + return cpufreq_register_driver(&cpufreq_us3_driver);
39379
39380 return -ENODEV;
39381 }
39382
39383 static void __exit us3_freq_exit(void)
39384 {
39385 - if (cpufreq_us3_driver) {
39386 - cpufreq_unregister_driver(cpufreq_us3_driver);
39387 - kfree(cpufreq_us3_driver);
39388 - cpufreq_us3_driver = NULL;
39389 - kfree(us3_freq_table);
39390 - us3_freq_table = NULL;
39391 - }
39392 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39393 }
39394
39395 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39396 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39397 index 6723f03..3465190 100644
39398 --- a/drivers/cpufreq/speedstep-centrino.c
39399 +++ b/drivers/cpufreq/speedstep-centrino.c
39400 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39401 !cpu_has(cpu, X86_FEATURE_EST))
39402 return -ENODEV;
39403
39404 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39405 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39406 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39407 + pax_open_kernel();
39408 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39409 + pax_close_kernel();
39410 + }
39411
39412 if (policy->cpu != 0)
39413 return -ENODEV;
39414 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39415 index 136d6a2..06e373d 100644
39416 --- a/drivers/cpuidle/driver.c
39417 +++ b/drivers/cpuidle/driver.c
39418 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39419
39420 static void poll_idle_init(struct cpuidle_driver *drv)
39421 {
39422 - struct cpuidle_state *state = &drv->states[0];
39423 + cpuidle_state_no_const *state = &drv->states[0];
39424
39425 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39426 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39427 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39428 index ca89412..a7b9c49 100644
39429 --- a/drivers/cpuidle/governor.c
39430 +++ b/drivers/cpuidle/governor.c
39431 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39432 mutex_lock(&cpuidle_lock);
39433 if (__cpuidle_find_governor(gov->name) == NULL) {
39434 ret = 0;
39435 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39436 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39437 if (!cpuidle_curr_governor ||
39438 cpuidle_curr_governor->rating < gov->rating)
39439 cpuidle_switch_governor(gov);
39440 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39441 index efe2f17..b8124f9 100644
39442 --- a/drivers/cpuidle/sysfs.c
39443 +++ b/drivers/cpuidle/sysfs.c
39444 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39445 NULL
39446 };
39447
39448 -static struct attribute_group cpuidle_attr_group = {
39449 +static attribute_group_no_const cpuidle_attr_group = {
39450 .attrs = cpuidle_default_attrs,
39451 .name = "cpuidle",
39452 };
39453 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39454 index 12fea3e..1e28f47 100644
39455 --- a/drivers/crypto/hifn_795x.c
39456 +++ b/drivers/crypto/hifn_795x.c
39457 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39458 MODULE_PARM_DESC(hifn_pll_ref,
39459 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39460
39461 -static atomic_t hifn_dev_number;
39462 +static atomic_unchecked_t hifn_dev_number;
39463
39464 #define ACRYPTO_OP_DECRYPT 0
39465 #define ACRYPTO_OP_ENCRYPT 1
39466 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39467 goto err_out_disable_pci_device;
39468
39469 snprintf(name, sizeof(name), "hifn%d",
39470 - atomic_inc_return(&hifn_dev_number)-1);
39471 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39472
39473 err = pci_request_regions(pdev, name);
39474 if (err)
39475 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39476 index 2042ec3..a9ce67f 100644
39477 --- a/drivers/devfreq/devfreq.c
39478 +++ b/drivers/devfreq/devfreq.c
39479 @@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39480 goto err_out;
39481 }
39482
39483 - list_add(&governor->node, &devfreq_governor_list);
39484 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39485
39486 list_for_each_entry(devfreq, &devfreq_list, node) {
39487 int ret = 0;
39488 @@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39489 }
39490 }
39491
39492 - list_del(&governor->node);
39493 + pax_list_del((struct list_head *)&governor->node);
39494 err_out:
39495 mutex_unlock(&devfreq_list_lock);
39496
39497 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39498 index 5239677..1cb71a8 100644
39499 --- a/drivers/dma/sh/shdma-base.c
39500 +++ b/drivers/dma/sh/shdma-base.c
39501 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39502 schan->slave_id = -EINVAL;
39503 }
39504
39505 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39506 - sdev->desc_size, GFP_KERNEL);
39507 + schan->desc = kcalloc(sdev->desc_size,
39508 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39509 if (!schan->desc) {
39510 ret = -ENOMEM;
39511 goto edescalloc;
39512 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39513 index dda7e75..0a4c867 100644
39514 --- a/drivers/dma/sh/shdmac.c
39515 +++ b/drivers/dma/sh/shdmac.c
39516 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39517 return ret;
39518 }
39519
39520 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39521 +static struct notifier_block sh_dmae_nmi_notifier = {
39522 .notifier_call = sh_dmae_nmi_handler,
39523
39524 /* Run before NMI debug handler and KGDB */
39525 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39526 index 592af5f..bb1d583 100644
39527 --- a/drivers/edac/edac_device.c
39528 +++ b/drivers/edac/edac_device.c
39529 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39530 */
39531 int edac_device_alloc_index(void)
39532 {
39533 - static atomic_t device_indexes = ATOMIC_INIT(0);
39534 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39535
39536 - return atomic_inc_return(&device_indexes) - 1;
39537 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39538 }
39539 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39540
39541 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39542 index 01fae82..1dd8289 100644
39543 --- a/drivers/edac/edac_mc_sysfs.c
39544 +++ b/drivers/edac/edac_mc_sysfs.c
39545 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39546 struct dev_ch_attribute {
39547 struct device_attribute attr;
39548 int channel;
39549 -};
39550 +} __do_const;
39551
39552 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39553 struct dev_ch_attribute dev_attr_legacy_##_name = \
39554 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39555 }
39556
39557 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39558 + pax_open_kernel();
39559 if (mci->get_sdram_scrub_rate) {
39560 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39561 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39562 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39563 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39564 }
39565 if (mci->set_sdram_scrub_rate) {
39566 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39567 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39568 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39569 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39570 }
39571 + pax_close_kernel();
39572 err = device_create_file(&mci->dev,
39573 &dev_attr_sdram_scrub_rate);
39574 if (err) {
39575 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39576 index 2cf44b4d..6dd2dc7 100644
39577 --- a/drivers/edac/edac_pci.c
39578 +++ b/drivers/edac/edac_pci.c
39579 @@ -29,7 +29,7 @@
39580
39581 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39582 static LIST_HEAD(edac_pci_list);
39583 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39584 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39585
39586 /*
39587 * edac_pci_alloc_ctl_info
39588 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39589 */
39590 int edac_pci_alloc_index(void)
39591 {
39592 - return atomic_inc_return(&pci_indexes) - 1;
39593 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39594 }
39595 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39596
39597 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39598 index e8658e4..22746d6 100644
39599 --- a/drivers/edac/edac_pci_sysfs.c
39600 +++ b/drivers/edac/edac_pci_sysfs.c
39601 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39602 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39603 static int edac_pci_poll_msec = 1000; /* one second workq period */
39604
39605 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39606 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39607 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39608 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39609
39610 static struct kobject *edac_pci_top_main_kobj;
39611 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39612 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39613 void *value;
39614 ssize_t(*show) (void *, char *);
39615 ssize_t(*store) (void *, const char *, size_t);
39616 -};
39617 +} __do_const;
39618
39619 /* Set of show/store abstract level functions for PCI Parity object */
39620 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39621 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39622 edac_printk(KERN_CRIT, EDAC_PCI,
39623 "Signaled System Error on %s\n",
39624 pci_name(dev));
39625 - atomic_inc(&pci_nonparity_count);
39626 + atomic_inc_unchecked(&pci_nonparity_count);
39627 }
39628
39629 if (status & (PCI_STATUS_PARITY)) {
39630 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39631 "Master Data Parity Error on %s\n",
39632 pci_name(dev));
39633
39634 - atomic_inc(&pci_parity_count);
39635 + atomic_inc_unchecked(&pci_parity_count);
39636 }
39637
39638 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39639 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39640 "Detected Parity Error on %s\n",
39641 pci_name(dev));
39642
39643 - atomic_inc(&pci_parity_count);
39644 + atomic_inc_unchecked(&pci_parity_count);
39645 }
39646 }
39647
39648 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39649 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39650 "Signaled System Error on %s\n",
39651 pci_name(dev));
39652 - atomic_inc(&pci_nonparity_count);
39653 + atomic_inc_unchecked(&pci_nonparity_count);
39654 }
39655
39656 if (status & (PCI_STATUS_PARITY)) {
39657 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39658 "Master Data Parity Error on "
39659 "%s\n", pci_name(dev));
39660
39661 - atomic_inc(&pci_parity_count);
39662 + atomic_inc_unchecked(&pci_parity_count);
39663 }
39664
39665 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39666 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39667 "Detected Parity Error on %s\n",
39668 pci_name(dev));
39669
39670 - atomic_inc(&pci_parity_count);
39671 + atomic_inc_unchecked(&pci_parity_count);
39672 }
39673 }
39674 }
39675 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39676 if (!check_pci_errors)
39677 return;
39678
39679 - before_count = atomic_read(&pci_parity_count);
39680 + before_count = atomic_read_unchecked(&pci_parity_count);
39681
39682 /* scan all PCI devices looking for a Parity Error on devices and
39683 * bridges.
39684 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39685 /* Only if operator has selected panic on PCI Error */
39686 if (edac_pci_get_panic_on_pe()) {
39687 /* If the count is different 'after' from 'before' */
39688 - if (before_count != atomic_read(&pci_parity_count))
39689 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39690 panic("EDAC: PCI Parity Error");
39691 }
39692 }
39693 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39694 index 51b7e3a..aa8a3e8 100644
39695 --- a/drivers/edac/mce_amd.h
39696 +++ b/drivers/edac/mce_amd.h
39697 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39698 bool (*mc0_mce)(u16, u8);
39699 bool (*mc1_mce)(u16, u8);
39700 bool (*mc2_mce)(u16, u8);
39701 -};
39702 +} __no_const;
39703
39704 void amd_report_gart_errors(bool);
39705 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39706 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39707 index 57ea7f4..af06b76 100644
39708 --- a/drivers/firewire/core-card.c
39709 +++ b/drivers/firewire/core-card.c
39710 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39711 const struct fw_card_driver *driver,
39712 struct device *device)
39713 {
39714 - static atomic_t index = ATOMIC_INIT(-1);
39715 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39716
39717 - card->index = atomic_inc_return(&index);
39718 + card->index = atomic_inc_return_unchecked(&index);
39719 card->driver = driver;
39720 card->device = device;
39721 card->current_tlabel = 0;
39722 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39723
39724 void fw_core_remove_card(struct fw_card *card)
39725 {
39726 - struct fw_card_driver dummy_driver = dummy_driver_template;
39727 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39728
39729 card->driver->update_phy_reg(card, 4,
39730 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39731 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39732 index 2c6d5e1..a2cca6b 100644
39733 --- a/drivers/firewire/core-device.c
39734 +++ b/drivers/firewire/core-device.c
39735 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39736 struct config_rom_attribute {
39737 struct device_attribute attr;
39738 u32 key;
39739 -};
39740 +} __do_const;
39741
39742 static ssize_t show_immediate(struct device *dev,
39743 struct device_attribute *dattr, char *buf)
39744 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39745 index eb6935c..3cc2bfa 100644
39746 --- a/drivers/firewire/core-transaction.c
39747 +++ b/drivers/firewire/core-transaction.c
39748 @@ -38,6 +38,7 @@
39749 #include <linux/timer.h>
39750 #include <linux/types.h>
39751 #include <linux/workqueue.h>
39752 +#include <linux/sched.h>
39753
39754 #include <asm/byteorder.h>
39755
39756 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39757 index f477308..2795f24 100644
39758 --- a/drivers/firewire/core.h
39759 +++ b/drivers/firewire/core.h
39760 @@ -111,6 +111,7 @@ struct fw_card_driver {
39761
39762 int (*stop_iso)(struct fw_iso_context *ctx);
39763 };
39764 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39765
39766 void fw_card_initialize(struct fw_card *card,
39767 const struct fw_card_driver *driver, struct device *device);
39768 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39769 index 586f2f7..3545ad2 100644
39770 --- a/drivers/firewire/ohci.c
39771 +++ b/drivers/firewire/ohci.c
39772 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39773 be32_to_cpu(ohci->next_header));
39774 }
39775
39776 +#ifndef CONFIG_GRKERNSEC
39777 if (param_remote_dma) {
39778 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39779 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39780 }
39781 +#endif
39782
39783 spin_unlock_irq(&ohci->lock);
39784
39785 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39786 unsigned long flags;
39787 int n, ret = 0;
39788
39789 +#ifndef CONFIG_GRKERNSEC
39790 if (param_remote_dma)
39791 return 0;
39792 +#endif
39793
39794 /*
39795 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39796 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39797 index 94a58a0..f5eba42 100644
39798 --- a/drivers/firmware/dmi-id.c
39799 +++ b/drivers/firmware/dmi-id.c
39800 @@ -16,7 +16,7 @@
39801 struct dmi_device_attribute{
39802 struct device_attribute dev_attr;
39803 int field;
39804 -};
39805 +} __do_const;
39806 #define to_dmi_dev_attr(_dev_attr) \
39807 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39808
39809 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39810 index 17afc51..0ef90cd 100644
39811 --- a/drivers/firmware/dmi_scan.c
39812 +++ b/drivers/firmware/dmi_scan.c
39813 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39814 if (buf == NULL)
39815 return -1;
39816
39817 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39818 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39819
39820 dmi_unmap(buf);
39821 return 0;
39822 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39823 index 1491dd4..aa910db 100644
39824 --- a/drivers/firmware/efi/cper.c
39825 +++ b/drivers/firmware/efi/cper.c
39826 @@ -41,12 +41,12 @@
39827 */
39828 u64 cper_next_record_id(void)
39829 {
39830 - static atomic64_t seq;
39831 + static atomic64_unchecked_t seq;
39832
39833 - if (!atomic64_read(&seq))
39834 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39835 + if (!atomic64_read_unchecked(&seq))
39836 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39837
39838 - return atomic64_inc_return(&seq);
39839 + return atomic64_inc_return_unchecked(&seq);
39840 }
39841 EXPORT_SYMBOL_GPL(cper_next_record_id);
39842
39843 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39844 index af20f17..4e4e545 100644
39845 --- a/drivers/firmware/efi/efi.c
39846 +++ b/drivers/firmware/efi/efi.c
39847 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39848 };
39849
39850 static struct efivars generic_efivars;
39851 -static struct efivar_operations generic_ops;
39852 +static efivar_operations_no_const generic_ops __read_only;
39853
39854 static int generic_ops_register(void)
39855 {
39856 - generic_ops.get_variable = efi.get_variable;
39857 - generic_ops.set_variable = efi.set_variable;
39858 - generic_ops.get_next_variable = efi.get_next_variable;
39859 - generic_ops.query_variable_store = efi_query_variable_store;
39860 + pax_open_kernel();
39861 + *(void **)&generic_ops.get_variable = efi.get_variable;
39862 + *(void **)&generic_ops.set_variable = efi.set_variable;
39863 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39864 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39865 + pax_close_kernel();
39866
39867 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39868 }
39869 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39870 index 50ea412..caccd6e9 100644
39871 --- a/drivers/firmware/efi/efivars.c
39872 +++ b/drivers/firmware/efi/efivars.c
39873 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39874 static int
39875 create_efivars_bin_attributes(void)
39876 {
39877 - struct bin_attribute *attr;
39878 + bin_attribute_no_const *attr;
39879 int error;
39880
39881 /* new_var */
39882 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39883 index 2f569aa..c95f4fb 100644
39884 --- a/drivers/firmware/google/memconsole.c
39885 +++ b/drivers/firmware/google/memconsole.c
39886 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39887 if (!found_memconsole())
39888 return -ENODEV;
39889
39890 - memconsole_bin_attr.size = memconsole_length;
39891 + pax_open_kernel();
39892 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39893 + pax_close_kernel();
39894 +
39895 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39896 }
39897
39898 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39899 index 8765bd6..2e5b147 100644
39900 --- a/drivers/gpio/gpio-em.c
39901 +++ b/drivers/gpio/gpio-em.c
39902 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39903 struct em_gio_priv *p;
39904 struct resource *io[2], *irq[2];
39905 struct gpio_chip *gpio_chip;
39906 - struct irq_chip *irq_chip;
39907 + irq_chip_no_const *irq_chip;
39908 const char *name = dev_name(&pdev->dev);
39909 int ret;
39910
39911 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39912 index 7030422..42a3fe9 100644
39913 --- a/drivers/gpio/gpio-ich.c
39914 +++ b/drivers/gpio/gpio-ich.c
39915 @@ -94,7 +94,7 @@ struct ichx_desc {
39916 * this option allows driver caching written output values
39917 */
39918 bool use_outlvl_cache;
39919 -};
39920 +} __do_const;
39921
39922 static struct {
39923 spinlock_t lock;
39924 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39925 index 03c9148..c66e753 100644
39926 --- a/drivers/gpio/gpio-rcar.c
39927 +++ b/drivers/gpio/gpio-rcar.c
39928 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39929 struct gpio_rcar_priv *p;
39930 struct resource *io, *irq;
39931 struct gpio_chip *gpio_chip;
39932 - struct irq_chip *irq_chip;
39933 + irq_chip_no_const *irq_chip;
39934 struct device *dev = &pdev->dev;
39935 const char *name = dev_name(dev);
39936 int ret;
39937 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39938 index 66cbcc1..0c5e622 100644
39939 --- a/drivers/gpio/gpio-vr41xx.c
39940 +++ b/drivers/gpio/gpio-vr41xx.c
39941 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39942 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39943 maskl, pendl, maskh, pendh);
39944
39945 - atomic_inc(&irq_err_count);
39946 + atomic_inc_unchecked(&irq_err_count);
39947
39948 return -EINVAL;
39949 }
39950 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39951 index d8b7099..8a314a5 100644
39952 --- a/drivers/gpu/drm/drm_crtc.c
39953 +++ b/drivers/gpu/drm/drm_crtc.c
39954 @@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39955 goto done;
39956 }
39957
39958 - if (copy_to_user(&enum_ptr[copied].name,
39959 + if (copy_to_user(enum_ptr[copied].name,
39960 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39961 ret = -EFAULT;
39962 goto done;
39963 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39964 old mode 100644
39965 new mode 100755
39966 index 03711d0..9960928a
39967 --- a/drivers/gpu/drm/drm_drv.c
39968 +++ b/drivers/gpu/drm/drm_drv.c
39969 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39970 /**
39971 * Copy and IOCTL return string to user space
39972 */
39973 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39974 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39975 {
39976 int len;
39977
39978 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
39979 struct drm_file *file_priv = filp->private_data;
39980 struct drm_device *dev;
39981 const struct drm_ioctl_desc *ioctl = NULL;
39982 - drm_ioctl_t *func;
39983 + drm_ioctl_no_const_t func;
39984 unsigned int nr = DRM_IOCTL_NR(cmd);
39985 int retcode = -EINVAL;
39986 char stack_kdata[128];
39987 @@ -419,8 +419,9 @@ long drm_ioctl(struct file *filp,
39988 retcode = -EFAULT;
39989 goto err_i1;
39990 }
39991 - } else
39992 + } else if (cmd & IOC_OUT) {
39993 memset(kdata, 0, usize);
39994 + }
39995
39996 if (ioctl->flags & DRM_UNLOCKED)
39997 retcode = func(dev, kdata, file_priv);
39998 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39999 index e1eba0b..98f69f9 100644
40000 --- a/drivers/gpu/drm/drm_fops.c
40001 +++ b/drivers/gpu/drm/drm_fops.c
40002 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40003 return PTR_ERR(minor);
40004
40005 dev = minor->dev;
40006 - if (!dev->open_count++)
40007 + if (local_inc_return(&dev->open_count) == 1)
40008 need_setup = 1;
40009
40010 /* share address_space across all char-devs of a single device */
40011 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40012 return 0;
40013
40014 err_undo:
40015 - dev->open_count--;
40016 + local_dec(&dev->open_count);
40017 drm_minor_release(minor);
40018 return retcode;
40019 }
40020 @@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40021
40022 mutex_lock(&drm_global_mutex);
40023
40024 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40025 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40026
40027 if (dev->driver->preclose)
40028 dev->driver->preclose(dev, file_priv);
40029 @@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40030 * Begin inline drm_release
40031 */
40032
40033 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40034 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40035 task_pid_nr(current),
40036 (long)old_encode_dev(file_priv->minor->kdev->devt),
40037 - dev->open_count);
40038 + local_read(&dev->open_count));
40039
40040 /* Release any auth tokens that might point to this file_priv,
40041 (do that under the drm_global_mutex) */
40042 @@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40043 * End inline drm_release
40044 */
40045
40046 - if (!--dev->open_count) {
40047 + if (local_dec_and_test(&dev->open_count)) {
40048 retcode = drm_lastclose(dev);
40049 if (drm_device_is_unplugged(dev))
40050 drm_put_dev(dev);
40051 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40052 index 3d2e91c..d31c4c9 100644
40053 --- a/drivers/gpu/drm/drm_global.c
40054 +++ b/drivers/gpu/drm/drm_global.c
40055 @@ -36,7 +36,7 @@
40056 struct drm_global_item {
40057 struct mutex mutex;
40058 void *object;
40059 - int refcount;
40060 + atomic_t refcount;
40061 };
40062
40063 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40064 @@ -49,7 +49,7 @@ void drm_global_init(void)
40065 struct drm_global_item *item = &glob[i];
40066 mutex_init(&item->mutex);
40067 item->object = NULL;
40068 - item->refcount = 0;
40069 + atomic_set(&item->refcount, 0);
40070 }
40071 }
40072
40073 @@ -59,7 +59,7 @@ void drm_global_release(void)
40074 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40075 struct drm_global_item *item = &glob[i];
40076 BUG_ON(item->object != NULL);
40077 - BUG_ON(item->refcount != 0);
40078 + BUG_ON(atomic_read(&item->refcount) != 0);
40079 }
40080 }
40081
40082 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40083 struct drm_global_item *item = &glob[ref->global_type];
40084
40085 mutex_lock(&item->mutex);
40086 - if (item->refcount == 0) {
40087 + if (atomic_read(&item->refcount) == 0) {
40088 item->object = kzalloc(ref->size, GFP_KERNEL);
40089 if (unlikely(item->object == NULL)) {
40090 ret = -ENOMEM;
40091 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40092 goto out_err;
40093
40094 }
40095 - ++item->refcount;
40096 + atomic_inc(&item->refcount);
40097 ref->object = item->object;
40098 mutex_unlock(&item->mutex);
40099 return 0;
40100 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40101 struct drm_global_item *item = &glob[ref->global_type];
40102
40103 mutex_lock(&item->mutex);
40104 - BUG_ON(item->refcount == 0);
40105 + BUG_ON(atomic_read(&item->refcount) == 0);
40106 BUG_ON(ref->object != item->object);
40107 - if (--item->refcount == 0) {
40108 + if (atomic_dec_and_test(&item->refcount)) {
40109 ref->release(ref);
40110 item->object = NULL;
40111 }
40112 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40113 index 7473035..a48b9c5 100644
40114 --- a/drivers/gpu/drm/drm_info.c
40115 +++ b/drivers/gpu/drm/drm_info.c
40116 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40117 struct drm_local_map *map;
40118 struct drm_map_list *r_list;
40119
40120 - /* Hardcoded from _DRM_FRAME_BUFFER,
40121 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40122 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40123 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40124 + static const char * const types[] = {
40125 + [_DRM_FRAME_BUFFER] = "FB",
40126 + [_DRM_REGISTERS] = "REG",
40127 + [_DRM_SHM] = "SHM",
40128 + [_DRM_AGP] = "AGP",
40129 + [_DRM_SCATTER_GATHER] = "SG",
40130 + [_DRM_CONSISTENT] = "PCI"};
40131 const char *type;
40132 int i;
40133
40134 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40135 map = r_list->map;
40136 if (!map)
40137 continue;
40138 - if (map->type < 0 || map->type > 5)
40139 + if (map->type >= ARRAY_SIZE(types))
40140 type = "??";
40141 else
40142 type = types[map->type];
40143 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40144 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40145 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40146 vma->vm_flags & VM_IO ? 'i' : '-',
40147 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40148 + 0);
40149 +#else
40150 vma->vm_pgoff);
40151 +#endif
40152
40153 #if defined(__i386__)
40154 pgprot = pgprot_val(vma->vm_page_prot);
40155 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40156 index 2f4c4343..dd12cd2 100644
40157 --- a/drivers/gpu/drm/drm_ioc32.c
40158 +++ b/drivers/gpu/drm/drm_ioc32.c
40159 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40160 request = compat_alloc_user_space(nbytes);
40161 if (!access_ok(VERIFY_WRITE, request, nbytes))
40162 return -EFAULT;
40163 - list = (struct drm_buf_desc *) (request + 1);
40164 + list = (struct drm_buf_desc __user *) (request + 1);
40165
40166 if (__put_user(count, &request->count)
40167 || __put_user(list, &request->list))
40168 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40169 request = compat_alloc_user_space(nbytes);
40170 if (!access_ok(VERIFY_WRITE, request, nbytes))
40171 return -EFAULT;
40172 - list = (struct drm_buf_pub *) (request + 1);
40173 + list = (struct drm_buf_pub __user *) (request + 1);
40174
40175 if (__put_user(count, &request->count)
40176 || __put_user(list, &request->list))
40177 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40178 return 0;
40179 }
40180
40181 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40182 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40183 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40184 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40185 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40186 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40187 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40188 {
40189 unsigned int nr = DRM_IOCTL_NR(cmd);
40190 - drm_ioctl_compat_t *fn;
40191 int ret;
40192
40193 /* Assume that ioctls without an explicit compat routine will just
40194 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40195 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40196 return drm_ioctl(filp, cmd, arg);
40197
40198 - fn = drm_compat_ioctls[nr];
40199 -
40200 - if (fn != NULL)
40201 - ret = (*fn) (filp, cmd, arg);
40202 + if (drm_compat_ioctls[nr] != NULL)
40203 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40204 else
40205 ret = drm_ioctl(filp, cmd, arg);
40206
40207 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40208 index 4c24c3a..c903cab 100644
40209 --- a/drivers/gpu/drm/drm_stub.c
40210 +++ b/drivers/gpu/drm/drm_stub.c
40211 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40212
40213 drm_device_set_unplugged(dev);
40214
40215 - if (dev->open_count == 0) {
40216 + if (local_read(&dev->open_count) == 0) {
40217 drm_put_dev(dev);
40218 }
40219 mutex_unlock(&drm_global_mutex);
40220 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40221 index c22c309..ae758c3 100644
40222 --- a/drivers/gpu/drm/drm_sysfs.c
40223 +++ b/drivers/gpu/drm/drm_sysfs.c
40224 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40225 */
40226 int drm_sysfs_device_add(struct drm_minor *minor)
40227 {
40228 - char *minor_str;
40229 + const char *minor_str;
40230 int r;
40231
40232 if (minor->type == DRM_MINOR_CONTROL)
40233 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40234 index d4d16ed..8fb0b51 100644
40235 --- a/drivers/gpu/drm/i810/i810_drv.h
40236 +++ b/drivers/gpu/drm/i810/i810_drv.h
40237 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40238 int page_flipping;
40239
40240 wait_queue_head_t irq_queue;
40241 - atomic_t irq_received;
40242 - atomic_t irq_emitted;
40243 + atomic_unchecked_t irq_received;
40244 + atomic_unchecked_t irq_emitted;
40245
40246 int front_offset;
40247 } drm_i810_private_t;
40248 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40249 index eedb023..25076a4 100644
40250 --- a/drivers/gpu/drm/i915/i915_dma.c
40251 +++ b/drivers/gpu/drm/i915/i915_dma.c
40252 @@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40253 bool can_switch;
40254
40255 spin_lock(&dev->count_lock);
40256 - can_switch = (dev->open_count == 0);
40257 + can_switch = (local_read(&dev->open_count) == 0);
40258 spin_unlock(&dev->count_lock);
40259 return can_switch;
40260 }
40261 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40262 index 20fef6c..76c78fb 100644
40263 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40264 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40265 @@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40266
40267 static int
40268 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40269 - int count)
40270 + unsigned int count)
40271 {
40272 - int i;
40273 + unsigned int i;
40274 unsigned relocs_total = 0;
40275 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40276
40277 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40278 index 3c59584..500f2e9 100644
40279 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40280 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40281 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40282 (unsigned long)request);
40283 }
40284
40285 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40286 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40287 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40288 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40289 [DRM_I915_GETPARAM] = compat_i915_getparam,
40290 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40291 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40292 {
40293 unsigned int nr = DRM_IOCTL_NR(cmd);
40294 - drm_ioctl_compat_t *fn = NULL;
40295 int ret;
40296
40297 if (nr < DRM_COMMAND_BASE)
40298 return drm_compat_ioctl(filp, cmd, arg);
40299
40300 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40301 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40302 -
40303 - if (fn != NULL)
40304 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40305 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40306 ret = (*fn) (filp, cmd, arg);
40307 - else
40308 + } else
40309 ret = drm_ioctl(filp, cmd, arg);
40310
40311 return ret;
40312 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40313 index 5b60e25..eac1625 100644
40314 --- a/drivers/gpu/drm/i915/intel_display.c
40315 +++ b/drivers/gpu/drm/i915/intel_display.c
40316 @@ -11171,13 +11171,13 @@ struct intel_quirk {
40317 int subsystem_vendor;
40318 int subsystem_device;
40319 void (*hook)(struct drm_device *dev);
40320 -};
40321 +} __do_const;
40322
40323 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40324 struct intel_dmi_quirk {
40325 void (*hook)(struct drm_device *dev);
40326 const struct dmi_system_id (*dmi_id_list)[];
40327 -};
40328 +} __do_const;
40329
40330 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40331 {
40332 @@ -11185,18 +11185,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40333 return 1;
40334 }
40335
40336 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40337 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40338 {
40339 - .dmi_id_list = &(const struct dmi_system_id[]) {
40340 - {
40341 - .callback = intel_dmi_reverse_brightness,
40342 - .ident = "NCR Corporation",
40343 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40344 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40345 - },
40346 - },
40347 - { } /* terminating entry */
40348 + .callback = intel_dmi_reverse_brightness,
40349 + .ident = "NCR Corporation",
40350 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40351 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40352 },
40353 + },
40354 + { } /* terminating entry */
40355 +};
40356 +
40357 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40358 + {
40359 + .dmi_id_list = &intel_dmi_quirks_table,
40360 .hook = quirk_invert_brightness,
40361 },
40362 };
40363 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40364 index fe45321..836fdca 100644
40365 --- a/drivers/gpu/drm/mga/mga_drv.h
40366 +++ b/drivers/gpu/drm/mga/mga_drv.h
40367 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40368 u32 clear_cmd;
40369 u32 maccess;
40370
40371 - atomic_t vbl_received; /**< Number of vblanks received. */
40372 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40373 wait_queue_head_t fence_queue;
40374 - atomic_t last_fence_retired;
40375 + atomic_unchecked_t last_fence_retired;
40376 u32 next_fence_to_post;
40377
40378 unsigned int fb_cpp;
40379 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40380 index 86b4bb8..ae237ad 100644
40381 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40382 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40383 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40384 return 0;
40385 }
40386
40387 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40388 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40389 [DRM_MGA_INIT] = compat_mga_init,
40390 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40391 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40392 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40393 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40394 {
40395 unsigned int nr = DRM_IOCTL_NR(cmd);
40396 - drm_ioctl_compat_t *fn = NULL;
40397 int ret;
40398
40399 if (nr < DRM_COMMAND_BASE)
40400 return drm_compat_ioctl(filp, cmd, arg);
40401
40402 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40403 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40404 -
40405 - if (fn != NULL)
40406 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40407 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40408 ret = (*fn) (filp, cmd, arg);
40409 - else
40410 + } else
40411 ret = drm_ioctl(filp, cmd, arg);
40412
40413 return ret;
40414 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40415 index 1b071b8..de8601a 100644
40416 --- a/drivers/gpu/drm/mga/mga_irq.c
40417 +++ b/drivers/gpu/drm/mga/mga_irq.c
40418 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40419 if (crtc != 0)
40420 return 0;
40421
40422 - return atomic_read(&dev_priv->vbl_received);
40423 + return atomic_read_unchecked(&dev_priv->vbl_received);
40424 }
40425
40426
40427 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40428 /* VBLANK interrupt */
40429 if (status & MGA_VLINEPEN) {
40430 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40431 - atomic_inc(&dev_priv->vbl_received);
40432 + atomic_inc_unchecked(&dev_priv->vbl_received);
40433 drm_handle_vblank(dev, 0);
40434 handled = 1;
40435 }
40436 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40437 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40438 MGA_WRITE(MGA_PRIMEND, prim_end);
40439
40440 - atomic_inc(&dev_priv->last_fence_retired);
40441 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40442 wake_up(&dev_priv->fence_queue);
40443 handled = 1;
40444 }
40445 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40446 * using fences.
40447 */
40448 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40449 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40450 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40451 - *sequence) <= (1 << 23)));
40452
40453 *sequence = cur_fence;
40454 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40455 index 8268a4c..5105708 100644
40456 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40457 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40458 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40459 struct bit_table {
40460 const char id;
40461 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40462 -};
40463 +} __no_const;
40464
40465 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40466
40467 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40468 index 7efbafa..19f8087 100644
40469 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40470 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40471 @@ -97,7 +97,6 @@ struct nouveau_drm {
40472 struct drm_global_reference mem_global_ref;
40473 struct ttm_bo_global_ref bo_global_ref;
40474 struct ttm_bo_device bdev;
40475 - atomic_t validate_sequence;
40476 int (*move)(struct nouveau_channel *,
40477 struct ttm_buffer_object *,
40478 struct ttm_mem_reg *, struct ttm_mem_reg *);
40479 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40480 index c1a7e5a..38b8539 100644
40481 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40482 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40483 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40484 unsigned long arg)
40485 {
40486 unsigned int nr = DRM_IOCTL_NR(cmd);
40487 - drm_ioctl_compat_t *fn = NULL;
40488 + drm_ioctl_compat_t fn = NULL;
40489 int ret;
40490
40491 if (nr < DRM_COMMAND_BASE)
40492 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40493 index ab0228f..20b756b 100644
40494 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40495 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40496 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40497 }
40498
40499 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40500 - nouveau_vram_manager_init,
40501 - nouveau_vram_manager_fini,
40502 - nouveau_vram_manager_new,
40503 - nouveau_vram_manager_del,
40504 - nouveau_vram_manager_debug
40505 + .init = nouveau_vram_manager_init,
40506 + .takedown = nouveau_vram_manager_fini,
40507 + .get_node = nouveau_vram_manager_new,
40508 + .put_node = nouveau_vram_manager_del,
40509 + .debug = nouveau_vram_manager_debug
40510 };
40511
40512 static int
40513 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40514 }
40515
40516 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40517 - nouveau_gart_manager_init,
40518 - nouveau_gart_manager_fini,
40519 - nouveau_gart_manager_new,
40520 - nouveau_gart_manager_del,
40521 - nouveau_gart_manager_debug
40522 + .init = nouveau_gart_manager_init,
40523 + .takedown = nouveau_gart_manager_fini,
40524 + .get_node = nouveau_gart_manager_new,
40525 + .put_node = nouveau_gart_manager_del,
40526 + .debug = nouveau_gart_manager_debug
40527 };
40528
40529 #include <core/subdev/vm/nv04.h>
40530 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40531 }
40532
40533 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40534 - nv04_gart_manager_init,
40535 - nv04_gart_manager_fini,
40536 - nv04_gart_manager_new,
40537 - nv04_gart_manager_del,
40538 - nv04_gart_manager_debug
40539 + .init = nv04_gart_manager_init,
40540 + .takedown = nv04_gart_manager_fini,
40541 + .get_node = nv04_gart_manager_new,
40542 + .put_node = nv04_gart_manager_del,
40543 + .debug = nv04_gart_manager_debug
40544 };
40545
40546 int
40547 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40548 index fb84da3..d7ee463 100644
40549 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40550 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40551 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40552 bool can_switch;
40553
40554 spin_lock(&dev->count_lock);
40555 - can_switch = (dev->open_count == 0);
40556 + can_switch = (local_read(&dev->open_count) == 0);
40557 spin_unlock(&dev->count_lock);
40558 return can_switch;
40559 }
40560 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40561 index eb89653..613cf71 100644
40562 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40563 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40564 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40565 int ret;
40566
40567 mutex_lock(&qdev->async_io_mutex);
40568 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40569 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40570 if (qdev->last_sent_io_cmd > irq_num) {
40571 if (intr)
40572 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40573 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40574 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40575 else
40576 ret = wait_event_timeout(qdev->io_cmd_event,
40577 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40578 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40579 /* 0 is timeout, just bail the "hw" has gone away */
40580 if (ret <= 0)
40581 goto out;
40582 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40583 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40584 }
40585 outb(val, addr);
40586 qdev->last_sent_io_cmd = irq_num + 1;
40587 if (intr)
40588 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40589 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40590 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40591 else
40592 ret = wait_event_timeout(qdev->io_cmd_event,
40593 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40594 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40595 out:
40596 if (ret > 0)
40597 ret = 0;
40598 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40599 index c3c2bbd..bc3c0fb 100644
40600 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40601 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40602 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40603 struct drm_info_node *node = (struct drm_info_node *) m->private;
40604 struct qxl_device *qdev = node->minor->dev->dev_private;
40605
40606 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40607 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40608 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40609 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40610 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40611 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40612 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40613 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40614 seq_printf(m, "%d\n", qdev->irq_received_error);
40615 return 0;
40616 }
40617 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40618 index 36ed40b..0397633 100644
40619 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40620 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40621 @@ -290,10 +290,10 @@ struct qxl_device {
40622 unsigned int last_sent_io_cmd;
40623
40624 /* interrupt handling */
40625 - atomic_t irq_received;
40626 - atomic_t irq_received_display;
40627 - atomic_t irq_received_cursor;
40628 - atomic_t irq_received_io_cmd;
40629 + atomic_unchecked_t irq_received;
40630 + atomic_unchecked_t irq_received_display;
40631 + atomic_unchecked_t irq_received_cursor;
40632 + atomic_unchecked_t irq_received_io_cmd;
40633 unsigned irq_received_error;
40634 wait_queue_head_t display_event;
40635 wait_queue_head_t cursor_event;
40636 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40637 index 0bb86e6..d41416d 100644
40638 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40639 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40640 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40641
40642 /* TODO copy slow path code from i915 */
40643 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40644 - 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);
40645 + 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);
40646
40647 {
40648 struct qxl_drawable *draw = fb_cmd;
40649 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40650 struct drm_qxl_reloc reloc;
40651
40652 if (copy_from_user(&reloc,
40653 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40654 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40655 sizeof(reloc))) {
40656 ret = -EFAULT;
40657 goto out_free_bos;
40658 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40659
40660 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40661
40662 - struct drm_qxl_command *commands =
40663 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40664 + struct drm_qxl_command __user *commands =
40665 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40666
40667 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40668 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40669 sizeof(user_cmd)))
40670 return -EFAULT;
40671
40672 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40673 index 28f84b4..fb3e224 100644
40674 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40675 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40676 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40677
40678 pending = xchg(&qdev->ram_header->int_pending, 0);
40679
40680 - atomic_inc(&qdev->irq_received);
40681 + atomic_inc_unchecked(&qdev->irq_received);
40682
40683 if (pending & QXL_INTERRUPT_DISPLAY) {
40684 - atomic_inc(&qdev->irq_received_display);
40685 + atomic_inc_unchecked(&qdev->irq_received_display);
40686 wake_up_all(&qdev->display_event);
40687 qxl_queue_garbage_collect(qdev, false);
40688 }
40689 if (pending & QXL_INTERRUPT_CURSOR) {
40690 - atomic_inc(&qdev->irq_received_cursor);
40691 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40692 wake_up_all(&qdev->cursor_event);
40693 }
40694 if (pending & QXL_INTERRUPT_IO_CMD) {
40695 - atomic_inc(&qdev->irq_received_io_cmd);
40696 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40697 wake_up_all(&qdev->io_cmd_event);
40698 }
40699 if (pending & QXL_INTERRUPT_ERROR) {
40700 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40701 init_waitqueue_head(&qdev->io_cmd_event);
40702 INIT_WORK(&qdev->client_monitors_config_work,
40703 qxl_client_monitors_config_work_func);
40704 - atomic_set(&qdev->irq_received, 0);
40705 - atomic_set(&qdev->irq_received_display, 0);
40706 - atomic_set(&qdev->irq_received_cursor, 0);
40707 - atomic_set(&qdev->irq_received_io_cmd, 0);
40708 + atomic_set_unchecked(&qdev->irq_received, 0);
40709 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40710 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40711 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40712 qdev->irq_received_error = 0;
40713 ret = drm_irq_install(qdev->ddev);
40714 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40715 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40716 index d52c275..4e6b43d 100644
40717 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40718 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40719 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40720 }
40721 }
40722
40723 -static struct vm_operations_struct qxl_ttm_vm_ops;
40724 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40725 static const struct vm_operations_struct *ttm_vm_ops;
40726
40727 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40728 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40729 return r;
40730 if (unlikely(ttm_vm_ops == NULL)) {
40731 ttm_vm_ops = vma->vm_ops;
40732 + pax_open_kernel();
40733 qxl_ttm_vm_ops = *ttm_vm_ops;
40734 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40735 + pax_close_kernel();
40736 }
40737 vma->vm_ops = &qxl_ttm_vm_ops;
40738 return 0;
40739 @@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40740 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40741 {
40742 #if defined(CONFIG_DEBUG_FS)
40743 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40744 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40745 - unsigned i;
40746 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40747 + {
40748 + .name = "qxl_mem_mm",
40749 + .show = &qxl_mm_dump_table,
40750 + },
40751 + {
40752 + .name = "qxl_surf_mm",
40753 + .show = &qxl_mm_dump_table,
40754 + }
40755 + };
40756
40757 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40758 - if (i == 0)
40759 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40760 - else
40761 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40762 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40763 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40764 - qxl_mem_types_list[i].driver_features = 0;
40765 - if (i == 0)
40766 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40767 - else
40768 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40769 + pax_open_kernel();
40770 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40771 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40772 + pax_close_kernel();
40773
40774 - }
40775 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40776 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40777 #else
40778 return 0;
40779 #endif
40780 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40781 index 59459fe..be26b31 100644
40782 --- a/drivers/gpu/drm/r128/r128_cce.c
40783 +++ b/drivers/gpu/drm/r128/r128_cce.c
40784 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40785
40786 /* GH: Simple idle check.
40787 */
40788 - atomic_set(&dev_priv->idle_count, 0);
40789 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40790
40791 /* We don't support anything other than bus-mastering ring mode,
40792 * but the ring can be in either AGP or PCI space for the ring
40793 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40794 index 5bf3f5f..7000661 100644
40795 --- a/drivers/gpu/drm/r128/r128_drv.h
40796 +++ b/drivers/gpu/drm/r128/r128_drv.h
40797 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40798 int is_pci;
40799 unsigned long cce_buffers_offset;
40800
40801 - atomic_t idle_count;
40802 + atomic_unchecked_t idle_count;
40803
40804 int page_flipping;
40805 int current_page;
40806 u32 crtc_offset;
40807 u32 crtc_offset_cntl;
40808
40809 - atomic_t vbl_received;
40810 + atomic_unchecked_t vbl_received;
40811
40812 u32 color_fmt;
40813 unsigned int front_offset;
40814 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40815 index b0d0fd3..a6fbbe4 100644
40816 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40817 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40818 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40819 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40820 }
40821
40822 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40823 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40824 [DRM_R128_INIT] = compat_r128_init,
40825 [DRM_R128_DEPTH] = compat_r128_depth,
40826 [DRM_R128_STIPPLE] = compat_r128_stipple,
40827 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40828 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40829 {
40830 unsigned int nr = DRM_IOCTL_NR(cmd);
40831 - drm_ioctl_compat_t *fn = NULL;
40832 int ret;
40833
40834 if (nr < DRM_COMMAND_BASE)
40835 return drm_compat_ioctl(filp, cmd, arg);
40836
40837 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40838 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40839 -
40840 - if (fn != NULL)
40841 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40842 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40843 ret = (*fn) (filp, cmd, arg);
40844 - else
40845 + } else
40846 ret = drm_ioctl(filp, cmd, arg);
40847
40848 return ret;
40849 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40850 index c2ae496..30b5993 100644
40851 --- a/drivers/gpu/drm/r128/r128_irq.c
40852 +++ b/drivers/gpu/drm/r128/r128_irq.c
40853 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40854 if (crtc != 0)
40855 return 0;
40856
40857 - return atomic_read(&dev_priv->vbl_received);
40858 + return atomic_read_unchecked(&dev_priv->vbl_received);
40859 }
40860
40861 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40862 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40863 /* VBLANK interrupt */
40864 if (status & R128_CRTC_VBLANK_INT) {
40865 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40866 - atomic_inc(&dev_priv->vbl_received);
40867 + atomic_inc_unchecked(&dev_priv->vbl_received);
40868 drm_handle_vblank(dev, 0);
40869 return IRQ_HANDLED;
40870 }
40871 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40872 index e806dac..f81d32f 100644
40873 --- a/drivers/gpu/drm/r128/r128_state.c
40874 +++ b/drivers/gpu/drm/r128/r128_state.c
40875 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40876
40877 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40878 {
40879 - if (atomic_read(&dev_priv->idle_count) == 0)
40880 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40881 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40882 else
40883 - atomic_set(&dev_priv->idle_count, 0);
40884 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40885 }
40886
40887 #endif
40888 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40889 index 4a85bb6..aaea819 100644
40890 --- a/drivers/gpu/drm/radeon/mkregtable.c
40891 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40892 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40893 regex_t mask_rex;
40894 regmatch_t match[4];
40895 char buf[1024];
40896 - size_t end;
40897 + long end;
40898 int len;
40899 int done = 0;
40900 int r;
40901 unsigned o;
40902 struct offset *offset;
40903 char last_reg_s[10];
40904 - int last_reg;
40905 + unsigned long last_reg;
40906
40907 if (regcomp
40908 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40909 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40910 index 2cd144c..a01c95a 100644
40911 --- a/drivers/gpu/drm/radeon/radeon_device.c
40912 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40913 @@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40914 bool can_switch;
40915
40916 spin_lock(&dev->count_lock);
40917 - can_switch = (dev->open_count == 0);
40918 + can_switch = (local_read(&dev->open_count) == 0);
40919 spin_unlock(&dev->count_lock);
40920 return can_switch;
40921 }
40922 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40923 index dafd812..1bf20c7 100644
40924 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40925 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40926 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40927
40928 /* SW interrupt */
40929 wait_queue_head_t swi_queue;
40930 - atomic_t swi_emitted;
40931 + atomic_unchecked_t swi_emitted;
40932 int vblank_crtc;
40933 uint32_t irq_enable_reg;
40934 uint32_t r500_disp_irq_reg;
40935 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40936 index bdb0f93..5ff558f 100644
40937 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40938 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40939 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40940 request = compat_alloc_user_space(sizeof(*request));
40941 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40942 || __put_user(req32.param, &request->param)
40943 - || __put_user((void __user *)(unsigned long)req32.value,
40944 + || __put_user((unsigned long)req32.value,
40945 &request->value))
40946 return -EFAULT;
40947
40948 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40949 #define compat_radeon_cp_setparam NULL
40950 #endif /* X86_64 || IA64 */
40951
40952 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40953 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40954 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40955 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40956 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40957 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40958 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40959 {
40960 unsigned int nr = DRM_IOCTL_NR(cmd);
40961 - drm_ioctl_compat_t *fn = NULL;
40962 int ret;
40963
40964 if (nr < DRM_COMMAND_BASE)
40965 return drm_compat_ioctl(filp, cmd, arg);
40966
40967 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40968 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40969 -
40970 - if (fn != NULL)
40971 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40972 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40973 ret = (*fn) (filp, cmd, arg);
40974 - else
40975 + } else
40976 ret = drm_ioctl(filp, cmd, arg);
40977
40978 return ret;
40979 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40980 index 244b19b..c19226d 100644
40981 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40982 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40983 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40984 unsigned int ret;
40985 RING_LOCALS;
40986
40987 - atomic_inc(&dev_priv->swi_emitted);
40988 - ret = atomic_read(&dev_priv->swi_emitted);
40989 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40990 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40991
40992 BEGIN_RING(4);
40993 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40994 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40995 drm_radeon_private_t *dev_priv =
40996 (drm_radeon_private_t *) dev->dev_private;
40997
40998 - atomic_set(&dev_priv->swi_emitted, 0);
40999 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41000 init_waitqueue_head(&dev_priv->swi_queue);
41001
41002 dev->max_vblank_count = 0x001fffff;
41003 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41004 index 956ab7f..fbd36d8 100644
41005 --- a/drivers/gpu/drm/radeon/radeon_state.c
41006 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41007 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41008 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41009 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41010
41011 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41012 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41013 sarea_priv->nbox * sizeof(depth_boxes[0])))
41014 return -EFAULT;
41015
41016 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41017 {
41018 drm_radeon_private_t *dev_priv = dev->dev_private;
41019 drm_radeon_getparam_t *param = data;
41020 - int value;
41021 + int value = 0;
41022
41023 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41024
41025 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41026 index c8a8a51..219dacc 100644
41027 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41028 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41029 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41030 man->size = size >> PAGE_SHIFT;
41031 }
41032
41033 -static struct vm_operations_struct radeon_ttm_vm_ops;
41034 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41035 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41036
41037 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41038 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41039 }
41040 if (unlikely(ttm_vm_ops == NULL)) {
41041 ttm_vm_ops = vma->vm_ops;
41042 + pax_open_kernel();
41043 radeon_ttm_vm_ops = *ttm_vm_ops;
41044 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41045 + pax_close_kernel();
41046 }
41047 vma->vm_ops = &radeon_ttm_vm_ops;
41048 return 0;
41049 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41050 index edb871d..a275c6ed 100644
41051 --- a/drivers/gpu/drm/tegra/dc.c
41052 +++ b/drivers/gpu/drm/tegra/dc.c
41053 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41054 }
41055
41056 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41057 - dc->debugfs_files[i].data = dc;
41058 + *(void **)&dc->debugfs_files[i].data = dc;
41059
41060 err = drm_debugfs_create_files(dc->debugfs_files,
41061 ARRAY_SIZE(debugfs_files),
41062 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41063 index 0e599f0..c9ea7c7 100644
41064 --- a/drivers/gpu/drm/tegra/dsi.c
41065 +++ b/drivers/gpu/drm/tegra/dsi.c
41066 @@ -39,7 +39,7 @@ struct tegra_dsi {
41067 struct clk *clk_lp;
41068 struct clk *clk;
41069
41070 - struct drm_info_list *debugfs_files;
41071 + drm_info_list_no_const *debugfs_files;
41072 struct drm_minor *minor;
41073 struct dentry *debugfs;
41074
41075 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41076 index 6928015..c9853e7 100644
41077 --- a/drivers/gpu/drm/tegra/hdmi.c
41078 +++ b/drivers/gpu/drm/tegra/hdmi.c
41079 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41080 bool stereo;
41081 bool dvi;
41082
41083 - struct drm_info_list *debugfs_files;
41084 + drm_info_list_no_const *debugfs_files;
41085 struct drm_minor *minor;
41086 struct dentry *debugfs;
41087 };
41088 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41089 index bd850c9..d9f3573 100644
41090 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41091 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41092 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41093 }
41094
41095 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41096 - ttm_bo_man_init,
41097 - ttm_bo_man_takedown,
41098 - ttm_bo_man_get_node,
41099 - ttm_bo_man_put_node,
41100 - ttm_bo_man_debug
41101 + .init = ttm_bo_man_init,
41102 + .takedown = ttm_bo_man_takedown,
41103 + .get_node = ttm_bo_man_get_node,
41104 + .put_node = ttm_bo_man_put_node,
41105 + .debug = ttm_bo_man_debug
41106 };
41107 EXPORT_SYMBOL(ttm_bo_manager_func);
41108 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41109 index dbc2def..0a9f710 100644
41110 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41111 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41112 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41113 zone->glob = glob;
41114 glob->zone_kernel = zone;
41115 ret = kobject_init_and_add(
41116 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41117 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41118 if (unlikely(ret != 0)) {
41119 kobject_put(&zone->kobj);
41120 return ret;
41121 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41122 zone->glob = glob;
41123 glob->zone_dma32 = zone;
41124 ret = kobject_init_and_add(
41125 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41126 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41127 if (unlikely(ret != 0)) {
41128 kobject_put(&zone->kobj);
41129 return ret;
41130 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41131 index 863bef9..cba15cf 100644
41132 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41133 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41134 @@ -391,9 +391,9 @@ out:
41135 static unsigned long
41136 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41137 {
41138 - static atomic_t start_pool = ATOMIC_INIT(0);
41139 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41140 unsigned i;
41141 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41142 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41143 struct ttm_page_pool *pool;
41144 int shrink_pages = sc->nr_to_scan;
41145 unsigned long freed = 0;
41146 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41147 index 3771763..883f206 100644
41148 --- a/drivers/gpu/drm/udl/udl_fb.c
41149 +++ b/drivers/gpu/drm/udl/udl_fb.c
41150 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41151 fb_deferred_io_cleanup(info);
41152 kfree(info->fbdefio);
41153 info->fbdefio = NULL;
41154 - info->fbops->fb_mmap = udl_fb_mmap;
41155 }
41156
41157 pr_warn("released /dev/fb%d user=%d count=%d\n",
41158 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41159 index ad02732..144f5ed 100644
41160 --- a/drivers/gpu/drm/via/via_drv.h
41161 +++ b/drivers/gpu/drm/via/via_drv.h
41162 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41163 typedef uint32_t maskarray_t[5];
41164
41165 typedef struct drm_via_irq {
41166 - atomic_t irq_received;
41167 + atomic_unchecked_t irq_received;
41168 uint32_t pending_mask;
41169 uint32_t enable_mask;
41170 wait_queue_head_t irq_queue;
41171 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41172 struct timeval last_vblank;
41173 int last_vblank_valid;
41174 unsigned usec_per_vblank;
41175 - atomic_t vbl_received;
41176 + atomic_unchecked_t vbl_received;
41177 drm_via_state_t hc_state;
41178 char pci_buf[VIA_PCI_BUF_SIZE];
41179 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41180 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41181 index 1319433..a993b0c 100644
41182 --- a/drivers/gpu/drm/via/via_irq.c
41183 +++ b/drivers/gpu/drm/via/via_irq.c
41184 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41185 if (crtc != 0)
41186 return 0;
41187
41188 - return atomic_read(&dev_priv->vbl_received);
41189 + return atomic_read_unchecked(&dev_priv->vbl_received);
41190 }
41191
41192 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41193 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41194
41195 status = VIA_READ(VIA_REG_INTERRUPT);
41196 if (status & VIA_IRQ_VBLANK_PENDING) {
41197 - atomic_inc(&dev_priv->vbl_received);
41198 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41199 + atomic_inc_unchecked(&dev_priv->vbl_received);
41200 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41201 do_gettimeofday(&cur_vblank);
41202 if (dev_priv->last_vblank_valid) {
41203 dev_priv->usec_per_vblank =
41204 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41205 dev_priv->last_vblank = cur_vblank;
41206 dev_priv->last_vblank_valid = 1;
41207 }
41208 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41209 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41210 DRM_DEBUG("US per vblank is: %u\n",
41211 dev_priv->usec_per_vblank);
41212 }
41213 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41214
41215 for (i = 0; i < dev_priv->num_irqs; ++i) {
41216 if (status & cur_irq->pending_mask) {
41217 - atomic_inc(&cur_irq->irq_received);
41218 + atomic_inc_unchecked(&cur_irq->irq_received);
41219 wake_up(&cur_irq->irq_queue);
41220 handled = 1;
41221 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41222 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41223 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41224 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41225 masks[irq][4]));
41226 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41227 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41228 } else {
41229 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41230 (((cur_irq_sequence =
41231 - atomic_read(&cur_irq->irq_received)) -
41232 + atomic_read_unchecked(&cur_irq->irq_received)) -
41233 *sequence) <= (1 << 23)));
41234 }
41235 *sequence = cur_irq_sequence;
41236 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41237 }
41238
41239 for (i = 0; i < dev_priv->num_irqs; ++i) {
41240 - atomic_set(&cur_irq->irq_received, 0);
41241 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41242 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41243 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41244 init_waitqueue_head(&cur_irq->irq_queue);
41245 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41246 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41247 case VIA_IRQ_RELATIVE:
41248 irqwait->request.sequence +=
41249 - atomic_read(&cur_irq->irq_received);
41250 + atomic_read_unchecked(&cur_irq->irq_received);
41251 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41252 case VIA_IRQ_ABSOLUTE:
41253 break;
41254 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41255 index 6b252a8..5975dfe 100644
41256 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41257 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41258 @@ -437,7 +437,7 @@ struct vmw_private {
41259 * Fencing and IRQs.
41260 */
41261
41262 - atomic_t marker_seq;
41263 + atomic_unchecked_t marker_seq;
41264 wait_queue_head_t fence_queue;
41265 wait_queue_head_t fifo_queue;
41266 int fence_queue_waiters; /* Protected by hw_mutex */
41267 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41268 index 6ccd993..618d592 100644
41269 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41270 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41271 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41272 (unsigned int) min,
41273 (unsigned int) fifo->capabilities);
41274
41275 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41276 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41277 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41278 vmw_marker_queue_init(&fifo->marker_queue);
41279 return vmw_fifo_send_fence(dev_priv, &dummy);
41280 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41281 if (reserveable)
41282 iowrite32(bytes, fifo_mem +
41283 SVGA_FIFO_RESERVED);
41284 - return fifo_mem + (next_cmd >> 2);
41285 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41286 } else {
41287 need_bounce = true;
41288 }
41289 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41290
41291 fm = vmw_fifo_reserve(dev_priv, bytes);
41292 if (unlikely(fm == NULL)) {
41293 - *seqno = atomic_read(&dev_priv->marker_seq);
41294 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41295 ret = -ENOMEM;
41296 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41297 false, 3*HZ);
41298 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41299 }
41300
41301 do {
41302 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41303 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41304 } while (*seqno == 0);
41305
41306 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41307 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41308 index b1273e8..9c274fd 100644
41309 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41310 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41311 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41312 }
41313
41314 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41315 - vmw_gmrid_man_init,
41316 - vmw_gmrid_man_takedown,
41317 - vmw_gmrid_man_get_node,
41318 - vmw_gmrid_man_put_node,
41319 - vmw_gmrid_man_debug
41320 + .init = vmw_gmrid_man_init,
41321 + .takedown = vmw_gmrid_man_takedown,
41322 + .get_node = vmw_gmrid_man_get_node,
41323 + .put_node = vmw_gmrid_man_put_node,
41324 + .debug = vmw_gmrid_man_debug
41325 };
41326 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41327 index 37881ec..319065d 100644
41328 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41329 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41330 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41331 int ret;
41332
41333 num_clips = arg->num_clips;
41334 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41335 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41336
41337 if (unlikely(num_clips == 0))
41338 return 0;
41339 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41340 int ret;
41341
41342 num_clips = arg->num_clips;
41343 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41344 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41345
41346 if (unlikely(num_clips == 0))
41347 return 0;
41348 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41349 index 0c42376..6febe77 100644
41350 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41351 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41352 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41353 * emitted. Then the fence is stale and signaled.
41354 */
41355
41356 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41357 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41358 > VMW_FENCE_WRAP);
41359
41360 return ret;
41361 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41362
41363 if (fifo_idle)
41364 down_read(&fifo_state->rwsem);
41365 - signal_seq = atomic_read(&dev_priv->marker_seq);
41366 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41367 ret = 0;
41368
41369 for (;;) {
41370 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41371 index 8a8725c2..afed796 100644
41372 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41373 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41374 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41375 while (!vmw_lag_lt(queue, us)) {
41376 spin_lock(&queue->lock);
41377 if (list_empty(&queue->head))
41378 - seqno = atomic_read(&dev_priv->marker_seq);
41379 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41380 else {
41381 marker = list_first_entry(&queue->head,
41382 struct vmw_marker, head);
41383 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41384 index ec0ae2d..dc0780b 100644
41385 --- a/drivers/gpu/vga/vga_switcheroo.c
41386 +++ b/drivers/gpu/vga/vga_switcheroo.c
41387 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41388
41389 /* this version is for the case where the power switch is separate
41390 to the device being powered down. */
41391 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41392 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41393 {
41394 /* copy over all the bus versions */
41395 if (dev->bus && dev->bus->pm) {
41396 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41397 return ret;
41398 }
41399
41400 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41401 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41402 {
41403 /* copy over all the bus versions */
41404 if (dev->bus && dev->bus->pm) {
41405 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41406 index a5c7927..025a2b4 100644
41407 --- a/drivers/hid/hid-core.c
41408 +++ b/drivers/hid/hid-core.c
41409 @@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41410
41411 int hid_add_device(struct hid_device *hdev)
41412 {
41413 - static atomic_t id = ATOMIC_INIT(0);
41414 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41415 int ret;
41416
41417 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41418 @@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41419 /* XXX hack, any other cleaner solution after the driver core
41420 * is converted to allow more than 20 bytes as the device name? */
41421 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41422 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41423 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41424
41425 hid_debug_register(hdev, dev_name(&hdev->dev));
41426 ret = device_add(&hdev->dev);
41427 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41428 index c13fb5b..55a3802 100644
41429 --- a/drivers/hid/hid-wiimote-debug.c
41430 +++ b/drivers/hid/hid-wiimote-debug.c
41431 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41432 else if (size == 0)
41433 return -EIO;
41434
41435 - if (copy_to_user(u, buf, size))
41436 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41437 return -EFAULT;
41438
41439 *off += size;
41440 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41441 index 0d078c3..cd0962c 100644
41442 --- a/drivers/hid/uhid.c
41443 +++ b/drivers/hid/uhid.c
41444 @@ -47,7 +47,7 @@ struct uhid_device {
41445 struct mutex report_lock;
41446 wait_queue_head_t report_wait;
41447 atomic_t report_done;
41448 - atomic_t report_id;
41449 + atomic_unchecked_t report_id;
41450 struct uhid_event report_buf;
41451 };
41452
41453 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41454
41455 spin_lock_irqsave(&uhid->qlock, flags);
41456 ev->type = UHID_FEATURE;
41457 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41458 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41459 ev->u.feature.rnum = rnum;
41460 ev->u.feature.rtype = report_type;
41461
41462 @@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41463 spin_lock_irqsave(&uhid->qlock, flags);
41464
41465 /* id for old report; drop it silently */
41466 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41467 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41468 goto unlock;
41469 if (atomic_read(&uhid->report_done))
41470 goto unlock;
41471 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41472 index 602ca86..10a6573 100644
41473 --- a/drivers/hv/channel.c
41474 +++ b/drivers/hv/channel.c
41475 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41476 int ret = 0;
41477 int t;
41478
41479 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41480 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41481 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41482 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41483
41484 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41485 if (ret)
41486 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41487 index bcb4950..61dba6c 100644
41488 --- a/drivers/hv/hv.c
41489 +++ b/drivers/hv/hv.c
41490 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41491 u64 output_address = (output) ? virt_to_phys(output) : 0;
41492 u32 output_address_hi = output_address >> 32;
41493 u32 output_address_lo = output_address & 0xFFFFFFFF;
41494 - void *hypercall_page = hv_context.hypercall_page;
41495 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41496
41497 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41498 "=a"(hv_status_lo) : "d" (control_hi),
41499 @@ -154,7 +154,7 @@ int hv_init(void)
41500 /* See if the hypercall page is already set */
41501 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41502
41503 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41504 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41505
41506 if (!virtaddr)
41507 goto cleanup;
41508 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41509 index 5e90c5d..d8fcefb 100644
41510 --- a/drivers/hv/hv_balloon.c
41511 +++ b/drivers/hv/hv_balloon.c
41512 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41513
41514 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41515 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41516 -static atomic_t trans_id = ATOMIC_INIT(0);
41517 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41518
41519 static int dm_ring_size = (5 * PAGE_SIZE);
41520
41521 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41522 pr_info("Memory hot add failed\n");
41523
41524 dm->state = DM_INITIALIZED;
41525 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41526 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41527 vmbus_sendpacket(dm->dev->channel, &resp,
41528 sizeof(struct dm_hot_add_response),
41529 (unsigned long)NULL,
41530 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41531 memset(&status, 0, sizeof(struct dm_status));
41532 status.hdr.type = DM_STATUS_REPORT;
41533 status.hdr.size = sizeof(struct dm_status);
41534 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41535 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41536
41537 /*
41538 * The host expects the guest to report free memory.
41539 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41540 * send the status. This can happen if we were interrupted
41541 * after we picked our transaction ID.
41542 */
41543 - if (status.hdr.trans_id != atomic_read(&trans_id))
41544 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41545 return;
41546
41547 /*
41548 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41549 */
41550
41551 do {
41552 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41553 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41554 ret = vmbus_sendpacket(dm_device.dev->channel,
41555 bl_resp,
41556 bl_resp->hdr.size,
41557 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41558
41559 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41560 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41561 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41562 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41563 resp.hdr.size = sizeof(struct dm_unballoon_response);
41564
41565 vmbus_sendpacket(dm_device.dev->channel, &resp,
41566 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41567 memset(&version_req, 0, sizeof(struct dm_version_request));
41568 version_req.hdr.type = DM_VERSION_REQUEST;
41569 version_req.hdr.size = sizeof(struct dm_version_request);
41570 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41571 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41572 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41573 version_req.is_last_attempt = 1;
41574
41575 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41576 memset(&version_req, 0, sizeof(struct dm_version_request));
41577 version_req.hdr.type = DM_VERSION_REQUEST;
41578 version_req.hdr.size = sizeof(struct dm_version_request);
41579 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41580 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41581 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41582 version_req.is_last_attempt = 0;
41583
41584 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41585 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41586 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41587 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41588 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41589 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41590
41591 cap_msg.caps.cap_bits.balloon = 1;
41592 cap_msg.caps.cap_bits.hot_add = 1;
41593 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41594 index 860134d..ea3a79a 100644
41595 --- a/drivers/hv/hyperv_vmbus.h
41596 +++ b/drivers/hv/hyperv_vmbus.h
41597 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41598 struct vmbus_connection {
41599 enum vmbus_connect_state conn_state;
41600
41601 - atomic_t next_gpadl_handle;
41602 + atomic_unchecked_t next_gpadl_handle;
41603
41604 /*
41605 * Represents channel interrupts. Each bit position represents a
41606 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41607 index 8e53a3c..7a64e44 100644
41608 --- a/drivers/hv/vmbus_drv.c
41609 +++ b/drivers/hv/vmbus_drv.c
41610 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41611 {
41612 int ret = 0;
41613
41614 - static atomic_t device_num = ATOMIC_INIT(0);
41615 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41616
41617 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41618 - atomic_inc_return(&device_num));
41619 + atomic_inc_return_unchecked(&device_num));
41620
41621 child_device_obj->device.bus = &hv_bus;
41622 child_device_obj->device.parent = &hv_acpi_dev->dev;
41623 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41624 index 579bdf9..75118b5 100644
41625 --- a/drivers/hwmon/acpi_power_meter.c
41626 +++ b/drivers/hwmon/acpi_power_meter.c
41627 @@ -116,7 +116,7 @@ struct sensor_template {
41628 struct device_attribute *devattr,
41629 const char *buf, size_t count);
41630 int index;
41631 -};
41632 +} __do_const;
41633
41634 /* Averaging interval */
41635 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41636 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41637 struct sensor_template *attrs)
41638 {
41639 struct device *dev = &resource->acpi_dev->dev;
41640 - struct sensor_device_attribute *sensors =
41641 + sensor_device_attribute_no_const *sensors =
41642 &resource->sensors[resource->num_sensors];
41643 int res = 0;
41644
41645 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41646 index 3288f13..71cfb4e 100644
41647 --- a/drivers/hwmon/applesmc.c
41648 +++ b/drivers/hwmon/applesmc.c
41649 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41650 {
41651 struct applesmc_node_group *grp;
41652 struct applesmc_dev_attr *node;
41653 - struct attribute *attr;
41654 + attribute_no_const *attr;
41655 int ret, i;
41656
41657 for (grp = groups; grp->format; grp++) {
41658 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41659 index ae208f6..48b6c5b 100644
41660 --- a/drivers/hwmon/asus_atk0110.c
41661 +++ b/drivers/hwmon/asus_atk0110.c
41662 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41663 struct atk_sensor_data {
41664 struct list_head list;
41665 struct atk_data *data;
41666 - struct device_attribute label_attr;
41667 - struct device_attribute input_attr;
41668 - struct device_attribute limit1_attr;
41669 - struct device_attribute limit2_attr;
41670 + device_attribute_no_const label_attr;
41671 + device_attribute_no_const input_attr;
41672 + device_attribute_no_const limit1_attr;
41673 + device_attribute_no_const limit2_attr;
41674 char label_attr_name[ATTR_NAME_SIZE];
41675 char input_attr_name[ATTR_NAME_SIZE];
41676 char limit1_attr_name[ATTR_NAME_SIZE];
41677 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41678 static struct device_attribute atk_name_attr =
41679 __ATTR(name, 0444, atk_name_show, NULL);
41680
41681 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41682 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41683 sysfs_show_func show)
41684 {
41685 sysfs_attr_init(&attr->attr);
41686 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41687 index d76f0b7..55ae976 100644
41688 --- a/drivers/hwmon/coretemp.c
41689 +++ b/drivers/hwmon/coretemp.c
41690 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41691 return NOTIFY_OK;
41692 }
41693
41694 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41695 +static struct notifier_block coretemp_cpu_notifier = {
41696 .notifier_call = coretemp_cpu_callback,
41697 };
41698
41699 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41700 index 632f1dc..57e6a58 100644
41701 --- a/drivers/hwmon/ibmaem.c
41702 +++ b/drivers/hwmon/ibmaem.c
41703 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41704 struct aem_rw_sensor_template *rw)
41705 {
41706 struct device *dev = &data->pdev->dev;
41707 - struct sensor_device_attribute *sensors = data->sensors;
41708 + sensor_device_attribute_no_const *sensors = data->sensors;
41709 int err;
41710
41711 /* Set up read-only sensors */
41712 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41713 index 9fbb1b1..efbaa3e 100644
41714 --- a/drivers/hwmon/iio_hwmon.c
41715 +++ b/drivers/hwmon/iio_hwmon.c
41716 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41717 {
41718 struct device *dev = &pdev->dev;
41719 struct iio_hwmon_state *st;
41720 - struct sensor_device_attribute *a;
41721 + sensor_device_attribute_no_const *a;
41722 int ret, i;
41723 int in_i = 1, temp_i = 1, curr_i = 1;
41724 enum iio_chan_type type;
41725 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41726 index 38d5a63..cf2c2ea 100644
41727 --- a/drivers/hwmon/nct6775.c
41728 +++ b/drivers/hwmon/nct6775.c
41729 @@ -944,10 +944,10 @@ static struct attribute_group *
41730 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41731 int repeat)
41732 {
41733 - struct attribute_group *group;
41734 + attribute_group_no_const *group;
41735 struct sensor_device_attr_u *su;
41736 - struct sensor_device_attribute *a;
41737 - struct sensor_device_attribute_2 *a2;
41738 + sensor_device_attribute_no_const *a;
41739 + sensor_device_attribute_2_no_const *a2;
41740 struct attribute **attrs;
41741 struct sensor_device_template **t;
41742 int i, count;
41743 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41744 index 291d11f..3f0dbbd 100644
41745 --- a/drivers/hwmon/pmbus/pmbus_core.c
41746 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41747 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41748 return 0;
41749 }
41750
41751 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41752 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41753 const char *name,
41754 umode_t mode,
41755 ssize_t (*show)(struct device *dev,
41756 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41757 dev_attr->store = store;
41758 }
41759
41760 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41761 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41762 const char *name,
41763 umode_t mode,
41764 ssize_t (*show)(struct device *dev,
41765 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41766 u16 reg, u8 mask)
41767 {
41768 struct pmbus_boolean *boolean;
41769 - struct sensor_device_attribute *a;
41770 + sensor_device_attribute_no_const *a;
41771
41772 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41773 if (!boolean)
41774 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41775 bool update, bool readonly)
41776 {
41777 struct pmbus_sensor *sensor;
41778 - struct device_attribute *a;
41779 + device_attribute_no_const *a;
41780
41781 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41782 if (!sensor)
41783 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41784 const char *lstring, int index)
41785 {
41786 struct pmbus_label *label;
41787 - struct device_attribute *a;
41788 + device_attribute_no_const *a;
41789
41790 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41791 if (!label)
41792 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41793 index 97cd45a..ac54d8b 100644
41794 --- a/drivers/hwmon/sht15.c
41795 +++ b/drivers/hwmon/sht15.c
41796 @@ -169,7 +169,7 @@ struct sht15_data {
41797 int supply_uv;
41798 bool supply_uv_valid;
41799 struct work_struct update_supply_work;
41800 - atomic_t interrupt_handled;
41801 + atomic_unchecked_t interrupt_handled;
41802 };
41803
41804 /**
41805 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41806 ret = gpio_direction_input(data->pdata->gpio_data);
41807 if (ret)
41808 return ret;
41809 - atomic_set(&data->interrupt_handled, 0);
41810 + atomic_set_unchecked(&data->interrupt_handled, 0);
41811
41812 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41813 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41814 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41815 /* Only relevant if the interrupt hasn't occurred. */
41816 - if (!atomic_read(&data->interrupt_handled))
41817 + if (!atomic_read_unchecked(&data->interrupt_handled))
41818 schedule_work(&data->read_work);
41819 }
41820 ret = wait_event_timeout(data->wait_queue,
41821 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41822
41823 /* First disable the interrupt */
41824 disable_irq_nosync(irq);
41825 - atomic_inc(&data->interrupt_handled);
41826 + atomic_inc_unchecked(&data->interrupt_handled);
41827 /* Then schedule a reading work struct */
41828 if (data->state != SHT15_READING_NOTHING)
41829 schedule_work(&data->read_work);
41830 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41831 * If not, then start the interrupt again - care here as could
41832 * have gone low in meantime so verify it hasn't!
41833 */
41834 - atomic_set(&data->interrupt_handled, 0);
41835 + atomic_set_unchecked(&data->interrupt_handled, 0);
41836 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41837 /* If still not occurred or another handler was scheduled */
41838 if (gpio_get_value(data->pdata->gpio_data)
41839 - || atomic_read(&data->interrupt_handled))
41840 + || atomic_read_unchecked(&data->interrupt_handled))
41841 return;
41842 }
41843
41844 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41845 index 8df43c5..b07b91d 100644
41846 --- a/drivers/hwmon/via-cputemp.c
41847 +++ b/drivers/hwmon/via-cputemp.c
41848 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41849 return NOTIFY_OK;
41850 }
41851
41852 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41853 +static struct notifier_block via_cputemp_cpu_notifier = {
41854 .notifier_call = via_cputemp_cpu_callback,
41855 };
41856
41857 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41858 index 41fc683..a39cfea 100644
41859 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41860 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41861 @@ -43,7 +43,7 @@
41862 extern struct i2c_adapter amd756_smbus;
41863
41864 static struct i2c_adapter *s4882_adapter;
41865 -static struct i2c_algorithm *s4882_algo;
41866 +static i2c_algorithm_no_const *s4882_algo;
41867
41868 /* Wrapper access functions for multiplexed SMBus */
41869 static DEFINE_MUTEX(amd756_lock);
41870 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41871 index 721f7eb..0fd2a09 100644
41872 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41873 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41874 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41875 /* usb layer */
41876
41877 /* Send command to device, and get response. */
41878 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41879 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41880 {
41881 int ret = 0;
41882 int actual;
41883 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41884 index b170bdf..3c76427 100644
41885 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41886 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41887 @@ -41,7 +41,7 @@
41888 extern struct i2c_adapter *nforce2_smbus;
41889
41890 static struct i2c_adapter *s4985_adapter;
41891 -static struct i2c_algorithm *s4985_algo;
41892 +static i2c_algorithm_no_const *s4985_algo;
41893
41894 /* Wrapper access functions for multiplexed SMBus */
41895 static DEFINE_MUTEX(nforce2_lock);
41896 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41897 index 80b47e8..1a6040d9 100644
41898 --- a/drivers/i2c/i2c-dev.c
41899 +++ b/drivers/i2c/i2c-dev.c
41900 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41901 break;
41902 }
41903
41904 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41905 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41906 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41907 if (IS_ERR(rdwr_pa[i].buf)) {
41908 res = PTR_ERR(rdwr_pa[i].buf);
41909 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41910 index 0b510ba..4fbb5085 100644
41911 --- a/drivers/ide/ide-cd.c
41912 +++ b/drivers/ide/ide-cd.c
41913 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41914 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41915 if ((unsigned long)buf & alignment
41916 || blk_rq_bytes(rq) & q->dma_pad_mask
41917 - || object_is_on_stack(buf))
41918 + || object_starts_on_stack(buf))
41919 drive->dma = 0;
41920 }
41921 }
41922 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41923 index ede16aec..e423e8a 100644
41924 --- a/drivers/iio/industrialio-core.c
41925 +++ b/drivers/iio/industrialio-core.c
41926 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41927 }
41928
41929 static
41930 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41931 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41932 const char *postfix,
41933 struct iio_chan_spec const *chan,
41934 ssize_t (*readfunc)(struct device *dev,
41935 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41936 index c323917..6ddea8b 100644
41937 --- a/drivers/infiniband/core/cm.c
41938 +++ b/drivers/infiniband/core/cm.c
41939 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41940
41941 struct cm_counter_group {
41942 struct kobject obj;
41943 - atomic_long_t counter[CM_ATTR_COUNT];
41944 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41945 };
41946
41947 struct cm_counter_attribute {
41948 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41949 struct ib_mad_send_buf *msg = NULL;
41950 int ret;
41951
41952 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41953 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41954 counter[CM_REQ_COUNTER]);
41955
41956 /* Quick state check to discard duplicate REQs. */
41957 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41958 if (!cm_id_priv)
41959 return;
41960
41961 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41962 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41963 counter[CM_REP_COUNTER]);
41964 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41965 if (ret)
41966 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41967 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41968 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41969 spin_unlock_irq(&cm_id_priv->lock);
41970 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41971 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41972 counter[CM_RTU_COUNTER]);
41973 goto out;
41974 }
41975 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
41976 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41977 dreq_msg->local_comm_id);
41978 if (!cm_id_priv) {
41979 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41980 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41981 counter[CM_DREQ_COUNTER]);
41982 cm_issue_drep(work->port, work->mad_recv_wc);
41983 return -EINVAL;
41984 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
41985 case IB_CM_MRA_REP_RCVD:
41986 break;
41987 case IB_CM_TIMEWAIT:
41988 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41989 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41990 counter[CM_DREQ_COUNTER]);
41991 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41992 goto unlock;
41993 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
41994 cm_free_msg(msg);
41995 goto deref;
41996 case IB_CM_DREQ_RCVD:
41997 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41998 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41999 counter[CM_DREQ_COUNTER]);
42000 goto unlock;
42001 default:
42002 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42003 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42004 cm_id_priv->msg, timeout)) {
42005 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42006 - atomic_long_inc(&work->port->
42007 + atomic_long_inc_unchecked(&work->port->
42008 counter_group[CM_RECV_DUPLICATES].
42009 counter[CM_MRA_COUNTER]);
42010 goto out;
42011 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42012 break;
42013 case IB_CM_MRA_REQ_RCVD:
42014 case IB_CM_MRA_REP_RCVD:
42015 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42016 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42017 counter[CM_MRA_COUNTER]);
42018 /* fall through */
42019 default:
42020 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42021 case IB_CM_LAP_IDLE:
42022 break;
42023 case IB_CM_MRA_LAP_SENT:
42024 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42025 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42026 counter[CM_LAP_COUNTER]);
42027 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42028 goto unlock;
42029 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42030 cm_free_msg(msg);
42031 goto deref;
42032 case IB_CM_LAP_RCVD:
42033 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42034 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42035 counter[CM_LAP_COUNTER]);
42036 goto unlock;
42037 default:
42038 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42039 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42040 if (cur_cm_id_priv) {
42041 spin_unlock_irq(&cm.lock);
42042 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42043 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42044 counter[CM_SIDR_REQ_COUNTER]);
42045 goto out; /* Duplicate message. */
42046 }
42047 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42048 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42049 msg->retries = 1;
42050
42051 - atomic_long_add(1 + msg->retries,
42052 + atomic_long_add_unchecked(1 + msg->retries,
42053 &port->counter_group[CM_XMIT].counter[attr_index]);
42054 if (msg->retries)
42055 - atomic_long_add(msg->retries,
42056 + atomic_long_add_unchecked(msg->retries,
42057 &port->counter_group[CM_XMIT_RETRIES].
42058 counter[attr_index]);
42059
42060 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42061 }
42062
42063 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42064 - atomic_long_inc(&port->counter_group[CM_RECV].
42065 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42066 counter[attr_id - CM_ATTR_ID_OFFSET]);
42067
42068 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42069 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42070 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42071
42072 return sprintf(buf, "%ld\n",
42073 - atomic_long_read(&group->counter[cm_attr->index]));
42074 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42075 }
42076
42077 static const struct sysfs_ops cm_counter_ops = {
42078 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42079 index 9f5ad7c..588cd84 100644
42080 --- a/drivers/infiniband/core/fmr_pool.c
42081 +++ b/drivers/infiniband/core/fmr_pool.c
42082 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42083
42084 struct task_struct *thread;
42085
42086 - atomic_t req_ser;
42087 - atomic_t flush_ser;
42088 + atomic_unchecked_t req_ser;
42089 + atomic_unchecked_t flush_ser;
42090
42091 wait_queue_head_t force_wait;
42092 };
42093 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42094 struct ib_fmr_pool *pool = pool_ptr;
42095
42096 do {
42097 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42098 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42099 ib_fmr_batch_release(pool);
42100
42101 - atomic_inc(&pool->flush_ser);
42102 + atomic_inc_unchecked(&pool->flush_ser);
42103 wake_up_interruptible(&pool->force_wait);
42104
42105 if (pool->flush_function)
42106 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42107 }
42108
42109 set_current_state(TASK_INTERRUPTIBLE);
42110 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42111 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42112 !kthread_should_stop())
42113 schedule();
42114 __set_current_state(TASK_RUNNING);
42115 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42116 pool->dirty_watermark = params->dirty_watermark;
42117 pool->dirty_len = 0;
42118 spin_lock_init(&pool->pool_lock);
42119 - atomic_set(&pool->req_ser, 0);
42120 - atomic_set(&pool->flush_ser, 0);
42121 + atomic_set_unchecked(&pool->req_ser, 0);
42122 + atomic_set_unchecked(&pool->flush_ser, 0);
42123 init_waitqueue_head(&pool->force_wait);
42124
42125 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42126 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42127 }
42128 spin_unlock_irq(&pool->pool_lock);
42129
42130 - serial = atomic_inc_return(&pool->req_ser);
42131 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42132 wake_up_process(pool->thread);
42133
42134 if (wait_event_interruptible(pool->force_wait,
42135 - atomic_read(&pool->flush_ser) - serial >= 0))
42136 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42137 return -EINTR;
42138
42139 return 0;
42140 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42141 } else {
42142 list_add_tail(&fmr->list, &pool->dirty_list);
42143 if (++pool->dirty_len >= pool->dirty_watermark) {
42144 - atomic_inc(&pool->req_ser);
42145 + atomic_inc_unchecked(&pool->req_ser);
42146 wake_up_process(pool->thread);
42147 }
42148 }
42149 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42150 index ec7a298..8742e59 100644
42151 --- a/drivers/infiniband/hw/cxgb4/mem.c
42152 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42153 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42154 int err;
42155 struct fw_ri_tpte tpt;
42156 u32 stag_idx;
42157 - static atomic_t key;
42158 + static atomic_unchecked_t key;
42159
42160 if (c4iw_fatal_error(rdev))
42161 return -EIO;
42162 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42163 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42164 rdev->stats.stag.max = rdev->stats.stag.cur;
42165 mutex_unlock(&rdev->stats.lock);
42166 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42167 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42168 }
42169 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42170 __func__, stag_state, type, pdid, stag_idx);
42171 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42172 index 79b3dbc..96e5fcc 100644
42173 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42174 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42175 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42176 struct ib_atomic_eth *ateth;
42177 struct ipath_ack_entry *e;
42178 u64 vaddr;
42179 - atomic64_t *maddr;
42180 + atomic64_unchecked_t *maddr;
42181 u64 sdata;
42182 u32 rkey;
42183 u8 next;
42184 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42185 IB_ACCESS_REMOTE_ATOMIC)))
42186 goto nack_acc_unlck;
42187 /* Perform atomic OP and save result. */
42188 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42189 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42190 sdata = be64_to_cpu(ateth->swap_data);
42191 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42192 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42193 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42194 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42195 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42196 be64_to_cpu(ateth->compare_data),
42197 sdata);
42198 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42199 index 1f95bba..9530f87 100644
42200 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42201 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42202 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42203 unsigned long flags;
42204 struct ib_wc wc;
42205 u64 sdata;
42206 - atomic64_t *maddr;
42207 + atomic64_unchecked_t *maddr;
42208 enum ib_wc_status send_status;
42209
42210 /*
42211 @@ -382,11 +382,11 @@ again:
42212 IB_ACCESS_REMOTE_ATOMIC)))
42213 goto acc_err;
42214 /* Perform atomic OP and save result. */
42215 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42216 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42217 sdata = wqe->wr.wr.atomic.compare_add;
42218 *(u64 *) sqp->s_sge.sge.vaddr =
42219 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42220 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42221 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42222 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42223 sdata, wqe->wr.wr.atomic.swap);
42224 goto send_comp;
42225 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42226 index fd36ec6..a6a082f 100644
42227 --- a/drivers/infiniband/hw/mlx4/mad.c
42228 +++ b/drivers/infiniband/hw/mlx4/mad.c
42229 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42230
42231 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42232 {
42233 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42234 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42235 cpu_to_be64(0xff00000000000000LL);
42236 }
42237
42238 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42239 index ed327e6..ca1739e0 100644
42240 --- a/drivers/infiniband/hw/mlx4/mcg.c
42241 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42242 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42243 {
42244 char name[20];
42245
42246 - atomic_set(&ctx->tid, 0);
42247 + atomic_set_unchecked(&ctx->tid, 0);
42248 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42249 ctx->mcg_wq = create_singlethread_workqueue(name);
42250 if (!ctx->mcg_wq)
42251 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42252 index 66b0b7d..f14836a 100644
42253 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42254 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42255 @@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42256 struct list_head mcg_mgid0_list;
42257 struct workqueue_struct *mcg_wq;
42258 struct mlx4_ib_demux_pv_ctx **tun;
42259 - atomic_t tid;
42260 + atomic_unchecked_t tid;
42261 int flushing; /* flushing the work queue */
42262 };
42263
42264 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42265 index 9d3e5c1..6f166df 100644
42266 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42267 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42268 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42269 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42270 }
42271
42272 -int mthca_QUERY_FW(struct mthca_dev *dev)
42273 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42274 {
42275 struct mthca_mailbox *mailbox;
42276 u32 *outbox;
42277 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42278 CMD_TIME_CLASS_B);
42279 }
42280
42281 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42282 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42283 int num_mtt)
42284 {
42285 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42286 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42287 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42288 }
42289
42290 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42291 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42292 int eq_num)
42293 {
42294 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42295 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42296 CMD_TIME_CLASS_B);
42297 }
42298
42299 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42300 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42301 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42302 void *in_mad, void *response_mad)
42303 {
42304 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42305 index ded76c1..0cf0a08 100644
42306 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42307 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42308 @@ -692,7 +692,7 @@ err_close:
42309 return err;
42310 }
42311
42312 -static int mthca_setup_hca(struct mthca_dev *dev)
42313 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42314 {
42315 int err;
42316
42317 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42318 index ed9a989..6aa5dc2 100644
42319 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42320 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42321 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42322 * through the bitmaps)
42323 */
42324
42325 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42326 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42327 {
42328 int o;
42329 int m;
42330 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42331 return key;
42332 }
42333
42334 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42335 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42336 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42337 {
42338 struct mthca_mailbox *mailbox;
42339 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42340 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42341 }
42342
42343 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42344 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42345 u64 *buffer_list, int buffer_size_shift,
42346 int list_len, u64 iova, u64 total_size,
42347 u32 access, struct mthca_mr *mr)
42348 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42349 index 415f8e1..e34214e 100644
42350 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42351 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42352 @@ -764,7 +764,7 @@ unlock:
42353 return 0;
42354 }
42355
42356 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42357 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42358 {
42359 struct mthca_dev *dev = to_mdev(ibcq->device);
42360 struct mthca_cq *cq = to_mcq(ibcq);
42361 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42362 index 353c7b0..c6ce921 100644
42363 --- a/drivers/infiniband/hw/nes/nes.c
42364 +++ b/drivers/infiniband/hw/nes/nes.c
42365 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42366 LIST_HEAD(nes_adapter_list);
42367 static LIST_HEAD(nes_dev_list);
42368
42369 -atomic_t qps_destroyed;
42370 +atomic_unchecked_t qps_destroyed;
42371
42372 static unsigned int ee_flsh_adapter;
42373 static unsigned int sysfs_nonidx_addr;
42374 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42375 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42376 struct nes_adapter *nesadapter = nesdev->nesadapter;
42377
42378 - atomic_inc(&qps_destroyed);
42379 + atomic_inc_unchecked(&qps_destroyed);
42380
42381 /* Free the control structures */
42382
42383 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42384 index 33cc589..3bd6538 100644
42385 --- a/drivers/infiniband/hw/nes/nes.h
42386 +++ b/drivers/infiniband/hw/nes/nes.h
42387 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42388 extern unsigned int wqm_quanta;
42389 extern struct list_head nes_adapter_list;
42390
42391 -extern atomic_t cm_connects;
42392 -extern atomic_t cm_accepts;
42393 -extern atomic_t cm_disconnects;
42394 -extern atomic_t cm_closes;
42395 -extern atomic_t cm_connecteds;
42396 -extern atomic_t cm_connect_reqs;
42397 -extern atomic_t cm_rejects;
42398 -extern atomic_t mod_qp_timouts;
42399 -extern atomic_t qps_created;
42400 -extern atomic_t qps_destroyed;
42401 -extern atomic_t sw_qps_destroyed;
42402 +extern atomic_unchecked_t cm_connects;
42403 +extern atomic_unchecked_t cm_accepts;
42404 +extern atomic_unchecked_t cm_disconnects;
42405 +extern atomic_unchecked_t cm_closes;
42406 +extern atomic_unchecked_t cm_connecteds;
42407 +extern atomic_unchecked_t cm_connect_reqs;
42408 +extern atomic_unchecked_t cm_rejects;
42409 +extern atomic_unchecked_t mod_qp_timouts;
42410 +extern atomic_unchecked_t qps_created;
42411 +extern atomic_unchecked_t qps_destroyed;
42412 +extern atomic_unchecked_t sw_qps_destroyed;
42413 extern u32 mh_detected;
42414 extern u32 mh_pauses_sent;
42415 extern u32 cm_packets_sent;
42416 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42417 extern u32 cm_packets_received;
42418 extern u32 cm_packets_dropped;
42419 extern u32 cm_packets_retrans;
42420 -extern atomic_t cm_listens_created;
42421 -extern atomic_t cm_listens_destroyed;
42422 +extern atomic_unchecked_t cm_listens_created;
42423 +extern atomic_unchecked_t cm_listens_destroyed;
42424 extern u32 cm_backlog_drops;
42425 -extern atomic_t cm_loopbacks;
42426 -extern atomic_t cm_nodes_created;
42427 -extern atomic_t cm_nodes_destroyed;
42428 -extern atomic_t cm_accel_dropped_pkts;
42429 -extern atomic_t cm_resets_recvd;
42430 -extern atomic_t pau_qps_created;
42431 -extern atomic_t pau_qps_destroyed;
42432 +extern atomic_unchecked_t cm_loopbacks;
42433 +extern atomic_unchecked_t cm_nodes_created;
42434 +extern atomic_unchecked_t cm_nodes_destroyed;
42435 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42436 +extern atomic_unchecked_t cm_resets_recvd;
42437 +extern atomic_unchecked_t pau_qps_created;
42438 +extern atomic_unchecked_t pau_qps_destroyed;
42439
42440 extern u32 int_mod_timer_init;
42441 extern u32 int_mod_cq_depth_256;
42442 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42443 index dfa9df4..6bf7221 100644
42444 --- a/drivers/infiniband/hw/nes/nes_cm.c
42445 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42446 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42447 u32 cm_packets_retrans;
42448 u32 cm_packets_created;
42449 u32 cm_packets_received;
42450 -atomic_t cm_listens_created;
42451 -atomic_t cm_listens_destroyed;
42452 +atomic_unchecked_t cm_listens_created;
42453 +atomic_unchecked_t cm_listens_destroyed;
42454 u32 cm_backlog_drops;
42455 -atomic_t cm_loopbacks;
42456 -atomic_t cm_nodes_created;
42457 -atomic_t cm_nodes_destroyed;
42458 -atomic_t cm_accel_dropped_pkts;
42459 -atomic_t cm_resets_recvd;
42460 +atomic_unchecked_t cm_loopbacks;
42461 +atomic_unchecked_t cm_nodes_created;
42462 +atomic_unchecked_t cm_nodes_destroyed;
42463 +atomic_unchecked_t cm_accel_dropped_pkts;
42464 +atomic_unchecked_t cm_resets_recvd;
42465
42466 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42467 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42468 @@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42469 /* instance of function pointers for client API */
42470 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42471 static struct nes_cm_ops nes_cm_api = {
42472 - mini_cm_accelerated,
42473 - mini_cm_listen,
42474 - mini_cm_del_listen,
42475 - mini_cm_connect,
42476 - mini_cm_close,
42477 - mini_cm_accept,
42478 - mini_cm_reject,
42479 - mini_cm_recv_pkt,
42480 - mini_cm_dealloc_core,
42481 - mini_cm_get,
42482 - mini_cm_set
42483 + .accelerated = mini_cm_accelerated,
42484 + .listen = mini_cm_listen,
42485 + .stop_listener = mini_cm_del_listen,
42486 + .connect = mini_cm_connect,
42487 + .close = mini_cm_close,
42488 + .accept = mini_cm_accept,
42489 + .reject = mini_cm_reject,
42490 + .recv_pkt = mini_cm_recv_pkt,
42491 + .destroy_cm_core = mini_cm_dealloc_core,
42492 + .get = mini_cm_get,
42493 + .set = mini_cm_set
42494 };
42495
42496 static struct nes_cm_core *g_cm_core;
42497
42498 -atomic_t cm_connects;
42499 -atomic_t cm_accepts;
42500 -atomic_t cm_disconnects;
42501 -atomic_t cm_closes;
42502 -atomic_t cm_connecteds;
42503 -atomic_t cm_connect_reqs;
42504 -atomic_t cm_rejects;
42505 +atomic_unchecked_t cm_connects;
42506 +atomic_unchecked_t cm_accepts;
42507 +atomic_unchecked_t cm_disconnects;
42508 +atomic_unchecked_t cm_closes;
42509 +atomic_unchecked_t cm_connecteds;
42510 +atomic_unchecked_t cm_connect_reqs;
42511 +atomic_unchecked_t cm_rejects;
42512
42513 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42514 {
42515 @@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42516 kfree(listener);
42517 listener = NULL;
42518 ret = 0;
42519 - atomic_inc(&cm_listens_destroyed);
42520 + atomic_inc_unchecked(&cm_listens_destroyed);
42521 } else {
42522 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42523 }
42524 @@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42525 cm_node->rem_mac);
42526
42527 add_hte_node(cm_core, cm_node);
42528 - atomic_inc(&cm_nodes_created);
42529 + atomic_inc_unchecked(&cm_nodes_created);
42530
42531 return cm_node;
42532 }
42533 @@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42534 }
42535
42536 atomic_dec(&cm_core->node_cnt);
42537 - atomic_inc(&cm_nodes_destroyed);
42538 + atomic_inc_unchecked(&cm_nodes_destroyed);
42539 nesqp = cm_node->nesqp;
42540 if (nesqp) {
42541 nesqp->cm_node = NULL;
42542 @@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42543
42544 static void drop_packet(struct sk_buff *skb)
42545 {
42546 - atomic_inc(&cm_accel_dropped_pkts);
42547 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42548 dev_kfree_skb_any(skb);
42549 }
42550
42551 @@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42552 {
42553
42554 int reset = 0; /* whether to send reset in case of err.. */
42555 - atomic_inc(&cm_resets_recvd);
42556 + atomic_inc_unchecked(&cm_resets_recvd);
42557 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42558 " refcnt=%d\n", cm_node, cm_node->state,
42559 atomic_read(&cm_node->ref_count));
42560 @@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42561 rem_ref_cm_node(cm_node->cm_core, cm_node);
42562 return NULL;
42563 }
42564 - atomic_inc(&cm_loopbacks);
42565 + atomic_inc_unchecked(&cm_loopbacks);
42566 loopbackremotenode->loopbackpartner = cm_node;
42567 loopbackremotenode->tcp_cntxt.rcv_wscale =
42568 NES_CM_DEFAULT_RCV_WND_SCALE;
42569 @@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42570 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42571 else {
42572 rem_ref_cm_node(cm_core, cm_node);
42573 - atomic_inc(&cm_accel_dropped_pkts);
42574 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42575 dev_kfree_skb_any(skb);
42576 }
42577 break;
42578 @@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42579
42580 if ((cm_id) && (cm_id->event_handler)) {
42581 if (issue_disconn) {
42582 - atomic_inc(&cm_disconnects);
42583 + atomic_inc_unchecked(&cm_disconnects);
42584 cm_event.event = IW_CM_EVENT_DISCONNECT;
42585 cm_event.status = disconn_status;
42586 cm_event.local_addr = cm_id->local_addr;
42587 @@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42588 }
42589
42590 if (issue_close) {
42591 - atomic_inc(&cm_closes);
42592 + atomic_inc_unchecked(&cm_closes);
42593 nes_disconnect(nesqp, 1);
42594
42595 cm_id->provider_data = nesqp;
42596 @@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42597
42598 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42599 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42600 - atomic_inc(&cm_accepts);
42601 + atomic_inc_unchecked(&cm_accepts);
42602
42603 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42604 netdev_refcnt_read(nesvnic->netdev));
42605 @@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42606 struct nes_cm_core *cm_core;
42607 u8 *start_buff;
42608
42609 - atomic_inc(&cm_rejects);
42610 + atomic_inc_unchecked(&cm_rejects);
42611 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42612 loopback = cm_node->loopbackpartner;
42613 cm_core = cm_node->cm_core;
42614 @@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42615 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42616 ntohs(laddr->sin_port));
42617
42618 - atomic_inc(&cm_connects);
42619 + atomic_inc_unchecked(&cm_connects);
42620 nesqp->active_conn = 1;
42621
42622 /* cache the cm_id in the qp */
42623 @@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42624 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42625 return err;
42626 }
42627 - atomic_inc(&cm_listens_created);
42628 + atomic_inc_unchecked(&cm_listens_created);
42629 }
42630
42631 cm_id->add_ref(cm_id);
42632 @@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42633
42634 if (nesqp->destroyed)
42635 return;
42636 - atomic_inc(&cm_connecteds);
42637 + atomic_inc_unchecked(&cm_connecteds);
42638 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42639 " local port 0x%04X. jiffies = %lu.\n",
42640 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42641 @@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42642
42643 cm_id->add_ref(cm_id);
42644 ret = cm_id->event_handler(cm_id, &cm_event);
42645 - atomic_inc(&cm_closes);
42646 + atomic_inc_unchecked(&cm_closes);
42647 cm_event.event = IW_CM_EVENT_CLOSE;
42648 cm_event.status = 0;
42649 cm_event.provider_data = cm_id->provider_data;
42650 @@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42651 return;
42652 cm_id = cm_node->cm_id;
42653
42654 - atomic_inc(&cm_connect_reqs);
42655 + atomic_inc_unchecked(&cm_connect_reqs);
42656 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42657 cm_node, cm_id, jiffies);
42658
42659 @@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42660 return;
42661 cm_id = cm_node->cm_id;
42662
42663 - atomic_inc(&cm_connect_reqs);
42664 + atomic_inc_unchecked(&cm_connect_reqs);
42665 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42666 cm_node, cm_id, jiffies);
42667
42668 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42669 index 4166452..fc952c3 100644
42670 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42671 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42672 @@ -40,8 +40,8 @@
42673 #include "nes.h"
42674 #include "nes_mgt.h"
42675
42676 -atomic_t pau_qps_created;
42677 -atomic_t pau_qps_destroyed;
42678 +atomic_unchecked_t pau_qps_created;
42679 +atomic_unchecked_t pau_qps_destroyed;
42680
42681 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42682 {
42683 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42684 {
42685 struct sk_buff *skb;
42686 unsigned long flags;
42687 - atomic_inc(&pau_qps_destroyed);
42688 + atomic_inc_unchecked(&pau_qps_destroyed);
42689
42690 /* Free packets that have not yet been forwarded */
42691 /* Lock is acquired by skb_dequeue when removing the skb */
42692 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42693 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42694 skb_queue_head_init(&nesqp->pau_list);
42695 spin_lock_init(&nesqp->pau_lock);
42696 - atomic_inc(&pau_qps_created);
42697 + atomic_inc_unchecked(&pau_qps_created);
42698 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42699 }
42700
42701 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42702 index 49eb511..a774366 100644
42703 --- a/drivers/infiniband/hw/nes/nes_nic.c
42704 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42705 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42706 target_stat_values[++index] = mh_detected;
42707 target_stat_values[++index] = mh_pauses_sent;
42708 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42709 - target_stat_values[++index] = atomic_read(&cm_connects);
42710 - target_stat_values[++index] = atomic_read(&cm_accepts);
42711 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42712 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42713 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42714 - target_stat_values[++index] = atomic_read(&cm_rejects);
42715 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42716 - target_stat_values[++index] = atomic_read(&qps_created);
42717 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42718 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42719 - target_stat_values[++index] = atomic_read(&cm_closes);
42720 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42721 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42722 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42723 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42724 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42725 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42726 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42727 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42728 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42729 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42730 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42731 target_stat_values[++index] = cm_packets_sent;
42732 target_stat_values[++index] = cm_packets_bounced;
42733 target_stat_values[++index] = cm_packets_created;
42734 target_stat_values[++index] = cm_packets_received;
42735 target_stat_values[++index] = cm_packets_dropped;
42736 target_stat_values[++index] = cm_packets_retrans;
42737 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42738 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42739 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42740 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42741 target_stat_values[++index] = cm_backlog_drops;
42742 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42743 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42744 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42745 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42746 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42747 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42748 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42749 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42750 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42751 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42752 target_stat_values[++index] = nesadapter->free_4kpbl;
42753 target_stat_values[++index] = nesadapter->free_256pbl;
42754 target_stat_values[++index] = int_mod_timer_init;
42755 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42756 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42757 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42758 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42759 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42760 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42761 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42762 }
42763
42764 /**
42765 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42766 index 218dd35..97ce31d 100644
42767 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42768 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42769 @@ -46,9 +46,9 @@
42770
42771 #include <rdma/ib_umem.h>
42772
42773 -atomic_t mod_qp_timouts;
42774 -atomic_t qps_created;
42775 -atomic_t sw_qps_destroyed;
42776 +atomic_unchecked_t mod_qp_timouts;
42777 +atomic_unchecked_t qps_created;
42778 +atomic_unchecked_t sw_qps_destroyed;
42779
42780 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42781
42782 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42783 if (init_attr->create_flags)
42784 return ERR_PTR(-EINVAL);
42785
42786 - atomic_inc(&qps_created);
42787 + atomic_inc_unchecked(&qps_created);
42788 switch (init_attr->qp_type) {
42789 case IB_QPT_RC:
42790 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42791 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42792 struct iw_cm_event cm_event;
42793 int ret = 0;
42794
42795 - atomic_inc(&sw_qps_destroyed);
42796 + atomic_inc_unchecked(&sw_qps_destroyed);
42797 nesqp->destroyed = 1;
42798
42799 /* Blow away the connection if it exists. */
42800 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42801 index c00ae09..04e91be 100644
42802 --- a/drivers/infiniband/hw/qib/qib.h
42803 +++ b/drivers/infiniband/hw/qib/qib.h
42804 @@ -52,6 +52,7 @@
42805 #include <linux/kref.h>
42806 #include <linux/sched.h>
42807 #include <linux/kthread.h>
42808 +#include <linux/slab.h>
42809
42810 #include "qib_common.h"
42811 #include "qib_verbs.h"
42812 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42813 index 24c41ba..102d71f 100644
42814 --- a/drivers/input/gameport/gameport.c
42815 +++ b/drivers/input/gameport/gameport.c
42816 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42817 */
42818 static void gameport_init_port(struct gameport *gameport)
42819 {
42820 - static atomic_t gameport_no = ATOMIC_INIT(0);
42821 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42822
42823 __module_get(THIS_MODULE);
42824
42825 mutex_init(&gameport->drv_mutex);
42826 device_initialize(&gameport->dev);
42827 dev_set_name(&gameport->dev, "gameport%lu",
42828 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42829 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42830 gameport->dev.bus = &gameport_bus;
42831 gameport->dev.release = gameport_release_port;
42832 if (gameport->parent)
42833 diff --git a/drivers/input/input.c b/drivers/input/input.c
42834 index 1c4c0db..6f7abe3 100644
42835 --- a/drivers/input/input.c
42836 +++ b/drivers/input/input.c
42837 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42838 */
42839 struct input_dev *input_allocate_device(void)
42840 {
42841 - static atomic_t input_no = ATOMIC_INIT(0);
42842 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42843 struct input_dev *dev;
42844
42845 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42846 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42847 INIT_LIST_HEAD(&dev->node);
42848
42849 dev_set_name(&dev->dev, "input%ld",
42850 - (unsigned long) atomic_inc_return(&input_no) - 1);
42851 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42852
42853 __module_get(THIS_MODULE);
42854 }
42855 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42856 index 4a95b22..874c182 100644
42857 --- a/drivers/input/joystick/sidewinder.c
42858 +++ b/drivers/input/joystick/sidewinder.c
42859 @@ -30,6 +30,7 @@
42860 #include <linux/kernel.h>
42861 #include <linux/module.h>
42862 #include <linux/slab.h>
42863 +#include <linux/sched.h>
42864 #include <linux/input.h>
42865 #include <linux/gameport.h>
42866 #include <linux/jiffies.h>
42867 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42868 index 603fe0d..f63decc 100644
42869 --- a/drivers/input/joystick/xpad.c
42870 +++ b/drivers/input/joystick/xpad.c
42871 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42872
42873 static int xpad_led_probe(struct usb_xpad *xpad)
42874 {
42875 - static atomic_t led_seq = ATOMIC_INIT(0);
42876 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42877 long led_no;
42878 struct xpad_led *led;
42879 struct led_classdev *led_cdev;
42880 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42881 if (!led)
42882 return -ENOMEM;
42883
42884 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42885 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42886
42887 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42888 led->xpad = xpad;
42889 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42890 index 5a73639..d586683 100644
42891 --- a/drivers/input/misc/ims-pcu.c
42892 +++ b/drivers/input/misc/ims-pcu.c
42893 @@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42894
42895 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42896 {
42897 - static atomic_t device_no = ATOMIC_INIT(0);
42898 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42899
42900 const struct ims_pcu_device_info *info;
42901 int error;
42902 @@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42903 }
42904
42905 /* Device appears to be operable, complete initialization */
42906 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42907 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42908
42909 /*
42910 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42911 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42912 index 2f0b39d..7370f13 100644
42913 --- a/drivers/input/mouse/psmouse.h
42914 +++ b/drivers/input/mouse/psmouse.h
42915 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42916 ssize_t (*set)(struct psmouse *psmouse, void *data,
42917 const char *buf, size_t count);
42918 bool protect;
42919 -};
42920 +} __do_const;
42921 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42922
42923 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42924 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42925 index b604564..3f14ae4 100644
42926 --- a/drivers/input/mousedev.c
42927 +++ b/drivers/input/mousedev.c
42928 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42929
42930 spin_unlock_irq(&client->packet_lock);
42931
42932 - if (copy_to_user(buffer, data, count))
42933 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42934 return -EFAULT;
42935
42936 return count;
42937 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42938 index b29134d..394deb0 100644
42939 --- a/drivers/input/serio/serio.c
42940 +++ b/drivers/input/serio/serio.c
42941 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
42942 */
42943 static void serio_init_port(struct serio *serio)
42944 {
42945 - static atomic_t serio_no = ATOMIC_INIT(0);
42946 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42947
42948 __module_get(THIS_MODULE);
42949
42950 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
42951 mutex_init(&serio->drv_mutex);
42952 device_initialize(&serio->dev);
42953 dev_set_name(&serio->dev, "serio%ld",
42954 - (long)atomic_inc_return(&serio_no) - 1);
42955 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42956 serio->dev.bus = &serio_bus;
42957 serio->dev.release = serio_release_port;
42958 serio->dev.groups = serio_device_attr_groups;
42959 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42960 index c9a02fe..0debc75 100644
42961 --- a/drivers/input/serio/serio_raw.c
42962 +++ b/drivers/input/serio/serio_raw.c
42963 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42964
42965 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42966 {
42967 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42968 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42969 struct serio_raw *serio_raw;
42970 int err;
42971
42972 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42973 }
42974
42975 snprintf(serio_raw->name, sizeof(serio_raw->name),
42976 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42977 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42978 kref_init(&serio_raw->kref);
42979 INIT_LIST_HEAD(&serio_raw->client_list);
42980 init_waitqueue_head(&serio_raw->wait);
42981 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42982 index e5555fc..937986d 100644
42983 --- a/drivers/iommu/iommu.c
42984 +++ b/drivers/iommu/iommu.c
42985 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42986 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42987 {
42988 bus_register_notifier(bus, &iommu_bus_nb);
42989 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42990 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42991 }
42992
42993 /**
42994 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42995 index 228632c9..edfe331 100644
42996 --- a/drivers/iommu/irq_remapping.c
42997 +++ b/drivers/iommu/irq_remapping.c
42998 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42999 void panic_if_irq_remap(const char *msg)
43000 {
43001 if (irq_remapping_enabled)
43002 - panic(msg);
43003 + panic("%s", msg);
43004 }
43005
43006 static void ir_ack_apic_edge(struct irq_data *data)
43007 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43008
43009 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43010 {
43011 - chip->irq_print_chip = ir_print_prefix;
43012 - chip->irq_ack = ir_ack_apic_edge;
43013 - chip->irq_eoi = ir_ack_apic_level;
43014 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43015 + pax_open_kernel();
43016 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43017 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43018 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43019 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43020 + pax_close_kernel();
43021 }
43022
43023 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43024 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43025 index 57d165e..611997e 100644
43026 --- a/drivers/irqchip/irq-gic.c
43027 +++ b/drivers/irqchip/irq-gic.c
43028 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43029 * Supported arch specific GIC irq extension.
43030 * Default make them NULL.
43031 */
43032 -struct irq_chip gic_arch_extn = {
43033 +irq_chip_no_const gic_arch_extn = {
43034 .irq_eoi = NULL,
43035 .irq_mask = NULL,
43036 .irq_unmask = NULL,
43037 @@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43038 chained_irq_exit(chip, desc);
43039 }
43040
43041 -static struct irq_chip gic_chip = {
43042 +static irq_chip_no_const gic_chip __read_only = {
43043 .name = "GIC",
43044 .irq_mask = gic_mask_irq,
43045 .irq_unmask = gic_unmask_irq,
43046 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43047 index 8777065..a4a9967 100644
43048 --- a/drivers/irqchip/irq-renesas-irqc.c
43049 +++ b/drivers/irqchip/irq-renesas-irqc.c
43050 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43051 struct irqc_priv *p;
43052 struct resource *io;
43053 struct resource *irq;
43054 - struct irq_chip *irq_chip;
43055 + irq_chip_no_const *irq_chip;
43056 const char *name = dev_name(&pdev->dev);
43057 int ret;
43058 int k;
43059 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43060 index ac6f72b..81150f2 100644
43061 --- a/drivers/isdn/capi/capi.c
43062 +++ b/drivers/isdn/capi/capi.c
43063 @@ -81,8 +81,8 @@ struct capiminor {
43064
43065 struct capi20_appl *ap;
43066 u32 ncci;
43067 - atomic_t datahandle;
43068 - atomic_t msgid;
43069 + atomic_unchecked_t datahandle;
43070 + atomic_unchecked_t msgid;
43071
43072 struct tty_port port;
43073 int ttyinstop;
43074 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43075 capimsg_setu16(s, 2, mp->ap->applid);
43076 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43077 capimsg_setu8 (s, 5, CAPI_RESP);
43078 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43079 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43080 capimsg_setu32(s, 8, mp->ncci);
43081 capimsg_setu16(s, 12, datahandle);
43082 }
43083 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43084 mp->outbytes -= len;
43085 spin_unlock_bh(&mp->outlock);
43086
43087 - datahandle = atomic_inc_return(&mp->datahandle);
43088 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43089 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43090 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43091 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43092 capimsg_setu16(skb->data, 2, mp->ap->applid);
43093 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43094 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43095 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43096 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43097 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43098 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43099 capimsg_setu16(skb->data, 16, len); /* Data length */
43100 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43101 index c44950d..10ac276 100644
43102 --- a/drivers/isdn/gigaset/bas-gigaset.c
43103 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43104 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43105
43106
43107 static const struct gigaset_ops gigops = {
43108 - gigaset_write_cmd,
43109 - gigaset_write_room,
43110 - gigaset_chars_in_buffer,
43111 - gigaset_brkchars,
43112 - gigaset_init_bchannel,
43113 - gigaset_close_bchannel,
43114 - gigaset_initbcshw,
43115 - gigaset_freebcshw,
43116 - gigaset_reinitbcshw,
43117 - gigaset_initcshw,
43118 - gigaset_freecshw,
43119 - gigaset_set_modem_ctrl,
43120 - gigaset_baud_rate,
43121 - gigaset_set_line_ctrl,
43122 - gigaset_isoc_send_skb,
43123 - gigaset_isoc_input,
43124 + .write_cmd = gigaset_write_cmd,
43125 + .write_room = gigaset_write_room,
43126 + .chars_in_buffer = gigaset_chars_in_buffer,
43127 + .brkchars = gigaset_brkchars,
43128 + .init_bchannel = gigaset_init_bchannel,
43129 + .close_bchannel = gigaset_close_bchannel,
43130 + .initbcshw = gigaset_initbcshw,
43131 + .freebcshw = gigaset_freebcshw,
43132 + .reinitbcshw = gigaset_reinitbcshw,
43133 + .initcshw = gigaset_initcshw,
43134 + .freecshw = gigaset_freecshw,
43135 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43136 + .baud_rate = gigaset_baud_rate,
43137 + .set_line_ctrl = gigaset_set_line_ctrl,
43138 + .send_skb = gigaset_isoc_send_skb,
43139 + .handle_input = gigaset_isoc_input,
43140 };
43141
43142 /* bas_gigaset_init
43143 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43144 index 600c79b..3752bab 100644
43145 --- a/drivers/isdn/gigaset/interface.c
43146 +++ b/drivers/isdn/gigaset/interface.c
43147 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43148 }
43149 tty->driver_data = cs;
43150
43151 - ++cs->port.count;
43152 + atomic_inc(&cs->port.count);
43153
43154 - if (cs->port.count == 1) {
43155 + if (atomic_read(&cs->port.count) == 1) {
43156 tty_port_tty_set(&cs->port, tty);
43157 cs->port.low_latency = 1;
43158 }
43159 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43160
43161 if (!cs->connected)
43162 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43163 - else if (!cs->port.count)
43164 + else if (!atomic_read(&cs->port.count))
43165 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43166 - else if (!--cs->port.count)
43167 + else if (!atomic_dec_return(&cs->port.count))
43168 tty_port_tty_set(&cs->port, NULL);
43169
43170 mutex_unlock(&cs->mutex);
43171 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43172 index 8c91fd5..14f13ce 100644
43173 --- a/drivers/isdn/gigaset/ser-gigaset.c
43174 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43175 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43176 }
43177
43178 static const struct gigaset_ops ops = {
43179 - gigaset_write_cmd,
43180 - gigaset_write_room,
43181 - gigaset_chars_in_buffer,
43182 - gigaset_brkchars,
43183 - gigaset_init_bchannel,
43184 - gigaset_close_bchannel,
43185 - gigaset_initbcshw,
43186 - gigaset_freebcshw,
43187 - gigaset_reinitbcshw,
43188 - gigaset_initcshw,
43189 - gigaset_freecshw,
43190 - gigaset_set_modem_ctrl,
43191 - gigaset_baud_rate,
43192 - gigaset_set_line_ctrl,
43193 - gigaset_m10x_send_skb, /* asyncdata.c */
43194 - gigaset_m10x_input, /* asyncdata.c */
43195 + .write_cmd = gigaset_write_cmd,
43196 + .write_room = gigaset_write_room,
43197 + .chars_in_buffer = gigaset_chars_in_buffer,
43198 + .brkchars = gigaset_brkchars,
43199 + .init_bchannel = gigaset_init_bchannel,
43200 + .close_bchannel = gigaset_close_bchannel,
43201 + .initbcshw = gigaset_initbcshw,
43202 + .freebcshw = gigaset_freebcshw,
43203 + .reinitbcshw = gigaset_reinitbcshw,
43204 + .initcshw = gigaset_initcshw,
43205 + .freecshw = gigaset_freecshw,
43206 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43207 + .baud_rate = gigaset_baud_rate,
43208 + .set_line_ctrl = gigaset_set_line_ctrl,
43209 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43210 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43211 };
43212
43213
43214 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43215 index d0a41cb..b953e50 100644
43216 --- a/drivers/isdn/gigaset/usb-gigaset.c
43217 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43218 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43219 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43220 memcpy(cs->hw.usb->bchars, buf, 6);
43221 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43222 - 0, 0, &buf, 6, 2000);
43223 + 0, 0, buf, 6, 2000);
43224 }
43225
43226 static void gigaset_freebcshw(struct bc_state *bcs)
43227 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43228 }
43229
43230 static const struct gigaset_ops ops = {
43231 - gigaset_write_cmd,
43232 - gigaset_write_room,
43233 - gigaset_chars_in_buffer,
43234 - gigaset_brkchars,
43235 - gigaset_init_bchannel,
43236 - gigaset_close_bchannel,
43237 - gigaset_initbcshw,
43238 - gigaset_freebcshw,
43239 - gigaset_reinitbcshw,
43240 - gigaset_initcshw,
43241 - gigaset_freecshw,
43242 - gigaset_set_modem_ctrl,
43243 - gigaset_baud_rate,
43244 - gigaset_set_line_ctrl,
43245 - gigaset_m10x_send_skb,
43246 - gigaset_m10x_input,
43247 + .write_cmd = gigaset_write_cmd,
43248 + .write_room = gigaset_write_room,
43249 + .chars_in_buffer = gigaset_chars_in_buffer,
43250 + .brkchars = gigaset_brkchars,
43251 + .init_bchannel = gigaset_init_bchannel,
43252 + .close_bchannel = gigaset_close_bchannel,
43253 + .initbcshw = gigaset_initbcshw,
43254 + .freebcshw = gigaset_freebcshw,
43255 + .reinitbcshw = gigaset_reinitbcshw,
43256 + .initcshw = gigaset_initcshw,
43257 + .freecshw = gigaset_freecshw,
43258 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43259 + .baud_rate = gigaset_baud_rate,
43260 + .set_line_ctrl = gigaset_set_line_ctrl,
43261 + .send_skb = gigaset_m10x_send_skb,
43262 + .handle_input = gigaset_m10x_input,
43263 };
43264
43265 /*
43266 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43267 index 4d9b195..455075c 100644
43268 --- a/drivers/isdn/hardware/avm/b1.c
43269 +++ b/drivers/isdn/hardware/avm/b1.c
43270 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43271 }
43272 if (left) {
43273 if (t4file->user) {
43274 - if (copy_from_user(buf, dp, left))
43275 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43276 return -EFAULT;
43277 } else {
43278 memcpy(buf, dp, left);
43279 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43280 }
43281 if (left) {
43282 if (config->user) {
43283 - if (copy_from_user(buf, dp, left))
43284 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43285 return -EFAULT;
43286 } else {
43287 memcpy(buf, dp, left);
43288 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43289 index 9b856e1..fa03c92 100644
43290 --- a/drivers/isdn/i4l/isdn_common.c
43291 +++ b/drivers/isdn/i4l/isdn_common.c
43292 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43293 } else
43294 return -EINVAL;
43295 case IIOCDBGVAR:
43296 + if (!capable(CAP_SYS_RAWIO))
43297 + return -EPERM;
43298 if (arg) {
43299 if (copy_to_user(argp, &dev, sizeof(ulong)))
43300 return -EFAULT;
43301 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43302 index 91d5730..336523e 100644
43303 --- a/drivers/isdn/i4l/isdn_concap.c
43304 +++ b/drivers/isdn/i4l/isdn_concap.c
43305 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43306 }
43307
43308 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43309 - &isdn_concap_dl_data_req,
43310 - &isdn_concap_dl_connect_req,
43311 - &isdn_concap_dl_disconn_req
43312 + .data_req = &isdn_concap_dl_data_req,
43313 + .connect_req = &isdn_concap_dl_connect_req,
43314 + .disconn_req = &isdn_concap_dl_disconn_req
43315 };
43316
43317 /* The following should better go into a dedicated source file such that
43318 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43319 index 3c5f249..5fac4d0 100644
43320 --- a/drivers/isdn/i4l/isdn_tty.c
43321 +++ b/drivers/isdn/i4l/isdn_tty.c
43322 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43323
43324 #ifdef ISDN_DEBUG_MODEM_OPEN
43325 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43326 - port->count);
43327 + atomic_read(&port->count));
43328 #endif
43329 - port->count++;
43330 + atomic_inc(&port->count);
43331 port->tty = tty;
43332 /*
43333 * Start up serial port
43334 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43335 #endif
43336 return;
43337 }
43338 - if ((tty->count == 1) && (port->count != 1)) {
43339 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43340 /*
43341 * Uh, oh. tty->count is 1, which means that the tty
43342 * structure will be freed. Info->count should always
43343 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43344 * serial port won't be shutdown.
43345 */
43346 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43347 - "info->count is %d\n", port->count);
43348 - port->count = 1;
43349 + "info->count is %d\n", atomic_read(&port->count));
43350 + atomic_set(&port->count, 1);
43351 }
43352 - if (--port->count < 0) {
43353 + if (atomic_dec_return(&port->count) < 0) {
43354 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43355 - info->line, port->count);
43356 - port->count = 0;
43357 + info->line, atomic_read(&port->count));
43358 + atomic_set(&port->count, 0);
43359 }
43360 - if (port->count) {
43361 + if (atomic_read(&port->count)) {
43362 #ifdef ISDN_DEBUG_MODEM_OPEN
43363 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43364 #endif
43365 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43366 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43367 return;
43368 isdn_tty_shutdown(info);
43369 - port->count = 0;
43370 + atomic_set(&port->count, 0);
43371 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43372 port->tty = NULL;
43373 wake_up_interruptible(&port->open_wait);
43374 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43375 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43376 modem_info *info = &dev->mdm.info[i];
43377
43378 - if (info->port.count == 0)
43379 + if (atomic_read(&info->port.count) == 0)
43380 continue;
43381 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43382 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43383 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43384 index e2d4e58..40cd045 100644
43385 --- a/drivers/isdn/i4l/isdn_x25iface.c
43386 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43387 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43388
43389
43390 static struct concap_proto_ops ix25_pops = {
43391 - &isdn_x25iface_proto_new,
43392 - &isdn_x25iface_proto_del,
43393 - &isdn_x25iface_proto_restart,
43394 - &isdn_x25iface_proto_close,
43395 - &isdn_x25iface_xmit,
43396 - &isdn_x25iface_receive,
43397 - &isdn_x25iface_connect_ind,
43398 - &isdn_x25iface_disconn_ind
43399 + .proto_new = &isdn_x25iface_proto_new,
43400 + .proto_del = &isdn_x25iface_proto_del,
43401 + .restart = &isdn_x25iface_proto_restart,
43402 + .close = &isdn_x25iface_proto_close,
43403 + .encap_and_xmit = &isdn_x25iface_xmit,
43404 + .data_ind = &isdn_x25iface_receive,
43405 + .connect_ind = &isdn_x25iface_connect_ind,
43406 + .disconn_ind = &isdn_x25iface_disconn_ind
43407 };
43408
43409 /* error message helper function */
43410 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43411 index 6a7447c..cae33fe 100644
43412 --- a/drivers/isdn/icn/icn.c
43413 +++ b/drivers/isdn/icn/icn.c
43414 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43415 if (count > len)
43416 count = len;
43417 if (user) {
43418 - if (copy_from_user(msg, buf, count))
43419 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43420 return -EFAULT;
43421 } else
43422 memcpy(msg, buf, count);
43423 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43424 index a4f05c5..1433bc5 100644
43425 --- a/drivers/isdn/mISDN/dsp_cmx.c
43426 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43427 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43428 static u16 dsp_count; /* last sample count */
43429 static int dsp_count_valid; /* if we have last sample count */
43430
43431 -void
43432 +void __intentional_overflow(-1)
43433 dsp_cmx_send(void *arg)
43434 {
43435 struct dsp_conf *conf;
43436 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43437 index f58a354..fbae176 100644
43438 --- a/drivers/leds/leds-clevo-mail.c
43439 +++ b/drivers/leds/leds-clevo-mail.c
43440 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43441 * detected as working, but in reality it is not) as low as
43442 * possible.
43443 */
43444 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43445 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43446 {
43447 .callback = clevo_mail_led_dmi_callback,
43448 .ident = "Clevo D410J",
43449 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43450 index 2eb3ef6..295891f 100644
43451 --- a/drivers/leds/leds-ss4200.c
43452 +++ b/drivers/leds/leds-ss4200.c
43453 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43454 * detected as working, but in reality it is not) as low as
43455 * possible.
43456 */
43457 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43458 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43459 {
43460 .callback = ss4200_led_dmi_callback,
43461 .ident = "Intel SS4200-E",
43462 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43463 index 0bf1e4e..b4bf44e 100644
43464 --- a/drivers/lguest/core.c
43465 +++ b/drivers/lguest/core.c
43466 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43467 * The end address needs +1 because __get_vm_area allocates an
43468 * extra guard page, so we need space for that.
43469 */
43470 +
43471 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43472 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43473 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43474 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43475 +#else
43476 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43477 VM_ALLOC, switcher_addr, switcher_addr
43478 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43479 +#endif
43480 +
43481 if (!switcher_vma) {
43482 err = -ENOMEM;
43483 printk("lguest: could not map switcher pages high\n");
43484 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43485 * Now the Switcher is mapped at the right address, we can't fail!
43486 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43487 */
43488 - memcpy(switcher_vma->addr, start_switcher_text,
43489 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43490 end_switcher_text - start_switcher_text);
43491
43492 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43493 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43494 index e8b55c3..3514c37 100644
43495 --- a/drivers/lguest/page_tables.c
43496 +++ b/drivers/lguest/page_tables.c
43497 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43498 /*:*/
43499
43500 #ifdef CONFIG_X86_PAE
43501 -static void release_pmd(pmd_t *spmd)
43502 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43503 {
43504 /* If the entry's not present, there's nothing to release. */
43505 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43506 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43507 index 922a1ac..9dd0c2a 100644
43508 --- a/drivers/lguest/x86/core.c
43509 +++ b/drivers/lguest/x86/core.c
43510 @@ -59,7 +59,7 @@ static struct {
43511 /* Offset from where switcher.S was compiled to where we've copied it */
43512 static unsigned long switcher_offset(void)
43513 {
43514 - return switcher_addr - (unsigned long)start_switcher_text;
43515 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43516 }
43517
43518 /* This cpu's struct lguest_pages (after the Switcher text page) */
43519 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43520 * These copies are pretty cheap, so we do them unconditionally: */
43521 /* Save the current Host top-level page directory.
43522 */
43523 +
43524 +#ifdef CONFIG_PAX_PER_CPU_PGD
43525 + pages->state.host_cr3 = read_cr3();
43526 +#else
43527 pages->state.host_cr3 = __pa(current->mm->pgd);
43528 +#endif
43529 +
43530 /*
43531 * Set up the Guest's page tables to see this CPU's pages (and no
43532 * other CPU's pages).
43533 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43534 * compiled-in switcher code and the high-mapped copy we just made.
43535 */
43536 for (i = 0; i < IDT_ENTRIES; i++)
43537 - default_idt_entries[i] += switcher_offset();
43538 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43539
43540 /*
43541 * Set up the Switcher's per-cpu areas.
43542 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43543 * it will be undisturbed when we switch. To change %cs and jump we
43544 * need this structure to feed to Intel's "lcall" instruction.
43545 */
43546 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43547 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43548 lguest_entry.segment = LGUEST_CS;
43549
43550 /*
43551 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43552 index 40634b0..4f5855e 100644
43553 --- a/drivers/lguest/x86/switcher_32.S
43554 +++ b/drivers/lguest/x86/switcher_32.S
43555 @@ -87,6 +87,7 @@
43556 #include <asm/page.h>
43557 #include <asm/segment.h>
43558 #include <asm/lguest.h>
43559 +#include <asm/processor-flags.h>
43560
43561 // We mark the start of the code to copy
43562 // It's placed in .text tho it's never run here
43563 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43564 // Changes type when we load it: damn Intel!
43565 // For after we switch over our page tables
43566 // That entry will be read-only: we'd crash.
43567 +
43568 +#ifdef CONFIG_PAX_KERNEXEC
43569 + mov %cr0, %edx
43570 + xor $X86_CR0_WP, %edx
43571 + mov %edx, %cr0
43572 +#endif
43573 +
43574 movl $(GDT_ENTRY_TSS*8), %edx
43575 ltr %dx
43576
43577 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43578 // Let's clear it again for our return.
43579 // The GDT descriptor of the Host
43580 // Points to the table after two "size" bytes
43581 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43582 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43583 // Clear "used" from type field (byte 5, bit 2)
43584 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43585 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43586 +
43587 +#ifdef CONFIG_PAX_KERNEXEC
43588 + mov %cr0, %eax
43589 + xor $X86_CR0_WP, %eax
43590 + mov %eax, %cr0
43591 +#endif
43592
43593 // Once our page table's switched, the Guest is live!
43594 // The Host fades as we run this final step.
43595 @@ -295,13 +309,12 @@ deliver_to_host:
43596 // I consulted gcc, and it gave
43597 // These instructions, which I gladly credit:
43598 leal (%edx,%ebx,8), %eax
43599 - movzwl (%eax),%edx
43600 - movl 4(%eax), %eax
43601 - xorw %ax, %ax
43602 - orl %eax, %edx
43603 + movl 4(%eax), %edx
43604 + movw (%eax), %dx
43605 // Now the address of the handler's in %edx
43606 // We call it now: its "iret" drops us home.
43607 - jmp *%edx
43608 + ljmp $__KERNEL_CS, $1f
43609 +1: jmp *%edx
43610
43611 // Every interrupt can come to us here
43612 // But we must truly tell each apart.
43613 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43614 index 7ef7461..5a09dac 100644
43615 --- a/drivers/md/bcache/closure.h
43616 +++ b/drivers/md/bcache/closure.h
43617 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43618 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43619 struct workqueue_struct *wq)
43620 {
43621 - BUG_ON(object_is_on_stack(cl));
43622 + BUG_ON(object_starts_on_stack(cl));
43623 closure_set_ip(cl);
43624 cl->fn = fn;
43625 cl->wq = wq;
43626 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43627 index 9a8e66a..10cc762 100644
43628 --- a/drivers/md/bitmap.c
43629 +++ b/drivers/md/bitmap.c
43630 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43631 chunk_kb ? "KB" : "B");
43632 if (bitmap->storage.file) {
43633 seq_printf(seq, ", file: ");
43634 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43635 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43636 }
43637
43638 seq_printf(seq, "\n");
43639 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43640 index 5152142..623d141 100644
43641 --- a/drivers/md/dm-ioctl.c
43642 +++ b/drivers/md/dm-ioctl.c
43643 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43644 cmd == DM_LIST_VERSIONS_CMD)
43645 return 0;
43646
43647 - if ((cmd == DM_DEV_CREATE_CMD)) {
43648 + if (cmd == DM_DEV_CREATE_CMD) {
43649 if (!*param->name) {
43650 DMWARN("name not supplied when creating device");
43651 return -EINVAL;
43652 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43653 index 7dfdb5c..4caada6 100644
43654 --- a/drivers/md/dm-raid1.c
43655 +++ b/drivers/md/dm-raid1.c
43656 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43657
43658 struct mirror {
43659 struct mirror_set *ms;
43660 - atomic_t error_count;
43661 + atomic_unchecked_t error_count;
43662 unsigned long error_type;
43663 struct dm_dev *dev;
43664 sector_t offset;
43665 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43666 struct mirror *m;
43667
43668 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43669 - if (!atomic_read(&m->error_count))
43670 + if (!atomic_read_unchecked(&m->error_count))
43671 return m;
43672
43673 return NULL;
43674 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43675 * simple way to tell if a device has encountered
43676 * errors.
43677 */
43678 - atomic_inc(&m->error_count);
43679 + atomic_inc_unchecked(&m->error_count);
43680
43681 if (test_and_set_bit(error_type, &m->error_type))
43682 return;
43683 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43684 struct mirror *m = get_default_mirror(ms);
43685
43686 do {
43687 - if (likely(!atomic_read(&m->error_count)))
43688 + if (likely(!atomic_read_unchecked(&m->error_count)))
43689 return m;
43690
43691 if (m-- == ms->mirror)
43692 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43693 {
43694 struct mirror *default_mirror = get_default_mirror(m->ms);
43695
43696 - return !atomic_read(&default_mirror->error_count);
43697 + return !atomic_read_unchecked(&default_mirror->error_count);
43698 }
43699
43700 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43701 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43702 */
43703 if (likely(region_in_sync(ms, region, 1)))
43704 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43705 - else if (m && atomic_read(&m->error_count))
43706 + else if (m && atomic_read_unchecked(&m->error_count))
43707 m = NULL;
43708
43709 if (likely(m))
43710 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43711 }
43712
43713 ms->mirror[mirror].ms = ms;
43714 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43715 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43716 ms->mirror[mirror].error_type = 0;
43717 ms->mirror[mirror].offset = offset;
43718
43719 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43720 */
43721 static char device_status_char(struct mirror *m)
43722 {
43723 - if (!atomic_read(&(m->error_count)))
43724 + if (!atomic_read_unchecked(&(m->error_count)))
43725 return 'A';
43726
43727 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43728 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43729 index 28a9012..9c0f6a5 100644
43730 --- a/drivers/md/dm-stats.c
43731 +++ b/drivers/md/dm-stats.c
43732 @@ -382,7 +382,7 @@ do_sync_free:
43733 synchronize_rcu_expedited();
43734 dm_stat_free(&s->rcu_head);
43735 } else {
43736 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43737 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43738 call_rcu(&s->rcu_head, dm_stat_free);
43739 }
43740 return 0;
43741 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43742 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43743 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43744 ));
43745 - ACCESS_ONCE(last->last_sector) = end_sector;
43746 - ACCESS_ONCE(last->last_rw) = bi_rw;
43747 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43748 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43749 }
43750
43751 rcu_read_lock();
43752 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43753 index d1600d2..4c3af3a 100644
43754 --- a/drivers/md/dm-stripe.c
43755 +++ b/drivers/md/dm-stripe.c
43756 @@ -21,7 +21,7 @@ struct stripe {
43757 struct dm_dev *dev;
43758 sector_t physical_start;
43759
43760 - atomic_t error_count;
43761 + atomic_unchecked_t error_count;
43762 };
43763
43764 struct stripe_c {
43765 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43766 kfree(sc);
43767 return r;
43768 }
43769 - atomic_set(&(sc->stripe[i].error_count), 0);
43770 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43771 }
43772
43773 ti->private = sc;
43774 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43775 DMEMIT("%d ", sc->stripes);
43776 for (i = 0; i < sc->stripes; i++) {
43777 DMEMIT("%s ", sc->stripe[i].dev->name);
43778 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43779 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43780 'D' : 'A';
43781 }
43782 buffer[i] = '\0';
43783 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43784 */
43785 for (i = 0; i < sc->stripes; i++)
43786 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43787 - atomic_inc(&(sc->stripe[i].error_count));
43788 - if (atomic_read(&(sc->stripe[i].error_count)) <
43789 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43790 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43791 DM_IO_ERROR_THRESHOLD)
43792 schedule_work(&sc->trigger_event);
43793 }
43794 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43795 index 50601ec..6d3b9dc 100644
43796 --- a/drivers/md/dm-table.c
43797 +++ b/drivers/md/dm-table.c
43798 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43799 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43800 struct mapped_device *md)
43801 {
43802 - static char *_claim_ptr = "I belong to device-mapper";
43803 + static char _claim_ptr[] = "I belong to device-mapper";
43804 struct block_device *bdev;
43805
43806 int r;
43807 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43808 if (!dev_size)
43809 return 0;
43810
43811 - if ((start >= dev_size) || (start + len > dev_size)) {
43812 + if ((start >= dev_size) || (len > dev_size - start)) {
43813 DMWARN("%s: %s too small for target: "
43814 "start=%llu, len=%llu, dev_size=%llu",
43815 dm_device_name(ti->table->md), bdevname(bdev, b),
43816 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43817 index b086a94..74cb67e 100644
43818 --- a/drivers/md/dm-thin-metadata.c
43819 +++ b/drivers/md/dm-thin-metadata.c
43820 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43821 {
43822 pmd->info.tm = pmd->tm;
43823 pmd->info.levels = 2;
43824 - pmd->info.value_type.context = pmd->data_sm;
43825 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43826 pmd->info.value_type.size = sizeof(__le64);
43827 pmd->info.value_type.inc = data_block_inc;
43828 pmd->info.value_type.dec = data_block_dec;
43829 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43830
43831 pmd->bl_info.tm = pmd->tm;
43832 pmd->bl_info.levels = 1;
43833 - pmd->bl_info.value_type.context = pmd->data_sm;
43834 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43835 pmd->bl_info.value_type.size = sizeof(__le64);
43836 pmd->bl_info.value_type.inc = data_block_inc;
43837 pmd->bl_info.value_type.dec = data_block_dec;
43838 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43839 index 455e649..1f214be 100644
43840 --- a/drivers/md/dm.c
43841 +++ b/drivers/md/dm.c
43842 @@ -178,9 +178,9 @@ struct mapped_device {
43843 /*
43844 * Event handling.
43845 */
43846 - atomic_t event_nr;
43847 + atomic_unchecked_t event_nr;
43848 wait_queue_head_t eventq;
43849 - atomic_t uevent_seq;
43850 + atomic_unchecked_t uevent_seq;
43851 struct list_head uevent_list;
43852 spinlock_t uevent_lock; /* Protect access to uevent_list */
43853
43854 @@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
43855 spin_lock_init(&md->deferred_lock);
43856 atomic_set(&md->holders, 1);
43857 atomic_set(&md->open_count, 0);
43858 - atomic_set(&md->event_nr, 0);
43859 - atomic_set(&md->uevent_seq, 0);
43860 + atomic_set_unchecked(&md->event_nr, 0);
43861 + atomic_set_unchecked(&md->uevent_seq, 0);
43862 INIT_LIST_HEAD(&md->uevent_list);
43863 spin_lock_init(&md->uevent_lock);
43864
43865 @@ -2039,7 +2039,7 @@ static void event_callback(void *context)
43866
43867 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43868
43869 - atomic_inc(&md->event_nr);
43870 + atomic_inc_unchecked(&md->event_nr);
43871 wake_up(&md->eventq);
43872 }
43873
43874 @@ -2732,18 +2732,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43875
43876 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43877 {
43878 - return atomic_add_return(1, &md->uevent_seq);
43879 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43880 }
43881
43882 uint32_t dm_get_event_nr(struct mapped_device *md)
43883 {
43884 - return atomic_read(&md->event_nr);
43885 + return atomic_read_unchecked(&md->event_nr);
43886 }
43887
43888 int dm_wait_event(struct mapped_device *md, int event_nr)
43889 {
43890 return wait_event_interruptible(md->eventq,
43891 - (event_nr != atomic_read(&md->event_nr)));
43892 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43893 }
43894
43895 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43896 diff --git a/drivers/md/md.c b/drivers/md/md.c
43897 index 2382cfc..0d7e551 100644
43898 --- a/drivers/md/md.c
43899 +++ b/drivers/md/md.c
43900 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43901 * start build, activate spare
43902 */
43903 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43904 -static atomic_t md_event_count;
43905 +static atomic_unchecked_t md_event_count;
43906 void md_new_event(struct mddev *mddev)
43907 {
43908 - atomic_inc(&md_event_count);
43909 + atomic_inc_unchecked(&md_event_count);
43910 wake_up(&md_event_waiters);
43911 }
43912 EXPORT_SYMBOL_GPL(md_new_event);
43913 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43914 */
43915 static void md_new_event_inintr(struct mddev *mddev)
43916 {
43917 - atomic_inc(&md_event_count);
43918 + atomic_inc_unchecked(&md_event_count);
43919 wake_up(&md_event_waiters);
43920 }
43921
43922 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43923 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43924 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43925 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43926 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43927 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43928
43929 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43930 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43931 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43932 else
43933 sb->resync_offset = cpu_to_le64(0);
43934
43935 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43936 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43937
43938 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43939 sb->size = cpu_to_le64(mddev->dev_sectors);
43940 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43941 static ssize_t
43942 errors_show(struct md_rdev *rdev, char *page)
43943 {
43944 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43945 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43946 }
43947
43948 static ssize_t
43949 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43950 char *e;
43951 unsigned long n = simple_strtoul(buf, &e, 10);
43952 if (*buf && (*e == 0 || *e == '\n')) {
43953 - atomic_set(&rdev->corrected_errors, n);
43954 + atomic_set_unchecked(&rdev->corrected_errors, n);
43955 return len;
43956 }
43957 return -EINVAL;
43958 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43959 rdev->sb_loaded = 0;
43960 rdev->bb_page = NULL;
43961 atomic_set(&rdev->nr_pending, 0);
43962 - atomic_set(&rdev->read_errors, 0);
43963 - atomic_set(&rdev->corrected_errors, 0);
43964 + atomic_set_unchecked(&rdev->read_errors, 0);
43965 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43966
43967 INIT_LIST_HEAD(&rdev->same_set);
43968 init_waitqueue_head(&rdev->blocked_wait);
43969 @@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43970
43971 spin_unlock(&pers_lock);
43972 seq_printf(seq, "\n");
43973 - seq->poll_event = atomic_read(&md_event_count);
43974 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43975 return 0;
43976 }
43977 if (v == (void*)2) {
43978 @@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43979 return error;
43980
43981 seq = file->private_data;
43982 - seq->poll_event = atomic_read(&md_event_count);
43983 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43984 return error;
43985 }
43986
43987 @@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43988 /* always allow read */
43989 mask = POLLIN | POLLRDNORM;
43990
43991 - if (seq->poll_event != atomic_read(&md_event_count))
43992 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43993 mask |= POLLERR | POLLPRI;
43994 return mask;
43995 }
43996 @@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43997 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43998 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43999 (int)part_stat_read(&disk->part0, sectors[1]) -
44000 - atomic_read(&disk->sync_io);
44001 + atomic_read_unchecked(&disk->sync_io);
44002 /* sync IO will cause sync_io to increase before the disk_stats
44003 * as sync_io is counted when a request starts, and
44004 * disk_stats is counted when it completes.
44005 diff --git a/drivers/md/md.h b/drivers/md/md.h
44006 index a49d991..3582bb7 100644
44007 --- a/drivers/md/md.h
44008 +++ b/drivers/md/md.h
44009 @@ -94,13 +94,13 @@ struct md_rdev {
44010 * only maintained for arrays that
44011 * support hot removal
44012 */
44013 - atomic_t read_errors; /* number of consecutive read errors that
44014 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44015 * we have tried to ignore.
44016 */
44017 struct timespec last_read_error; /* monotonic time since our
44018 * last read error
44019 */
44020 - atomic_t corrected_errors; /* number of corrected read errors,
44021 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44022 * for reporting to userspace and storing
44023 * in superblock.
44024 */
44025 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44026
44027 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44028 {
44029 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44030 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44031 }
44032
44033 struct md_personality
44034 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44035 index 786b689..ea8c956 100644
44036 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44037 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44038 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44039 * Flick into a mode where all blocks get allocated in the new area.
44040 */
44041 smm->begin = old_len;
44042 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44043 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44044
44045 /*
44046 * Extend.
44047 @@ -710,7 +710,7 @@ out:
44048 /*
44049 * Switch back to normal behaviour.
44050 */
44051 - memcpy(sm, &ops, sizeof(*sm));
44052 + memcpy((void *)sm, &ops, sizeof(*sm));
44053 return r;
44054 }
44055
44056 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44057 index 3e6d115..ffecdeb 100644
44058 --- a/drivers/md/persistent-data/dm-space-map.h
44059 +++ b/drivers/md/persistent-data/dm-space-map.h
44060 @@ -71,6 +71,7 @@ struct dm_space_map {
44061 dm_sm_threshold_fn fn,
44062 void *context);
44063 };
44064 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44065
44066 /*----------------------------------------------------------------*/
44067
44068 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44069 index 56e24c0..e1c8e1f 100644
44070 --- a/drivers/md/raid1.c
44071 +++ b/drivers/md/raid1.c
44072 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44073 if (r1_sync_page_io(rdev, sect, s,
44074 bio->bi_io_vec[idx].bv_page,
44075 READ) != 0)
44076 - atomic_add(s, &rdev->corrected_errors);
44077 + atomic_add_unchecked(s, &rdev->corrected_errors);
44078 }
44079 sectors -= s;
44080 sect += s;
44081 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44082 test_bit(In_sync, &rdev->flags)) {
44083 if (r1_sync_page_io(rdev, sect, s,
44084 conf->tmppage, READ)) {
44085 - atomic_add(s, &rdev->corrected_errors);
44086 + atomic_add_unchecked(s, &rdev->corrected_errors);
44087 printk(KERN_INFO
44088 "md/raid1:%s: read error corrected "
44089 "(%d sectors at %llu on %s)\n",
44090 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44091 index cb882aa..9bd076e 100644
44092 --- a/drivers/md/raid10.c
44093 +++ b/drivers/md/raid10.c
44094 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44095 /* The write handler will notice the lack of
44096 * R10BIO_Uptodate and record any errors etc
44097 */
44098 - atomic_add(r10_bio->sectors,
44099 + atomic_add_unchecked(r10_bio->sectors,
44100 &conf->mirrors[d].rdev->corrected_errors);
44101
44102 /* for reconstruct, we always reschedule after a read.
44103 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44104 {
44105 struct timespec cur_time_mon;
44106 unsigned long hours_since_last;
44107 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44108 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44109
44110 ktime_get_ts(&cur_time_mon);
44111
44112 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44113 * overflowing the shift of read_errors by hours_since_last.
44114 */
44115 if (hours_since_last >= 8 * sizeof(read_errors))
44116 - atomic_set(&rdev->read_errors, 0);
44117 + atomic_set_unchecked(&rdev->read_errors, 0);
44118 else
44119 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44120 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44121 }
44122
44123 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44124 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44125 return;
44126
44127 check_decay_read_errors(mddev, rdev);
44128 - atomic_inc(&rdev->read_errors);
44129 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44130 + atomic_inc_unchecked(&rdev->read_errors);
44131 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44132 char b[BDEVNAME_SIZE];
44133 bdevname(rdev->bdev, b);
44134
44135 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44136 "md/raid10:%s: %s: Raid device exceeded "
44137 "read_error threshold [cur %d:max %d]\n",
44138 mdname(mddev), b,
44139 - atomic_read(&rdev->read_errors), max_read_errors);
44140 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44141 printk(KERN_NOTICE
44142 "md/raid10:%s: %s: Failing raid device\n",
44143 mdname(mddev), b);
44144 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44145 sect +
44146 choose_data_offset(r10_bio, rdev)),
44147 bdevname(rdev->bdev, b));
44148 - atomic_add(s, &rdev->corrected_errors);
44149 + atomic_add_unchecked(s, &rdev->corrected_errors);
44150 }
44151
44152 rdev_dec_pending(rdev, mddev);
44153 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44154 index ad1b9be..b417412 100644
44155 --- a/drivers/md/raid5.c
44156 +++ b/drivers/md/raid5.c
44157 @@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44158 return 1;
44159 }
44160
44161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44162 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44163 +#endif
44164 +
44165 static int grow_stripes(struct r5conf *conf, int num)
44166 {
44167 struct kmem_cache *sc;
44168 @@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44169 "raid%d-%s", conf->level, mdname(conf->mddev));
44170 else
44171 sprintf(conf->cache_name[0],
44172 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44173 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44174 +#else
44175 "raid%d-%p", conf->level, conf->mddev);
44176 +#endif
44177 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44178
44179 conf->active_name = 0;
44180 @@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44181 mdname(conf->mddev), STRIPE_SECTORS,
44182 (unsigned long long)s,
44183 bdevname(rdev->bdev, b));
44184 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44185 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44186 clear_bit(R5_ReadError, &sh->dev[i].flags);
44187 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44188 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44189 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44190
44191 - if (atomic_read(&rdev->read_errors))
44192 - atomic_set(&rdev->read_errors, 0);
44193 + if (atomic_read_unchecked(&rdev->read_errors))
44194 + atomic_set_unchecked(&rdev->read_errors, 0);
44195 } else {
44196 const char *bdn = bdevname(rdev->bdev, b);
44197 int retry = 0;
44198 int set_bad = 0;
44199
44200 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44201 - atomic_inc(&rdev->read_errors);
44202 + atomic_inc_unchecked(&rdev->read_errors);
44203 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44204 printk_ratelimited(
44205 KERN_WARNING
44206 @@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44207 mdname(conf->mddev),
44208 (unsigned long long)s,
44209 bdn);
44210 - } else if (atomic_read(&rdev->read_errors)
44211 + } else if (atomic_read_unchecked(&rdev->read_errors)
44212 > conf->max_nr_stripes)
44213 printk(KERN_WARNING
44214 "md/raid:%s: Too many read errors, failing device %s.\n",
44215 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44216 index 983db75..ef9248c 100644
44217 --- a/drivers/media/dvb-core/dvbdev.c
44218 +++ b/drivers/media/dvb-core/dvbdev.c
44219 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44220 const struct dvb_device *template, void *priv, int type)
44221 {
44222 struct dvb_device *dvbdev;
44223 - struct file_operations *dvbdevfops;
44224 + file_operations_no_const *dvbdevfops;
44225 struct device *clsdev;
44226 int minor;
44227 int id;
44228 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44229 index 539f4db..cdd403b 100644
44230 --- a/drivers/media/dvb-frontends/af9033.h
44231 +++ b/drivers/media/dvb-frontends/af9033.h
44232 @@ -82,7 +82,7 @@ struct af9033_ops {
44233 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44234 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44235 int onoff);
44236 -};
44237 +} __no_const;
44238
44239
44240 #if IS_ENABLED(CONFIG_DVB_AF9033)
44241 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44242 index 9b6c3bb..baeb5c7 100644
44243 --- a/drivers/media/dvb-frontends/dib3000.h
44244 +++ b/drivers/media/dvb-frontends/dib3000.h
44245 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44246 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44247 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44248 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44249 -};
44250 +} __no_const;
44251
44252 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44253 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44254 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44255 index ed8cb90..5ef7f79 100644
44256 --- a/drivers/media/pci/cx88/cx88-video.c
44257 +++ b/drivers/media/pci/cx88/cx88-video.c
44258 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44259
44260 /* ------------------------------------------------------------------ */
44261
44262 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44263 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44264 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44265 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44266 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44267 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44268
44269 module_param_array(video_nr, int, NULL, 0444);
44270 module_param_array(vbi_nr, int, NULL, 0444);
44271 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44272 index 802642d..5534900 100644
44273 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44274 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44275 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44276 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44277
44278 /* ivtv instance counter */
44279 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44280 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44281
44282 /* Parameter declarations */
44283 static int cardtype[IVTV_MAX_CARDS];
44284 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44285 index 9a726ea..f5e9b52 100644
44286 --- a/drivers/media/platform/omap/omap_vout.c
44287 +++ b/drivers/media/platform/omap/omap_vout.c
44288 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44289 OMAP_VIDEO2,
44290 };
44291
44292 -static struct videobuf_queue_ops video_vbq_ops;
44293 /* Variables configurable through module params*/
44294 static u32 video1_numbuffers = 3;
44295 static u32 video2_numbuffers = 3;
44296 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44297 {
44298 struct videobuf_queue *q;
44299 struct omap_vout_device *vout = NULL;
44300 + static struct videobuf_queue_ops video_vbq_ops = {
44301 + .buf_setup = omap_vout_buffer_setup,
44302 + .buf_prepare = omap_vout_buffer_prepare,
44303 + .buf_release = omap_vout_buffer_release,
44304 + .buf_queue = omap_vout_buffer_queue,
44305 + };
44306
44307 vout = video_drvdata(file);
44308 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44309 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44310 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44311
44312 q = &vout->vbq;
44313 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44314 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44315 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44316 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44317 spin_lock_init(&vout->vbq_lock);
44318
44319 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44320 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44321 index fb2acc5..a2fcbdc4 100644
44322 --- a/drivers/media/platform/s5p-tv/mixer.h
44323 +++ b/drivers/media/platform/s5p-tv/mixer.h
44324 @@ -156,7 +156,7 @@ struct mxr_layer {
44325 /** layer index (unique identifier) */
44326 int idx;
44327 /** callbacks for layer methods */
44328 - struct mxr_layer_ops ops;
44329 + struct mxr_layer_ops *ops;
44330 /** format array */
44331 const struct mxr_format **fmt_array;
44332 /** size of format array */
44333 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44334 index 74344c7..a39e70e 100644
44335 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44336 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44337 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44338 {
44339 struct mxr_layer *layer;
44340 int ret;
44341 - struct mxr_layer_ops ops = {
44342 + static struct mxr_layer_ops ops = {
44343 .release = mxr_graph_layer_release,
44344 .buffer_set = mxr_graph_buffer_set,
44345 .stream_set = mxr_graph_stream_set,
44346 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44347 index b713403..53cb5ad 100644
44348 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44349 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44350 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44351 layer->update_buf = next;
44352 }
44353
44354 - layer->ops.buffer_set(layer, layer->update_buf);
44355 + layer->ops->buffer_set(layer, layer->update_buf);
44356
44357 if (done && done != layer->shadow_buf)
44358 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44359 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44360 index a1ce55f..4a3c4d9 100644
44361 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44362 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44363 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44364 layer->geo.src.height = layer->geo.src.full_height;
44365
44366 mxr_geometry_dump(mdev, &layer->geo);
44367 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44368 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44369 mxr_geometry_dump(mdev, &layer->geo);
44370 }
44371
44372 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44373 layer->geo.dst.full_width = mbus_fmt.width;
44374 layer->geo.dst.full_height = mbus_fmt.height;
44375 layer->geo.dst.field = mbus_fmt.field;
44376 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44377 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44378
44379 mxr_geometry_dump(mdev, &layer->geo);
44380 }
44381 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44382 /* set source size to highest accepted value */
44383 geo->src.full_width = max(geo->dst.full_width, pix->width);
44384 geo->src.full_height = max(geo->dst.full_height, pix->height);
44385 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44386 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44387 mxr_geometry_dump(mdev, &layer->geo);
44388 /* set cropping to total visible screen */
44389 geo->src.width = pix->width;
44390 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44391 geo->src.x_offset = 0;
44392 geo->src.y_offset = 0;
44393 /* assure consistency of geometry */
44394 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44395 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44396 mxr_geometry_dump(mdev, &layer->geo);
44397 /* set full size to lowest possible value */
44398 geo->src.full_width = 0;
44399 geo->src.full_height = 0;
44400 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44401 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44402 mxr_geometry_dump(mdev, &layer->geo);
44403
44404 /* returning results */
44405 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44406 target->width = s->r.width;
44407 target->height = s->r.height;
44408
44409 - layer->ops.fix_geometry(layer, stage, s->flags);
44410 + layer->ops->fix_geometry(layer, stage, s->flags);
44411
44412 /* retrieve update selection rectangle */
44413 res.left = target->x_offset;
44414 @@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44415 mxr_output_get(mdev);
44416
44417 mxr_layer_update_output(layer);
44418 - layer->ops.format_set(layer);
44419 + layer->ops->format_set(layer);
44420 /* enabling layer in hardware */
44421 spin_lock_irqsave(&layer->enq_slock, flags);
44422 layer->state = MXR_LAYER_STREAMING;
44423 spin_unlock_irqrestore(&layer->enq_slock, flags);
44424
44425 - layer->ops.stream_set(layer, MXR_ENABLE);
44426 + layer->ops->stream_set(layer, MXR_ENABLE);
44427 mxr_streamer_get(mdev);
44428
44429 return 0;
44430 @@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44431 spin_unlock_irqrestore(&layer->enq_slock, flags);
44432
44433 /* disabling layer in hardware */
44434 - layer->ops.stream_set(layer, MXR_DISABLE);
44435 + layer->ops->stream_set(layer, MXR_DISABLE);
44436 /* remove one streamer */
44437 mxr_streamer_put(mdev);
44438 /* allow changes in output configuration */
44439 @@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44440
44441 void mxr_layer_release(struct mxr_layer *layer)
44442 {
44443 - if (layer->ops.release)
44444 - layer->ops.release(layer);
44445 + if (layer->ops->release)
44446 + layer->ops->release(layer);
44447 }
44448
44449 void mxr_base_layer_release(struct mxr_layer *layer)
44450 @@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44451
44452 layer->mdev = mdev;
44453 layer->idx = idx;
44454 - layer->ops = *ops;
44455 + layer->ops = ops;
44456
44457 spin_lock_init(&layer->enq_slock);
44458 INIT_LIST_HEAD(&layer->enq_list);
44459 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44460 index c9388c4..ce71ece 100644
44461 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44462 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44463 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44464 {
44465 struct mxr_layer *layer;
44466 int ret;
44467 - struct mxr_layer_ops ops = {
44468 + static struct mxr_layer_ops ops = {
44469 .release = mxr_vp_layer_release,
44470 .buffer_set = mxr_vp_buffer_set,
44471 .stream_set = mxr_vp_stream_set,
44472 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44473 index 3890f4f..b5c7511 100644
44474 --- a/drivers/media/platform/vivi.c
44475 +++ b/drivers/media/platform/vivi.c
44476 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44477 MODULE_LICENSE("Dual BSD/GPL");
44478 MODULE_VERSION(VIVI_VERSION);
44479
44480 -static unsigned video_nr = -1;
44481 -module_param(video_nr, uint, 0644);
44482 +static int video_nr = -1;
44483 +module_param(video_nr, int, 0644);
44484 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44485
44486 static unsigned n_devs = 1;
44487 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44488 index d719e59..63f3470 100644
44489 --- a/drivers/media/radio/radio-cadet.c
44490 +++ b/drivers/media/radio/radio-cadet.c
44491 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44492 unsigned char readbuf[RDS_BUFFER];
44493 int i = 0;
44494
44495 + if (count > RDS_BUFFER)
44496 + return -EFAULT;
44497 mutex_lock(&dev->lock);
44498 if (dev->rdsstat == 0)
44499 cadet_start_rds(dev);
44500 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44501 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44502 mutex_unlock(&dev->lock);
44503
44504 - if (i && copy_to_user(data, readbuf, i))
44505 - return -EFAULT;
44506 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44507 + i = -EFAULT;
44508 +
44509 return i;
44510 }
44511
44512 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44513 index 5236035..c622c74 100644
44514 --- a/drivers/media/radio/radio-maxiradio.c
44515 +++ b/drivers/media/radio/radio-maxiradio.c
44516 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44517 /* TEA5757 pin mappings */
44518 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44519
44520 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44521 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44522
44523 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44524 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44525 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44526 index 050b3bb..79f62b9 100644
44527 --- a/drivers/media/radio/radio-shark.c
44528 +++ b/drivers/media/radio/radio-shark.c
44529 @@ -79,7 +79,7 @@ struct shark_device {
44530 u32 last_val;
44531 };
44532
44533 -static atomic_t shark_instance = ATOMIC_INIT(0);
44534 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44535
44536 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44537 {
44538 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44539 index 8654e0d..0608a64 100644
44540 --- a/drivers/media/radio/radio-shark2.c
44541 +++ b/drivers/media/radio/radio-shark2.c
44542 @@ -74,7 +74,7 @@ struct shark_device {
44543 u8 *transfer_buffer;
44544 };
44545
44546 -static atomic_t shark_instance = ATOMIC_INIT(0);
44547 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44548
44549 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44550 {
44551 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44552 index 2fd9009..278cc1e 100644
44553 --- a/drivers/media/radio/radio-si476x.c
44554 +++ b/drivers/media/radio/radio-si476x.c
44555 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44556 struct si476x_radio *radio;
44557 struct v4l2_ctrl *ctrl;
44558
44559 - static atomic_t instance = ATOMIC_INIT(0);
44560 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44561
44562 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44563 if (!radio)
44564 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44565 index a1c641e..3007da9 100644
44566 --- a/drivers/media/usb/dvb-usb/cxusb.c
44567 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44568 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44569
44570 struct dib0700_adapter_state {
44571 int (*set_param_save) (struct dvb_frontend *);
44572 -};
44573 +} __no_const;
44574
44575 static int dib7070_set_param_override(struct dvb_frontend *fe)
44576 {
44577 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44578 index ae0f56a..ec71784 100644
44579 --- a/drivers/media/usb/dvb-usb/dw2102.c
44580 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44581 @@ -118,7 +118,7 @@ struct su3000_state {
44582
44583 struct s6x0_state {
44584 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44585 -};
44586 +} __no_const;
44587
44588 /* debug */
44589 static int dvb_usb_dw2102_debug;
44590 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44591 index 7e2411c..cef73ca 100644
44592 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44593 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44594 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44595 __u32 reserved;
44596 };
44597
44598 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44599 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44600 enum v4l2_memory memory)
44601 {
44602 void __user *up_pln;
44603 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44604 return 0;
44605 }
44606
44607 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44608 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44609 enum v4l2_memory memory)
44610 {
44611 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44612 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44613 * by passing a very big num_planes value */
44614 uplane = compat_alloc_user_space(num_planes *
44615 sizeof(struct v4l2_plane));
44616 - kp->m.planes = uplane;
44617 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44618
44619 while (--num_planes >= 0) {
44620 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44621 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44622 if (num_planes == 0)
44623 return 0;
44624
44625 - uplane = kp->m.planes;
44626 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44627 if (get_user(p, &up->m.planes))
44628 return -EFAULT;
44629 uplane32 = compat_ptr(p);
44630 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44631 get_user(kp->capability, &up->capability) ||
44632 get_user(kp->flags, &up->flags))
44633 return -EFAULT;
44634 - kp->base = compat_ptr(tmp);
44635 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44636 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44637 return 0;
44638 }
44639 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44640 n * sizeof(struct v4l2_ext_control32)))
44641 return -EFAULT;
44642 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44643 - kp->controls = kcontrols;
44644 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44645 while (--n >= 0) {
44646 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44647 return -EFAULT;
44648 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44649 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44650 {
44651 struct v4l2_ext_control32 __user *ucontrols;
44652 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44653 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44654 int n = kp->count;
44655 compat_caddr_t p;
44656
44657 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44658 put_user(kp->start_block, &up->start_block) ||
44659 put_user(kp->blocks, &up->blocks) ||
44660 put_user(tmp, &up->edid) ||
44661 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44662 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44663 return -EFAULT;
44664 return 0;
44665 }
44666 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44667 index 55c6832..a91c7a6 100644
44668 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44669 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44670 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44671 return 0;
44672
44673 case V4L2_CTRL_TYPE_STRING:
44674 - len = strlen(c->string);
44675 - if (len < ctrl->minimum)
44676 + len = strlen_user(c->string);
44677 + if (!len || len < ctrl->minimum)
44678 return -ERANGE;
44679 if ((len - ctrl->minimum) % ctrl->step)
44680 return -ERANGE;
44681 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44682 index 02d1b63..5fd6b16 100644
44683 --- a/drivers/media/v4l2-core/v4l2-device.c
44684 +++ b/drivers/media/v4l2-core/v4l2-device.c
44685 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44686 EXPORT_SYMBOL_GPL(v4l2_device_put);
44687
44688 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44689 - atomic_t *instance)
44690 + atomic_unchecked_t *instance)
44691 {
44692 - int num = atomic_inc_return(instance) - 1;
44693 + int num = atomic_inc_return_unchecked(instance) - 1;
44694 int len = strlen(basename);
44695
44696 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44697 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44698 index d9113cc..7de6ccc 100644
44699 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44700 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44701 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
44702 struct file *file, void *fh, void *p);
44703 } u;
44704 void (*debug)(const void *arg, bool write_only);
44705 -};
44706 +} __do_const;
44707 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44708
44709 /* This control needs a priority check */
44710 #define INFO_FL_PRIO (1 << 0)
44711 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
44712 struct video_device *vfd = video_devdata(file);
44713 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44714 bool write_only = false;
44715 - struct v4l2_ioctl_info default_info;
44716 + v4l2_ioctl_info_no_const default_info;
44717 const struct v4l2_ioctl_info *info;
44718 void *fh = file->private_data;
44719 struct v4l2_fh *vfh = NULL;
44720 @@ -2260,7 +2261,7 @@ done:
44721 }
44722
44723 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44724 - void * __user *user_ptr, void ***kernel_ptr)
44725 + void __user **user_ptr, void ***kernel_ptr)
44726 {
44727 int ret = 0;
44728
44729 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44730 ret = -EINVAL;
44731 break;
44732 }
44733 - *user_ptr = (void __user *)buf->m.planes;
44734 + *user_ptr = (void __force_user *)buf->m.planes;
44735 *kernel_ptr = (void *)&buf->m.planes;
44736 *array_size = sizeof(struct v4l2_plane) * buf->length;
44737 ret = 1;
44738 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44739 ret = -EINVAL;
44740 break;
44741 }
44742 - *user_ptr = (void __user *)ctrls->controls;
44743 + *user_ptr = (void __force_user *)ctrls->controls;
44744 *kernel_ptr = (void *)&ctrls->controls;
44745 *array_size = sizeof(struct v4l2_ext_control)
44746 * ctrls->count;
44747 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44748 }
44749
44750 if (has_array_args) {
44751 - *kernel_ptr = user_ptr;
44752 + *kernel_ptr = (void __force_kernel *)user_ptr;
44753 if (copy_to_user(user_ptr, mbuf, array_size))
44754 err = -EFAULT;
44755 goto out_array_args;
44756 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44757 index 570b18a..f880314 100644
44758 --- a/drivers/message/fusion/mptbase.c
44759 +++ b/drivers/message/fusion/mptbase.c
44760 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44761 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44762 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44763
44764 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44765 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44766 +#else
44767 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44768 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44769 +#endif
44770 +
44771 /*
44772 * Rounding UP to nearest 4-kB boundary here...
44773 */
44774 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44775 ioc->facts.GlobalCredits);
44776
44777 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44778 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44779 + NULL, NULL);
44780 +#else
44781 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44782 +#endif
44783 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44784 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44785 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44786 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44787 index 00d339c..2ea899d 100644
44788 --- a/drivers/message/fusion/mptsas.c
44789 +++ b/drivers/message/fusion/mptsas.c
44790 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44791 return 0;
44792 }
44793
44794 +static inline void
44795 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44796 +{
44797 + if (phy_info->port_details) {
44798 + phy_info->port_details->rphy = rphy;
44799 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44800 + ioc->name, rphy));
44801 + }
44802 +
44803 + if (rphy) {
44804 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44805 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44806 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44807 + ioc->name, rphy, rphy->dev.release));
44808 + }
44809 +}
44810 +
44811 /* no mutex */
44812 static void
44813 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44814 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44815 return NULL;
44816 }
44817
44818 -static inline void
44819 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44820 -{
44821 - if (phy_info->port_details) {
44822 - phy_info->port_details->rphy = rphy;
44823 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44824 - ioc->name, rphy));
44825 - }
44826 -
44827 - if (rphy) {
44828 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44829 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44830 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44831 - ioc->name, rphy, rphy->dev.release));
44832 - }
44833 -}
44834 -
44835 static inline struct sas_port *
44836 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44837 {
44838 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44839 index 727819c..ad74694 100644
44840 --- a/drivers/message/fusion/mptscsih.c
44841 +++ b/drivers/message/fusion/mptscsih.c
44842 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44843
44844 h = shost_priv(SChost);
44845
44846 - if (h) {
44847 - if (h->info_kbuf == NULL)
44848 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44849 - return h->info_kbuf;
44850 - h->info_kbuf[0] = '\0';
44851 + if (!h)
44852 + return NULL;
44853
44854 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44855 - h->info_kbuf[size-1] = '\0';
44856 - }
44857 + if (h->info_kbuf == NULL)
44858 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44859 + return h->info_kbuf;
44860 + h->info_kbuf[0] = '\0';
44861 +
44862 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44863 + h->info_kbuf[size-1] = '\0';
44864
44865 return h->info_kbuf;
44866 }
44867 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44868 index b7d87cd..3fb36da 100644
44869 --- a/drivers/message/i2o/i2o_proc.c
44870 +++ b/drivers/message/i2o/i2o_proc.c
44871 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44872 "Array Controller Device"
44873 };
44874
44875 -static char *chtostr(char *tmp, u8 *chars, int n)
44876 -{
44877 - tmp[0] = 0;
44878 - return strncat(tmp, (char *)chars, n);
44879 -}
44880 -
44881 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44882 char *group)
44883 {
44884 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44885 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44886 {
44887 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44888 - static u32 work32[5];
44889 - static u8 *work8 = (u8 *) work32;
44890 - static u16 *work16 = (u16 *) work32;
44891 + u32 work32[5];
44892 + u8 *work8 = (u8 *) work32;
44893 + u16 *work16 = (u16 *) work32;
44894 int token;
44895 u32 hwcap;
44896
44897 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44898 } *result;
44899
44900 i2o_exec_execute_ddm_table ddm_table;
44901 - char tmp[28 + 1];
44902
44903 result = kmalloc(sizeof(*result), GFP_KERNEL);
44904 if (!result)
44905 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44906
44907 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44908 seq_printf(seq, "%-#8x", ddm_table.module_id);
44909 - seq_printf(seq, "%-29s",
44910 - chtostr(tmp, ddm_table.module_name_version, 28));
44911 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44912 seq_printf(seq, "%9d ", ddm_table.data_size);
44913 seq_printf(seq, "%8d", ddm_table.code_size);
44914
44915 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44916
44917 i2o_driver_result_table *result;
44918 i2o_driver_store_table *dst;
44919 - char tmp[28 + 1];
44920
44921 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44922 if (result == NULL)
44923 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44924
44925 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44926 seq_printf(seq, "%-#8x", dst->module_id);
44927 - seq_printf(seq, "%-29s",
44928 - chtostr(tmp, dst->module_name_version, 28));
44929 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44930 + seq_printf(seq, "%-.28s", dst->module_name_version);
44931 + seq_printf(seq, "%-.8s", dst->date);
44932 seq_printf(seq, "%8d ", dst->module_size);
44933 seq_printf(seq, "%8d ", dst->mpb_size);
44934 seq_printf(seq, "0x%04x", dst->module_flags);
44935 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44936 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44937 {
44938 struct i2o_device *d = (struct i2o_device *)seq->private;
44939 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44940 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44941 // == (allow) 512d bytes (max)
44942 - static u16 *work16 = (u16 *) work32;
44943 + u16 *work16 = (u16 *) work32;
44944 int token;
44945 - char tmp[16 + 1];
44946
44947 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44948
44949 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44950 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44951 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44952 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44953 - seq_printf(seq, "Vendor info : %s\n",
44954 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44955 - seq_printf(seq, "Product info : %s\n",
44956 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44957 - seq_printf(seq, "Description : %s\n",
44958 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44959 - seq_printf(seq, "Product rev. : %s\n",
44960 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44961 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44962 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44963 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44964 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44965
44966 seq_printf(seq, "Serial number : ");
44967 print_serial_number(seq, (u8 *) (work32 + 16),
44968 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44969 u8 pad[256]; // allow up to 256 byte (max) serial number
44970 } result;
44971
44972 - char tmp[24 + 1];
44973 -
44974 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44975
44976 if (token < 0) {
44977 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44978 }
44979
44980 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44981 - seq_printf(seq, "Module name : %s\n",
44982 - chtostr(tmp, result.module_name, 24));
44983 - seq_printf(seq, "Module revision : %s\n",
44984 - chtostr(tmp, result.module_rev, 8));
44985 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44986 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44987
44988 seq_printf(seq, "Serial number : ");
44989 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44990 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44991 u8 instance_number[4];
44992 } result;
44993
44994 - char tmp[64 + 1];
44995 -
44996 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44997
44998 if (token < 0) {
44999 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45000 return 0;
45001 }
45002
45003 - seq_printf(seq, "Device name : %s\n",
45004 - chtostr(tmp, result.device_name, 64));
45005 - seq_printf(seq, "Service name : %s\n",
45006 - chtostr(tmp, result.service_name, 64));
45007 - seq_printf(seq, "Physical name : %s\n",
45008 - chtostr(tmp, result.physical_location, 64));
45009 - seq_printf(seq, "Instance number : %s\n",
45010 - chtostr(tmp, result.instance_number, 4));
45011 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45012 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45013 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45014 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45015
45016 return 0;
45017 }
45018 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45019 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45020 {
45021 struct i2o_device *d = (struct i2o_device *)seq->private;
45022 - static u32 work32[12];
45023 - static u16 *work16 = (u16 *) work32;
45024 - static u8 *work8 = (u8 *) work32;
45025 + u32 work32[12];
45026 + u16 *work16 = (u16 *) work32;
45027 + u8 *work8 = (u8 *) work32;
45028 int token;
45029
45030 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45031 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45032 index 92752fb..a7494f6 100644
45033 --- a/drivers/message/i2o/iop.c
45034 +++ b/drivers/message/i2o/iop.c
45035 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45036
45037 spin_lock_irqsave(&c->context_list_lock, flags);
45038
45039 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45040 - atomic_inc(&c->context_list_counter);
45041 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45042 + atomic_inc_unchecked(&c->context_list_counter);
45043
45044 - entry->context = atomic_read(&c->context_list_counter);
45045 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45046
45047 list_add(&entry->list, &c->context_list);
45048
45049 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45050
45051 #if BITS_PER_LONG == 64
45052 spin_lock_init(&c->context_list_lock);
45053 - atomic_set(&c->context_list_counter, 0);
45054 + atomic_set_unchecked(&c->context_list_counter, 0);
45055 INIT_LIST_HEAD(&c->context_list);
45056 #endif
45057
45058 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45059 index d1a22aa..d0f7bf7 100644
45060 --- a/drivers/mfd/ab8500-debugfs.c
45061 +++ b/drivers/mfd/ab8500-debugfs.c
45062 @@ -100,7 +100,7 @@ static int irq_last;
45063 static u32 *irq_count;
45064 static int num_irqs;
45065
45066 -static struct device_attribute **dev_attr;
45067 +static device_attribute_no_const **dev_attr;
45068 static char **event_name;
45069
45070 static u8 avg_sample = SAMPLE_16;
45071 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45072 index a83eed5..62a58a9 100644
45073 --- a/drivers/mfd/max8925-i2c.c
45074 +++ b/drivers/mfd/max8925-i2c.c
45075 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45076 const struct i2c_device_id *id)
45077 {
45078 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45079 - static struct max8925_chip *chip;
45080 + struct max8925_chip *chip;
45081 struct device_node *node = client->dev.of_node;
45082
45083 if (node && !pdata) {
45084 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45085 index 460a014..21d3061 100644
45086 --- a/drivers/mfd/tps65910.c
45087 +++ b/drivers/mfd/tps65910.c
45088 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45089 struct tps65910_platform_data *pdata)
45090 {
45091 int ret = 0;
45092 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45093 + struct regmap_irq_chip *tps6591x_irqs_chip;
45094
45095 if (!irq) {
45096 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45097 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45098 index 596b1f6..5b6ab74 100644
45099 --- a/drivers/mfd/twl4030-irq.c
45100 +++ b/drivers/mfd/twl4030-irq.c
45101 @@ -34,6 +34,7 @@
45102 #include <linux/of.h>
45103 #include <linux/irqdomain.h>
45104 #include <linux/i2c/twl.h>
45105 +#include <asm/pgtable.h>
45106
45107 #include "twl-core.h"
45108
45109 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45110 * Install an irq handler for each of the SIH modules;
45111 * clone dummy irq_chip since PIH can't *do* anything
45112 */
45113 - twl4030_irq_chip = dummy_irq_chip;
45114 - twl4030_irq_chip.name = "twl4030";
45115 + pax_open_kernel();
45116 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45117 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45118
45119 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45120 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45121 + pax_close_kernel();
45122
45123 for (i = irq_base; i < irq_end; i++) {
45124 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45125 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45126 index 464419b..64bae8d 100644
45127 --- a/drivers/misc/c2port/core.c
45128 +++ b/drivers/misc/c2port/core.c
45129 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45130 goto error_idr_alloc;
45131 c2dev->id = ret;
45132
45133 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45134 + pax_open_kernel();
45135 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45136 + pax_close_kernel();
45137
45138 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45139 "c2port%d", c2dev->id);
45140 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45141 index 3f2b625..945e179 100644
45142 --- a/drivers/misc/eeprom/sunxi_sid.c
45143 +++ b/drivers/misc/eeprom/sunxi_sid.c
45144 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45145
45146 platform_set_drvdata(pdev, sid_data);
45147
45148 - sid_bin_attr.size = sid_data->keysize;
45149 + pax_open_kernel();
45150 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45151 + pax_close_kernel();
45152 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45153 return -ENODEV;
45154
45155 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45156 index 36f5d52..32311c3 100644
45157 --- a/drivers/misc/kgdbts.c
45158 +++ b/drivers/misc/kgdbts.c
45159 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45160 char before[BREAK_INSTR_SIZE];
45161 char after[BREAK_INSTR_SIZE];
45162
45163 - probe_kernel_read(before, (char *)kgdbts_break_test,
45164 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45165 BREAK_INSTR_SIZE);
45166 init_simple_test();
45167 ts.tst = plant_and_detach_test;
45168 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45169 /* Activate test with initial breakpoint */
45170 if (!is_early)
45171 kgdb_breakpoint();
45172 - probe_kernel_read(after, (char *)kgdbts_break_test,
45173 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45174 BREAK_INSTR_SIZE);
45175 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45176 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45177 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45178 index 3ef4627..8d00486 100644
45179 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45180 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45181 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45182 * the lid is closed. This leads to interrupts as soon as a little move
45183 * is done.
45184 */
45185 - atomic_inc(&lis3->count);
45186 + atomic_inc_unchecked(&lis3->count);
45187
45188 wake_up_interruptible(&lis3->misc_wait);
45189 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45190 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45191 if (lis3->pm_dev)
45192 pm_runtime_get_sync(lis3->pm_dev);
45193
45194 - atomic_set(&lis3->count, 0);
45195 + atomic_set_unchecked(&lis3->count, 0);
45196 return 0;
45197 }
45198
45199 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45200 add_wait_queue(&lis3->misc_wait, &wait);
45201 while (true) {
45202 set_current_state(TASK_INTERRUPTIBLE);
45203 - data = atomic_xchg(&lis3->count, 0);
45204 + data = atomic_xchg_unchecked(&lis3->count, 0);
45205 if (data)
45206 break;
45207
45208 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45209 struct lis3lv02d, miscdev);
45210
45211 poll_wait(file, &lis3->misc_wait, wait);
45212 - if (atomic_read(&lis3->count))
45213 + if (atomic_read_unchecked(&lis3->count))
45214 return POLLIN | POLLRDNORM;
45215 return 0;
45216 }
45217 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45218 index c439c82..1f20f57 100644
45219 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45220 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45221 @@ -297,7 +297,7 @@ struct lis3lv02d {
45222 struct input_polled_dev *idev; /* input device */
45223 struct platform_device *pdev; /* platform device */
45224 struct regulator_bulk_data regulators[2];
45225 - atomic_t count; /* interrupt count after last read */
45226 + atomic_unchecked_t count; /* interrupt count after last read */
45227 union axis_conversion ac; /* hw -> logical axis */
45228 int mapped_btns[3];
45229
45230 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45231 index 2f30bad..c4c13d0 100644
45232 --- a/drivers/misc/sgi-gru/gruhandles.c
45233 +++ b/drivers/misc/sgi-gru/gruhandles.c
45234 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45235 unsigned long nsec;
45236
45237 nsec = CLKS2NSEC(clks);
45238 - atomic_long_inc(&mcs_op_statistics[op].count);
45239 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45240 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45241 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45242 if (mcs_op_statistics[op].max < nsec)
45243 mcs_op_statistics[op].max = nsec;
45244 }
45245 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45246 index 4f76359..cdfcb2e 100644
45247 --- a/drivers/misc/sgi-gru/gruprocfs.c
45248 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45249 @@ -32,9 +32,9 @@
45250
45251 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45252
45253 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45254 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45255 {
45256 - unsigned long val = atomic_long_read(v);
45257 + unsigned long val = atomic_long_read_unchecked(v);
45258
45259 seq_printf(s, "%16lu %s\n", val, id);
45260 }
45261 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45262
45263 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45264 for (op = 0; op < mcsop_last; op++) {
45265 - count = atomic_long_read(&mcs_op_statistics[op].count);
45266 - total = atomic_long_read(&mcs_op_statistics[op].total);
45267 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45268 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45269 max = mcs_op_statistics[op].max;
45270 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45271 count ? total / count : 0, max);
45272 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45273 index 5c3ce24..4915ccb 100644
45274 --- a/drivers/misc/sgi-gru/grutables.h
45275 +++ b/drivers/misc/sgi-gru/grutables.h
45276 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45277 * GRU statistics.
45278 */
45279 struct gru_stats_s {
45280 - atomic_long_t vdata_alloc;
45281 - atomic_long_t vdata_free;
45282 - atomic_long_t gts_alloc;
45283 - atomic_long_t gts_free;
45284 - atomic_long_t gms_alloc;
45285 - atomic_long_t gms_free;
45286 - atomic_long_t gts_double_allocate;
45287 - atomic_long_t assign_context;
45288 - atomic_long_t assign_context_failed;
45289 - atomic_long_t free_context;
45290 - atomic_long_t load_user_context;
45291 - atomic_long_t load_kernel_context;
45292 - atomic_long_t lock_kernel_context;
45293 - atomic_long_t unlock_kernel_context;
45294 - atomic_long_t steal_user_context;
45295 - atomic_long_t steal_kernel_context;
45296 - atomic_long_t steal_context_failed;
45297 - atomic_long_t nopfn;
45298 - atomic_long_t asid_new;
45299 - atomic_long_t asid_next;
45300 - atomic_long_t asid_wrap;
45301 - atomic_long_t asid_reuse;
45302 - atomic_long_t intr;
45303 - atomic_long_t intr_cbr;
45304 - atomic_long_t intr_tfh;
45305 - atomic_long_t intr_spurious;
45306 - atomic_long_t intr_mm_lock_failed;
45307 - atomic_long_t call_os;
45308 - atomic_long_t call_os_wait_queue;
45309 - atomic_long_t user_flush_tlb;
45310 - atomic_long_t user_unload_context;
45311 - atomic_long_t user_exception;
45312 - atomic_long_t set_context_option;
45313 - atomic_long_t check_context_retarget_intr;
45314 - atomic_long_t check_context_unload;
45315 - atomic_long_t tlb_dropin;
45316 - atomic_long_t tlb_preload_page;
45317 - atomic_long_t tlb_dropin_fail_no_asid;
45318 - atomic_long_t tlb_dropin_fail_upm;
45319 - atomic_long_t tlb_dropin_fail_invalid;
45320 - atomic_long_t tlb_dropin_fail_range_active;
45321 - atomic_long_t tlb_dropin_fail_idle;
45322 - atomic_long_t tlb_dropin_fail_fmm;
45323 - atomic_long_t tlb_dropin_fail_no_exception;
45324 - atomic_long_t tfh_stale_on_fault;
45325 - atomic_long_t mmu_invalidate_range;
45326 - atomic_long_t mmu_invalidate_page;
45327 - atomic_long_t flush_tlb;
45328 - atomic_long_t flush_tlb_gru;
45329 - atomic_long_t flush_tlb_gru_tgh;
45330 - atomic_long_t flush_tlb_gru_zero_asid;
45331 + atomic_long_unchecked_t vdata_alloc;
45332 + atomic_long_unchecked_t vdata_free;
45333 + atomic_long_unchecked_t gts_alloc;
45334 + atomic_long_unchecked_t gts_free;
45335 + atomic_long_unchecked_t gms_alloc;
45336 + atomic_long_unchecked_t gms_free;
45337 + atomic_long_unchecked_t gts_double_allocate;
45338 + atomic_long_unchecked_t assign_context;
45339 + atomic_long_unchecked_t assign_context_failed;
45340 + atomic_long_unchecked_t free_context;
45341 + atomic_long_unchecked_t load_user_context;
45342 + atomic_long_unchecked_t load_kernel_context;
45343 + atomic_long_unchecked_t lock_kernel_context;
45344 + atomic_long_unchecked_t unlock_kernel_context;
45345 + atomic_long_unchecked_t steal_user_context;
45346 + atomic_long_unchecked_t steal_kernel_context;
45347 + atomic_long_unchecked_t steal_context_failed;
45348 + atomic_long_unchecked_t nopfn;
45349 + atomic_long_unchecked_t asid_new;
45350 + atomic_long_unchecked_t asid_next;
45351 + atomic_long_unchecked_t asid_wrap;
45352 + atomic_long_unchecked_t asid_reuse;
45353 + atomic_long_unchecked_t intr;
45354 + atomic_long_unchecked_t intr_cbr;
45355 + atomic_long_unchecked_t intr_tfh;
45356 + atomic_long_unchecked_t intr_spurious;
45357 + atomic_long_unchecked_t intr_mm_lock_failed;
45358 + atomic_long_unchecked_t call_os;
45359 + atomic_long_unchecked_t call_os_wait_queue;
45360 + atomic_long_unchecked_t user_flush_tlb;
45361 + atomic_long_unchecked_t user_unload_context;
45362 + atomic_long_unchecked_t user_exception;
45363 + atomic_long_unchecked_t set_context_option;
45364 + atomic_long_unchecked_t check_context_retarget_intr;
45365 + atomic_long_unchecked_t check_context_unload;
45366 + atomic_long_unchecked_t tlb_dropin;
45367 + atomic_long_unchecked_t tlb_preload_page;
45368 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45369 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45370 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45371 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45372 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45373 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45374 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45375 + atomic_long_unchecked_t tfh_stale_on_fault;
45376 + atomic_long_unchecked_t mmu_invalidate_range;
45377 + atomic_long_unchecked_t mmu_invalidate_page;
45378 + atomic_long_unchecked_t flush_tlb;
45379 + atomic_long_unchecked_t flush_tlb_gru;
45380 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45381 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45382
45383 - atomic_long_t copy_gpa;
45384 - atomic_long_t read_gpa;
45385 + atomic_long_unchecked_t copy_gpa;
45386 + atomic_long_unchecked_t read_gpa;
45387
45388 - atomic_long_t mesq_receive;
45389 - atomic_long_t mesq_receive_none;
45390 - atomic_long_t mesq_send;
45391 - atomic_long_t mesq_send_failed;
45392 - atomic_long_t mesq_noop;
45393 - atomic_long_t mesq_send_unexpected_error;
45394 - atomic_long_t mesq_send_lb_overflow;
45395 - atomic_long_t mesq_send_qlimit_reached;
45396 - atomic_long_t mesq_send_amo_nacked;
45397 - atomic_long_t mesq_send_put_nacked;
45398 - atomic_long_t mesq_page_overflow;
45399 - atomic_long_t mesq_qf_locked;
45400 - atomic_long_t mesq_qf_noop_not_full;
45401 - atomic_long_t mesq_qf_switch_head_failed;
45402 - atomic_long_t mesq_qf_unexpected_error;
45403 - atomic_long_t mesq_noop_unexpected_error;
45404 - atomic_long_t mesq_noop_lb_overflow;
45405 - atomic_long_t mesq_noop_qlimit_reached;
45406 - atomic_long_t mesq_noop_amo_nacked;
45407 - atomic_long_t mesq_noop_put_nacked;
45408 - atomic_long_t mesq_noop_page_overflow;
45409 + atomic_long_unchecked_t mesq_receive;
45410 + atomic_long_unchecked_t mesq_receive_none;
45411 + atomic_long_unchecked_t mesq_send;
45412 + atomic_long_unchecked_t mesq_send_failed;
45413 + atomic_long_unchecked_t mesq_noop;
45414 + atomic_long_unchecked_t mesq_send_unexpected_error;
45415 + atomic_long_unchecked_t mesq_send_lb_overflow;
45416 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45417 + atomic_long_unchecked_t mesq_send_amo_nacked;
45418 + atomic_long_unchecked_t mesq_send_put_nacked;
45419 + atomic_long_unchecked_t mesq_page_overflow;
45420 + atomic_long_unchecked_t mesq_qf_locked;
45421 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45422 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45423 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45424 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45425 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45426 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45427 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45428 + atomic_long_unchecked_t mesq_noop_put_nacked;
45429 + atomic_long_unchecked_t mesq_noop_page_overflow;
45430
45431 };
45432
45433 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45434 tghop_invalidate, mcsop_last};
45435
45436 struct mcs_op_statistic {
45437 - atomic_long_t count;
45438 - atomic_long_t total;
45439 + atomic_long_unchecked_t count;
45440 + atomic_long_unchecked_t total;
45441 unsigned long max;
45442 };
45443
45444 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45445
45446 #define STAT(id) do { \
45447 if (gru_options & OPT_STATS) \
45448 - atomic_long_inc(&gru_stats.id); \
45449 + atomic_long_inc_unchecked(&gru_stats.id); \
45450 } while (0)
45451
45452 #ifdef CONFIG_SGI_GRU_DEBUG
45453 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45454 index c862cd4..0d176fe 100644
45455 --- a/drivers/misc/sgi-xp/xp.h
45456 +++ b/drivers/misc/sgi-xp/xp.h
45457 @@ -288,7 +288,7 @@ struct xpc_interface {
45458 xpc_notify_func, void *);
45459 void (*received) (short, int, void *);
45460 enum xp_retval (*partid_to_nasids) (short, void *);
45461 -};
45462 +} __no_const;
45463
45464 extern struct xpc_interface xpc_interface;
45465
45466 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45467 index 01be66d..e3a0c7e 100644
45468 --- a/drivers/misc/sgi-xp/xp_main.c
45469 +++ b/drivers/misc/sgi-xp/xp_main.c
45470 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45471 }
45472
45473 struct xpc_interface xpc_interface = {
45474 - (void (*)(int))xpc_notloaded,
45475 - (void (*)(int))xpc_notloaded,
45476 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45477 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45478 + .connect = (void (*)(int))xpc_notloaded,
45479 + .disconnect = (void (*)(int))xpc_notloaded,
45480 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45481 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45482 void *))xpc_notloaded,
45483 - (void (*)(short, int, void *))xpc_notloaded,
45484 - (enum xp_retval(*)(short, void *))xpc_notloaded
45485 + .received = (void (*)(short, int, void *))xpc_notloaded,
45486 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45487 };
45488 EXPORT_SYMBOL_GPL(xpc_interface);
45489
45490 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45491 index b94d5f7..7f494c5 100644
45492 --- a/drivers/misc/sgi-xp/xpc.h
45493 +++ b/drivers/misc/sgi-xp/xpc.h
45494 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45495 void (*received_payload) (struct xpc_channel *, void *);
45496 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45497 };
45498 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45499
45500 /* struct xpc_partition act_state values (for XPC HB) */
45501
45502 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45503 /* found in xpc_main.c */
45504 extern struct device *xpc_part;
45505 extern struct device *xpc_chan;
45506 -extern struct xpc_arch_operations xpc_arch_ops;
45507 +extern xpc_arch_operations_no_const xpc_arch_ops;
45508 extern int xpc_disengage_timelimit;
45509 extern int xpc_disengage_timedout;
45510 extern int xpc_activate_IRQ_rcvd;
45511 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45512 index 82dc574..8539ab2 100644
45513 --- a/drivers/misc/sgi-xp/xpc_main.c
45514 +++ b/drivers/misc/sgi-xp/xpc_main.c
45515 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45516 .notifier_call = xpc_system_die,
45517 };
45518
45519 -struct xpc_arch_operations xpc_arch_ops;
45520 +xpc_arch_operations_no_const xpc_arch_ops;
45521
45522 /*
45523 * Timer function to enforce the timelimit on the partition disengage.
45524 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45525
45526 if (((die_args->trapnr == X86_TRAP_MF) ||
45527 (die_args->trapnr == X86_TRAP_XF)) &&
45528 - !user_mode_vm(die_args->regs))
45529 + !user_mode(die_args->regs))
45530 xpc_die_deactivate();
45531
45532 break;
45533 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45534 index 452782b..0c10e40 100644
45535 --- a/drivers/mmc/card/block.c
45536 +++ b/drivers/mmc/card/block.c
45537 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45538 if (idata->ic.postsleep_min_us)
45539 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45540
45541 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45542 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45543 err = -EFAULT;
45544 goto cmd_rel_host;
45545 }
45546 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45547 index f51b5ba..86614a7 100644
45548 --- a/drivers/mmc/core/mmc_ops.c
45549 +++ b/drivers/mmc/core/mmc_ops.c
45550 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45551 void *data_buf;
45552 int is_on_stack;
45553
45554 - is_on_stack = object_is_on_stack(buf);
45555 + is_on_stack = object_starts_on_stack(buf);
45556 if (is_on_stack) {
45557 /*
45558 * dma onto stack is unsafe/nonportable, but callers to this
45559 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45560 index 6834977..824ee1b 100644
45561 --- a/drivers/mmc/host/dw_mmc.h
45562 +++ b/drivers/mmc/host/dw_mmc.h
45563 @@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45564 int (*parse_dt)(struct dw_mci *host);
45565 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45566 struct dw_mci_tuning_data *tuning_data);
45567 -};
45568 +} __do_const;
45569 #endif /* _DW_MMC_H_ */
45570 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45571 index 771c60a..12cb615 100644
45572 --- a/drivers/mmc/host/mmci.c
45573 +++ b/drivers/mmc/host/mmci.c
45574 @@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45575 mmc->caps2 = plat->capabilities2;
45576
45577 if (variant->busy_detect) {
45578 - mmci_ops.card_busy = mmci_card_busy;
45579 + pax_open_kernel();
45580 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45581 + pax_close_kernel();
45582 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45583 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45584 mmc->max_busy_timeout = 0;
45585 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45586 index b841bb7..d82712f5 100644
45587 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45588 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45589 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45590 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45591 }
45592
45593 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45594 - sdhci_esdhc_ops.platform_execute_tuning =
45595 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45596 + pax_open_kernel();
45597 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45598 esdhc_executing_tuning;
45599 + pax_close_kernel();
45600 + }
45601
45602 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45603 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45604 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45605 index d61eb5a..88c0f5d 100644
45606 --- a/drivers/mmc/host/sdhci-s3c.c
45607 +++ b/drivers/mmc/host/sdhci-s3c.c
45608 @@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45609 * we can use overriding functions instead of default.
45610 */
45611 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45612 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45613 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45614 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45615 + pax_open_kernel();
45616 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45617 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45618 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45619 + pax_close_kernel();
45620 }
45621
45622 /* It supports additional host capabilities if needed */
45623 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45624 index 6293855..3415551 100644
45625 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45626 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45627 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45628 size_t totlen = 0, thislen;
45629 int ret = 0;
45630 size_t buflen = 0;
45631 - static char *buffer;
45632 + char *buffer;
45633
45634 if (!ECCBUF_SIZE) {
45635 /* We should fall back to a general writev implementation.
45636 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45637 index c07cd57..61c4fbd 100644
45638 --- a/drivers/mtd/nand/denali.c
45639 +++ b/drivers/mtd/nand/denali.c
45640 @@ -24,6 +24,7 @@
45641 #include <linux/slab.h>
45642 #include <linux/mtd/mtd.h>
45643 #include <linux/module.h>
45644 +#include <linux/slab.h>
45645
45646 #include "denali.h"
45647
45648 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45649 index bb77f75..47539b1 100644
45650 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45651 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45652 @@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45653
45654 /* first try to map the upper buffer directly */
45655 if (virt_addr_valid(this->upper_buf) &&
45656 - !object_is_on_stack(this->upper_buf)) {
45657 + !object_starts_on_stack(this->upper_buf)) {
45658 sg_init_one(sgl, this->upper_buf, this->upper_len);
45659 ret = dma_map_sg(this->dev, sgl, 1, dr);
45660 if (ret == 0)
45661 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45662 index 51b9d6a..52af9a7 100644
45663 --- a/drivers/mtd/nftlmount.c
45664 +++ b/drivers/mtd/nftlmount.c
45665 @@ -24,6 +24,7 @@
45666 #include <asm/errno.h>
45667 #include <linux/delay.h>
45668 #include <linux/slab.h>
45669 +#include <linux/sched.h>
45670 #include <linux/mtd/mtd.h>
45671 #include <linux/mtd/nand.h>
45672 #include <linux/mtd/nftl.h>
45673 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45674 index cf49c22..971b133 100644
45675 --- a/drivers/mtd/sm_ftl.c
45676 +++ b/drivers/mtd/sm_ftl.c
45677 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45678 #define SM_CIS_VENDOR_OFFSET 0x59
45679 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45680 {
45681 - struct attribute_group *attr_group;
45682 + attribute_group_no_const *attr_group;
45683 struct attribute **attributes;
45684 struct sm_sysfs_attribute *vendor_attribute;
45685 char *vendor;
45686 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45687 index d3a6789..198ec21 100644
45688 --- a/drivers/net/bonding/bond_main.c
45689 +++ b/drivers/net/bonding/bond_main.c
45690 @@ -4504,6 +4504,7 @@ static void __exit bonding_exit(void)
45691
45692 bond_netlink_fini();
45693 unregister_pernet_subsys(&bond_net_ops);
45694 + rtnl_link_unregister(&bond_link_ops);
45695
45696 #ifdef CONFIG_NET_POLL_CONTROLLER
45697 /*
45698 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45699 index f847e16..fc8dbe9 100644
45700 --- a/drivers/net/bonding/bond_netlink.c
45701 +++ b/drivers/net/bonding/bond_netlink.c
45702 @@ -542,7 +542,7 @@ nla_put_failure:
45703 return -EMSGSIZE;
45704 }
45705
45706 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45707 +struct rtnl_link_ops bond_link_ops = {
45708 .kind = "bond",
45709 .priv_size = sizeof(struct bonding),
45710 .setup = bond_setup,
45711 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45712 index 9e7d95d..d447b88 100644
45713 --- a/drivers/net/can/Kconfig
45714 +++ b/drivers/net/can/Kconfig
45715 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45716
45717 config CAN_FLEXCAN
45718 tristate "Support for Freescale FLEXCAN based chips"
45719 - depends on ARM || PPC
45720 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45721 ---help---
45722 Say Y here if you want to support for Freescale FlexCAN.
45723
45724 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45725 index 455d4c3..3353ee7 100644
45726 --- a/drivers/net/ethernet/8390/ax88796.c
45727 +++ b/drivers/net/ethernet/8390/ax88796.c
45728 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45729 if (ax->plat->reg_offsets)
45730 ei_local->reg_offset = ax->plat->reg_offsets;
45731 else {
45732 + resource_size_t _mem_size = mem_size;
45733 + do_div(_mem_size, 0x18);
45734 ei_local->reg_offset = ax->reg_offsets;
45735 for (ret = 0; ret < 0x18; ret++)
45736 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45737 + ax->reg_offsets[ret] = _mem_size * ret;
45738 }
45739
45740 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45741 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
45742 index 7330681..7e9e463 100644
45743 --- a/drivers/net/ethernet/altera/altera_tse_main.c
45744 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
45745 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
45746 return 0;
45747 }
45748
45749 -static struct net_device_ops altera_tse_netdev_ops = {
45750 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
45751 .ndo_open = tse_open,
45752 .ndo_stop = tse_shutdown,
45753 .ndo_start_xmit = tse_start_xmit,
45754 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
45755 ndev->netdev_ops = &altera_tse_netdev_ops;
45756 altera_tse_set_ethtool_ops(ndev);
45757
45758 + pax_open_kernel();
45759 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
45760
45761 if (priv->hash_filter)
45762 altera_tse_netdev_ops.ndo_set_rx_mode =
45763 tse_set_rx_mode_hashfilter;
45764 + pax_close_kernel();
45765
45766 /* Scatter/gather IO is not supported,
45767 * so it is turned off
45768 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45769 index 3448cc0..67b2dc4 100644
45770 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45771 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45772 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45773 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45774 {
45775 /* RX_MODE controlling object */
45776 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45777 + bnx2x_init_rx_mode_obj(bp);
45778
45779 /* multicast configuration controlling object */
45780 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45781 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45782 index 31297266..944cf6e 100644
45783 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45784 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45785 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45786 return rc;
45787 }
45788
45789 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45790 - struct bnx2x_rx_mode_obj *o)
45791 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45792 {
45793 if (CHIP_IS_E1x(bp)) {
45794 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45795 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45796 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45797 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45798 } else {
45799 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45800 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45801 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45802 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45803 }
45804 }
45805
45806 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45807 index 80f6c79..fb7d12d 100644
45808 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45809 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45810 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45811
45812 /********************* RX MODE ****************/
45813
45814 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45815 - struct bnx2x_rx_mode_obj *o);
45816 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45817
45818 /**
45819 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45820 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45821 index 04321e5..b51cdc4 100644
45822 --- a/drivers/net/ethernet/broadcom/tg3.h
45823 +++ b/drivers/net/ethernet/broadcom/tg3.h
45824 @@ -150,6 +150,7 @@
45825 #define CHIPREV_ID_5750_A0 0x4000
45826 #define CHIPREV_ID_5750_A1 0x4001
45827 #define CHIPREV_ID_5750_A3 0x4003
45828 +#define CHIPREV_ID_5750_C1 0x4201
45829 #define CHIPREV_ID_5750_C2 0x4202
45830 #define CHIPREV_ID_5752_A0_HW 0x5000
45831 #define CHIPREV_ID_5752_A0 0x6000
45832 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45833 index 13f9636..228040f 100644
45834 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45835 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45836 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45837 }
45838
45839 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45840 - bna_cb_ioceth_enable,
45841 - bna_cb_ioceth_disable,
45842 - bna_cb_ioceth_hbfail,
45843 - bna_cb_ioceth_reset
45844 + .enable_cbfn = bna_cb_ioceth_enable,
45845 + .disable_cbfn = bna_cb_ioceth_disable,
45846 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45847 + .reset_cbfn = bna_cb_ioceth_reset
45848 };
45849
45850 static void bna_attr_init(struct bna_ioceth *ioceth)
45851 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45852 index 8cffcdf..aadf043 100644
45853 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45854 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45855 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45856 */
45857 struct l2t_skb_cb {
45858 arp_failure_handler_func arp_failure_handler;
45859 -};
45860 +} __no_const;
45861
45862 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45863
45864 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45865 index 24e16e3..bfe6ef2 100644
45866 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45867 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45868 @@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45869
45870 int i;
45871 struct adapter *ap = netdev2adap(dev);
45872 - static const unsigned int *reg_ranges;
45873 + const unsigned int *reg_ranges;
45874 int arr_size = 0, buf_size = 0;
45875
45876 if (is_t4(ap->params.chip)) {
45877 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45878 index c05b66d..ed69872 100644
45879 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45880 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45881 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45882 for (i=0; i<ETH_ALEN; i++) {
45883 tmp.addr[i] = dev->dev_addr[i];
45884 }
45885 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45886 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45887 break;
45888
45889 case DE4X5_SET_HWADDR: /* Set the hardware address */
45890 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45891 spin_lock_irqsave(&lp->lock, flags);
45892 memcpy(&statbuf, &lp->pktStats, ioc->len);
45893 spin_unlock_irqrestore(&lp->lock, flags);
45894 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45895 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45896 return -EFAULT;
45897 break;
45898 }
45899 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45900 index dc19bc5..f2d4548 100644
45901 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45902 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45903 @@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45904
45905 if (wrapped)
45906 newacc += 65536;
45907 - ACCESS_ONCE(*acc) = newacc;
45908 + ACCESS_ONCE_RW(*acc) = newacc;
45909 }
45910
45911 static void populate_erx_stats(struct be_adapter *adapter,
45912 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45913 index 68069ea..c4484f6 100644
45914 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45915 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45916 @@ -30,6 +30,8 @@
45917 #include <linux/netdevice.h>
45918 #include <linux/phy.h>
45919 #include <linux/platform_device.h>
45920 +#include <linux/interrupt.h>
45921 +#include <linux/irqreturn.h>
45922 #include <net/ip.h>
45923
45924 #include "ftgmac100.h"
45925 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45926 index 8be5b40..081bc1b 100644
45927 --- a/drivers/net/ethernet/faraday/ftmac100.c
45928 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45929 @@ -31,6 +31,8 @@
45930 #include <linux/module.h>
45931 #include <linux/netdevice.h>
45932 #include <linux/platform_device.h>
45933 +#include <linux/interrupt.h>
45934 +#include <linux/irqreturn.h>
45935
45936 #include "ftmac100.h"
45937
45938 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45939 index e61e637..9117795 100644
45940 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45941 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45942 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45943 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45944
45945 /* Update the base adjustement value. */
45946 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
45947 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45948 smp_mb(); /* Force the above update. */
45949 }
45950
45951 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45952 index 8902ae6..e7bcdce 100644
45953 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45954 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45955 @@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45956 }
45957
45958 /* update the base incval used to calculate frequency adjustment */
45959 - ACCESS_ONCE(adapter->base_incval) = incval;
45960 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45961 smp_mb();
45962
45963 /* need lock to prevent incorrect read while modifying cyclecounter */
45964 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45965 index 089b713..28d87ae 100644
45966 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45967 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45968 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45969 struct __vxge_hw_fifo *fifo;
45970 struct vxge_hw_fifo_config *config;
45971 u32 txdl_size, txdl_per_memblock;
45972 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45973 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45974 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45975 + };
45976 +
45977 struct __vxge_hw_virtualpath *vpath;
45978
45979 if ((vp == NULL) || (attr == NULL)) {
45980 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45981 goto exit;
45982 }
45983
45984 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45985 -
45986 fifo->mempool =
45987 __vxge_hw_mempool_create(vpath->hldev,
45988 fifo->config->memblock_size,
45989 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45990 index ba20c72..f30c0fe 100644
45991 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45992 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45993 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45994 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45995 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45996 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45997 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45998 + pax_open_kernel();
45999 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46000 + pax_close_kernel();
46001 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46002 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46003 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46004 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46005 index be7d7a6..a8983f8 100644
46006 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46007 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46008 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46009 case QLCNIC_NON_PRIV_FUNC:
46010 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46011 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46012 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46013 + pax_open_kernel();
46014 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46015 + pax_close_kernel();
46016 break;
46017 case QLCNIC_PRIV_FUNC:
46018 ahw->op_mode = QLCNIC_PRIV_FUNC;
46019 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46020 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46021 + pax_open_kernel();
46022 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46023 + pax_close_kernel();
46024 break;
46025 case QLCNIC_MGMT_FUNC:
46026 ahw->op_mode = QLCNIC_MGMT_FUNC;
46027 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46028 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46029 + pax_open_kernel();
46030 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46031 + pax_close_kernel();
46032 break;
46033 default:
46034 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46035 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46036 index 37b979b..50f5b95 100644
46037 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46038 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46039 @@ -1217,7 +1217,7 @@ flash_temp:
46040 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46041 {
46042 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46043 - static const struct qlcnic_dump_operations *fw_dump_ops;
46044 + const struct qlcnic_dump_operations *fw_dump_ops;
46045 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46046 u32 entry_offset, dump, no_entries, buf_offset = 0;
46047 int i, k, ops_cnt, ops_index, dump_size = 0;
46048 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46049 index aa1c079..2b1a3e8 100644
46050 --- a/drivers/net/ethernet/realtek/r8169.c
46051 +++ b/drivers/net/ethernet/realtek/r8169.c
46052 @@ -758,22 +758,22 @@ struct rtl8169_private {
46053 struct mdio_ops {
46054 void (*write)(struct rtl8169_private *, int, int);
46055 int (*read)(struct rtl8169_private *, int);
46056 - } mdio_ops;
46057 + } __no_const mdio_ops;
46058
46059 struct pll_power_ops {
46060 void (*down)(struct rtl8169_private *);
46061 void (*up)(struct rtl8169_private *);
46062 - } pll_power_ops;
46063 + } __no_const pll_power_ops;
46064
46065 struct jumbo_ops {
46066 void (*enable)(struct rtl8169_private *);
46067 void (*disable)(struct rtl8169_private *);
46068 - } jumbo_ops;
46069 + } __no_const jumbo_ops;
46070
46071 struct csi_ops {
46072 void (*write)(struct rtl8169_private *, int, int);
46073 u32 (*read)(struct rtl8169_private *, int);
46074 - } csi_ops;
46075 + } __no_const csi_ops;
46076
46077 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46078 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46079 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46080 index 6b861e3..204ac86 100644
46081 --- a/drivers/net/ethernet/sfc/ptp.c
46082 +++ b/drivers/net/ethernet/sfc/ptp.c
46083 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46084 ptp->start.dma_addr);
46085
46086 /* Clear flag that signals MC ready */
46087 - ACCESS_ONCE(*start) = 0;
46088 + ACCESS_ONCE_RW(*start) = 0;
46089 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46090 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46091 EFX_BUG_ON_PARANOID(rc);
46092 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46093 index 50617c5..b13724c 100644
46094 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46095 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46096 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46097
46098 writel(value, ioaddr + MMC_CNTRL);
46099
46100 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46101 - MMC_CNTRL, value);
46102 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46103 +// MMC_CNTRL, value);
46104 }
46105
46106 /* To mask all all interrupts.*/
46107 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46108 index d18f711d..5755800 100644
46109 --- a/drivers/net/hyperv/hyperv_net.h
46110 +++ b/drivers/net/hyperv/hyperv_net.h
46111 @@ -101,7 +101,7 @@ struct rndis_device {
46112
46113 enum rndis_device_state state;
46114 bool link_state;
46115 - atomic_t new_req_id;
46116 + atomic_unchecked_t new_req_id;
46117
46118 spinlock_t request_lock;
46119 struct list_head req_list;
46120 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46121 index 143a98c..d54fbaa 100644
46122 --- a/drivers/net/hyperv/rndis_filter.c
46123 +++ b/drivers/net/hyperv/rndis_filter.c
46124 @@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46125 * template
46126 */
46127 set = &rndis_msg->msg.set_req;
46128 - set->req_id = atomic_inc_return(&dev->new_req_id);
46129 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46130
46131 /* Add to the request list */
46132 spin_lock_irqsave(&dev->request_lock, flags);
46133 @@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46134
46135 /* Setup the rndis set */
46136 halt = &request->request_msg.msg.halt_req;
46137 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46138 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46139
46140 /* Ignore return since this msg is optional. */
46141 rndis_filter_send_request(dev, request);
46142 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46143 index 78f18be..1d19c62 100644
46144 --- a/drivers/net/ieee802154/fakehard.c
46145 +++ b/drivers/net/ieee802154/fakehard.c
46146 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46147 phy->transmit_power = 0xbf;
46148
46149 dev->netdev_ops = &fake_ops;
46150 - dev->ml_priv = &fake_mlme;
46151 + dev->ml_priv = (void *)&fake_mlme;
46152
46153 priv = netdev_priv(dev);
46154 priv->phy = phy;
46155 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46156 index 7eec598..90b8428 100644
46157 --- a/drivers/net/macvlan.c
46158 +++ b/drivers/net/macvlan.c
46159 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46160 int macvlan_link_register(struct rtnl_link_ops *ops)
46161 {
46162 /* common fields */
46163 - ops->priv_size = sizeof(struct macvlan_dev);
46164 - ops->validate = macvlan_validate;
46165 - ops->maxtype = IFLA_MACVLAN_MAX;
46166 - ops->policy = macvlan_policy;
46167 - ops->changelink = macvlan_changelink;
46168 - ops->get_size = macvlan_get_size;
46169 - ops->fill_info = macvlan_fill_info;
46170 + pax_open_kernel();
46171 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46172 + *(void **)&ops->validate = macvlan_validate;
46173 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46174 + *(const void **)&ops->policy = macvlan_policy;
46175 + *(void **)&ops->changelink = macvlan_changelink;
46176 + *(void **)&ops->get_size = macvlan_get_size;
46177 + *(void **)&ops->fill_info = macvlan_fill_info;
46178 + pax_close_kernel();
46179
46180 return rtnl_link_register(ops);
46181 };
46182 @@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46183 return NOTIFY_DONE;
46184 }
46185
46186 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46187 +static struct notifier_block macvlan_notifier_block = {
46188 .notifier_call = macvlan_device_event,
46189 };
46190
46191 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46192 index 3381c4f..dea5fd5 100644
46193 --- a/drivers/net/macvtap.c
46194 +++ b/drivers/net/macvtap.c
46195 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46196 }
46197
46198 ret = 0;
46199 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46200 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46201 put_user(q->flags, &ifr->ifr_flags))
46202 ret = -EFAULT;
46203 macvtap_put_vlan(vlan);
46204 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46205 return NOTIFY_DONE;
46206 }
46207
46208 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46209 +static struct notifier_block macvtap_notifier_block = {
46210 .notifier_call = macvtap_device_event,
46211 };
46212
46213 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46214 index daec9b0..6428fcb 100644
46215 --- a/drivers/net/phy/mdio-bitbang.c
46216 +++ b/drivers/net/phy/mdio-bitbang.c
46217 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46218 struct mdiobb_ctrl *ctrl = bus->priv;
46219
46220 module_put(ctrl->ops->owner);
46221 + mdiobus_unregister(bus);
46222 mdiobus_free(bus);
46223 }
46224 EXPORT_SYMBOL(free_mdio_bitbang);
46225 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46226 index e3923eb..2a0373b 100644
46227 --- a/drivers/net/ppp/ppp_generic.c
46228 +++ b/drivers/net/ppp/ppp_generic.c
46229 @@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46230 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46231 struct ppp_stats stats;
46232 struct ppp_comp_stats cstats;
46233 - char *vers;
46234
46235 switch (cmd) {
46236 case SIOCGPPPSTATS:
46237 @@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46238 break;
46239
46240 case SIOCGPPPVER:
46241 - vers = PPP_VERSION;
46242 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46243 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46244 break;
46245 err = 0;
46246 break;
46247 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46248 index 1252d9c..80e660b 100644
46249 --- a/drivers/net/slip/slhc.c
46250 +++ b/drivers/net/slip/slhc.c
46251 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46252 register struct tcphdr *thp;
46253 register struct iphdr *ip;
46254 register struct cstate *cs;
46255 - int len, hdrlen;
46256 + long len, hdrlen;
46257 unsigned char *cp = icp;
46258
46259 /* We've got a compressed packet; read the change byte */
46260 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46261 index ce4989b..b40b328 100644
46262 --- a/drivers/net/team/team.c
46263 +++ b/drivers/net/team/team.c
46264 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46265 return NOTIFY_DONE;
46266 }
46267
46268 -static struct notifier_block team_notifier_block __read_mostly = {
46269 +static struct notifier_block team_notifier_block = {
46270 .notifier_call = team_device_event,
46271 };
46272
46273 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46274 index ee328ba..c4a0041 100644
46275 --- a/drivers/net/tun.c
46276 +++ b/drivers/net/tun.c
46277 @@ -1876,7 +1876,7 @@ unlock:
46278 }
46279
46280 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46281 - unsigned long arg, int ifreq_len)
46282 + unsigned long arg, size_t ifreq_len)
46283 {
46284 struct tun_file *tfile = file->private_data;
46285 struct tun_struct *tun;
46286 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46287 unsigned int ifindex;
46288 int ret;
46289
46290 + if (ifreq_len > sizeof ifr)
46291 + return -EFAULT;
46292 +
46293 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46294 if (copy_from_user(&ifr, argp, ifreq_len))
46295 return -EFAULT;
46296 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46297 index 660bd5e..ac59452 100644
46298 --- a/drivers/net/usb/hso.c
46299 +++ b/drivers/net/usb/hso.c
46300 @@ -71,7 +71,7 @@
46301 #include <asm/byteorder.h>
46302 #include <linux/serial_core.h>
46303 #include <linux/serial.h>
46304 -
46305 +#include <asm/local.h>
46306
46307 #define MOD_AUTHOR "Option Wireless"
46308 #define MOD_DESCRIPTION "USB High Speed Option driver"
46309 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46310 struct urb *urb;
46311
46312 urb = serial->rx_urb[0];
46313 - if (serial->port.count > 0) {
46314 + if (atomic_read(&serial->port.count) > 0) {
46315 count = put_rxbuf_data(urb, serial);
46316 if (count == -1)
46317 return;
46318 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46319 DUMP1(urb->transfer_buffer, urb->actual_length);
46320
46321 /* Anyone listening? */
46322 - if (serial->port.count == 0)
46323 + if (atomic_read(&serial->port.count) == 0)
46324 return;
46325
46326 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46327 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46328 tty_port_tty_set(&serial->port, tty);
46329
46330 /* check for port already opened, if not set the termios */
46331 - serial->port.count++;
46332 - if (serial->port.count == 1) {
46333 + if (atomic_inc_return(&serial->port.count) == 1) {
46334 serial->rx_state = RX_IDLE;
46335 /* Force default termio settings */
46336 _hso_serial_set_termios(tty, NULL);
46337 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46338 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46339 if (result) {
46340 hso_stop_serial_device(serial->parent);
46341 - serial->port.count--;
46342 + atomic_dec(&serial->port.count);
46343 kref_put(&serial->parent->ref, hso_serial_ref_free);
46344 }
46345 } else {
46346 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46347
46348 /* reset the rts and dtr */
46349 /* do the actual close */
46350 - serial->port.count--;
46351 + atomic_dec(&serial->port.count);
46352
46353 - if (serial->port.count <= 0) {
46354 - serial->port.count = 0;
46355 + if (atomic_read(&serial->port.count) <= 0) {
46356 + atomic_set(&serial->port.count, 0);
46357 tty_port_tty_set(&serial->port, NULL);
46358 if (!usb_gone)
46359 hso_stop_serial_device(serial->parent);
46360 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46361
46362 /* the actual setup */
46363 spin_lock_irqsave(&serial->serial_lock, flags);
46364 - if (serial->port.count)
46365 + if (atomic_read(&serial->port.count))
46366 _hso_serial_set_termios(tty, old);
46367 else
46368 tty->termios = *old;
46369 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46370 D1("Pending read interrupt on port %d\n", i);
46371 spin_lock(&serial->serial_lock);
46372 if (serial->rx_state == RX_IDLE &&
46373 - serial->port.count > 0) {
46374 + atomic_read(&serial->port.count) > 0) {
46375 /* Setup and send a ctrl req read on
46376 * port i */
46377 if (!serial->rx_urb_filled[0]) {
46378 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46379 /* Start all serial ports */
46380 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46381 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46382 - if (dev2ser(serial_table[i])->port.count) {
46383 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46384 result =
46385 hso_start_serial_device(serial_table[i], GFP_NOIO);
46386 hso_kick_transmit(dev2ser(serial_table[i]));
46387 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46388 index 3fbfb08..2c16265 100644
46389 --- a/drivers/net/usb/r8152.c
46390 +++ b/drivers/net/usb/r8152.c
46391 @@ -567,7 +567,7 @@ struct r8152 {
46392 void (*up)(struct r8152 *);
46393 void (*down)(struct r8152 *);
46394 void (*unload)(struct r8152 *);
46395 - } rtl_ops;
46396 + } __no_const rtl_ops;
46397
46398 int intr_interval;
46399 u32 saved_wolopts;
46400 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46401 index a2515887..6d13233 100644
46402 --- a/drivers/net/usb/sierra_net.c
46403 +++ b/drivers/net/usb/sierra_net.c
46404 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46405 /* atomic counter partially included in MAC address to make sure 2 devices
46406 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46407 */
46408 -static atomic_t iface_counter = ATOMIC_INIT(0);
46409 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46410
46411 /*
46412 * SYNC Timer Delay definition used to set the expiry time
46413 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46414 dev->net->netdev_ops = &sierra_net_device_ops;
46415
46416 /* change MAC addr to include, ifacenum, and to be unique */
46417 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46418 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46419 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46420
46421 /* we will have to manufacture ethernet headers, prepare template */
46422 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46423 index 77dcf92..549924a 100644
46424 --- a/drivers/net/vxlan.c
46425 +++ b/drivers/net/vxlan.c
46426 @@ -2839,7 +2839,7 @@ nla_put_failure:
46427 return -EMSGSIZE;
46428 }
46429
46430 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46431 +static struct rtnl_link_ops vxlan_link_ops = {
46432 .kind = "vxlan",
46433 .maxtype = IFLA_VXLAN_MAX,
46434 .policy = vxlan_policy,
46435 @@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46436 return NOTIFY_DONE;
46437 }
46438
46439 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46440 +static struct notifier_block vxlan_notifier_block = {
46441 .notifier_call = vxlan_lowerdev_event,
46442 };
46443
46444 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46445 index 5920c99..ff2e4a5 100644
46446 --- a/drivers/net/wan/lmc/lmc_media.c
46447 +++ b/drivers/net/wan/lmc/lmc_media.c
46448 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46449 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46450
46451 lmc_media_t lmc_ds3_media = {
46452 - lmc_ds3_init, /* special media init stuff */
46453 - lmc_ds3_default, /* reset to default state */
46454 - lmc_ds3_set_status, /* reset status to state provided */
46455 - lmc_dummy_set_1, /* set clock source */
46456 - lmc_dummy_set2_1, /* set line speed */
46457 - lmc_ds3_set_100ft, /* set cable length */
46458 - lmc_ds3_set_scram, /* set scrambler */
46459 - lmc_ds3_get_link_status, /* get link status */
46460 - lmc_dummy_set_1, /* set link status */
46461 - lmc_ds3_set_crc_length, /* set CRC length */
46462 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46463 - lmc_ds3_watchdog
46464 + .init = lmc_ds3_init, /* special media init stuff */
46465 + .defaults = lmc_ds3_default, /* reset to default state */
46466 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46467 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46468 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46469 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46470 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46471 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46472 + .set_link_status = lmc_dummy_set_1, /* set link status */
46473 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46474 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46475 + .watchdog = lmc_ds3_watchdog
46476 };
46477
46478 lmc_media_t lmc_hssi_media = {
46479 - lmc_hssi_init, /* special media init stuff */
46480 - lmc_hssi_default, /* reset to default state */
46481 - lmc_hssi_set_status, /* reset status to state provided */
46482 - lmc_hssi_set_clock, /* set clock source */
46483 - lmc_dummy_set2_1, /* set line speed */
46484 - lmc_dummy_set_1, /* set cable length */
46485 - lmc_dummy_set_1, /* set scrambler */
46486 - lmc_hssi_get_link_status, /* get link status */
46487 - lmc_hssi_set_link_status, /* set link status */
46488 - lmc_hssi_set_crc_length, /* set CRC length */
46489 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46490 - lmc_hssi_watchdog
46491 + .init = lmc_hssi_init, /* special media init stuff */
46492 + .defaults = lmc_hssi_default, /* reset to default state */
46493 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46494 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46495 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46496 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46497 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46498 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46499 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46500 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46501 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46502 + .watchdog = lmc_hssi_watchdog
46503 };
46504
46505 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46506 - lmc_ssi_default, /* reset to default state */
46507 - lmc_ssi_set_status, /* reset status to state provided */
46508 - lmc_ssi_set_clock, /* set clock source */
46509 - lmc_ssi_set_speed, /* set line speed */
46510 - lmc_dummy_set_1, /* set cable length */
46511 - lmc_dummy_set_1, /* set scrambler */
46512 - lmc_ssi_get_link_status, /* get link status */
46513 - lmc_ssi_set_link_status, /* set link status */
46514 - lmc_ssi_set_crc_length, /* set CRC length */
46515 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46516 - lmc_ssi_watchdog
46517 +lmc_media_t lmc_ssi_media = {
46518 + .init = lmc_ssi_init, /* special media init stuff */
46519 + .defaults = lmc_ssi_default, /* reset to default state */
46520 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46521 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46522 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46523 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46524 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46525 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46526 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46527 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46528 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46529 + .watchdog = lmc_ssi_watchdog
46530 };
46531
46532 lmc_media_t lmc_t1_media = {
46533 - lmc_t1_init, /* special media init stuff */
46534 - lmc_t1_default, /* reset to default state */
46535 - lmc_t1_set_status, /* reset status to state provided */
46536 - lmc_t1_set_clock, /* set clock source */
46537 - lmc_dummy_set2_1, /* set line speed */
46538 - lmc_dummy_set_1, /* set cable length */
46539 - lmc_dummy_set_1, /* set scrambler */
46540 - lmc_t1_get_link_status, /* get link status */
46541 - lmc_dummy_set_1, /* set link status */
46542 - lmc_t1_set_crc_length, /* set CRC length */
46543 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46544 - lmc_t1_watchdog
46545 + .init = lmc_t1_init, /* special media init stuff */
46546 + .defaults = lmc_t1_default, /* reset to default state */
46547 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46548 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46549 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46550 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46551 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46552 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46553 + .set_link_status = lmc_dummy_set_1, /* set link status */
46554 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46555 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46556 + .watchdog = lmc_t1_watchdog
46557 };
46558
46559 static void
46560 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46561 index feacc3b..5bac0de 100644
46562 --- a/drivers/net/wan/z85230.c
46563 +++ b/drivers/net/wan/z85230.c
46564 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46565
46566 struct z8530_irqhandler z8530_sync =
46567 {
46568 - z8530_rx,
46569 - z8530_tx,
46570 - z8530_status
46571 + .rx = z8530_rx,
46572 + .tx = z8530_tx,
46573 + .status = z8530_status
46574 };
46575
46576 EXPORT_SYMBOL(z8530_sync);
46577 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46578 }
46579
46580 static struct z8530_irqhandler z8530_dma_sync = {
46581 - z8530_dma_rx,
46582 - z8530_dma_tx,
46583 - z8530_dma_status
46584 + .rx = z8530_dma_rx,
46585 + .tx = z8530_dma_tx,
46586 + .status = z8530_dma_status
46587 };
46588
46589 static struct z8530_irqhandler z8530_txdma_sync = {
46590 - z8530_rx,
46591 - z8530_dma_tx,
46592 - z8530_dma_status
46593 + .rx = z8530_rx,
46594 + .tx = z8530_dma_tx,
46595 + .status = z8530_dma_status
46596 };
46597
46598 /**
46599 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46600
46601 struct z8530_irqhandler z8530_nop=
46602 {
46603 - z8530_rx_clear,
46604 - z8530_tx_clear,
46605 - z8530_status_clear
46606 + .rx = z8530_rx_clear,
46607 + .tx = z8530_tx_clear,
46608 + .status = z8530_status_clear
46609 };
46610
46611
46612 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46613 index 0b60295..b8bfa5b 100644
46614 --- a/drivers/net/wimax/i2400m/rx.c
46615 +++ b/drivers/net/wimax/i2400m/rx.c
46616 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46617 if (i2400m->rx_roq == NULL)
46618 goto error_roq_alloc;
46619
46620 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46621 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46622 GFP_KERNEL);
46623 if (rd == NULL) {
46624 result = -ENOMEM;
46625 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46626 index 64747d4..17c4cf3 100644
46627 --- a/drivers/net/wireless/airo.c
46628 +++ b/drivers/net/wireless/airo.c
46629 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46630 struct airo_info *ai = dev->ml_priv;
46631 int ridcode;
46632 int enabled;
46633 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46634 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46635 unsigned char *iobuf;
46636
46637 /* Only super-user can write RIDs */
46638 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46639 index 99b3bfa..9559372 100644
46640 --- a/drivers/net/wireless/at76c50x-usb.c
46641 +++ b/drivers/net/wireless/at76c50x-usb.c
46642 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46643 }
46644
46645 /* Convert timeout from the DFU status to jiffies */
46646 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46647 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46648 {
46649 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46650 | (s->poll_timeout[1] << 8)
46651 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46652 index 7f1bccd..ca2ffca 100644
46653 --- a/drivers/net/wireless/ath/ath10k/htc.c
46654 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46655 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46656 /* registered target arrival callback from the HIF layer */
46657 int ath10k_htc_init(struct ath10k *ar)
46658 {
46659 - struct ath10k_hif_cb htc_callbacks;
46660 + static struct ath10k_hif_cb htc_callbacks = {
46661 + .rx_completion = ath10k_htc_rx_completion_handler,
46662 + .tx_completion = ath10k_htc_tx_completion_handler,
46663 + };
46664 struct ath10k_htc_ep *ep = NULL;
46665 struct ath10k_htc *htc = &ar->htc;
46666
46667 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
46668 ath10k_htc_reset_endpoint_states(htc);
46669
46670 /* setup HIF layer callbacks */
46671 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46672 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46673 htc->ar = ar;
46674
46675 /* Get HIF default pipe for HTC message exchange */
46676 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46677 index 4716d33..a688310 100644
46678 --- a/drivers/net/wireless/ath/ath10k/htc.h
46679 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46680 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46681
46682 struct ath10k_htc_ops {
46683 void (*target_send_suspend_complete)(struct ath10k *ar);
46684 -};
46685 +} __no_const;
46686
46687 struct ath10k_htc_ep_ops {
46688 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46689 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46690 void (*ep_tx_credits)(struct ath10k *);
46691 -};
46692 +} __no_const;
46693
46694 /* service connection information */
46695 struct ath10k_htc_svc_conn_req {
46696 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46697 index 741b38d..b7ae41b 100644
46698 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46699 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46700 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46701 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46702 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46703
46704 - ACCESS_ONCE(ads->ds_link) = i->link;
46705 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46706 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46707 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46708
46709 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46710 ctl6 = SM(i->keytype, AR_EncrType);
46711 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46712
46713 if ((i->is_first || i->is_last) &&
46714 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46715 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46716 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46717 | set11nTries(i->rates, 1)
46718 | set11nTries(i->rates, 2)
46719 | set11nTries(i->rates, 3)
46720 | (i->dur_update ? AR_DurUpdateEna : 0)
46721 | SM(0, AR_BurstDur);
46722
46723 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46724 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46725 | set11nRate(i->rates, 1)
46726 | set11nRate(i->rates, 2)
46727 | set11nRate(i->rates, 3);
46728 } else {
46729 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46730 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46731 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46732 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46733 }
46734
46735 if (!i->is_first) {
46736 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46737 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46738 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46739 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46740 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46741 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46742 return;
46743 }
46744
46745 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46746 break;
46747 }
46748
46749 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46750 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46751 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46752 | SM(i->txpower, AR_XmitPower)
46753 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46754 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46755 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46756 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46757
46758 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46759 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46760 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46761 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46762
46763 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46764 return;
46765
46766 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46767 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46768 | set11nPktDurRTSCTS(i->rates, 1);
46769
46770 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46771 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46772 | set11nPktDurRTSCTS(i->rates, 3);
46773
46774 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46775 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46776 | set11nRateFlags(i->rates, 1)
46777 | set11nRateFlags(i->rates, 2)
46778 | set11nRateFlags(i->rates, 3)
46779 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46780 index 729ffbf..49f50e3 100644
46781 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46782 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46783 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46784 (i->qcu << AR_TxQcuNum_S) | desc_len;
46785
46786 checksum += val;
46787 - ACCESS_ONCE(ads->info) = val;
46788 + ACCESS_ONCE_RW(ads->info) = val;
46789
46790 checksum += i->link;
46791 - ACCESS_ONCE(ads->link) = i->link;
46792 + ACCESS_ONCE_RW(ads->link) = i->link;
46793
46794 checksum += i->buf_addr[0];
46795 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46796 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46797 checksum += i->buf_addr[1];
46798 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46799 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46800 checksum += i->buf_addr[2];
46801 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46802 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46803 checksum += i->buf_addr[3];
46804 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46805 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46806
46807 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46808 - ACCESS_ONCE(ads->ctl3) = val;
46809 + ACCESS_ONCE_RW(ads->ctl3) = val;
46810 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46811 - ACCESS_ONCE(ads->ctl5) = val;
46812 + ACCESS_ONCE_RW(ads->ctl5) = val;
46813 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46814 - ACCESS_ONCE(ads->ctl7) = val;
46815 + ACCESS_ONCE_RW(ads->ctl7) = val;
46816 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46817 - ACCESS_ONCE(ads->ctl9) = val;
46818 + ACCESS_ONCE_RW(ads->ctl9) = val;
46819
46820 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46821 - ACCESS_ONCE(ads->ctl10) = checksum;
46822 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46823
46824 if (i->is_first || i->is_last) {
46825 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46826 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46827 | set11nTries(i->rates, 1)
46828 | set11nTries(i->rates, 2)
46829 | set11nTries(i->rates, 3)
46830 | (i->dur_update ? AR_DurUpdateEna : 0)
46831 | SM(0, AR_BurstDur);
46832
46833 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46834 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46835 | set11nRate(i->rates, 1)
46836 | set11nRate(i->rates, 2)
46837 | set11nRate(i->rates, 3);
46838 } else {
46839 - ACCESS_ONCE(ads->ctl13) = 0;
46840 - ACCESS_ONCE(ads->ctl14) = 0;
46841 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46842 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46843 }
46844
46845 ads->ctl20 = 0;
46846 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46847
46848 ctl17 = SM(i->keytype, AR_EncrType);
46849 if (!i->is_first) {
46850 - ACCESS_ONCE(ads->ctl11) = 0;
46851 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46852 - ACCESS_ONCE(ads->ctl15) = 0;
46853 - ACCESS_ONCE(ads->ctl16) = 0;
46854 - ACCESS_ONCE(ads->ctl17) = ctl17;
46855 - ACCESS_ONCE(ads->ctl18) = 0;
46856 - ACCESS_ONCE(ads->ctl19) = 0;
46857 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46858 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46859 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46860 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46861 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46862 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46863 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46864 return;
46865 }
46866
46867 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46868 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46869 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46870 | SM(i->txpower, AR_XmitPower)
46871 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46872 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46873 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46874 ctl12 |= SM(val, AR_PAPRDChainMask);
46875
46876 - ACCESS_ONCE(ads->ctl12) = ctl12;
46877 - ACCESS_ONCE(ads->ctl17) = ctl17;
46878 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46879 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46880
46881 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46882 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46883 | set11nPktDurRTSCTS(i->rates, 1);
46884
46885 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46886 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46887 | set11nPktDurRTSCTS(i->rates, 3);
46888
46889 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46890 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46891 | set11nRateFlags(i->rates, 1)
46892 | set11nRateFlags(i->rates, 2)
46893 | set11nRateFlags(i->rates, 3)
46894 | SM(i->rtscts_rate, AR_RTSCTSRate);
46895
46896 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46897 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46898 }
46899
46900 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46901 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46902 index 0acd4b5..0591c91 100644
46903 --- a/drivers/net/wireless/ath/ath9k/hw.h
46904 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46905 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46906
46907 /* ANI */
46908 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46909 -};
46910 +} __no_const;
46911
46912 /**
46913 * struct ath_spec_scan - parameters for Atheros spectral scan
46914 @@ -706,7 +706,7 @@ struct ath_hw_ops {
46915 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46916 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46917 #endif
46918 -};
46919 +} __no_const;
46920
46921 struct ath_nf_limits {
46922 s16 max;
46923 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46924 index 92190da..f3a4c4c 100644
46925 --- a/drivers/net/wireless/b43/phy_lp.c
46926 +++ b/drivers/net/wireless/b43/phy_lp.c
46927 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46928 {
46929 struct ssb_bus *bus = dev->dev->sdev->bus;
46930
46931 - static const struct b206x_channel *chandata = NULL;
46932 + const struct b206x_channel *chandata = NULL;
46933 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46934 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46935 u16 old_comm15, scale;
46936 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46937 index dc1d20c..f7a4f06 100644
46938 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46939 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46940 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46941 */
46942 if (il3945_mod_params.disable_hw_scan) {
46943 D_INFO("Disabling hw_scan\n");
46944 - il3945_mac_ops.hw_scan = NULL;
46945 + pax_open_kernel();
46946 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46947 + pax_close_kernel();
46948 }
46949
46950 D_INFO("*** LOAD DRIVER ***\n");
46951 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46952 index d2fe259..0c4c682 100644
46953 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46954 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46955 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46956 {
46957 struct iwl_priv *priv = file->private_data;
46958 char buf[64];
46959 - int buf_size;
46960 + size_t buf_size;
46961 u32 offset, len;
46962
46963 memset(buf, 0, sizeof(buf));
46964 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46965 struct iwl_priv *priv = file->private_data;
46966
46967 char buf[8];
46968 - int buf_size;
46969 + size_t buf_size;
46970 u32 reset_flag;
46971
46972 memset(buf, 0, sizeof(buf));
46973 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46974 {
46975 struct iwl_priv *priv = file->private_data;
46976 char buf[8];
46977 - int buf_size;
46978 + size_t buf_size;
46979 int ht40;
46980
46981 memset(buf, 0, sizeof(buf));
46982 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46983 {
46984 struct iwl_priv *priv = file->private_data;
46985 char buf[8];
46986 - int buf_size;
46987 + size_t buf_size;
46988 int value;
46989
46990 memset(buf, 0, sizeof(buf));
46991 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46992 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46993 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46994
46995 -static const char *fmt_value = " %-30s %10u\n";
46996 -static const char *fmt_hex = " %-30s 0x%02X\n";
46997 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46998 -static const char *fmt_header =
46999 +static const char fmt_value[] = " %-30s %10u\n";
47000 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47001 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47002 +static const char fmt_header[] =
47003 "%-32s current cumulative delta max\n";
47004
47005 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47006 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47007 {
47008 struct iwl_priv *priv = file->private_data;
47009 char buf[8];
47010 - int buf_size;
47011 + size_t buf_size;
47012 int clear;
47013
47014 memset(buf, 0, sizeof(buf));
47015 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47016 {
47017 struct iwl_priv *priv = file->private_data;
47018 char buf[8];
47019 - int buf_size;
47020 + size_t buf_size;
47021 int trace;
47022
47023 memset(buf, 0, sizeof(buf));
47024 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47025 {
47026 struct iwl_priv *priv = file->private_data;
47027 char buf[8];
47028 - int buf_size;
47029 + size_t buf_size;
47030 int missed;
47031
47032 memset(buf, 0, sizeof(buf));
47033 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47034
47035 struct iwl_priv *priv = file->private_data;
47036 char buf[8];
47037 - int buf_size;
47038 + size_t buf_size;
47039 int plcp;
47040
47041 memset(buf, 0, sizeof(buf));
47042 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47043
47044 struct iwl_priv *priv = file->private_data;
47045 char buf[8];
47046 - int buf_size;
47047 + size_t buf_size;
47048 int flush;
47049
47050 memset(buf, 0, sizeof(buf));
47051 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47052
47053 struct iwl_priv *priv = file->private_data;
47054 char buf[8];
47055 - int buf_size;
47056 + size_t buf_size;
47057 int rts;
47058
47059 if (!priv->cfg->ht_params)
47060 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47061 {
47062 struct iwl_priv *priv = file->private_data;
47063 char buf[8];
47064 - int buf_size;
47065 + size_t buf_size;
47066
47067 memset(buf, 0, sizeof(buf));
47068 buf_size = min(count, sizeof(buf) - 1);
47069 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47070 struct iwl_priv *priv = file->private_data;
47071 u32 event_log_flag;
47072 char buf[8];
47073 - int buf_size;
47074 + size_t buf_size;
47075
47076 /* check that the interface is up */
47077 if (!iwl_is_ready(priv))
47078 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47079 struct iwl_priv *priv = file->private_data;
47080 char buf[8];
47081 u32 calib_disabled;
47082 - int buf_size;
47083 + size_t buf_size;
47084
47085 memset(buf, 0, sizeof(buf));
47086 buf_size = min(count, sizeof(buf) - 1);
47087 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47088 index 6a6df71..eb5c93a 100644
47089 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47090 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47091 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47092 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47093 {
47094 struct iwl_nvm_data *data = priv->nvm_data;
47095 - char *debug_msg;
47096 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47097
47098 if (data->sku_cap_11n_enable &&
47099 !priv->cfg->ht_params) {
47100 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47101 return -EINVAL;
47102 }
47103
47104 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47105 IWL_DEBUG_INFO(priv, debug_msg,
47106 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47107 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47108 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47109 index 2365553..97126d8 100644
47110 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47111 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47112 @@ -1552,7 +1552,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47113 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47114
47115 char buf[8];
47116 - int buf_size;
47117 + size_t buf_size;
47118 u32 reset_flag;
47119
47120 memset(buf, 0, sizeof(buf));
47121 @@ -1573,7 +1573,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47122 {
47123 struct iwl_trans *trans = file->private_data;
47124 char buf[8];
47125 - int buf_size;
47126 + size_t buf_size;
47127 int csr;
47128
47129 memset(buf, 0, sizeof(buf));
47130 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47131 index 9d7a52f..2729a99 100644
47132 --- a/drivers/net/wireless/mac80211_hwsim.c
47133 +++ b/drivers/net/wireless/mac80211_hwsim.c
47134 @@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47135 if (channels < 1)
47136 return -EINVAL;
47137
47138 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47139 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47140 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47141 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47142 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47143 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47144 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47145 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47146 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47147 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47148 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47149 - mac80211_hwsim_assign_vif_chanctx;
47150 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47151 - mac80211_hwsim_unassign_vif_chanctx;
47152 + pax_open_kernel();
47153 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47154 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47155 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47156 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47157 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47158 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47159 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47160 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47161 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47162 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47163 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47164 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47165 + pax_close_kernel();
47166
47167 spin_lock_init(&hwsim_radio_lock);
47168 INIT_LIST_HEAD(&hwsim_radios);
47169 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47170 index 39d22a1..4ec8612 100644
47171 --- a/drivers/net/wireless/rndis_wlan.c
47172 +++ b/drivers/net/wireless/rndis_wlan.c
47173 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47174
47175 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47176
47177 - if (rts_threshold < 0 || rts_threshold > 2347)
47178 + if (rts_threshold > 2347)
47179 rts_threshold = 2347;
47180
47181 tmp = cpu_to_le32(rts_threshold);
47182 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47183 index e3b885d..7a7de2f 100644
47184 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47185 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47186 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47187 * for hardware which doesn't support hardware
47188 * sequence counting.
47189 */
47190 - atomic_t seqno;
47191 + atomic_unchecked_t seqno;
47192 };
47193
47194 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47195 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47196 index 5642ccc..01f03eb 100644
47197 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47198 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47199 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47200 * sequence counter given by mac80211.
47201 */
47202 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47203 - seqno = atomic_add_return(0x10, &intf->seqno);
47204 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47205 else
47206 - seqno = atomic_read(&intf->seqno);
47207 + seqno = atomic_read_unchecked(&intf->seqno);
47208
47209 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47210 hdr->seq_ctrl |= cpu_to_le16(seqno);
47211 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47212 index b661f896..ddf7d2b 100644
47213 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47214 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47215 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47216
47217 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47218
47219 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47220 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47221 + pax_open_kernel();
47222 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47223 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47224 + pax_close_kernel();
47225
47226 wl1251_info("using dedicated interrupt line");
47227 } else {
47228 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47229 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47230 + pax_open_kernel();
47231 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47232 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47233 + pax_close_kernel();
47234
47235 wl1251_info("using SDIO interrupt");
47236 }
47237 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47238 index d50dfac..0a6f5be3 100644
47239 --- a/drivers/net/wireless/ti/wl12xx/main.c
47240 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47241 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47242 sizeof(wl->conf.mem));
47243
47244 /* read data preparation is only needed by wl127x */
47245 - wl->ops->prepare_read = wl127x_prepare_read;
47246 + pax_open_kernel();
47247 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47248 + pax_close_kernel();
47249
47250 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47251 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47252 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47253 sizeof(wl->conf.mem));
47254
47255 /* read data preparation is only needed by wl127x */
47256 - wl->ops->prepare_read = wl127x_prepare_read;
47257 + pax_open_kernel();
47258 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47259 + pax_close_kernel();
47260
47261 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47262 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47263 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47264 index de5b4fa..7996ec6 100644
47265 --- a/drivers/net/wireless/ti/wl18xx/main.c
47266 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47267 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47268 }
47269
47270 if (!checksum_param) {
47271 - wl18xx_ops.set_rx_csum = NULL;
47272 - wl18xx_ops.init_vif = NULL;
47273 + pax_open_kernel();
47274 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47275 + *(void **)&wl18xx_ops.init_vif = NULL;
47276 + pax_close_kernel();
47277 }
47278
47279 /* Enable 11a Band only if we have 5G antennas */
47280 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47281 index a912dc0..a8225ba 100644
47282 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47283 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47284 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47285 {
47286 struct zd_usb *usb = urb->context;
47287 struct zd_usb_interrupt *intr = &usb->intr;
47288 - int len;
47289 + unsigned int len;
47290 u16 int_num;
47291
47292 ZD_ASSERT(in_interrupt());
47293 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47294 index 683671a..4519fc2 100644
47295 --- a/drivers/nfc/nfcwilink.c
47296 +++ b/drivers/nfc/nfcwilink.c
47297 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47298
47299 static int nfcwilink_probe(struct platform_device *pdev)
47300 {
47301 - static struct nfcwilink *drv;
47302 + struct nfcwilink *drv;
47303 int rc;
47304 __u32 protocols;
47305
47306 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47307 index d93b2b6..ae50401 100644
47308 --- a/drivers/oprofile/buffer_sync.c
47309 +++ b/drivers/oprofile/buffer_sync.c
47310 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47311 if (cookie == NO_COOKIE)
47312 offset = pc;
47313 if (cookie == INVALID_COOKIE) {
47314 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47315 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47316 offset = pc;
47317 }
47318 if (cookie != last_cookie) {
47319 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47320 /* add userspace sample */
47321
47322 if (!mm) {
47323 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47324 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47325 return 0;
47326 }
47327
47328 cookie = lookup_dcookie(mm, s->eip, &offset);
47329
47330 if (cookie == INVALID_COOKIE) {
47331 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47332 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47333 return 0;
47334 }
47335
47336 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47337 /* ignore backtraces if failed to add a sample */
47338 if (state == sb_bt_start) {
47339 state = sb_bt_ignore;
47340 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47341 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47342 }
47343 }
47344 release_mm(mm);
47345 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47346 index c0cc4e7..44d4e54 100644
47347 --- a/drivers/oprofile/event_buffer.c
47348 +++ b/drivers/oprofile/event_buffer.c
47349 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47350 }
47351
47352 if (buffer_pos == buffer_size) {
47353 - atomic_inc(&oprofile_stats.event_lost_overflow);
47354 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47355 return;
47356 }
47357
47358 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47359 index ed2c3ec..deda85a 100644
47360 --- a/drivers/oprofile/oprof.c
47361 +++ b/drivers/oprofile/oprof.c
47362 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47363 if (oprofile_ops.switch_events())
47364 return;
47365
47366 - atomic_inc(&oprofile_stats.multiplex_counter);
47367 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47368 start_switch_worker();
47369 }
47370
47371 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47372 index ee2cfce..7f8f699 100644
47373 --- a/drivers/oprofile/oprofile_files.c
47374 +++ b/drivers/oprofile/oprofile_files.c
47375 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47376
47377 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47378
47379 -static ssize_t timeout_read(struct file *file, char __user *buf,
47380 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47381 size_t count, loff_t *offset)
47382 {
47383 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47384 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47385 index 59659ce..6c860a0 100644
47386 --- a/drivers/oprofile/oprofile_stats.c
47387 +++ b/drivers/oprofile/oprofile_stats.c
47388 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47389 cpu_buf->sample_invalid_eip = 0;
47390 }
47391
47392 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47393 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47394 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47395 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47396 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47397 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47398 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47399 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47400 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47401 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47402 }
47403
47404
47405 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47406 index 1fc622b..8c48fc3 100644
47407 --- a/drivers/oprofile/oprofile_stats.h
47408 +++ b/drivers/oprofile/oprofile_stats.h
47409 @@ -13,11 +13,11 @@
47410 #include <linux/atomic.h>
47411
47412 struct oprofile_stat_struct {
47413 - atomic_t sample_lost_no_mm;
47414 - atomic_t sample_lost_no_mapping;
47415 - atomic_t bt_lost_no_mapping;
47416 - atomic_t event_lost_overflow;
47417 - atomic_t multiplex_counter;
47418 + atomic_unchecked_t sample_lost_no_mm;
47419 + atomic_unchecked_t sample_lost_no_mapping;
47420 + atomic_unchecked_t bt_lost_no_mapping;
47421 + atomic_unchecked_t event_lost_overflow;
47422 + atomic_unchecked_t multiplex_counter;
47423 };
47424
47425 extern struct oprofile_stat_struct oprofile_stats;
47426 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47427 index 3f49345..c750d0b 100644
47428 --- a/drivers/oprofile/oprofilefs.c
47429 +++ b/drivers/oprofile/oprofilefs.c
47430 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47431
47432 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47433 {
47434 - atomic_t *val = file->private_data;
47435 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47436 + atomic_unchecked_t *val = file->private_data;
47437 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47438 }
47439
47440
47441 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47442
47443
47444 int oprofilefs_create_ro_atomic(struct dentry *root,
47445 - char const *name, atomic_t *val)
47446 + char const *name, atomic_unchecked_t *val)
47447 {
47448 return __oprofilefs_create_file(root, name,
47449 &atomic_ro_fops, 0444, val);
47450 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47451 index 61be1d9..dec05d7 100644
47452 --- a/drivers/oprofile/timer_int.c
47453 +++ b/drivers/oprofile/timer_int.c
47454 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47455 return NOTIFY_OK;
47456 }
47457
47458 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47459 +static struct notifier_block oprofile_cpu_notifier = {
47460 .notifier_call = oprofile_cpu_notify,
47461 };
47462
47463 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47464 index 92ed045..62d39bd7 100644
47465 --- a/drivers/parport/procfs.c
47466 +++ b/drivers/parport/procfs.c
47467 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47468
47469 *ppos += len;
47470
47471 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47472 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47473 }
47474
47475 #ifdef CONFIG_PARPORT_1284
47476 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47477
47478 *ppos += len;
47479
47480 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47481 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47482 }
47483 #endif /* IEEE1284.3 support. */
47484
47485 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47486 index 8dcccff..35d701d 100644
47487 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47488 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47489 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47490 goto init_cleanup;
47491 }
47492
47493 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47494 + pax_open_kernel();
47495 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47496 + pax_close_kernel();
47497 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47498
47499 return retval;
47500 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47501 index 7536eef..52dc8fa 100644
47502 --- a/drivers/pci/hotplug/cpcihp_generic.c
47503 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47504 @@ -73,7 +73,6 @@ static u16 port;
47505 static unsigned int enum_bit;
47506 static u8 enum_mask;
47507
47508 -static struct cpci_hp_controller_ops generic_hpc_ops;
47509 static struct cpci_hp_controller generic_hpc;
47510
47511 static int __init validate_parameters(void)
47512 @@ -139,6 +138,10 @@ static int query_enum(void)
47513 return ((value & enum_mask) == enum_mask);
47514 }
47515
47516 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47517 + .query_enum = query_enum,
47518 +};
47519 +
47520 static int __init cpcihp_generic_init(void)
47521 {
47522 int status;
47523 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47524 pci_dev_put(dev);
47525
47526 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47527 - generic_hpc_ops.query_enum = query_enum;
47528 generic_hpc.ops = &generic_hpc_ops;
47529
47530 status = cpci_hp_register_controller(&generic_hpc);
47531 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47532 index e8c4a7c..7046f5c 100644
47533 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47534 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47535 @@ -59,7 +59,6 @@
47536 /* local variables */
47537 static bool debug;
47538 static bool poll;
47539 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47540 static struct cpci_hp_controller zt5550_hpc;
47541
47542 /* Primary cPCI bus bridge device */
47543 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47544 return 0;
47545 }
47546
47547 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47548 + .query_enum = zt5550_hc_query_enum,
47549 +};
47550 +
47551 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47552 {
47553 int status;
47554 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47555 dbg("returned from zt5550_hc_config");
47556
47557 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47558 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47559 zt5550_hpc.ops = &zt5550_hpc_ops;
47560 if(!poll) {
47561 zt5550_hpc.irq = hc_dev->irq;
47562 zt5550_hpc.irq_flags = IRQF_SHARED;
47563 zt5550_hpc.dev_id = hc_dev;
47564
47565 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47566 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47567 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47568 + pax_open_kernel();
47569 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47570 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47571 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47572 + pax_open_kernel();
47573 } else {
47574 info("using ENUM# polling mode");
47575 }
47576 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47577 index 76ba8a1..20ca857 100644
47578 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47579 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47580 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47581
47582 void compaq_nvram_init (void __iomem *rom_start)
47583 {
47584 +
47585 +#ifndef CONFIG_PAX_KERNEXEC
47586 if (rom_start) {
47587 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47588 }
47589 +#endif
47590 +
47591 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47592
47593 /* initialize our int15 lock */
47594 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47595 index cfa92a9..29539c5 100644
47596 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47597 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47598 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47599 return -EINVAL;
47600 }
47601
47602 - slot->ops->owner = owner;
47603 - slot->ops->mod_name = mod_name;
47604 + pax_open_kernel();
47605 + *(struct module **)&slot->ops->owner = owner;
47606 + *(const char **)&slot->ops->mod_name = mod_name;
47607 + pax_close_kernel();
47608
47609 mutex_lock(&pci_hp_mutex);
47610 /*
47611 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47612 index 0e0a2ff..29dff57 100644
47613 --- a/drivers/pci/hotplug/pciehp_core.c
47614 +++ b/drivers/pci/hotplug/pciehp_core.c
47615 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47616 struct slot *slot = ctrl->slot;
47617 struct hotplug_slot *hotplug = NULL;
47618 struct hotplug_slot_info *info = NULL;
47619 - struct hotplug_slot_ops *ops = NULL;
47620 + hotplug_slot_ops_no_const *ops = NULL;
47621 char name[SLOT_NAME_SIZE];
47622 int retval = -ENOMEM;
47623
47624 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47625 index fb02fc2..83dc2c3 100644
47626 --- a/drivers/pci/msi.c
47627 +++ b/drivers/pci/msi.c
47628 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47629 {
47630 struct attribute **msi_attrs;
47631 struct attribute *msi_attr;
47632 - struct device_attribute *msi_dev_attr;
47633 - struct attribute_group *msi_irq_group;
47634 + device_attribute_no_const *msi_dev_attr;
47635 + attribute_group_no_const *msi_irq_group;
47636 const struct attribute_group **msi_irq_groups;
47637 struct msi_desc *entry;
47638 int ret = -ENOMEM;
47639 @@ -589,7 +589,7 @@ error_attrs:
47640 count = 0;
47641 msi_attr = msi_attrs[count];
47642 while (msi_attr) {
47643 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47644 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47645 kfree(msi_attr->name);
47646 kfree(msi_dev_attr);
47647 ++count;
47648 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47649 index 4e0acef..bd98e31 100644
47650 --- a/drivers/pci/pci-sysfs.c
47651 +++ b/drivers/pci/pci-sysfs.c
47652 @@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47653 {
47654 /* allocate attribute structure, piggyback attribute name */
47655 int name_len = write_combine ? 13 : 10;
47656 - struct bin_attribute *res_attr;
47657 + bin_attribute_no_const *res_attr;
47658 int retval;
47659
47660 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47661 @@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47662 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47663 {
47664 int retval;
47665 - struct bin_attribute *attr;
47666 + bin_attribute_no_const *attr;
47667
47668 /* If the device has VPD, try to expose it in sysfs. */
47669 if (dev->vpd) {
47670 @@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47671 {
47672 int retval;
47673 int rom_size = 0;
47674 - struct bin_attribute *attr;
47675 + bin_attribute_no_const *attr;
47676
47677 if (!sysfs_initialized)
47678 return -EACCES;
47679 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47680 index 6bd0822..35bc2b3 100644
47681 --- a/drivers/pci/pci.h
47682 +++ b/drivers/pci/pci.h
47683 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
47684 struct pci_vpd {
47685 unsigned int len;
47686 const struct pci_vpd_ops *ops;
47687 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47688 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47689 };
47690
47691 int pci_vpd_pci22_init(struct pci_dev *dev);
47692 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47693 index e1e7026..d28dd33 100644
47694 --- a/drivers/pci/pcie/aspm.c
47695 +++ b/drivers/pci/pcie/aspm.c
47696 @@ -27,9 +27,9 @@
47697 #define MODULE_PARAM_PREFIX "pcie_aspm."
47698
47699 /* Note: those are not register definitions */
47700 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47701 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47702 -#define ASPM_STATE_L1 (4) /* L1 state */
47703 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47704 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47705 +#define ASPM_STATE_L1 (4U) /* L1 state */
47706 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47707 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47708
47709 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47710 index ef09f5f..49ac62f 100644
47711 --- a/drivers/pci/probe.c
47712 +++ b/drivers/pci/probe.c
47713 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47714 struct pci_bus_region region, inverted_region;
47715 bool bar_too_big = false, bar_disabled = false;
47716
47717 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47718 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47719
47720 /* No printks while decoding is disabled! */
47721 if (!dev->mmio_always_on) {
47722 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47723 index 46d1378..30e452b 100644
47724 --- a/drivers/pci/proc.c
47725 +++ b/drivers/pci/proc.c
47726 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47727 static int __init pci_proc_init(void)
47728 {
47729 struct pci_dev *dev = NULL;
47730 +
47731 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47732 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47733 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47734 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47735 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47736 +#endif
47737 +#else
47738 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47739 +#endif
47740 proc_create("devices", 0, proc_bus_pci_dir,
47741 &proc_bus_pci_dev_operations);
47742 proc_initialized = 1;
47743 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47744 index 7f3aad0..7d604bb 100644
47745 --- a/drivers/platform/chrome/chromeos_laptop.c
47746 +++ b/drivers/platform/chrome/chromeos_laptop.c
47747 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47748 .callback = chromeos_laptop_dmi_matched, \
47749 .driver_data = (void *)&board_
47750
47751 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47752 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47753 {
47754 .ident = "Samsung Series 5 550",
47755 .matches = {
47756 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
47757 index 541f951..4dfd598 100644
47758 --- a/drivers/platform/x86/alienware-wmi.c
47759 +++ b/drivers/platform/x86/alienware-wmi.c
47760 @@ -132,7 +132,7 @@ struct wmax_led_args {
47761 } __packed;
47762
47763 static struct platform_device *platform_device;
47764 -static struct device_attribute *zone_dev_attrs;
47765 +static device_attribute_no_const *zone_dev_attrs;
47766 static struct attribute **zone_attrs;
47767 static struct platform_zone *zone_data;
47768
47769 @@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
47770 }
47771 };
47772
47773 -static struct attribute_group zone_attribute_group = {
47774 +static attribute_group_no_const zone_attribute_group = {
47775 .name = "rgb_zones",
47776 };
47777
47778 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47779 index c5e082f..d6307a0 100644
47780 --- a/drivers/platform/x86/asus-wmi.c
47781 +++ b/drivers/platform/x86/asus-wmi.c
47782 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47783 int err;
47784 u32 retval = -1;
47785
47786 +#ifdef CONFIG_GRKERNSEC_KMEM
47787 + return -EPERM;
47788 +#endif
47789 +
47790 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47791
47792 if (err < 0)
47793 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47794 int err;
47795 u32 retval = -1;
47796
47797 +#ifdef CONFIG_GRKERNSEC_KMEM
47798 + return -EPERM;
47799 +#endif
47800 +
47801 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47802 &retval);
47803
47804 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47805 union acpi_object *obj;
47806 acpi_status status;
47807
47808 +#ifdef CONFIG_GRKERNSEC_KMEM
47809 + return -EPERM;
47810 +#endif
47811 +
47812 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47813 1, asus->debug.method_id,
47814 &input, &output);
47815 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47816 index 62f8030..c7f2a45 100644
47817 --- a/drivers/platform/x86/msi-laptop.c
47818 +++ b/drivers/platform/x86/msi-laptop.c
47819 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47820
47821 if (!quirks->ec_read_only) {
47822 /* allow userland write sysfs file */
47823 - dev_attr_bluetooth.store = store_bluetooth;
47824 - dev_attr_wlan.store = store_wlan;
47825 - dev_attr_threeg.store = store_threeg;
47826 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47827 - dev_attr_wlan.attr.mode |= S_IWUSR;
47828 - dev_attr_threeg.attr.mode |= S_IWUSR;
47829 + pax_open_kernel();
47830 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47831 + *(void **)&dev_attr_wlan.store = store_wlan;
47832 + *(void **)&dev_attr_threeg.store = store_threeg;
47833 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47834 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47835 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47836 + pax_close_kernel();
47837 }
47838
47839 /* disable hardware control by fn key */
47840 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47841 index 70222f2..8c8ce66 100644
47842 --- a/drivers/platform/x86/msi-wmi.c
47843 +++ b/drivers/platform/x86/msi-wmi.c
47844 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47845 static void msi_wmi_notify(u32 value, void *context)
47846 {
47847 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47848 - static struct key_entry *key;
47849 + struct key_entry *key;
47850 union acpi_object *obj;
47851 acpi_status status;
47852
47853 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47854 index 9c5a074..06c976a 100644
47855 --- a/drivers/platform/x86/sony-laptop.c
47856 +++ b/drivers/platform/x86/sony-laptop.c
47857 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47858 }
47859
47860 /* High speed charging function */
47861 -static struct device_attribute *hsc_handle;
47862 +static device_attribute_no_const *hsc_handle;
47863
47864 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47865 struct device_attribute *attr,
47866 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
47867 }
47868
47869 /* low battery function */
47870 -static struct device_attribute *lowbatt_handle;
47871 +static device_attribute_no_const *lowbatt_handle;
47872
47873 static ssize_t sony_nc_lowbatt_store(struct device *dev,
47874 struct device_attribute *attr,
47875 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
47876 }
47877
47878 /* fan speed function */
47879 -static struct device_attribute *fan_handle, *hsf_handle;
47880 +static device_attribute_no_const *fan_handle, *hsf_handle;
47881
47882 static ssize_t sony_nc_hsfan_store(struct device *dev,
47883 struct device_attribute *attr,
47884 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
47885 }
47886
47887 /* USB charge function */
47888 -static struct device_attribute *uc_handle;
47889 +static device_attribute_no_const *uc_handle;
47890
47891 static ssize_t sony_nc_usb_charge_store(struct device *dev,
47892 struct device_attribute *attr,
47893 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
47894 }
47895
47896 /* Panel ID function */
47897 -static struct device_attribute *panel_handle;
47898 +static device_attribute_no_const *panel_handle;
47899
47900 static ssize_t sony_nc_panelid_show(struct device *dev,
47901 struct device_attribute *attr, char *buffer)
47902 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
47903 }
47904
47905 /* smart connect function */
47906 -static struct device_attribute *sc_handle;
47907 +static device_attribute_no_const *sc_handle;
47908
47909 static ssize_t sony_nc_smart_conn_store(struct device *dev,
47910 struct device_attribute *attr,
47911 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47912 index 15e61c1..40a39c7 100644
47913 --- a/drivers/platform/x86/thinkpad_acpi.c
47914 +++ b/drivers/platform/x86/thinkpad_acpi.c
47915 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47916 return 0;
47917 }
47918
47919 -void static hotkey_mask_warn_incomplete_mask(void)
47920 +static void hotkey_mask_warn_incomplete_mask(void)
47921 {
47922 /* log only what the user can fix... */
47923 const u32 wantedmask = hotkey_driver_mask &
47924 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47925 && !tp_features.bright_unkfw)
47926 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47927 }
47928 +}
47929
47930 #undef TPACPI_COMPARE_KEY
47931 #undef TPACPI_MAY_SEND_KEY
47932 -}
47933
47934 /*
47935 * Polling driver
47936 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47937 index 438d4c7..ca8a2fb 100644
47938 --- a/drivers/pnp/pnpbios/bioscalls.c
47939 +++ b/drivers/pnp/pnpbios/bioscalls.c
47940 @@ -59,7 +59,7 @@ do { \
47941 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47942 } while(0)
47943
47944 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47945 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47946 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47947
47948 /*
47949 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47950
47951 cpu = get_cpu();
47952 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47953 +
47954 + pax_open_kernel();
47955 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47956 + pax_close_kernel();
47957
47958 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47959 spin_lock_irqsave(&pnp_bios_lock, flags);
47960 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47961 :"memory");
47962 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47963
47964 + pax_open_kernel();
47965 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47966 + pax_close_kernel();
47967 +
47968 put_cpu();
47969
47970 /* If we get here and this is set then the PnP BIOS faulted on us. */
47971 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47972 return status;
47973 }
47974
47975 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47976 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47977 {
47978 int i;
47979
47980 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47981 pnp_bios_callpoint.offset = header->fields.pm16offset;
47982 pnp_bios_callpoint.segment = PNP_CS16;
47983
47984 + pax_open_kernel();
47985 +
47986 for_each_possible_cpu(i) {
47987 struct desc_struct *gdt = get_cpu_gdt_table(i);
47988 if (!gdt)
47989 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47990 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47991 (unsigned long)__va(header->fields.pm16dseg));
47992 }
47993 +
47994 + pax_close_kernel();
47995 }
47996 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47997 index 01712cb..782e822 100644
47998 --- a/drivers/pnp/resource.c
47999 +++ b/drivers/pnp/resource.c
48000 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48001 return 1;
48002
48003 /* check if the resource is valid */
48004 - if (*irq < 0 || *irq > 15)
48005 + if (*irq > 15)
48006 return 0;
48007
48008 /* check if the resource is reserved */
48009 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48010 return 1;
48011
48012 /* check if the resource is valid */
48013 - if (*dma < 0 || *dma == 4 || *dma > 7)
48014 + if (*dma == 4 || *dma > 7)
48015 return 0;
48016
48017 /* check if the resource is reserved */
48018 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48019 index 0c52e2a..3421ab7 100644
48020 --- a/drivers/power/pda_power.c
48021 +++ b/drivers/power/pda_power.c
48022 @@ -37,7 +37,11 @@ static int polling;
48023
48024 #if IS_ENABLED(CONFIG_USB_PHY)
48025 static struct usb_phy *transceiver;
48026 -static struct notifier_block otg_nb;
48027 +static int otg_handle_notification(struct notifier_block *nb,
48028 + unsigned long event, void *unused);
48029 +static struct notifier_block otg_nb = {
48030 + .notifier_call = otg_handle_notification
48031 +};
48032 #endif
48033
48034 static struct regulator *ac_draw;
48035 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48036
48037 #if IS_ENABLED(CONFIG_USB_PHY)
48038 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48039 - otg_nb.notifier_call = otg_handle_notification;
48040 ret = usb_register_notifier(transceiver, &otg_nb);
48041 if (ret) {
48042 dev_err(dev, "failure to register otg notifier\n");
48043 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48044 index cc439fd..8fa30df 100644
48045 --- a/drivers/power/power_supply.h
48046 +++ b/drivers/power/power_supply.h
48047 @@ -16,12 +16,12 @@ struct power_supply;
48048
48049 #ifdef CONFIG_SYSFS
48050
48051 -extern void power_supply_init_attrs(struct device_type *dev_type);
48052 +extern void power_supply_init_attrs(void);
48053 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48054
48055 #else
48056
48057 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48058 +static inline void power_supply_init_attrs(void) {}
48059 #define power_supply_uevent NULL
48060
48061 #endif /* CONFIG_SYSFS */
48062 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48063 index 2660664..75fcb04 100644
48064 --- a/drivers/power/power_supply_core.c
48065 +++ b/drivers/power/power_supply_core.c
48066 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48067 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48068 EXPORT_SYMBOL_GPL(power_supply_notifier);
48069
48070 -static struct device_type power_supply_dev_type;
48071 +extern const struct attribute_group *power_supply_attr_groups[];
48072 +static struct device_type power_supply_dev_type = {
48073 + .groups = power_supply_attr_groups,
48074 +};
48075
48076 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48077 struct power_supply *supply)
48078 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48079 return PTR_ERR(power_supply_class);
48080
48081 power_supply_class->dev_uevent = power_supply_uevent;
48082 - power_supply_init_attrs(&power_supply_dev_type);
48083 + power_supply_init_attrs();
48084
48085 return 0;
48086 }
48087 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48088 index 44420d1..967126e 100644
48089 --- a/drivers/power/power_supply_sysfs.c
48090 +++ b/drivers/power/power_supply_sysfs.c
48091 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48092 .is_visible = power_supply_attr_is_visible,
48093 };
48094
48095 -static const struct attribute_group *power_supply_attr_groups[] = {
48096 +const struct attribute_group *power_supply_attr_groups[] = {
48097 &power_supply_attr_group,
48098 NULL,
48099 };
48100
48101 -void power_supply_init_attrs(struct device_type *dev_type)
48102 +void power_supply_init_attrs(void)
48103 {
48104 int i;
48105
48106 - dev_type->groups = power_supply_attr_groups;
48107 -
48108 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48109 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48110 }
48111 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48112 index 84419af..268ede8 100644
48113 --- a/drivers/powercap/powercap_sys.c
48114 +++ b/drivers/powercap/powercap_sys.c
48115 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48116 struct device_attribute name_attr;
48117 };
48118
48119 +static ssize_t show_constraint_name(struct device *dev,
48120 + struct device_attribute *dev_attr,
48121 + char *buf);
48122 +
48123 static struct powercap_constraint_attr
48124 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48125 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48126 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48127 + .power_limit_attr = {
48128 + .attr = {
48129 + .name = NULL,
48130 + .mode = S_IWUSR | S_IRUGO
48131 + },
48132 + .show = show_constraint_power_limit_uw,
48133 + .store = store_constraint_power_limit_uw
48134 + },
48135 +
48136 + .time_window_attr = {
48137 + .attr = {
48138 + .name = NULL,
48139 + .mode = S_IWUSR | S_IRUGO
48140 + },
48141 + .show = show_constraint_time_window_us,
48142 + .store = store_constraint_time_window_us
48143 + },
48144 +
48145 + .max_power_attr = {
48146 + .attr = {
48147 + .name = NULL,
48148 + .mode = S_IRUGO
48149 + },
48150 + .show = show_constraint_max_power_uw,
48151 + .store = NULL
48152 + },
48153 +
48154 + .min_power_attr = {
48155 + .attr = {
48156 + .name = NULL,
48157 + .mode = S_IRUGO
48158 + },
48159 + .show = show_constraint_min_power_uw,
48160 + .store = NULL
48161 + },
48162 +
48163 + .max_time_window_attr = {
48164 + .attr = {
48165 + .name = NULL,
48166 + .mode = S_IRUGO
48167 + },
48168 + .show = show_constraint_max_time_window_us,
48169 + .store = NULL
48170 + },
48171 +
48172 + .min_time_window_attr = {
48173 + .attr = {
48174 + .name = NULL,
48175 + .mode = S_IRUGO
48176 + },
48177 + .show = show_constraint_min_time_window_us,
48178 + .store = NULL
48179 + },
48180 +
48181 + .name_attr = {
48182 + .attr = {
48183 + .name = NULL,
48184 + .mode = S_IRUGO
48185 + },
48186 + .show = show_constraint_name,
48187 + .store = NULL
48188 + }
48189 + }
48190 +};
48191
48192 /* A list of powercap control_types */
48193 static LIST_HEAD(powercap_cntrl_list);
48194 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48195 }
48196
48197 static int create_constraint_attribute(int id, const char *name,
48198 - int mode,
48199 - struct device_attribute *dev_attr,
48200 - ssize_t (*show)(struct device *,
48201 - struct device_attribute *, char *),
48202 - ssize_t (*store)(struct device *,
48203 - struct device_attribute *,
48204 - const char *, size_t)
48205 - )
48206 + struct device_attribute *dev_attr)
48207 {
48208 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48209
48210 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48211 - id, name);
48212 - if (!dev_attr->attr.name)
48213 + if (!name)
48214 return -ENOMEM;
48215 - dev_attr->attr.mode = mode;
48216 - dev_attr->show = show;
48217 - dev_attr->store = store;
48218 +
48219 + pax_open_kernel();
48220 + *(const char **)&dev_attr->attr.name = name;
48221 + pax_close_kernel();
48222
48223 return 0;
48224 }
48225 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48226
48227 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48228 ret = create_constraint_attribute(i, "power_limit_uw",
48229 - S_IWUSR | S_IRUGO,
48230 - &constraint_attrs[i].power_limit_attr,
48231 - show_constraint_power_limit_uw,
48232 - store_constraint_power_limit_uw);
48233 + &constraint_attrs[i].power_limit_attr);
48234 if (ret)
48235 goto err_alloc;
48236 ret = create_constraint_attribute(i, "time_window_us",
48237 - S_IWUSR | S_IRUGO,
48238 - &constraint_attrs[i].time_window_attr,
48239 - show_constraint_time_window_us,
48240 - store_constraint_time_window_us);
48241 + &constraint_attrs[i].time_window_attr);
48242 if (ret)
48243 goto err_alloc;
48244 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48245 - &constraint_attrs[i].name_attr,
48246 - show_constraint_name,
48247 - NULL);
48248 + ret = create_constraint_attribute(i, "name",
48249 + &constraint_attrs[i].name_attr);
48250 if (ret)
48251 goto err_alloc;
48252 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48253 - &constraint_attrs[i].max_power_attr,
48254 - show_constraint_max_power_uw,
48255 - NULL);
48256 + ret = create_constraint_attribute(i, "max_power_uw",
48257 + &constraint_attrs[i].max_power_attr);
48258 if (ret)
48259 goto err_alloc;
48260 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48261 - &constraint_attrs[i].min_power_attr,
48262 - show_constraint_min_power_uw,
48263 - NULL);
48264 + ret = create_constraint_attribute(i, "min_power_uw",
48265 + &constraint_attrs[i].min_power_attr);
48266 if (ret)
48267 goto err_alloc;
48268 ret = create_constraint_attribute(i, "max_time_window_us",
48269 - S_IRUGO,
48270 - &constraint_attrs[i].max_time_window_attr,
48271 - show_constraint_max_time_window_us,
48272 - NULL);
48273 + &constraint_attrs[i].max_time_window_attr);
48274 if (ret)
48275 goto err_alloc;
48276 ret = create_constraint_attribute(i, "min_time_window_us",
48277 - S_IRUGO,
48278 - &constraint_attrs[i].min_time_window_attr,
48279 - show_constraint_min_time_window_us,
48280 - NULL);
48281 + &constraint_attrs[i].min_time_window_attr);
48282 if (ret)
48283 goto err_alloc;
48284
48285 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48286 power_zone->zone_dev_attrs[count++] =
48287 &dev_attr_max_energy_range_uj.attr;
48288 if (power_zone->ops->get_energy_uj) {
48289 + pax_open_kernel();
48290 if (power_zone->ops->reset_energy_uj)
48291 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48292 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48293 else
48294 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48295 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48296 + pax_close_kernel();
48297 power_zone->zone_dev_attrs[count++] =
48298 &dev_attr_energy_uj.attr;
48299 }
48300 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48301 index 9c5d414..c7900ce 100644
48302 --- a/drivers/ptp/ptp_private.h
48303 +++ b/drivers/ptp/ptp_private.h
48304 @@ -51,7 +51,7 @@ struct ptp_clock {
48305 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48306 wait_queue_head_t tsev_wq;
48307 int defunct; /* tells readers to go away when clock is being removed */
48308 - struct device_attribute *pin_dev_attr;
48309 + device_attribute_no_const *pin_dev_attr;
48310 struct attribute **pin_attr;
48311 struct attribute_group pin_attr_group;
48312 };
48313 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48314 index 302e626..12579af 100644
48315 --- a/drivers/ptp/ptp_sysfs.c
48316 +++ b/drivers/ptp/ptp_sysfs.c
48317 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48318 goto no_pin_attr;
48319
48320 for (i = 0; i < n_pins; i++) {
48321 - struct device_attribute *da = &ptp->pin_dev_attr[i];
48322 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48323 sysfs_attr_init(&da->attr);
48324 da->attr.name = info->pin_config[i].name;
48325 da->attr.mode = 0644;
48326 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48327 index 9a09f3c..450b523 100644
48328 --- a/drivers/regulator/core.c
48329 +++ b/drivers/regulator/core.c
48330 @@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48331 {
48332 const struct regulation_constraints *constraints = NULL;
48333 const struct regulator_init_data *init_data;
48334 - static atomic_t regulator_no = ATOMIC_INIT(0);
48335 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48336 struct regulator_dev *rdev;
48337 struct device *dev;
48338 int ret, i;
48339 @@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48340 rdev->dev.of_node = config->of_node;
48341 rdev->dev.parent = dev;
48342 dev_set_name(&rdev->dev, "regulator.%d",
48343 - atomic_inc_return(&regulator_no) - 1);
48344 + atomic_inc_return_unchecked(&regulator_no) - 1);
48345 ret = device_register(&rdev->dev);
48346 if (ret != 0) {
48347 put_device(&rdev->dev);
48348 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48349 index 2fc4111..6aa88ca 100644
48350 --- a/drivers/regulator/max8660.c
48351 +++ b/drivers/regulator/max8660.c
48352 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48353 max8660->shadow_regs[MAX8660_OVER1] = 5;
48354 } else {
48355 /* Otherwise devices can be toggled via software */
48356 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48357 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48358 + pax_open_kernel();
48359 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48360 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48361 + pax_close_kernel();
48362 }
48363
48364 /*
48365 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48366 index dbedf17..18ff6b7 100644
48367 --- a/drivers/regulator/max8973-regulator.c
48368 +++ b/drivers/regulator/max8973-regulator.c
48369 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48370 if (!pdata || !pdata->enable_ext_control) {
48371 max->desc.enable_reg = MAX8973_VOUT;
48372 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48373 - max->ops.enable = regulator_enable_regmap;
48374 - max->ops.disable = regulator_disable_regmap;
48375 - max->ops.is_enabled = regulator_is_enabled_regmap;
48376 + pax_open_kernel();
48377 + *(void **)&max->ops.enable = regulator_enable_regmap;
48378 + *(void **)&max->ops.disable = regulator_disable_regmap;
48379 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48380 + pax_close_kernel();
48381 }
48382
48383 if (pdata) {
48384 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48385 index f374fa5..26f0683 100644
48386 --- a/drivers/regulator/mc13892-regulator.c
48387 +++ b/drivers/regulator/mc13892-regulator.c
48388 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48389 }
48390 mc13xxx_unlock(mc13892);
48391
48392 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48393 + pax_open_kernel();
48394 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48395 = mc13892_vcam_set_mode;
48396 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48397 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48398 = mc13892_vcam_get_mode;
48399 + pax_close_kernel();
48400
48401 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48402 ARRAY_SIZE(mc13892_regulators));
48403 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48404 index 0963c93..ea29cce 100644
48405 --- a/drivers/rtc/rtc-cmos.c
48406 +++ b/drivers/rtc/rtc-cmos.c
48407 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48408 hpet_rtc_timer_init();
48409
48410 /* export at least the first block of NVRAM */
48411 - nvram.size = address_space - NVRAM_OFFSET;
48412 + pax_open_kernel();
48413 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48414 + pax_close_kernel();
48415 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48416 if (retval < 0) {
48417 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48418 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48419 index d049393..bb20be0 100644
48420 --- a/drivers/rtc/rtc-dev.c
48421 +++ b/drivers/rtc/rtc-dev.c
48422 @@ -16,6 +16,7 @@
48423 #include <linux/module.h>
48424 #include <linux/rtc.h>
48425 #include <linux/sched.h>
48426 +#include <linux/grsecurity.h>
48427 #include "rtc-core.h"
48428
48429 static dev_t rtc_devt;
48430 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48431 if (copy_from_user(&tm, uarg, sizeof(tm)))
48432 return -EFAULT;
48433
48434 + gr_log_timechange();
48435 +
48436 return rtc_set_time(rtc, &tm);
48437
48438 case RTC_PIE_ON:
48439 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48440 index f03d5ba..8325bf6 100644
48441 --- a/drivers/rtc/rtc-ds1307.c
48442 +++ b/drivers/rtc/rtc-ds1307.c
48443 @@ -107,7 +107,7 @@ struct ds1307 {
48444 u8 offset; /* register's offset */
48445 u8 regs[11];
48446 u16 nvram_offset;
48447 - struct bin_attribute *nvram;
48448 + bin_attribute_no_const *nvram;
48449 enum ds_type type;
48450 unsigned long flags;
48451 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48452 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48453 index 11880c1..b823aa4 100644
48454 --- a/drivers/rtc/rtc-m48t59.c
48455 +++ b/drivers/rtc/rtc-m48t59.c
48456 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48457 if (IS_ERR(m48t59->rtc))
48458 return PTR_ERR(m48t59->rtc);
48459
48460 - m48t59_nvram_attr.size = pdata->offset;
48461 + pax_open_kernel();
48462 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48463 + pax_close_kernel();
48464
48465 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48466 if (ret)
48467 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48468 index 14b5f8d..cc9bd26 100644
48469 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48470 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48471 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48472 for (bit = 0; bit < 8; bit++) {
48473
48474 if ((pci_status[i] & (0x1 << bit)) != 0) {
48475 - static const char *s;
48476 + const char *s;
48477
48478 s = pci_status_strings[bit];
48479 if (i == 7/*TARG*/ && bit == 3)
48480 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48481
48482 for (bit = 0; bit < 8; bit++) {
48483
48484 - if ((split_status[i] & (0x1 << bit)) != 0) {
48485 - static const char *s;
48486 -
48487 - s = split_status_strings[bit];
48488 - printk(s, ahd_name(ahd),
48489 + if ((split_status[i] & (0x1 << bit)) != 0)
48490 + printk(split_status_strings[bit], ahd_name(ahd),
48491 split_status_source[i]);
48492 - }
48493
48494 if (i > 1)
48495 continue;
48496
48497 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48498 - static const char *s;
48499 -
48500 - s = split_status_strings[bit];
48501 - printk(s, ahd_name(ahd), "SG");
48502 - }
48503 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48504 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48505 }
48506 }
48507 /*
48508 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48509 index e693af6..2e525b6 100644
48510 --- a/drivers/scsi/bfa/bfa_fcpim.h
48511 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48512 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48513
48514 struct bfa_itn_s {
48515 bfa_isr_func_t isr;
48516 -};
48517 +} __no_const;
48518
48519 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48520 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48521 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48522 index a3ab5cc..8143622 100644
48523 --- a/drivers/scsi/bfa/bfa_fcs.c
48524 +++ b/drivers/scsi/bfa/bfa_fcs.c
48525 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48526 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48527
48528 static struct bfa_fcs_mod_s fcs_modules[] = {
48529 - { bfa_fcs_port_attach, NULL, NULL },
48530 - { bfa_fcs_uf_attach, NULL, NULL },
48531 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48532 - bfa_fcs_fabric_modexit },
48533 + {
48534 + .attach = bfa_fcs_port_attach,
48535 + .modinit = NULL,
48536 + .modexit = NULL
48537 + },
48538 + {
48539 + .attach = bfa_fcs_uf_attach,
48540 + .modinit = NULL,
48541 + .modexit = NULL
48542 + },
48543 + {
48544 + .attach = bfa_fcs_fabric_attach,
48545 + .modinit = bfa_fcs_fabric_modinit,
48546 + .modexit = bfa_fcs_fabric_modexit
48547 + },
48548 };
48549
48550 /*
48551 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48552 index ff75ef8..2dfe00a 100644
48553 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48554 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48555 @@ -89,15 +89,26 @@ static struct {
48556 void (*offline) (struct bfa_fcs_lport_s *port);
48557 } __port_action[] = {
48558 {
48559 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48560 - bfa_fcs_lport_unknown_offline}, {
48561 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48562 - bfa_fcs_lport_fab_offline}, {
48563 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48564 - bfa_fcs_lport_n2n_offline}, {
48565 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48566 - bfa_fcs_lport_loop_offline},
48567 - };
48568 + .init = bfa_fcs_lport_unknown_init,
48569 + .online = bfa_fcs_lport_unknown_online,
48570 + .offline = bfa_fcs_lport_unknown_offline
48571 + },
48572 + {
48573 + .init = bfa_fcs_lport_fab_init,
48574 + .online = bfa_fcs_lport_fab_online,
48575 + .offline = bfa_fcs_lport_fab_offline
48576 + },
48577 + {
48578 + .init = bfa_fcs_lport_n2n_init,
48579 + .online = bfa_fcs_lport_n2n_online,
48580 + .offline = bfa_fcs_lport_n2n_offline
48581 + },
48582 + {
48583 + .init = bfa_fcs_lport_loop_init,
48584 + .online = bfa_fcs_lport_loop_online,
48585 + .offline = bfa_fcs_lport_loop_offline
48586 + },
48587 +};
48588
48589 /*
48590 * fcs_port_sm FCS logical port state machine
48591 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48592 index 2e28392..9d865b6 100644
48593 --- a/drivers/scsi/bfa/bfa_ioc.h
48594 +++ b/drivers/scsi/bfa/bfa_ioc.h
48595 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48596 bfa_ioc_disable_cbfn_t disable_cbfn;
48597 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48598 bfa_ioc_reset_cbfn_t reset_cbfn;
48599 -};
48600 +} __no_const;
48601
48602 /*
48603 * IOC event notification mechanism.
48604 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48605 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48606 enum bfi_ioc_state fwstate);
48607 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48608 -};
48609 +} __no_const;
48610
48611 /*
48612 * Queue element to wait for room in request queue. FIFO order is
48613 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48614 index a14c784..6de6790 100644
48615 --- a/drivers/scsi/bfa/bfa_modules.h
48616 +++ b/drivers/scsi/bfa/bfa_modules.h
48617 @@ -78,12 +78,12 @@ enum {
48618 \
48619 extern struct bfa_module_s hal_mod_ ## __mod; \
48620 struct bfa_module_s hal_mod_ ## __mod = { \
48621 - bfa_ ## __mod ## _meminfo, \
48622 - bfa_ ## __mod ## _attach, \
48623 - bfa_ ## __mod ## _detach, \
48624 - bfa_ ## __mod ## _start, \
48625 - bfa_ ## __mod ## _stop, \
48626 - bfa_ ## __mod ## _iocdisable, \
48627 + .meminfo = bfa_ ## __mod ## _meminfo, \
48628 + .attach = bfa_ ## __mod ## _attach, \
48629 + .detach = bfa_ ## __mod ## _detach, \
48630 + .start = bfa_ ## __mod ## _start, \
48631 + .stop = bfa_ ## __mod ## _stop, \
48632 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48633 }
48634
48635 #define BFA_CACHELINE_SZ (256)
48636 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48637 index 045c4e1..13de803 100644
48638 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48639 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48640 @@ -33,8 +33,8 @@
48641 */
48642 #include "libfcoe.h"
48643
48644 -static atomic_t ctlr_num;
48645 -static atomic_t fcf_num;
48646 +static atomic_unchecked_t ctlr_num;
48647 +static atomic_unchecked_t fcf_num;
48648
48649 /*
48650 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48651 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48652 if (!ctlr)
48653 goto out;
48654
48655 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48656 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48657 ctlr->f = f;
48658 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48659 INIT_LIST_HEAD(&ctlr->fcfs);
48660 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48661 fcf->dev.parent = &ctlr->dev;
48662 fcf->dev.bus = &fcoe_bus_type;
48663 fcf->dev.type = &fcoe_fcf_device_type;
48664 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48665 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48666 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48667
48668 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48669 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48670 {
48671 int error;
48672
48673 - atomic_set(&ctlr_num, 0);
48674 - atomic_set(&fcf_num, 0);
48675 + atomic_set_unchecked(&ctlr_num, 0);
48676 + atomic_set_unchecked(&fcf_num, 0);
48677
48678 error = bus_register(&fcoe_bus_type);
48679 if (error)
48680 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48681 index 3cbb57a..95e47a3 100644
48682 --- a/drivers/scsi/hosts.c
48683 +++ b/drivers/scsi/hosts.c
48684 @@ -42,7 +42,7 @@
48685 #include "scsi_logging.h"
48686
48687
48688 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48689 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48690
48691
48692 static void scsi_host_cls_release(struct device *dev)
48693 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48694 * subtract one because we increment first then return, but we need to
48695 * know what the next host number was before increment
48696 */
48697 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48698 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48699 shost->dma_channel = 0xff;
48700
48701 /* These three are default values which can be overridden */
48702 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48703 index 9a6e4a2..27843b6 100644
48704 --- a/drivers/scsi/hpsa.c
48705 +++ b/drivers/scsi/hpsa.c
48706 @@ -687,10 +687,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48707 unsigned long flags;
48708
48709 if (h->transMethod & CFGTBL_Trans_io_accel1)
48710 - return h->access.command_completed(h, q);
48711 + return h->access->command_completed(h, q);
48712
48713 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48714 - return h->access.command_completed(h, q);
48715 + return h->access->command_completed(h, q);
48716
48717 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48718 a = rq->head[rq->current_entry];
48719 @@ -5448,7 +5448,7 @@ static void start_io(struct ctlr_info *h)
48720 while (!list_empty(&h->reqQ)) {
48721 c = list_entry(h->reqQ.next, struct CommandList, list);
48722 /* can't do anything if fifo is full */
48723 - if ((h->access.fifo_full(h))) {
48724 + if ((h->access->fifo_full(h))) {
48725 h->fifo_recently_full = 1;
48726 dev_warn(&h->pdev->dev, "fifo full\n");
48727 break;
48728 @@ -5472,7 +5472,7 @@ static void start_io(struct ctlr_info *h)
48729
48730 /* Tell the controller execute command */
48731 spin_unlock_irqrestore(&h->lock, flags);
48732 - h->access.submit_command(h, c);
48733 + h->access->submit_command(h, c);
48734 spin_lock_irqsave(&h->lock, flags);
48735 }
48736 spin_unlock_irqrestore(&h->lock, flags);
48737 @@ -5480,17 +5480,17 @@ static void start_io(struct ctlr_info *h)
48738
48739 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48740 {
48741 - return h->access.command_completed(h, q);
48742 + return h->access->command_completed(h, q);
48743 }
48744
48745 static inline bool interrupt_pending(struct ctlr_info *h)
48746 {
48747 - return h->access.intr_pending(h);
48748 + return h->access->intr_pending(h);
48749 }
48750
48751 static inline long interrupt_not_for_us(struct ctlr_info *h)
48752 {
48753 - return (h->access.intr_pending(h) == 0) ||
48754 + return (h->access->intr_pending(h) == 0) ||
48755 (h->interrupts_enabled == 0);
48756 }
48757
48758 @@ -6444,7 +6444,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48759 if (prod_index < 0)
48760 return -ENODEV;
48761 h->product_name = products[prod_index].product_name;
48762 - h->access = *(products[prod_index].access);
48763 + h->access = products[prod_index].access;
48764
48765 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48766 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48767 @@ -6723,7 +6723,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48768 {
48769 unsigned long flags;
48770
48771 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48772 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48773 spin_lock_irqsave(&h->lock, flags);
48774 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48775 spin_unlock_irqrestore(&h->lock, flags);
48776 @@ -6951,7 +6951,7 @@ reinit_after_soft_reset:
48777 }
48778
48779 /* make sure the board interrupts are off */
48780 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48781 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48782
48783 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48784 goto clean2;
48785 @@ -6986,7 +6986,7 @@ reinit_after_soft_reset:
48786 * fake ones to scoop up any residual completions.
48787 */
48788 spin_lock_irqsave(&h->lock, flags);
48789 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48790 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48791 spin_unlock_irqrestore(&h->lock, flags);
48792 free_irqs(h);
48793 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48794 @@ -7005,9 +7005,9 @@ reinit_after_soft_reset:
48795 dev_info(&h->pdev->dev, "Board READY.\n");
48796 dev_info(&h->pdev->dev,
48797 "Waiting for stale completions to drain.\n");
48798 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48799 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48800 msleep(10000);
48801 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48802 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48803
48804 rc = controller_reset_failed(h->cfgtable);
48805 if (rc)
48806 @@ -7033,7 +7033,7 @@ reinit_after_soft_reset:
48807 h->drv_req_rescan = 0;
48808
48809 /* Turn the interrupts on so we can service requests */
48810 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48811 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48812
48813 hpsa_hba_inquiry(h);
48814 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48815 @@ -7102,7 +7102,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48816 * To write all data in the battery backed cache to disks
48817 */
48818 hpsa_flush_cache(h);
48819 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48820 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48821 hpsa_free_irqs_and_disable_msix(h);
48822 }
48823
48824 @@ -7220,7 +7220,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48825 CFGTBL_Trans_enable_directed_msix |
48826 (trans_support & (CFGTBL_Trans_io_accel1 |
48827 CFGTBL_Trans_io_accel2));
48828 - struct access_method access = SA5_performant_access;
48829 + struct access_method *access = &SA5_performant_access;
48830
48831 /* This is a bit complicated. There are 8 registers on
48832 * the controller which we write to to tell it 8 different
48833 @@ -7285,12 +7285,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48834 * enable outbound interrupt coalescing in accelerator mode;
48835 */
48836 if (trans_support & CFGTBL_Trans_io_accel1) {
48837 - access = SA5_ioaccel_mode1_access;
48838 + access = &SA5_ioaccel_mode1_access;
48839 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48840 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48841 } else {
48842 if (trans_support & CFGTBL_Trans_io_accel2) {
48843 - access = SA5_ioaccel_mode2_access;
48844 + access = &SA5_ioaccel_mode2_access;
48845 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48846 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48847 }
48848 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48849 index 44235a2..962e91b 100644
48850 --- a/drivers/scsi/hpsa.h
48851 +++ b/drivers/scsi/hpsa.h
48852 @@ -128,7 +128,7 @@ struct ctlr_info {
48853 unsigned int msix_vector;
48854 unsigned int msi_vector;
48855 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48856 - struct access_method access;
48857 + struct access_method *access;
48858 char hba_mode_enabled;
48859
48860 /* queue and queue Info */
48861 @@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
48862 }
48863
48864 static struct access_method SA5_access = {
48865 - SA5_submit_command,
48866 - SA5_intr_mask,
48867 - SA5_fifo_full,
48868 - SA5_intr_pending,
48869 - SA5_completed,
48870 + .submit_command = SA5_submit_command,
48871 + .set_intr_mask = SA5_intr_mask,
48872 + .fifo_full = SA5_fifo_full,
48873 + .intr_pending = SA5_intr_pending,
48874 + .command_completed = SA5_completed,
48875 };
48876
48877 static struct access_method SA5_ioaccel_mode1_access = {
48878 - SA5_submit_command,
48879 - SA5_performant_intr_mask,
48880 - SA5_fifo_full,
48881 - SA5_ioaccel_mode1_intr_pending,
48882 - SA5_ioaccel_mode1_completed,
48883 + .submit_command = SA5_submit_command,
48884 + .set_intr_mask = SA5_performant_intr_mask,
48885 + .fifo_full = SA5_fifo_full,
48886 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
48887 + .command_completed = SA5_ioaccel_mode1_completed,
48888 };
48889
48890 static struct access_method SA5_ioaccel_mode2_access = {
48891 - SA5_submit_command_ioaccel2,
48892 - SA5_performant_intr_mask,
48893 - SA5_fifo_full,
48894 - SA5_performant_intr_pending,
48895 - SA5_performant_completed,
48896 + .submit_command = SA5_submit_command_ioaccel2,
48897 + .set_intr_mask = SA5_performant_intr_mask,
48898 + .fifo_full = SA5_fifo_full,
48899 + .intr_pending = SA5_performant_intr_pending,
48900 + .command_completed = SA5_performant_completed,
48901 };
48902
48903 static struct access_method SA5_performant_access = {
48904 - SA5_submit_command,
48905 - SA5_performant_intr_mask,
48906 - SA5_fifo_full,
48907 - SA5_performant_intr_pending,
48908 - SA5_performant_completed,
48909 + .submit_command = SA5_submit_command,
48910 + .set_intr_mask = SA5_performant_intr_mask,
48911 + .fifo_full = SA5_fifo_full,
48912 + .intr_pending = SA5_performant_intr_pending,
48913 + .command_completed = SA5_performant_completed,
48914 };
48915
48916 struct board_type {
48917 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48918 index 1b3a094..068e683 100644
48919 --- a/drivers/scsi/libfc/fc_exch.c
48920 +++ b/drivers/scsi/libfc/fc_exch.c
48921 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48922 u16 pool_max_index;
48923
48924 struct {
48925 - atomic_t no_free_exch;
48926 - atomic_t no_free_exch_xid;
48927 - atomic_t xid_not_found;
48928 - atomic_t xid_busy;
48929 - atomic_t seq_not_found;
48930 - atomic_t non_bls_resp;
48931 + atomic_unchecked_t no_free_exch;
48932 + atomic_unchecked_t no_free_exch_xid;
48933 + atomic_unchecked_t xid_not_found;
48934 + atomic_unchecked_t xid_busy;
48935 + atomic_unchecked_t seq_not_found;
48936 + atomic_unchecked_t non_bls_resp;
48937 } stats;
48938 };
48939
48940 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48941 /* allocate memory for exchange */
48942 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48943 if (!ep) {
48944 - atomic_inc(&mp->stats.no_free_exch);
48945 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48946 goto out;
48947 }
48948 memset(ep, 0, sizeof(*ep));
48949 @@ -874,7 +874,7 @@ out:
48950 return ep;
48951 err:
48952 spin_unlock_bh(&pool->lock);
48953 - atomic_inc(&mp->stats.no_free_exch_xid);
48954 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48955 mempool_free(ep, mp->ep_pool);
48956 return NULL;
48957 }
48958 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48959 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48960 ep = fc_exch_find(mp, xid);
48961 if (!ep) {
48962 - atomic_inc(&mp->stats.xid_not_found);
48963 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48964 reject = FC_RJT_OX_ID;
48965 goto out;
48966 }
48967 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48968 ep = fc_exch_find(mp, xid);
48969 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48970 if (ep) {
48971 - atomic_inc(&mp->stats.xid_busy);
48972 + atomic_inc_unchecked(&mp->stats.xid_busy);
48973 reject = FC_RJT_RX_ID;
48974 goto rel;
48975 }
48976 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48977 }
48978 xid = ep->xid; /* get our XID */
48979 } else if (!ep) {
48980 - atomic_inc(&mp->stats.xid_not_found);
48981 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48982 reject = FC_RJT_RX_ID; /* XID not found */
48983 goto out;
48984 }
48985 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48986 } else {
48987 sp = &ep->seq;
48988 if (sp->id != fh->fh_seq_id) {
48989 - atomic_inc(&mp->stats.seq_not_found);
48990 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48991 if (f_ctl & FC_FC_END_SEQ) {
48992 /*
48993 * Update sequence_id based on incoming last
48994 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48995
48996 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48997 if (!ep) {
48998 - atomic_inc(&mp->stats.xid_not_found);
48999 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49000 goto out;
49001 }
49002 if (ep->esb_stat & ESB_ST_COMPLETE) {
49003 - atomic_inc(&mp->stats.xid_not_found);
49004 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49005 goto rel;
49006 }
49007 if (ep->rxid == FC_XID_UNKNOWN)
49008 ep->rxid = ntohs(fh->fh_rx_id);
49009 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49010 - atomic_inc(&mp->stats.xid_not_found);
49011 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49012 goto rel;
49013 }
49014 if (ep->did != ntoh24(fh->fh_s_id) &&
49015 ep->did != FC_FID_FLOGI) {
49016 - atomic_inc(&mp->stats.xid_not_found);
49017 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49018 goto rel;
49019 }
49020 sof = fr_sof(fp);
49021 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49022 sp->ssb_stat |= SSB_ST_RESP;
49023 sp->id = fh->fh_seq_id;
49024 } else if (sp->id != fh->fh_seq_id) {
49025 - atomic_inc(&mp->stats.seq_not_found);
49026 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49027 goto rel;
49028 }
49029
49030 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49031 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49032
49033 if (!sp)
49034 - atomic_inc(&mp->stats.xid_not_found);
49035 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49036 else
49037 - atomic_inc(&mp->stats.non_bls_resp);
49038 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49039
49040 fc_frame_free(fp);
49041 }
49042 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49043
49044 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49045 mp = ema->mp;
49046 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49047 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49048 st->fc_no_free_exch_xid +=
49049 - atomic_read(&mp->stats.no_free_exch_xid);
49050 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49051 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49052 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49053 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49054 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49055 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49056 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49057 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49058 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49059 }
49060 }
49061 EXPORT_SYMBOL(fc_exch_update_stats);
49062 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49063 index 766098a..1c6c971 100644
49064 --- a/drivers/scsi/libsas/sas_ata.c
49065 +++ b/drivers/scsi/libsas/sas_ata.c
49066 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49067 .postreset = ata_std_postreset,
49068 .error_handler = ata_std_error_handler,
49069 .post_internal_cmd = sas_ata_post_internal,
49070 - .qc_defer = ata_std_qc_defer,
49071 + .qc_defer = ata_std_qc_defer,
49072 .qc_prep = ata_noop_qc_prep,
49073 .qc_issue = sas_ata_qc_issue,
49074 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49075 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49076 index 94a3caf..a118dec 100644
49077 --- a/drivers/scsi/lpfc/lpfc.h
49078 +++ b/drivers/scsi/lpfc/lpfc.h
49079 @@ -430,7 +430,7 @@ struct lpfc_vport {
49080 struct dentry *debug_nodelist;
49081 struct dentry *vport_debugfs_root;
49082 struct lpfc_debugfs_trc *disc_trc;
49083 - atomic_t disc_trc_cnt;
49084 + atomic_unchecked_t disc_trc_cnt;
49085 #endif
49086 uint8_t stat_data_enabled;
49087 uint8_t stat_data_blocked;
49088 @@ -879,8 +879,8 @@ struct lpfc_hba {
49089 struct timer_list fabric_block_timer;
49090 unsigned long bit_flags;
49091 #define FABRIC_COMANDS_BLOCKED 0
49092 - atomic_t num_rsrc_err;
49093 - atomic_t num_cmd_success;
49094 + atomic_unchecked_t num_rsrc_err;
49095 + atomic_unchecked_t num_cmd_success;
49096 unsigned long last_rsrc_error_time;
49097 unsigned long last_ramp_down_time;
49098 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49099 @@ -915,7 +915,7 @@ struct lpfc_hba {
49100
49101 struct dentry *debug_slow_ring_trc;
49102 struct lpfc_debugfs_trc *slow_ring_trc;
49103 - atomic_t slow_ring_trc_cnt;
49104 + atomic_unchecked_t slow_ring_trc_cnt;
49105 /* iDiag debugfs sub-directory */
49106 struct dentry *idiag_root;
49107 struct dentry *idiag_pci_cfg;
49108 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49109 index 828c08e..e3378e0 100644
49110 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49111 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49112 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49113
49114 #include <linux/debugfs.h>
49115
49116 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49117 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49118 static unsigned long lpfc_debugfs_start_time = 0L;
49119
49120 /* iDiag */
49121 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49122 lpfc_debugfs_enable = 0;
49123
49124 len = 0;
49125 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49126 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49127 (lpfc_debugfs_max_disc_trc - 1);
49128 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49129 dtp = vport->disc_trc + i;
49130 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49131 lpfc_debugfs_enable = 0;
49132
49133 len = 0;
49134 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49135 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49136 (lpfc_debugfs_max_slow_ring_trc - 1);
49137 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49138 dtp = phba->slow_ring_trc + i;
49139 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49140 !vport || !vport->disc_trc)
49141 return;
49142
49143 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49144 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49145 (lpfc_debugfs_max_disc_trc - 1);
49146 dtp = vport->disc_trc + index;
49147 dtp->fmt = fmt;
49148 dtp->data1 = data1;
49149 dtp->data2 = data2;
49150 dtp->data3 = data3;
49151 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49152 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49153 dtp->jif = jiffies;
49154 #endif
49155 return;
49156 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49157 !phba || !phba->slow_ring_trc)
49158 return;
49159
49160 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49161 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49162 (lpfc_debugfs_max_slow_ring_trc - 1);
49163 dtp = phba->slow_ring_trc + index;
49164 dtp->fmt = fmt;
49165 dtp->data1 = data1;
49166 dtp->data2 = data2;
49167 dtp->data3 = data3;
49168 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49169 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49170 dtp->jif = jiffies;
49171 #endif
49172 return;
49173 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49174 "slow_ring buffer\n");
49175 goto debug_failed;
49176 }
49177 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49178 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49179 memset(phba->slow_ring_trc, 0,
49180 (sizeof(struct lpfc_debugfs_trc) *
49181 lpfc_debugfs_max_slow_ring_trc));
49182 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49183 "buffer\n");
49184 goto debug_failed;
49185 }
49186 - atomic_set(&vport->disc_trc_cnt, 0);
49187 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49188
49189 snprintf(name, sizeof(name), "discovery_trace");
49190 vport->debug_disc_trc =
49191 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49192 index 635eeb3..038aef6 100644
49193 --- a/drivers/scsi/lpfc/lpfc_init.c
49194 +++ b/drivers/scsi/lpfc/lpfc_init.c
49195 @@ -11194,8 +11194,10 @@ lpfc_init(void)
49196 "misc_register returned with status %d", error);
49197
49198 if (lpfc_enable_npiv) {
49199 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49200 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49201 + pax_open_kernel();
49202 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49203 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49204 + pax_close_kernel();
49205 }
49206 lpfc_transport_template =
49207 fc_attach_transport(&lpfc_transport_functions);
49208 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49209 index 462453e..c0023a6 100644
49210 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49211 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49212 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49213 uint32_t evt_posted;
49214
49215 spin_lock_irqsave(&phba->hbalock, flags);
49216 - atomic_inc(&phba->num_rsrc_err);
49217 + atomic_inc_unchecked(&phba->num_rsrc_err);
49218 phba->last_rsrc_error_time = jiffies;
49219
49220 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49221 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49222 unsigned long num_rsrc_err, num_cmd_success;
49223 int i;
49224
49225 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49226 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49227 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49228 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49229
49230 /*
49231 * The error and success command counters are global per
49232 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49233 }
49234 }
49235 lpfc_destroy_vport_work_array(phba, vports);
49236 - atomic_set(&phba->num_rsrc_err, 0);
49237 - atomic_set(&phba->num_cmd_success, 0);
49238 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49239 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49240 }
49241
49242 /**
49243 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49244 index 6fd7d40..b444223 100644
49245 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49246 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49247 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49248 {
49249 struct scsi_device *sdev = to_scsi_device(dev);
49250 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49251 - static struct _raid_device *raid_device;
49252 + struct _raid_device *raid_device;
49253 unsigned long flags;
49254 Mpi2RaidVolPage0_t vol_pg0;
49255 Mpi2ConfigReply_t mpi_reply;
49256 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49257 {
49258 struct scsi_device *sdev = to_scsi_device(dev);
49259 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49260 - static struct _raid_device *raid_device;
49261 + struct _raid_device *raid_device;
49262 unsigned long flags;
49263 Mpi2RaidVolPage0_t vol_pg0;
49264 Mpi2ConfigReply_t mpi_reply;
49265 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49266 struct fw_event_work *fw_event)
49267 {
49268 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49269 - static struct _raid_device *raid_device;
49270 + struct _raid_device *raid_device;
49271 unsigned long flags;
49272 u16 handle;
49273
49274 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49275 u64 sas_address;
49276 struct _sas_device *sas_device;
49277 struct _sas_node *expander_device;
49278 - static struct _raid_device *raid_device;
49279 + struct _raid_device *raid_device;
49280 u8 retry_count;
49281 unsigned long flags;
49282
49283 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49284 index be8ce54..94ed33a 100644
49285 --- a/drivers/scsi/pmcraid.c
49286 +++ b/drivers/scsi/pmcraid.c
49287 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49288 res->scsi_dev = scsi_dev;
49289 scsi_dev->hostdata = res;
49290 res->change_detected = 0;
49291 - atomic_set(&res->read_failures, 0);
49292 - atomic_set(&res->write_failures, 0);
49293 + atomic_set_unchecked(&res->read_failures, 0);
49294 + atomic_set_unchecked(&res->write_failures, 0);
49295 rc = 0;
49296 }
49297 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49298 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49299
49300 /* If this was a SCSI read/write command keep count of errors */
49301 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49302 - atomic_inc(&res->read_failures);
49303 + atomic_inc_unchecked(&res->read_failures);
49304 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49305 - atomic_inc(&res->write_failures);
49306 + atomic_inc_unchecked(&res->write_failures);
49307
49308 if (!RES_IS_GSCSI(res->cfg_entry) &&
49309 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49310 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49311 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49312 * hrrq_id assigned here in queuecommand
49313 */
49314 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49315 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49316 pinstance->num_hrrq;
49317 cmd->cmd_done = pmcraid_io_done;
49318
49319 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49320 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49321 * hrrq_id assigned here in queuecommand
49322 */
49323 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49324 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49325 pinstance->num_hrrq;
49326
49327 if (request_size) {
49328 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49329
49330 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49331 /* add resources only after host is added into system */
49332 - if (!atomic_read(&pinstance->expose_resources))
49333 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49334 return;
49335
49336 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49337 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49338 init_waitqueue_head(&pinstance->reset_wait_q);
49339
49340 atomic_set(&pinstance->outstanding_cmds, 0);
49341 - atomic_set(&pinstance->last_message_id, 0);
49342 - atomic_set(&pinstance->expose_resources, 0);
49343 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49344 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49345
49346 INIT_LIST_HEAD(&pinstance->free_res_q);
49347 INIT_LIST_HEAD(&pinstance->used_res_q);
49348 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49349 /* Schedule worker thread to handle CCN and take care of adding and
49350 * removing devices to OS
49351 */
49352 - atomic_set(&pinstance->expose_resources, 1);
49353 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49354 schedule_work(&pinstance->worker_q);
49355 return rc;
49356
49357 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49358 index e1d150f..6c6df44 100644
49359 --- a/drivers/scsi/pmcraid.h
49360 +++ b/drivers/scsi/pmcraid.h
49361 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49362 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49363
49364 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49365 - atomic_t last_message_id;
49366 + atomic_unchecked_t last_message_id;
49367
49368 /* configuration table */
49369 struct pmcraid_config_table *cfg_table;
49370 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49371 atomic_t outstanding_cmds;
49372
49373 /* should add/delete resources to mid-layer now ?*/
49374 - atomic_t expose_resources;
49375 + atomic_unchecked_t expose_resources;
49376
49377
49378
49379 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49380 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49381 };
49382 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49383 - atomic_t read_failures; /* count of failed READ commands */
49384 - atomic_t write_failures; /* count of failed WRITE commands */
49385 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49386 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49387
49388 /* To indicate add/delete/modify during CCN */
49389 u8 change_detected;
49390 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49391 index 07befcf..c0bff13 100644
49392 --- a/drivers/scsi/qla2xxx/qla_attr.c
49393 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49394 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49395 return 0;
49396 }
49397
49398 -struct fc_function_template qla2xxx_transport_functions = {
49399 +fc_function_template_no_const qla2xxx_transport_functions = {
49400
49401 .show_host_node_name = 1,
49402 .show_host_port_name = 1,
49403 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49404 .bsg_timeout = qla24xx_bsg_timeout,
49405 };
49406
49407 -struct fc_function_template qla2xxx_transport_vport_functions = {
49408 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49409
49410 .show_host_node_name = 1,
49411 .show_host_port_name = 1,
49412 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49413 index e665e81..16e84e6 100644
49414 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49415 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49416 @@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49417 struct device_attribute;
49418 extern struct device_attribute *qla2x00_host_attrs[];
49419 struct fc_function_template;
49420 -extern struct fc_function_template qla2xxx_transport_functions;
49421 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49422 +extern fc_function_template_no_const qla2xxx_transport_functions;
49423 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49424 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49425 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49426 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49427 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49428 index 19e99cc..b3c0b7b 100644
49429 --- a/drivers/scsi/qla2xxx/qla_os.c
49430 +++ b/drivers/scsi/qla2xxx/qla_os.c
49431 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49432 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49433 /* Ok, a 64bit DMA mask is applicable. */
49434 ha->flags.enable_64bit_addressing = 1;
49435 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49436 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49437 + pax_open_kernel();
49438 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49439 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49440 + pax_close_kernel();
49441 return;
49442 }
49443 }
49444 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49445 index 73a5022..4e0797c 100644
49446 --- a/drivers/scsi/qla4xxx/ql4_def.h
49447 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49448 @@ -305,7 +305,7 @@ struct ddb_entry {
49449 * (4000 only) */
49450 atomic_t relogin_timer; /* Max Time to wait for
49451 * relogin to complete */
49452 - atomic_t relogin_retry_count; /* Num of times relogin has been
49453 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49454 * retried */
49455 uint32_t default_time2wait; /* Default Min time between
49456 * relogins (+aens) */
49457 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49458 index 459b9f7..2930a68 100644
49459 --- a/drivers/scsi/qla4xxx/ql4_os.c
49460 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49461 @@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49462 */
49463 if (!iscsi_is_session_online(cls_sess)) {
49464 /* Reset retry relogin timer */
49465 - atomic_inc(&ddb_entry->relogin_retry_count);
49466 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49467 DEBUG2(ql4_printk(KERN_INFO, ha,
49468 "%s: index[%d] relogin timed out-retrying"
49469 " relogin (%d), retry (%d)\n", __func__,
49470 ddb_entry->fw_ddb_index,
49471 - atomic_read(&ddb_entry->relogin_retry_count),
49472 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49473 ddb_entry->default_time2wait + 4));
49474 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49475 atomic_set(&ddb_entry->retry_relogin_timer,
49476 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49477
49478 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49479 atomic_set(&ddb_entry->relogin_timer, 0);
49480 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49481 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49482 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49483 ddb_entry->default_relogin_timeout =
49484 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49485 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49486 index 88d46fe..7351be5 100644
49487 --- a/drivers/scsi/scsi.c
49488 +++ b/drivers/scsi/scsi.c
49489 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49490 struct Scsi_Host *host = cmd->device->host;
49491 int rtn = 0;
49492
49493 - atomic_inc(&cmd->device->iorequest_cnt);
49494 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49495
49496 /* check if the device is still usable */
49497 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49498 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49499 index 9db097a..ca5c291 100644
49500 --- a/drivers/scsi/scsi_lib.c
49501 +++ b/drivers/scsi/scsi_lib.c
49502 @@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49503 shost = sdev->host;
49504 scsi_init_cmd_errh(cmd);
49505 cmd->result = DID_NO_CONNECT << 16;
49506 - atomic_inc(&cmd->device->iorequest_cnt);
49507 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49508
49509 /*
49510 * SCSI request completion path will do scsi_device_unbusy(),
49511 @@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49512
49513 INIT_LIST_HEAD(&cmd->eh_entry);
49514
49515 - atomic_inc(&cmd->device->iodone_cnt);
49516 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49517 if (cmd->result)
49518 - atomic_inc(&cmd->device->ioerr_cnt);
49519 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49520
49521 disposition = scsi_decide_disposition(cmd);
49522 if (disposition != SUCCESS &&
49523 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49524 index 074e8cc..f612e5c 100644
49525 --- a/drivers/scsi/scsi_sysfs.c
49526 +++ b/drivers/scsi/scsi_sysfs.c
49527 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49528 char *buf) \
49529 { \
49530 struct scsi_device *sdev = to_scsi_device(dev); \
49531 - unsigned long long count = atomic_read(&sdev->field); \
49532 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49533 return snprintf(buf, 20, "0x%llx\n", count); \
49534 } \
49535 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49536 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49537 index e51add0..1e06a96 100644
49538 --- a/drivers/scsi/scsi_tgt_lib.c
49539 +++ b/drivers/scsi/scsi_tgt_lib.c
49540 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49541 int err;
49542
49543 dprintk("%lx %u\n", uaddr, len);
49544 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49545 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49546 if (err) {
49547 /*
49548 * TODO: need to fixup sg_tablesize, max_segment_size,
49549 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49550 index f80908f..22aba76 100644
49551 --- a/drivers/scsi/scsi_transport_fc.c
49552 +++ b/drivers/scsi/scsi_transport_fc.c
49553 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49554 * Netlink Infrastructure
49555 */
49556
49557 -static atomic_t fc_event_seq;
49558 +static atomic_unchecked_t fc_event_seq;
49559
49560 /**
49561 * fc_get_event_number - Obtain the next sequential FC event number
49562 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49563 u32
49564 fc_get_event_number(void)
49565 {
49566 - return atomic_add_return(1, &fc_event_seq);
49567 + return atomic_add_return_unchecked(1, &fc_event_seq);
49568 }
49569 EXPORT_SYMBOL(fc_get_event_number);
49570
49571 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49572 {
49573 int error;
49574
49575 - atomic_set(&fc_event_seq, 0);
49576 + atomic_set_unchecked(&fc_event_seq, 0);
49577
49578 error = transport_class_register(&fc_host_class);
49579 if (error)
49580 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49581 char *cp;
49582
49583 *val = simple_strtoul(buf, &cp, 0);
49584 - if ((*cp && (*cp != '\n')) || (*val < 0))
49585 + if (*cp && (*cp != '\n'))
49586 return -EINVAL;
49587 /*
49588 * Check for overflow; dev_loss_tmo is u32
49589 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49590 index 0102a2d..cc3f8e9 100644
49591 --- a/drivers/scsi/scsi_transport_iscsi.c
49592 +++ b/drivers/scsi/scsi_transport_iscsi.c
49593 @@ -79,7 +79,7 @@ struct iscsi_internal {
49594 struct transport_container session_cont;
49595 };
49596
49597 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49598 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49599 static struct workqueue_struct *iscsi_eh_timer_workq;
49600
49601 static DEFINE_IDA(iscsi_sess_ida);
49602 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49603 int err;
49604
49605 ihost = shost->shost_data;
49606 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49607 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49608
49609 if (target_id == ISCSI_MAX_TARGET) {
49610 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49611 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49612 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49613 ISCSI_TRANSPORT_VERSION);
49614
49615 - atomic_set(&iscsi_session_nr, 0);
49616 + atomic_set_unchecked(&iscsi_session_nr, 0);
49617
49618 err = class_register(&iscsi_transport_class);
49619 if (err)
49620 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49621 index 13e8983..d306a68 100644
49622 --- a/drivers/scsi/scsi_transport_srp.c
49623 +++ b/drivers/scsi/scsi_transport_srp.c
49624 @@ -36,7 +36,7 @@
49625 #include "scsi_transport_srp_internal.h"
49626
49627 struct srp_host_attrs {
49628 - atomic_t next_port_id;
49629 + atomic_unchecked_t next_port_id;
49630 };
49631 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49632
49633 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49634 struct Scsi_Host *shost = dev_to_shost(dev);
49635 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49636
49637 - atomic_set(&srp_host->next_port_id, 0);
49638 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49639 return 0;
49640 }
49641
49642 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49643 rport_fast_io_fail_timedout);
49644 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49645
49646 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49647 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49648 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49649
49650 transport_setup_device(&rport->dev);
49651 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49652 index efcbcd1..aeaf26e 100644
49653 --- a/drivers/scsi/sd.c
49654 +++ b/drivers/scsi/sd.c
49655 @@ -2968,7 +2968,7 @@ static int sd_probe(struct device *dev)
49656 sdkp->disk = gd;
49657 sdkp->index = index;
49658 atomic_set(&sdkp->openers, 0);
49659 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49660 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49661
49662 if (!sdp->request_queue->rq_timeout) {
49663 if (sdp->type != TYPE_MOD)
49664 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49665 index df5e961..df6b97f 100644
49666 --- a/drivers/scsi/sg.c
49667 +++ b/drivers/scsi/sg.c
49668 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49669 sdp->disk->disk_name,
49670 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49671 NULL,
49672 - (char *)arg);
49673 + (char __user *)arg);
49674 case BLKTRACESTART:
49675 return blk_trace_startstop(sdp->device->request_queue, 1);
49676 case BLKTRACESTOP:
49677 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49678 index 939edf4..3f50423 100644
49679 --- a/drivers/spi/spi.c
49680 +++ b/drivers/spi/spi.c
49681 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
49682 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49683
49684 /* portable code must never pass more than 32 bytes */
49685 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49686 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49687
49688 static u8 *buf;
49689
49690 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49691 index 2c61783..4d49e4e 100644
49692 --- a/drivers/staging/android/timed_output.c
49693 +++ b/drivers/staging/android/timed_output.c
49694 @@ -25,7 +25,7 @@
49695 #include "timed_output.h"
49696
49697 static struct class *timed_output_class;
49698 -static atomic_t device_count;
49699 +static atomic_unchecked_t device_count;
49700
49701 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49702 char *buf)
49703 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49704 timed_output_class = class_create(THIS_MODULE, "timed_output");
49705 if (IS_ERR(timed_output_class))
49706 return PTR_ERR(timed_output_class);
49707 - atomic_set(&device_count, 0);
49708 + atomic_set_unchecked(&device_count, 0);
49709 timed_output_class->dev_groups = timed_output_groups;
49710 }
49711
49712 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49713 if (ret < 0)
49714 return ret;
49715
49716 - tdev->index = atomic_inc_return(&device_count);
49717 + tdev->index = atomic_inc_return_unchecked(&device_count);
49718 tdev->dev = device_create(timed_output_class, NULL,
49719 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49720 if (IS_ERR(tdev->dev))
49721 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49722 index fe47cd3..19a1bd1 100644
49723 --- a/drivers/staging/gdm724x/gdm_tty.c
49724 +++ b/drivers/staging/gdm724x/gdm_tty.c
49725 @@ -44,7 +44,7 @@
49726 #define gdm_tty_send_control(n, r, v, d, l) (\
49727 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49728
49729 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49730 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49731
49732 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49733 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49734 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49735 index c270c9a..94ddf82 100644
49736 --- a/drivers/staging/imx-drm/imx-drm-core.c
49737 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49738 @@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
49739 if (imxdrm->pipes >= MAX_CRTC)
49740 return -EINVAL;
49741
49742 - if (imxdrm->drm->open_count)
49743 + if (local_read(&imxdrm->drm->open_count))
49744 return -EBUSY;
49745
49746 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
49747 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49748 index 3f8020c..649fded 100644
49749 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49750 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49751 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49752 return 0;
49753 }
49754
49755 -sfw_test_client_ops_t brw_test_client;
49756 -void brw_init_test_client(void)
49757 -{
49758 - brw_test_client.tso_init = brw_client_init;
49759 - brw_test_client.tso_fini = brw_client_fini;
49760 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49761 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49762 +sfw_test_client_ops_t brw_test_client = {
49763 + .tso_init = brw_client_init,
49764 + .tso_fini = brw_client_fini,
49765 + .tso_prep_rpc = brw_client_prep_rpc,
49766 + .tso_done_rpc = brw_client_done_rpc,
49767 };
49768
49769 srpc_service_t brw_test_service;
49770 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49771 index 050723a..fa6fdf1 100644
49772 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49773 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49774 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49775
49776 extern sfw_test_client_ops_t ping_test_client;
49777 extern srpc_service_t ping_test_service;
49778 -extern void ping_init_test_client(void);
49779 extern void ping_init_test_service(void);
49780
49781 extern sfw_test_client_ops_t brw_test_client;
49782 extern srpc_service_t brw_test_service;
49783 -extern void brw_init_test_client(void);
49784 extern void brw_init_test_service(void);
49785
49786
49787 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49788 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49789 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49790
49791 - brw_init_test_client();
49792 brw_init_test_service();
49793 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49794 LASSERT (rc == 0);
49795
49796 - ping_init_test_client();
49797 ping_init_test_service();
49798 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49799 LASSERT (rc == 0);
49800 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49801 index 750cac4..e4d751f 100644
49802 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49803 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49804 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49805 return 0;
49806 }
49807
49808 -sfw_test_client_ops_t ping_test_client;
49809 -void ping_init_test_client(void)
49810 -{
49811 - ping_test_client.tso_init = ping_client_init;
49812 - ping_test_client.tso_fini = ping_client_fini;
49813 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49814 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49815 -}
49816 +sfw_test_client_ops_t ping_test_client = {
49817 + .tso_init = ping_client_init,
49818 + .tso_fini = ping_client_fini,
49819 + .tso_prep_rpc = ping_client_prep_rpc,
49820 + .tso_done_rpc = ping_client_done_rpc,
49821 +};
49822
49823 srpc_service_t ping_test_service;
49824 void ping_init_test_service(void)
49825 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49826 index 3e25f00..0d59cf5 100644
49827 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49828 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49829 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49830 ldlm_completion_callback lcs_completion;
49831 ldlm_blocking_callback lcs_blocking;
49832 ldlm_glimpse_callback lcs_glimpse;
49833 -};
49834 +} __no_const;
49835
49836 /* ldlm_lockd.c */
49837 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49838 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49839 index 72cf3fe..4beac19 100644
49840 --- a/drivers/staging/lustre/lustre/include/obd.h
49841 +++ b/drivers/staging/lustre/lustre/include/obd.h
49842 @@ -1427,7 +1427,7 @@ struct md_ops {
49843 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49844 * wrapper function in include/linux/obd_class.h.
49845 */
49846 -};
49847 +} __no_const;
49848
49849 struct lsm_operations {
49850 void (*lsm_free)(struct lov_stripe_md *);
49851 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49852 index 986bf38..eab2558f 100644
49853 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49854 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49855 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49856 int added = (mode == LCK_NL);
49857 int overlaps = 0;
49858 int splitted = 0;
49859 - const struct ldlm_callback_suite null_cbs = { NULL };
49860 + const struct ldlm_callback_suite null_cbs = { };
49861
49862 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49863 LPU64" end "LPU64"\n", *flags,
49864 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49865 index e947b91..f408990 100644
49866 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49867 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49868 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49869 int LL_PROC_PROTO(proc_console_max_delay_cs)
49870 {
49871 int rc, max_delay_cs;
49872 - ctl_table_t dummy = *table;
49873 + ctl_table_no_const dummy = *table;
49874 cfs_duration_t d;
49875
49876 dummy.data = &max_delay_cs;
49877 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49878 int LL_PROC_PROTO(proc_console_min_delay_cs)
49879 {
49880 int rc, min_delay_cs;
49881 - ctl_table_t dummy = *table;
49882 + ctl_table_no_const dummy = *table;
49883 cfs_duration_t d;
49884
49885 dummy.data = &min_delay_cs;
49886 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49887 int LL_PROC_PROTO(proc_console_backoff)
49888 {
49889 int rc, backoff;
49890 - ctl_table_t dummy = *table;
49891 + ctl_table_no_const dummy = *table;
49892
49893 dummy.data = &backoff;
49894 dummy.proc_handler = &proc_dointvec;
49895 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49896 index 24ae26d..9d09cab 100644
49897 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49898 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49899 @@ -313,11 +313,11 @@ out:
49900
49901
49902 struct cfs_psdev_ops libcfs_psdev_ops = {
49903 - libcfs_psdev_open,
49904 - libcfs_psdev_release,
49905 - NULL,
49906 - NULL,
49907 - libcfs_ioctl
49908 + .p_open = libcfs_psdev_open,
49909 + .p_close = libcfs_psdev_release,
49910 + .p_read = NULL,
49911 + .p_write = NULL,
49912 + .p_ioctl = libcfs_ioctl
49913 };
49914
49915 extern int insert_proc(void);
49916 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49917 index 7fbc18e..f982071 100644
49918 --- a/drivers/staging/lustre/lustre/llite/dir.c
49919 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49920 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49921 int mode;
49922 int err;
49923
49924 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49925 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49926 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49927 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49928 lump);
49929 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49930 index f670469..03b7438 100644
49931 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49932 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49933 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49934
49935 static int solo_sysfs_init(struct solo_dev *solo_dev)
49936 {
49937 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49938 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49939 struct device *dev = &solo_dev->dev;
49940 const char *driver;
49941 int i;
49942 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49943 index 74f037b..5b5bb76 100644
49944 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49945 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49946 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49947
49948 int solo_g723_init(struct solo_dev *solo_dev)
49949 {
49950 - static struct snd_device_ops ops = { NULL };
49951 + static struct snd_device_ops ops = { };
49952 struct snd_card *card;
49953 struct snd_kcontrol_new kctl;
49954 char name[32];
49955 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49956 index 7f2f247..d999137 100644
49957 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49958 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49959 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49960
49961 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49962 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49963 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49964 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49965 if (p2m_id < 0)
49966 p2m_id = -p2m_id;
49967 }
49968 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49969 index 8964f8b..36eb087 100644
49970 --- a/drivers/staging/media/solo6x10/solo6x10.h
49971 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49972 @@ -237,7 +237,7 @@ struct solo_dev {
49973
49974 /* P2M DMA Engine */
49975 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49976 - atomic_t p2m_count;
49977 + atomic_unchecked_t p2m_count;
49978 int p2m_jiffies;
49979 unsigned int p2m_timeouts;
49980
49981 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49982 index a0f4868..139f1fb 100644
49983 --- a/drivers/staging/octeon/ethernet-rx.c
49984 +++ b/drivers/staging/octeon/ethernet-rx.c
49985 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49986 /* Increment RX stats for virtual ports */
49987 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49988 #ifdef CONFIG_64BIT
49989 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49990 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49991 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49992 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49993 #else
49994 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49995 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49996 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49997 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49998 #endif
49999 }
50000 netif_receive_skb(skb);
50001 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50002 dev->name);
50003 */
50004 #ifdef CONFIG_64BIT
50005 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50006 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50007 #else
50008 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50009 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50010 #endif
50011 dev_kfree_skb_irq(skb);
50012 }
50013 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50014 index ff7214a..6dd90f0 100644
50015 --- a/drivers/staging/octeon/ethernet.c
50016 +++ b/drivers/staging/octeon/ethernet.c
50017 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50018 * since the RX tasklet also increments it.
50019 */
50020 #ifdef CONFIG_64BIT
50021 - atomic64_add(rx_status.dropped_packets,
50022 - (atomic64_t *)&priv->stats.rx_dropped);
50023 + atomic64_add_unchecked(rx_status.dropped_packets,
50024 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50025 #else
50026 - atomic_add(rx_status.dropped_packets,
50027 - (atomic_t *)&priv->stats.rx_dropped);
50028 + atomic_add_unchecked(rx_status.dropped_packets,
50029 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50030 #endif
50031 }
50032
50033 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50034 index c274b34..f84de76 100644
50035 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50036 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50037 @@ -271,7 +271,7 @@ struct hal_ops {
50038 s32 (*c2h_handler)(struct adapter *padapter,
50039 struct c2h_evt_hdr *c2h_evt);
50040 c2h_id_filter c2h_id_filter_ccx;
50041 -};
50042 +} __no_const;
50043
50044 enum rt_eeprom_type {
50045 EEPROM_93C46,
50046 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50047 index e8790f8..b4a5980 100644
50048 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50049 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50050 @@ -124,7 +124,7 @@ struct _io_ops {
50051 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50052 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50053 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50054 -};
50055 +} __no_const;
50056
50057 struct io_req {
50058 struct list_head list;
50059 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50060 index dc23395..cf7e9b1 100644
50061 --- a/drivers/staging/rtl8712/rtl871x_io.h
50062 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50063 @@ -108,7 +108,7 @@ struct _io_ops {
50064 u8 *pmem);
50065 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50066 u8 *pmem);
50067 -};
50068 +} __no_const;
50069
50070 struct io_req {
50071 struct list_head list;
50072 diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50073 index d183f4b..3f4903d 100644
50074 --- a/drivers/staging/rtl8723au/include/hal_intf.h
50075 +++ b/drivers/staging/rtl8723au/include/hal_intf.h
50076 @@ -251,7 +251,7 @@ struct hal_ops {
50077 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50078 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50079 c2h_id_filter c2h_id_filter_ccx;
50080 -};
50081 +} __no_const;
50082
50083 enum rt_eeprom_type {
50084 EEPROM_93C46,
50085 diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50086 index 8d39d800..3f21c0c 100644
50087 --- a/drivers/staging/rtl8723au/include/rtw_io.h
50088 +++ b/drivers/staging/rtl8723au/include/rtw_io.h
50089 @@ -130,7 +130,7 @@ struct _io_ops
50090 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50091 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50092
50093 -};
50094 +} __no_const;
50095
50096 struct io_req {
50097 struct list_head list;
50098 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50099 index fe6c951..72935ba 100644
50100 --- a/drivers/staging/sbe-2t3e3/netdev.c
50101 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50102 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50103 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50104
50105 if (rlen)
50106 - if (copy_to_user(data, &resp, rlen))
50107 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50108 return -EFAULT;
50109
50110 return 0;
50111 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50112 index a863a98..d272795 100644
50113 --- a/drivers/staging/usbip/vhci.h
50114 +++ b/drivers/staging/usbip/vhci.h
50115 @@ -83,7 +83,7 @@ struct vhci_hcd {
50116 unsigned resuming:1;
50117 unsigned long re_timeout;
50118
50119 - atomic_t seqnum;
50120 + atomic_unchecked_t seqnum;
50121
50122 /*
50123 * NOTE:
50124 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50125 index 70e1755..de41855 100644
50126 --- a/drivers/staging/usbip/vhci_hcd.c
50127 +++ b/drivers/staging/usbip/vhci_hcd.c
50128 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50129
50130 spin_lock(&vdev->priv_lock);
50131
50132 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50133 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50134 if (priv->seqnum == 0xffff)
50135 dev_info(&urb->dev->dev, "seqnum max\n");
50136
50137 @@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50138 return -ENOMEM;
50139 }
50140
50141 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50142 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50143 if (unlink->seqnum == 0xffff)
50144 pr_info("seqnum max\n");
50145
50146 @@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50147 vdev->rhport = rhport;
50148 }
50149
50150 - atomic_set(&vhci->seqnum, 0);
50151 + atomic_set_unchecked(&vhci->seqnum, 0);
50152 spin_lock_init(&vhci->lock);
50153
50154 hcd->power_budget = 0; /* no limit */
50155 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50156 index d07fcb5..358e1e1 100644
50157 --- a/drivers/staging/usbip/vhci_rx.c
50158 +++ b/drivers/staging/usbip/vhci_rx.c
50159 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50160 if (!urb) {
50161 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50162 pr_info("max seqnum %d\n",
50163 - atomic_read(&the_controller->seqnum));
50164 + atomic_read_unchecked(&the_controller->seqnum));
50165 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50166 return;
50167 }
50168 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50169 index 6eecd53..29317c6 100644
50170 --- a/drivers/staging/vt6655/hostap.c
50171 +++ b/drivers/staging/vt6655/hostap.c
50172 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50173 *
50174 */
50175
50176 +static net_device_ops_no_const apdev_netdev_ops;
50177 +
50178 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50179 {
50180 PSDevice apdev_priv;
50181 struct net_device *dev = pDevice->dev;
50182 int ret;
50183 - const struct net_device_ops apdev_netdev_ops = {
50184 - .ndo_start_xmit = pDevice->tx_80211,
50185 - };
50186
50187 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50188
50189 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50190 *apdev_priv = *pDevice;
50191 eth_hw_addr_inherit(pDevice->apdev, dev);
50192
50193 + /* only half broken now */
50194 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50195 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50196
50197 pDevice->apdev->type = ARPHRD_IEEE80211;
50198 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50199 index 67ba48b..24e602f 100644
50200 --- a/drivers/staging/vt6656/hostap.c
50201 +++ b/drivers/staging/vt6656/hostap.c
50202 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50203 *
50204 */
50205
50206 +static net_device_ops_no_const apdev_netdev_ops;
50207 +
50208 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50209 {
50210 struct vnt_private *apdev_priv;
50211 struct net_device *dev = pDevice->dev;
50212 int ret;
50213 - const struct net_device_ops apdev_netdev_ops = {
50214 - .ndo_start_xmit = pDevice->tx_80211,
50215 - };
50216
50217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50218
50219 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50220 *apdev_priv = *pDevice;
50221 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50222
50223 + /* only half broken now */
50224 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50225 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50226
50227 pDevice->apdev->type = ARPHRD_IEEE80211;
50228 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50229 index e7e9372..161f530 100644
50230 --- a/drivers/target/sbp/sbp_target.c
50231 +++ b/drivers/target/sbp/sbp_target.c
50232 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50233
50234 #define SESSION_MAINTENANCE_INTERVAL HZ
50235
50236 -static atomic_t login_id = ATOMIC_INIT(0);
50237 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50238
50239 static void session_maintenance_work(struct work_struct *);
50240 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50241 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50242 login->lun = se_lun;
50243 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50244 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50245 - login->login_id = atomic_inc_return(&login_id);
50246 + login->login_id = atomic_inc_return_unchecked(&login_id);
50247
50248 login->tgt_agt = sbp_target_agent_register(login);
50249 if (IS_ERR(login->tgt_agt)) {
50250 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50251 index 26416c1..e796a3d 100644
50252 --- a/drivers/target/target_core_device.c
50253 +++ b/drivers/target/target_core_device.c
50254 @@ -1524,7 +1524,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50255 spin_lock_init(&dev->se_tmr_lock);
50256 spin_lock_init(&dev->qf_cmd_lock);
50257 sema_init(&dev->caw_sem, 1);
50258 - atomic_set(&dev->dev_ordered_id, 0);
50259 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50260 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50261 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50262 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50263 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50264 index 14772e9..42d9f63 100644
50265 --- a/drivers/target/target_core_transport.c
50266 +++ b/drivers/target/target_core_transport.c
50267 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50268 * Used to determine when ORDERED commands should go from
50269 * Dormant to Active status.
50270 */
50271 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50272 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50273 smp_mb__after_atomic_inc();
50274 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50275 cmd->se_ordered_id, cmd->sam_task_attr,
50276 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50277 index 04b1be7..5eff86d 100644
50278 --- a/drivers/thermal/of-thermal.c
50279 +++ b/drivers/thermal/of-thermal.c
50280 @@ -30,6 +30,7 @@
50281 #include <linux/err.h>
50282 #include <linux/export.h>
50283 #include <linux/string.h>
50284 +#include <linux/mm.h>
50285
50286 #include "thermal_core.h"
50287
50288 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50289 tz->get_trend = get_trend;
50290 tz->sensor_data = data;
50291
50292 - tzd->ops->get_temp = of_thermal_get_temp;
50293 - tzd->ops->get_trend = of_thermal_get_trend;
50294 + pax_open_kernel();
50295 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50296 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50297 + pax_close_kernel();
50298 mutex_unlock(&tzd->lock);
50299
50300 return tzd;
50301 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50302 return;
50303
50304 mutex_lock(&tzd->lock);
50305 - tzd->ops->get_temp = NULL;
50306 - tzd->ops->get_trend = NULL;
50307 + pax_open_kernel();
50308 + *(void **)&tzd->ops->get_temp = NULL;
50309 + *(void **)&tzd->ops->get_trend = NULL;
50310 + pax_close_kernel();
50311
50312 tz->get_temp = NULL;
50313 tz->get_trend = NULL;
50314 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50315 index a57bb5a..1f727d33 100644
50316 --- a/drivers/tty/cyclades.c
50317 +++ b/drivers/tty/cyclades.c
50318 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50319 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50320 info->port.count);
50321 #endif
50322 - info->port.count++;
50323 + atomic_inc(&info->port.count);
50324 #ifdef CY_DEBUG_COUNT
50325 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50326 - current->pid, info->port.count);
50327 + current->pid, atomic_read(&info->port.count));
50328 #endif
50329
50330 /*
50331 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50332 for (j = 0; j < cy_card[i].nports; j++) {
50333 info = &cy_card[i].ports[j];
50334
50335 - if (info->port.count) {
50336 + if (atomic_read(&info->port.count)) {
50337 /* XXX is the ldisc num worth this? */
50338 struct tty_struct *tty;
50339 struct tty_ldisc *ld;
50340 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50341 index 0ff7fda..dbc7d52 100644
50342 --- a/drivers/tty/hvc/hvc_console.c
50343 +++ b/drivers/tty/hvc/hvc_console.c
50344 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50345
50346 spin_lock_irqsave(&hp->port.lock, flags);
50347 /* Check and then increment for fast path open. */
50348 - if (hp->port.count++ > 0) {
50349 + if (atomic_inc_return(&hp->port.count) > 1) {
50350 spin_unlock_irqrestore(&hp->port.lock, flags);
50351 hvc_kick();
50352 return 0;
50353 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50354
50355 spin_lock_irqsave(&hp->port.lock, flags);
50356
50357 - if (--hp->port.count == 0) {
50358 + if (atomic_dec_return(&hp->port.count) == 0) {
50359 spin_unlock_irqrestore(&hp->port.lock, flags);
50360 /* We are done with the tty pointer now. */
50361 tty_port_tty_set(&hp->port, NULL);
50362 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50363 */
50364 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50365 } else {
50366 - if (hp->port.count < 0)
50367 + if (atomic_read(&hp->port.count) < 0)
50368 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50369 - hp->vtermno, hp->port.count);
50370 + hp->vtermno, atomic_read(&hp->port.count));
50371 spin_unlock_irqrestore(&hp->port.lock, flags);
50372 }
50373 }
50374 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50375 * open->hangup case this can be called after the final close so prevent
50376 * that from happening for now.
50377 */
50378 - if (hp->port.count <= 0) {
50379 + if (atomic_read(&hp->port.count) <= 0) {
50380 spin_unlock_irqrestore(&hp->port.lock, flags);
50381 return;
50382 }
50383
50384 - hp->port.count = 0;
50385 + atomic_set(&hp->port.count, 0);
50386 spin_unlock_irqrestore(&hp->port.lock, flags);
50387 tty_port_tty_set(&hp->port, NULL);
50388
50389 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50390 return -EPIPE;
50391
50392 /* FIXME what's this (unprotected) check for? */
50393 - if (hp->port.count <= 0)
50394 + if (atomic_read(&hp->port.count) <= 0)
50395 return -EIO;
50396
50397 spin_lock_irqsave(&hp->lock, flags);
50398 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50399 index 81e939e..95ead10 100644
50400 --- a/drivers/tty/hvc/hvcs.c
50401 +++ b/drivers/tty/hvc/hvcs.c
50402 @@ -83,6 +83,7 @@
50403 #include <asm/hvcserver.h>
50404 #include <asm/uaccess.h>
50405 #include <asm/vio.h>
50406 +#include <asm/local.h>
50407
50408 /*
50409 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50410 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50411
50412 spin_lock_irqsave(&hvcsd->lock, flags);
50413
50414 - if (hvcsd->port.count > 0) {
50415 + if (atomic_read(&hvcsd->port.count) > 0) {
50416 spin_unlock_irqrestore(&hvcsd->lock, flags);
50417 printk(KERN_INFO "HVCS: vterm state unchanged. "
50418 "The hvcs device node is still in use.\n");
50419 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50420 }
50421 }
50422
50423 - hvcsd->port.count = 0;
50424 + atomic_set(&hvcsd->port.count, 0);
50425 hvcsd->port.tty = tty;
50426 tty->driver_data = hvcsd;
50427
50428 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50429 unsigned long flags;
50430
50431 spin_lock_irqsave(&hvcsd->lock, flags);
50432 - hvcsd->port.count++;
50433 + atomic_inc(&hvcsd->port.count);
50434 hvcsd->todo_mask |= HVCS_SCHED_READ;
50435 spin_unlock_irqrestore(&hvcsd->lock, flags);
50436
50437 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50438 hvcsd = tty->driver_data;
50439
50440 spin_lock_irqsave(&hvcsd->lock, flags);
50441 - if (--hvcsd->port.count == 0) {
50442 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50443
50444 vio_disable_interrupts(hvcsd->vdev);
50445
50446 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50447
50448 free_irq(irq, hvcsd);
50449 return;
50450 - } else if (hvcsd->port.count < 0) {
50451 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50452 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50453 " is missmanaged.\n",
50454 - hvcsd->vdev->unit_address, hvcsd->port.count);
50455 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50456 }
50457
50458 spin_unlock_irqrestore(&hvcsd->lock, flags);
50459 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50460
50461 spin_lock_irqsave(&hvcsd->lock, flags);
50462 /* Preserve this so that we know how many kref refs to put */
50463 - temp_open_count = hvcsd->port.count;
50464 + temp_open_count = atomic_read(&hvcsd->port.count);
50465
50466 /*
50467 * Don't kref put inside the spinlock because the destruction
50468 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50469 tty->driver_data = NULL;
50470 hvcsd->port.tty = NULL;
50471
50472 - hvcsd->port.count = 0;
50473 + atomic_set(&hvcsd->port.count, 0);
50474
50475 /* This will drop any buffered data on the floor which is OK in a hangup
50476 * scenario. */
50477 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50478 * the middle of a write operation? This is a crummy place to do this
50479 * but we want to keep it all in the spinlock.
50480 */
50481 - if (hvcsd->port.count <= 0) {
50482 + if (atomic_read(&hvcsd->port.count) <= 0) {
50483 spin_unlock_irqrestore(&hvcsd->lock, flags);
50484 return -ENODEV;
50485 }
50486 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50487 {
50488 struct hvcs_struct *hvcsd = tty->driver_data;
50489
50490 - if (!hvcsd || hvcsd->port.count <= 0)
50491 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50492 return 0;
50493
50494 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50495 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50496 index 4190199..06d5bfa 100644
50497 --- a/drivers/tty/hvc/hvsi.c
50498 +++ b/drivers/tty/hvc/hvsi.c
50499 @@ -85,7 +85,7 @@ struct hvsi_struct {
50500 int n_outbuf;
50501 uint32_t vtermno;
50502 uint32_t virq;
50503 - atomic_t seqno; /* HVSI packet sequence number */
50504 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50505 uint16_t mctrl;
50506 uint8_t state; /* HVSI protocol state */
50507 uint8_t flags;
50508 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50509
50510 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50511 packet.hdr.len = sizeof(struct hvsi_query_response);
50512 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50513 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50514 packet.verb = VSV_SEND_VERSION_NUMBER;
50515 packet.u.version = HVSI_VERSION;
50516 packet.query_seqno = query_seqno+1;
50517 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50518
50519 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50520 packet.hdr.len = sizeof(struct hvsi_query);
50521 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50522 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50523 packet.verb = verb;
50524
50525 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50526 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50527 int wrote;
50528
50529 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50530 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50531 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50532 packet.hdr.len = sizeof(struct hvsi_control);
50533 packet.verb = VSV_SET_MODEM_CTL;
50534 packet.mask = HVSI_TSDTR;
50535 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50536 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50537
50538 packet.hdr.type = VS_DATA_PACKET_HEADER;
50539 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50540 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50541 packet.hdr.len = count + sizeof(struct hvsi_header);
50542 memcpy(&packet.data, buf, count);
50543
50544 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50545 struct hvsi_control packet __ALIGNED__;
50546
50547 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50548 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50549 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50550 packet.hdr.len = 6;
50551 packet.verb = VSV_CLOSE_PROTOCOL;
50552
50553 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50554
50555 tty_port_tty_set(&hp->port, tty);
50556 spin_lock_irqsave(&hp->lock, flags);
50557 - hp->port.count++;
50558 + atomic_inc(&hp->port.count);
50559 atomic_set(&hp->seqno, 0);
50560 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50561 spin_unlock_irqrestore(&hp->lock, flags);
50562 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50563
50564 spin_lock_irqsave(&hp->lock, flags);
50565
50566 - if (--hp->port.count == 0) {
50567 + if (atomic_dec_return(&hp->port.count) == 0) {
50568 tty_port_tty_set(&hp->port, NULL);
50569 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50570
50571 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50572
50573 spin_lock_irqsave(&hp->lock, flags);
50574 }
50575 - } else if (hp->port.count < 0)
50576 + } else if (atomic_read(&hp->port.count) < 0)
50577 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50578 - hp - hvsi_ports, hp->port.count);
50579 + hp - hvsi_ports, atomic_read(&hp->port.count));
50580
50581 spin_unlock_irqrestore(&hp->lock, flags);
50582 }
50583 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50584 tty_port_tty_set(&hp->port, NULL);
50585
50586 spin_lock_irqsave(&hp->lock, flags);
50587 - hp->port.count = 0;
50588 + atomic_set(&hp->port.count, 0);
50589 hp->n_outbuf = 0;
50590 spin_unlock_irqrestore(&hp->lock, flags);
50591 }
50592 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50593 index 7ae6c29..05c6dba 100644
50594 --- a/drivers/tty/hvc/hvsi_lib.c
50595 +++ b/drivers/tty/hvc/hvsi_lib.c
50596 @@ -8,7 +8,7 @@
50597
50598 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50599 {
50600 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50601 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50602
50603 /* Assumes that always succeeds, works in practice */
50604 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50605 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50606
50607 /* Reset state */
50608 pv->established = 0;
50609 - atomic_set(&pv->seqno, 0);
50610 + atomic_set_unchecked(&pv->seqno, 0);
50611
50612 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50613
50614 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50615 index 17ee3bf..8d2520d 100644
50616 --- a/drivers/tty/ipwireless/tty.c
50617 +++ b/drivers/tty/ipwireless/tty.c
50618 @@ -28,6 +28,7 @@
50619 #include <linux/tty_driver.h>
50620 #include <linux/tty_flip.h>
50621 #include <linux/uaccess.h>
50622 +#include <asm/local.h>
50623
50624 #include "tty.h"
50625 #include "network.h"
50626 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50627 mutex_unlock(&tty->ipw_tty_mutex);
50628 return -ENODEV;
50629 }
50630 - if (tty->port.count == 0)
50631 + if (atomic_read(&tty->port.count) == 0)
50632 tty->tx_bytes_queued = 0;
50633
50634 - tty->port.count++;
50635 + atomic_inc(&tty->port.count);
50636
50637 tty->port.tty = linux_tty;
50638 linux_tty->driver_data = tty;
50639 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50640
50641 static void do_ipw_close(struct ipw_tty *tty)
50642 {
50643 - tty->port.count--;
50644 -
50645 - if (tty->port.count == 0) {
50646 + if (atomic_dec_return(&tty->port.count) == 0) {
50647 struct tty_struct *linux_tty = tty->port.tty;
50648
50649 if (linux_tty != NULL) {
50650 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50651 return;
50652
50653 mutex_lock(&tty->ipw_tty_mutex);
50654 - if (tty->port.count == 0) {
50655 + if (atomic_read(&tty->port.count) == 0) {
50656 mutex_unlock(&tty->ipw_tty_mutex);
50657 return;
50658 }
50659 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50660
50661 mutex_lock(&tty->ipw_tty_mutex);
50662
50663 - if (!tty->port.count) {
50664 + if (!atomic_read(&tty->port.count)) {
50665 mutex_unlock(&tty->ipw_tty_mutex);
50666 return;
50667 }
50668 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50669 return -ENODEV;
50670
50671 mutex_lock(&tty->ipw_tty_mutex);
50672 - if (!tty->port.count) {
50673 + if (!atomic_read(&tty->port.count)) {
50674 mutex_unlock(&tty->ipw_tty_mutex);
50675 return -EINVAL;
50676 }
50677 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50678 if (!tty)
50679 return -ENODEV;
50680
50681 - if (!tty->port.count)
50682 + if (!atomic_read(&tty->port.count))
50683 return -EINVAL;
50684
50685 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50686 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50687 if (!tty)
50688 return 0;
50689
50690 - if (!tty->port.count)
50691 + if (!atomic_read(&tty->port.count))
50692 return 0;
50693
50694 return tty->tx_bytes_queued;
50695 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50696 if (!tty)
50697 return -ENODEV;
50698
50699 - if (!tty->port.count)
50700 + if (!atomic_read(&tty->port.count))
50701 return -EINVAL;
50702
50703 return get_control_lines(tty);
50704 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50705 if (!tty)
50706 return -ENODEV;
50707
50708 - if (!tty->port.count)
50709 + if (!atomic_read(&tty->port.count))
50710 return -EINVAL;
50711
50712 return set_control_lines(tty, set, clear);
50713 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50714 if (!tty)
50715 return -ENODEV;
50716
50717 - if (!tty->port.count)
50718 + if (!atomic_read(&tty->port.count))
50719 return -EINVAL;
50720
50721 /* FIXME: Exactly how is the tty object locked here .. */
50722 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50723 * are gone */
50724 mutex_lock(&ttyj->ipw_tty_mutex);
50725 }
50726 - while (ttyj->port.count)
50727 + while (atomic_read(&ttyj->port.count))
50728 do_ipw_close(ttyj);
50729 ipwireless_disassociate_network_ttys(network,
50730 ttyj->channel_idx);
50731 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50732 index 1deaca4..c8582d4 100644
50733 --- a/drivers/tty/moxa.c
50734 +++ b/drivers/tty/moxa.c
50735 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50736 }
50737
50738 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50739 - ch->port.count++;
50740 + atomic_inc(&ch->port.count);
50741 tty->driver_data = ch;
50742 tty_port_tty_set(&ch->port, tty);
50743 mutex_lock(&ch->port.mutex);
50744 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50745 index 2ebe47b..3205833 100644
50746 --- a/drivers/tty/n_gsm.c
50747 +++ b/drivers/tty/n_gsm.c
50748 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50749 spin_lock_init(&dlci->lock);
50750 mutex_init(&dlci->mutex);
50751 dlci->fifo = &dlci->_fifo;
50752 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50753 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50754 kfree(dlci);
50755 return NULL;
50756 }
50757 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50758 struct gsm_dlci *dlci = tty->driver_data;
50759 struct tty_port *port = &dlci->port;
50760
50761 - port->count++;
50762 + atomic_inc(&port->count);
50763 tty_port_tty_set(port, tty);
50764
50765 dlci->modem_rx = 0;
50766 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50767 index fe9d129..477300f 100644
50768 --- a/drivers/tty/n_tty.c
50769 +++ b/drivers/tty/n_tty.c
50770 @@ -115,7 +115,7 @@ struct n_tty_data {
50771 int minimum_to_wake;
50772
50773 /* consumer-published */
50774 - size_t read_tail;
50775 + size_t read_tail __intentional_overflow(-1);
50776 size_t line_start;
50777
50778 /* protected by output lock */
50779 @@ -2516,6 +2516,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50780 {
50781 *ops = tty_ldisc_N_TTY;
50782 ops->owner = NULL;
50783 - ops->refcount = ops->flags = 0;
50784 + atomic_set(&ops->refcount, 0);
50785 + ops->flags = 0;
50786 }
50787 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50788 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50789 index 25c9bc7..24077b7 100644
50790 --- a/drivers/tty/pty.c
50791 +++ b/drivers/tty/pty.c
50792 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50793 panic("Couldn't register Unix98 pts driver");
50794
50795 /* Now create the /dev/ptmx special device */
50796 + pax_open_kernel();
50797 tty_default_fops(&ptmx_fops);
50798 - ptmx_fops.open = ptmx_open;
50799 + *(void **)&ptmx_fops.open = ptmx_open;
50800 + pax_close_kernel();
50801
50802 cdev_init(&ptmx_cdev, &ptmx_fops);
50803 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50804 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50805 index 383c4c7..d408e21 100644
50806 --- a/drivers/tty/rocket.c
50807 +++ b/drivers/tty/rocket.c
50808 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50809 tty->driver_data = info;
50810 tty_port_tty_set(port, tty);
50811
50812 - if (port->count++ == 0) {
50813 + if (atomic_inc_return(&port->count) == 1) {
50814 atomic_inc(&rp_num_ports_open);
50815
50816 #ifdef ROCKET_DEBUG_OPEN
50817 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50818 #endif
50819 }
50820 #ifdef ROCKET_DEBUG_OPEN
50821 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50822 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50823 #endif
50824
50825 /*
50826 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50827 spin_unlock_irqrestore(&info->port.lock, flags);
50828 return;
50829 }
50830 - if (info->port.count)
50831 + if (atomic_read(&info->port.count))
50832 atomic_dec(&rp_num_ports_open);
50833 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50834 spin_unlock_irqrestore(&info->port.lock, flags);
50835 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50836 index 1274499..f541382 100644
50837 --- a/drivers/tty/serial/ioc4_serial.c
50838 +++ b/drivers/tty/serial/ioc4_serial.c
50839 @@ -437,7 +437,7 @@ struct ioc4_soft {
50840 } is_intr_info[MAX_IOC4_INTR_ENTS];
50841
50842 /* Number of entries active in the above array */
50843 - atomic_t is_num_intrs;
50844 + atomic_unchecked_t is_num_intrs;
50845 } is_intr_type[IOC4_NUM_INTR_TYPES];
50846
50847 /* is_ir_lock must be held while
50848 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50849 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50850 || (type == IOC4_OTHER_INTR_TYPE)));
50851
50852 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50853 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50854 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50855
50856 /* Save off the lower level interrupt handler */
50857 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50858
50859 soft = arg;
50860 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50861 - num_intrs = (int)atomic_read(
50862 + num_intrs = (int)atomic_read_unchecked(
50863 &soft->is_intr_type[intr_type].is_num_intrs);
50864
50865 this_mir = this_ir = pending_intrs(soft, intr_type);
50866 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50867 index a260cde..6b2b5ce 100644
50868 --- a/drivers/tty/serial/kgdboc.c
50869 +++ b/drivers/tty/serial/kgdboc.c
50870 @@ -24,8 +24,9 @@
50871 #define MAX_CONFIG_LEN 40
50872
50873 static struct kgdb_io kgdboc_io_ops;
50874 +static struct kgdb_io kgdboc_io_ops_console;
50875
50876 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50877 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50878 static int configured = -1;
50879
50880 static char config[MAX_CONFIG_LEN];
50881 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50882 kgdboc_unregister_kbd();
50883 if (configured == 1)
50884 kgdb_unregister_io_module(&kgdboc_io_ops);
50885 + else if (configured == 2)
50886 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50887 }
50888
50889 static int configure_kgdboc(void)
50890 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50891 int err;
50892 char *cptr = config;
50893 struct console *cons;
50894 + int is_console = 0;
50895
50896 err = kgdboc_option_setup(config);
50897 if (err || !strlen(config) || isspace(config[0]))
50898 goto noconfig;
50899
50900 err = -ENODEV;
50901 - kgdboc_io_ops.is_console = 0;
50902 kgdb_tty_driver = NULL;
50903
50904 kgdboc_use_kms = 0;
50905 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50906 int idx;
50907 if (cons->device && cons->device(cons, &idx) == p &&
50908 idx == tty_line) {
50909 - kgdboc_io_ops.is_console = 1;
50910 + is_console = 1;
50911 break;
50912 }
50913 cons = cons->next;
50914 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50915 kgdb_tty_line = tty_line;
50916
50917 do_register:
50918 - err = kgdb_register_io_module(&kgdboc_io_ops);
50919 + if (is_console) {
50920 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50921 + configured = 2;
50922 + } else {
50923 + err = kgdb_register_io_module(&kgdboc_io_ops);
50924 + configured = 1;
50925 + }
50926 if (err)
50927 goto noconfig;
50928
50929 @@ -205,8 +214,6 @@ do_register:
50930 if (err)
50931 goto nmi_con_failed;
50932
50933 - configured = 1;
50934 -
50935 return 0;
50936
50937 nmi_con_failed:
50938 @@ -223,7 +230,7 @@ noconfig:
50939 static int __init init_kgdboc(void)
50940 {
50941 /* Already configured? */
50942 - if (configured == 1)
50943 + if (configured >= 1)
50944 return 0;
50945
50946 return configure_kgdboc();
50947 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50948 if (config[len - 1] == '\n')
50949 config[len - 1] = '\0';
50950
50951 - if (configured == 1)
50952 + if (configured >= 1)
50953 cleanup_kgdboc();
50954
50955 /* Go and configure with the new params. */
50956 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50957 .post_exception = kgdboc_post_exp_handler,
50958 };
50959
50960 +static struct kgdb_io kgdboc_io_ops_console = {
50961 + .name = "kgdboc",
50962 + .read_char = kgdboc_get_char,
50963 + .write_char = kgdboc_put_char,
50964 + .pre_exception = kgdboc_pre_exp_handler,
50965 + .post_exception = kgdboc_post_exp_handler,
50966 + .is_console = 1
50967 +};
50968 +
50969 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50970 /* This is only available if kgdboc is a built in for early debugging */
50971 static int __init kgdboc_early_init(char *opt)
50972 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50973 index 053b98e..86742e5 100644
50974 --- a/drivers/tty/serial/msm_serial.c
50975 +++ b/drivers/tty/serial/msm_serial.c
50976 @@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
50977 .cons = MSM_CONSOLE,
50978 };
50979
50980 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50981 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50982
50983 static const struct of_device_id msm_uartdm_table[] = {
50984 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
50985 @@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50986 int irq;
50987
50988 if (pdev->id == -1)
50989 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50990 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50991
50992 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50993 return -ENXIO;
50994 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50995 index 1f5505e..a1a767d 100644
50996 --- a/drivers/tty/serial/samsung.c
50997 +++ b/drivers/tty/serial/samsung.c
50998 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50999 }
51000 }
51001
51002 +static int s3c64xx_serial_startup(struct uart_port *port);
51003 static int s3c24xx_serial_startup(struct uart_port *port)
51004 {
51005 struct s3c24xx_uart_port *ourport = to_ourport(port);
51006 int ret;
51007
51008 + /* Startup sequence is different for s3c64xx and higher SoC's */
51009 + if (s3c24xx_serial_has_interrupt_mask(port))
51010 + return s3c64xx_serial_startup(port);
51011 +
51012 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51013 port->mapbase, port->membase);
51014
51015 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51016 /* setup info for port */
51017 port->dev = &platdev->dev;
51018
51019 - /* Startup sequence is different for s3c64xx and higher SoC's */
51020 - if (s3c24xx_serial_has_interrupt_mask(port))
51021 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51022 -
51023 port->uartclk = 1;
51024
51025 if (cfg->uart_flags & UPF_CONS_FLOW) {
51026 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51027 index b68550d..a62d7f8 100644
51028 --- a/drivers/tty/serial/serial_core.c
51029 +++ b/drivers/tty/serial/serial_core.c
51030 @@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51031
51032 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51033
51034 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51035 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51036 return;
51037
51038 /*
51039 @@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51040 uart_flush_buffer(tty);
51041 uart_shutdown(tty, state);
51042 spin_lock_irqsave(&port->lock, flags);
51043 - port->count = 0;
51044 + atomic_set(&port->count, 0);
51045 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51046 spin_unlock_irqrestore(&port->lock, flags);
51047 tty_port_tty_set(port, NULL);
51048 @@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51049 goto end;
51050 }
51051
51052 - port->count++;
51053 + atomic_inc(&port->count);
51054 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51055 retval = -ENXIO;
51056 goto err_dec_count;
51057 @@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51058 end:
51059 return retval;
51060 err_dec_count:
51061 - port->count--;
51062 + atomic_inc(&port->count);
51063 mutex_unlock(&port->mutex);
51064 goto end;
51065 }
51066 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51067 index d48e040..0f52764 100644
51068 --- a/drivers/tty/synclink.c
51069 +++ b/drivers/tty/synclink.c
51070 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51071
51072 if (debug_level >= DEBUG_LEVEL_INFO)
51073 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51074 - __FILE__,__LINE__, info->device_name, info->port.count);
51075 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51076
51077 if (tty_port_close_start(&info->port, tty, filp) == 0)
51078 goto cleanup;
51079 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51080 cleanup:
51081 if (debug_level >= DEBUG_LEVEL_INFO)
51082 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51083 - tty->driver->name, info->port.count);
51084 + tty->driver->name, atomic_read(&info->port.count));
51085
51086 } /* end of mgsl_close() */
51087
51088 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51089
51090 mgsl_flush_buffer(tty);
51091 shutdown(info);
51092 -
51093 - info->port.count = 0;
51094 +
51095 + atomic_set(&info->port.count, 0);
51096 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51097 info->port.tty = NULL;
51098
51099 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51100
51101 if (debug_level >= DEBUG_LEVEL_INFO)
51102 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51103 - __FILE__,__LINE__, tty->driver->name, port->count );
51104 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51105
51106 spin_lock_irqsave(&info->irq_spinlock, flags);
51107 if (!tty_hung_up_p(filp)) {
51108 extra_count = true;
51109 - port->count--;
51110 + atomic_dec(&port->count);
51111 }
51112 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51113 port->blocked_open++;
51114 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51115
51116 if (debug_level >= DEBUG_LEVEL_INFO)
51117 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51118 - __FILE__,__LINE__, tty->driver->name, port->count );
51119 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51120
51121 tty_unlock(tty);
51122 schedule();
51123 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51124
51125 /* FIXME: Racy on hangup during close wait */
51126 if (extra_count)
51127 - port->count++;
51128 + atomic_inc(&port->count);
51129 port->blocked_open--;
51130
51131 if (debug_level >= DEBUG_LEVEL_INFO)
51132 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51133 - __FILE__,__LINE__, tty->driver->name, port->count );
51134 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51135
51136 if (!retval)
51137 port->flags |= ASYNC_NORMAL_ACTIVE;
51138 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51139
51140 if (debug_level >= DEBUG_LEVEL_INFO)
51141 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51142 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51143 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51144
51145 /* If port is closing, signal caller to try again */
51146 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51147 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51148 spin_unlock_irqrestore(&info->netlock, flags);
51149 goto cleanup;
51150 }
51151 - info->port.count++;
51152 + atomic_inc(&info->port.count);
51153 spin_unlock_irqrestore(&info->netlock, flags);
51154
51155 - if (info->port.count == 1) {
51156 + if (atomic_read(&info->port.count) == 1) {
51157 /* 1st open on this device, init hardware */
51158 retval = startup(info);
51159 if (retval < 0)
51160 @@ -3446,8 +3446,8 @@ cleanup:
51161 if (retval) {
51162 if (tty->count == 1)
51163 info->port.tty = NULL; /* tty layer will release tty struct */
51164 - if(info->port.count)
51165 - info->port.count--;
51166 + if (atomic_read(&info->port.count))
51167 + atomic_dec(&info->port.count);
51168 }
51169
51170 return retval;
51171 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51172 unsigned short new_crctype;
51173
51174 /* return error if TTY interface open */
51175 - if (info->port.count)
51176 + if (atomic_read(&info->port.count))
51177 return -EBUSY;
51178
51179 switch (encoding)
51180 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51181
51182 /* arbitrate between network and tty opens */
51183 spin_lock_irqsave(&info->netlock, flags);
51184 - if (info->port.count != 0 || info->netcount != 0) {
51185 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51186 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51187 spin_unlock_irqrestore(&info->netlock, flags);
51188 return -EBUSY;
51189 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51190 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51191
51192 /* return error if TTY interface open */
51193 - if (info->port.count)
51194 + if (atomic_read(&info->port.count))
51195 return -EBUSY;
51196
51197 if (cmd != SIOCWANDEV)
51198 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51199 index c359a91..959fc26 100644
51200 --- a/drivers/tty/synclink_gt.c
51201 +++ b/drivers/tty/synclink_gt.c
51202 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51203 tty->driver_data = info;
51204 info->port.tty = tty;
51205
51206 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51207 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51208
51209 /* If port is closing, signal caller to try again */
51210 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51211 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51212 mutex_unlock(&info->port.mutex);
51213 goto cleanup;
51214 }
51215 - info->port.count++;
51216 + atomic_inc(&info->port.count);
51217 spin_unlock_irqrestore(&info->netlock, flags);
51218
51219 - if (info->port.count == 1) {
51220 + if (atomic_read(&info->port.count) == 1) {
51221 /* 1st open on this device, init hardware */
51222 retval = startup(info);
51223 if (retval < 0) {
51224 @@ -715,8 +715,8 @@ cleanup:
51225 if (retval) {
51226 if (tty->count == 1)
51227 info->port.tty = NULL; /* tty layer will release tty struct */
51228 - if(info->port.count)
51229 - info->port.count--;
51230 + if(atomic_read(&info->port.count))
51231 + atomic_dec(&info->port.count);
51232 }
51233
51234 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51235 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51236
51237 if (sanity_check(info, tty->name, "close"))
51238 return;
51239 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51240 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51241
51242 if (tty_port_close_start(&info->port, tty, filp) == 0)
51243 goto cleanup;
51244 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51245 tty_port_close_end(&info->port, tty);
51246 info->port.tty = NULL;
51247 cleanup:
51248 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51249 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51250 }
51251
51252 static void hangup(struct tty_struct *tty)
51253 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51254 shutdown(info);
51255
51256 spin_lock_irqsave(&info->port.lock, flags);
51257 - info->port.count = 0;
51258 + atomic_set(&info->port.count, 0);
51259 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51260 info->port.tty = NULL;
51261 spin_unlock_irqrestore(&info->port.lock, flags);
51262 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51263 unsigned short new_crctype;
51264
51265 /* return error if TTY interface open */
51266 - if (info->port.count)
51267 + if (atomic_read(&info->port.count))
51268 return -EBUSY;
51269
51270 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51271 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51272
51273 /* arbitrate between network and tty opens */
51274 spin_lock_irqsave(&info->netlock, flags);
51275 - if (info->port.count != 0 || info->netcount != 0) {
51276 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51277 DBGINFO(("%s hdlc_open busy\n", dev->name));
51278 spin_unlock_irqrestore(&info->netlock, flags);
51279 return -EBUSY;
51280 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51281 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51282
51283 /* return error if TTY interface open */
51284 - if (info->port.count)
51285 + if (atomic_read(&info->port.count))
51286 return -EBUSY;
51287
51288 if (cmd != SIOCWANDEV)
51289 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51290 if (port == NULL)
51291 continue;
51292 spin_lock(&port->lock);
51293 - if ((port->port.count || port->netcount) &&
51294 + if ((atomic_read(&port->port.count) || port->netcount) &&
51295 port->pending_bh && !port->bh_running &&
51296 !port->bh_requested) {
51297 DBGISR(("%s bh queued\n", port->device_name));
51298 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51299 spin_lock_irqsave(&info->lock, flags);
51300 if (!tty_hung_up_p(filp)) {
51301 extra_count = true;
51302 - port->count--;
51303 + atomic_dec(&port->count);
51304 }
51305 spin_unlock_irqrestore(&info->lock, flags);
51306 port->blocked_open++;
51307 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51308 remove_wait_queue(&port->open_wait, &wait);
51309
51310 if (extra_count)
51311 - port->count++;
51312 + atomic_inc(&port->count);
51313 port->blocked_open--;
51314
51315 if (!retval)
51316 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51317 index 53ba853..3c30f6d 100644
51318 --- a/drivers/tty/synclinkmp.c
51319 +++ b/drivers/tty/synclinkmp.c
51320 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51321
51322 if (debug_level >= DEBUG_LEVEL_INFO)
51323 printk("%s(%d):%s open(), old ref count = %d\n",
51324 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51325 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51326
51327 /* If port is closing, signal caller to try again */
51328 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51329 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51330 spin_unlock_irqrestore(&info->netlock, flags);
51331 goto cleanup;
51332 }
51333 - info->port.count++;
51334 + atomic_inc(&info->port.count);
51335 spin_unlock_irqrestore(&info->netlock, flags);
51336
51337 - if (info->port.count == 1) {
51338 + if (atomic_read(&info->port.count) == 1) {
51339 /* 1st open on this device, init hardware */
51340 retval = startup(info);
51341 if (retval < 0)
51342 @@ -796,8 +796,8 @@ cleanup:
51343 if (retval) {
51344 if (tty->count == 1)
51345 info->port.tty = NULL; /* tty layer will release tty struct */
51346 - if(info->port.count)
51347 - info->port.count--;
51348 + if(atomic_read(&info->port.count))
51349 + atomic_dec(&info->port.count);
51350 }
51351
51352 return retval;
51353 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51354
51355 if (debug_level >= DEBUG_LEVEL_INFO)
51356 printk("%s(%d):%s close() entry, count=%d\n",
51357 - __FILE__,__LINE__, info->device_name, info->port.count);
51358 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51359
51360 if (tty_port_close_start(&info->port, tty, filp) == 0)
51361 goto cleanup;
51362 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51363 cleanup:
51364 if (debug_level >= DEBUG_LEVEL_INFO)
51365 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51366 - tty->driver->name, info->port.count);
51367 + tty->driver->name, atomic_read(&info->port.count));
51368 }
51369
51370 /* Called by tty_hangup() when a hangup is signaled.
51371 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51372 shutdown(info);
51373
51374 spin_lock_irqsave(&info->port.lock, flags);
51375 - info->port.count = 0;
51376 + atomic_set(&info->port.count, 0);
51377 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51378 info->port.tty = NULL;
51379 spin_unlock_irqrestore(&info->port.lock, flags);
51380 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51381 unsigned short new_crctype;
51382
51383 /* return error if TTY interface open */
51384 - if (info->port.count)
51385 + if (atomic_read(&info->port.count))
51386 return -EBUSY;
51387
51388 switch (encoding)
51389 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51390
51391 /* arbitrate between network and tty opens */
51392 spin_lock_irqsave(&info->netlock, flags);
51393 - if (info->port.count != 0 || info->netcount != 0) {
51394 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51395 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51396 spin_unlock_irqrestore(&info->netlock, flags);
51397 return -EBUSY;
51398 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51399 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51400
51401 /* return error if TTY interface open */
51402 - if (info->port.count)
51403 + if (atomic_read(&info->port.count))
51404 return -EBUSY;
51405
51406 if (cmd != SIOCWANDEV)
51407 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51408 * do not request bottom half processing if the
51409 * device is not open in a normal mode.
51410 */
51411 - if ( port && (port->port.count || port->netcount) &&
51412 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51413 port->pending_bh && !port->bh_running &&
51414 !port->bh_requested ) {
51415 if ( debug_level >= DEBUG_LEVEL_ISR )
51416 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51417
51418 if (debug_level >= DEBUG_LEVEL_INFO)
51419 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51420 - __FILE__,__LINE__, tty->driver->name, port->count );
51421 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51422
51423 spin_lock_irqsave(&info->lock, flags);
51424 if (!tty_hung_up_p(filp)) {
51425 extra_count = true;
51426 - port->count--;
51427 + atomic_dec(&port->count);
51428 }
51429 spin_unlock_irqrestore(&info->lock, flags);
51430 port->blocked_open++;
51431 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51432
51433 if (debug_level >= DEBUG_LEVEL_INFO)
51434 printk("%s(%d):%s block_til_ready() count=%d\n",
51435 - __FILE__,__LINE__, tty->driver->name, port->count );
51436 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51437
51438 tty_unlock(tty);
51439 schedule();
51440 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51441 remove_wait_queue(&port->open_wait, &wait);
51442
51443 if (extra_count)
51444 - port->count++;
51445 + atomic_inc(&port->count);
51446 port->blocked_open--;
51447
51448 if (debug_level >= DEBUG_LEVEL_INFO)
51449 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51450 - __FILE__,__LINE__, tty->driver->name, port->count );
51451 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51452
51453 if (!retval)
51454 port->flags |= ASYNC_NORMAL_ACTIVE;
51455 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51456 index ce396ec..04a37be 100644
51457 --- a/drivers/tty/sysrq.c
51458 +++ b/drivers/tty/sysrq.c
51459 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51460 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51461 size_t count, loff_t *ppos)
51462 {
51463 - if (count) {
51464 + if (count && capable(CAP_SYS_ADMIN)) {
51465 char c;
51466
51467 if (get_user(c, buf))
51468 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51469 index 3411071..86f2cf2 100644
51470 --- a/drivers/tty/tty_io.c
51471 +++ b/drivers/tty/tty_io.c
51472 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51473
51474 void tty_default_fops(struct file_operations *fops)
51475 {
51476 - *fops = tty_fops;
51477 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51478 }
51479
51480 /*
51481 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51482 index 2d822aa..a566234 100644
51483 --- a/drivers/tty/tty_ldisc.c
51484 +++ b/drivers/tty/tty_ldisc.c
51485 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51486 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51487 tty_ldiscs[disc] = new_ldisc;
51488 new_ldisc->num = disc;
51489 - new_ldisc->refcount = 0;
51490 + atomic_set(&new_ldisc->refcount, 0);
51491 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51492
51493 return ret;
51494 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51495 return -EINVAL;
51496
51497 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51498 - if (tty_ldiscs[disc]->refcount)
51499 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51500 ret = -EBUSY;
51501 else
51502 tty_ldiscs[disc] = NULL;
51503 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51504 if (ldops) {
51505 ret = ERR_PTR(-EAGAIN);
51506 if (try_module_get(ldops->owner)) {
51507 - ldops->refcount++;
51508 + atomic_inc(&ldops->refcount);
51509 ret = ldops;
51510 }
51511 }
51512 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51513 unsigned long flags;
51514
51515 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51516 - ldops->refcount--;
51517 + atomic_dec(&ldops->refcount);
51518 module_put(ldops->owner);
51519 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51520 }
51521 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51522 index 3f746c8..2f2fcaa 100644
51523 --- a/drivers/tty/tty_port.c
51524 +++ b/drivers/tty/tty_port.c
51525 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51526 unsigned long flags;
51527
51528 spin_lock_irqsave(&port->lock, flags);
51529 - port->count = 0;
51530 + atomic_set(&port->count, 0);
51531 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51532 tty = port->tty;
51533 if (tty)
51534 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51535 /* The port lock protects the port counts */
51536 spin_lock_irqsave(&port->lock, flags);
51537 if (!tty_hung_up_p(filp))
51538 - port->count--;
51539 + atomic_dec(&port->count);
51540 port->blocked_open++;
51541 spin_unlock_irqrestore(&port->lock, flags);
51542
51543 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51544 we must not mess that up further */
51545 spin_lock_irqsave(&port->lock, flags);
51546 if (!tty_hung_up_p(filp))
51547 - port->count++;
51548 + atomic_inc(&port->count);
51549 port->blocked_open--;
51550 if (retval == 0)
51551 port->flags |= ASYNC_NORMAL_ACTIVE;
51552 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51553 return 0;
51554 }
51555
51556 - if (tty->count == 1 && port->count != 1) {
51557 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51558 printk(KERN_WARNING
51559 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51560 - port->count);
51561 - port->count = 1;
51562 + atomic_read(&port->count));
51563 + atomic_set(&port->count, 1);
51564 }
51565 - if (--port->count < 0) {
51566 + if (atomic_dec_return(&port->count) < 0) {
51567 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51568 - port->count);
51569 - port->count = 0;
51570 + atomic_read(&port->count));
51571 + atomic_set(&port->count, 0);
51572 }
51573
51574 - if (port->count) {
51575 + if (atomic_read(&port->count)) {
51576 spin_unlock_irqrestore(&port->lock, flags);
51577 return 0;
51578 }
51579 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51580 {
51581 spin_lock_irq(&port->lock);
51582 if (!tty_hung_up_p(filp))
51583 - ++port->count;
51584 + atomic_inc(&port->count);
51585 spin_unlock_irq(&port->lock);
51586 tty_port_tty_set(port, tty);
51587
51588 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51589 index d0e3a44..5f8b754 100644
51590 --- a/drivers/tty/vt/keyboard.c
51591 +++ b/drivers/tty/vt/keyboard.c
51592 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51593 kbd->kbdmode == VC_OFF) &&
51594 value != KVAL(K_SAK))
51595 return; /* SAK is allowed even in raw mode */
51596 +
51597 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51598 + {
51599 + void *func = fn_handler[value];
51600 + if (func == fn_show_state || func == fn_show_ptregs ||
51601 + func == fn_show_mem)
51602 + return;
51603 + }
51604 +#endif
51605 +
51606 fn_handler[value](vc);
51607 }
51608
51609 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51610 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51611 return -EFAULT;
51612
51613 - if (!capable(CAP_SYS_TTY_CONFIG))
51614 - perm = 0;
51615 -
51616 switch (cmd) {
51617 case KDGKBENT:
51618 /* Ensure another thread doesn't free it under us */
51619 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51620 spin_unlock_irqrestore(&kbd_event_lock, flags);
51621 return put_user(val, &user_kbe->kb_value);
51622 case KDSKBENT:
51623 + if (!capable(CAP_SYS_TTY_CONFIG))
51624 + perm = 0;
51625 +
51626 if (!perm)
51627 return -EPERM;
51628 if (!i && v == K_NOSUCHMAP) {
51629 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51630 int i, j, k;
51631 int ret;
51632
51633 - if (!capable(CAP_SYS_TTY_CONFIG))
51634 - perm = 0;
51635 -
51636 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51637 if (!kbs) {
51638 ret = -ENOMEM;
51639 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51640 kfree(kbs);
51641 return ((p && *p) ? -EOVERFLOW : 0);
51642 case KDSKBSENT:
51643 + if (!capable(CAP_SYS_TTY_CONFIG))
51644 + perm = 0;
51645 +
51646 if (!perm) {
51647 ret = -EPERM;
51648 goto reterr;
51649 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51650 index a673e5b..36e5d32 100644
51651 --- a/drivers/uio/uio.c
51652 +++ b/drivers/uio/uio.c
51653 @@ -25,6 +25,7 @@
51654 #include <linux/kobject.h>
51655 #include <linux/cdev.h>
51656 #include <linux/uio_driver.h>
51657 +#include <asm/local.h>
51658
51659 #define UIO_MAX_DEVICES (1U << MINORBITS)
51660
51661 @@ -32,7 +33,7 @@ struct uio_device {
51662 struct module *owner;
51663 struct device *dev;
51664 int minor;
51665 - atomic_t event;
51666 + atomic_unchecked_t event;
51667 struct fasync_struct *async_queue;
51668 wait_queue_head_t wait;
51669 struct uio_info *info;
51670 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51671 struct device_attribute *attr, char *buf)
51672 {
51673 struct uio_device *idev = dev_get_drvdata(dev);
51674 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51675 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51676 }
51677 static DEVICE_ATTR_RO(event);
51678
51679 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51680 {
51681 struct uio_device *idev = info->uio_dev;
51682
51683 - atomic_inc(&idev->event);
51684 + atomic_inc_unchecked(&idev->event);
51685 wake_up_interruptible(&idev->wait);
51686 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51687 }
51688 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51689 }
51690
51691 listener->dev = idev;
51692 - listener->event_count = atomic_read(&idev->event);
51693 + listener->event_count = atomic_read_unchecked(&idev->event);
51694 filep->private_data = listener;
51695
51696 if (idev->info->open) {
51697 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51698 return -EIO;
51699
51700 poll_wait(filep, &idev->wait, wait);
51701 - if (listener->event_count != atomic_read(&idev->event))
51702 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51703 return POLLIN | POLLRDNORM;
51704 return 0;
51705 }
51706 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51707 do {
51708 set_current_state(TASK_INTERRUPTIBLE);
51709
51710 - event_count = atomic_read(&idev->event);
51711 + event_count = atomic_read_unchecked(&idev->event);
51712 if (event_count != listener->event_count) {
51713 if (copy_to_user(buf, &event_count, count))
51714 retval = -EFAULT;
51715 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51716 static int uio_find_mem_index(struct vm_area_struct *vma)
51717 {
51718 struct uio_device *idev = vma->vm_private_data;
51719 + unsigned long size;
51720
51721 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51722 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51723 + size = idev->info->mem[vma->vm_pgoff].size;
51724 + if (size == 0)
51725 + return -1;
51726 + if (vma->vm_end - vma->vm_start > size)
51727 return -1;
51728 return (int)vma->vm_pgoff;
51729 }
51730 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51731 idev->owner = owner;
51732 idev->info = info;
51733 init_waitqueue_head(&idev->wait);
51734 - atomic_set(&idev->event, 0);
51735 + atomic_set_unchecked(&idev->event, 0);
51736
51737 ret = uio_get_minor(idev);
51738 if (ret)
51739 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51740 index 813d4d3..a71934f 100644
51741 --- a/drivers/usb/atm/cxacru.c
51742 +++ b/drivers/usb/atm/cxacru.c
51743 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51744 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51745 if (ret < 2)
51746 return -EINVAL;
51747 - if (index < 0 || index > 0x7f)
51748 + if (index > 0x7f)
51749 return -EINVAL;
51750 pos += tmp;
51751
51752 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51753 index dada014..1d0d517 100644
51754 --- a/drivers/usb/atm/usbatm.c
51755 +++ b/drivers/usb/atm/usbatm.c
51756 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51757 if (printk_ratelimit())
51758 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51759 __func__, vpi, vci);
51760 - atomic_inc(&vcc->stats->rx_err);
51761 + atomic_inc_unchecked(&vcc->stats->rx_err);
51762 return;
51763 }
51764
51765 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51766 if (length > ATM_MAX_AAL5_PDU) {
51767 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51768 __func__, length, vcc);
51769 - atomic_inc(&vcc->stats->rx_err);
51770 + atomic_inc_unchecked(&vcc->stats->rx_err);
51771 goto out;
51772 }
51773
51774 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51775 if (sarb->len < pdu_length) {
51776 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51777 __func__, pdu_length, sarb->len, vcc);
51778 - atomic_inc(&vcc->stats->rx_err);
51779 + atomic_inc_unchecked(&vcc->stats->rx_err);
51780 goto out;
51781 }
51782
51783 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51784 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51785 __func__, vcc);
51786 - atomic_inc(&vcc->stats->rx_err);
51787 + atomic_inc_unchecked(&vcc->stats->rx_err);
51788 goto out;
51789 }
51790
51791 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51792 if (printk_ratelimit())
51793 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51794 __func__, length);
51795 - atomic_inc(&vcc->stats->rx_drop);
51796 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51797 goto out;
51798 }
51799
51800 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51801
51802 vcc->push(vcc, skb);
51803
51804 - atomic_inc(&vcc->stats->rx);
51805 + atomic_inc_unchecked(&vcc->stats->rx);
51806 out:
51807 skb_trim(sarb, 0);
51808 }
51809 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51810 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51811
51812 usbatm_pop(vcc, skb);
51813 - atomic_inc(&vcc->stats->tx);
51814 + atomic_inc_unchecked(&vcc->stats->tx);
51815
51816 skb = skb_dequeue(&instance->sndqueue);
51817 }
51818 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51819 if (!left--)
51820 return sprintf(page,
51821 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51822 - atomic_read(&atm_dev->stats.aal5.tx),
51823 - atomic_read(&atm_dev->stats.aal5.tx_err),
51824 - atomic_read(&atm_dev->stats.aal5.rx),
51825 - atomic_read(&atm_dev->stats.aal5.rx_err),
51826 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51827 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51828 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51829 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51830 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51831 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51832
51833 if (!left--) {
51834 if (instance->disconnected)
51835 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51836 index 2a3bbdf..91d72cf 100644
51837 --- a/drivers/usb/core/devices.c
51838 +++ b/drivers/usb/core/devices.c
51839 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51840 * time it gets called.
51841 */
51842 static struct device_connect_event {
51843 - atomic_t count;
51844 + atomic_unchecked_t count;
51845 wait_queue_head_t wait;
51846 } device_event = {
51847 .count = ATOMIC_INIT(1),
51848 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51849
51850 void usbfs_conn_disc_event(void)
51851 {
51852 - atomic_add(2, &device_event.count);
51853 + atomic_add_unchecked(2, &device_event.count);
51854 wake_up(&device_event.wait);
51855 }
51856
51857 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51858
51859 poll_wait(file, &device_event.wait, wait);
51860
51861 - event_count = atomic_read(&device_event.count);
51862 + event_count = atomic_read_unchecked(&device_event.count);
51863 if (file->f_version != event_count) {
51864 file->f_version = event_count;
51865 return POLLIN | POLLRDNORM;
51866 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51867 index 257876e..4304364 100644
51868 --- a/drivers/usb/core/devio.c
51869 +++ b/drivers/usb/core/devio.c
51870 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51871 struct usb_dev_state *ps = file->private_data;
51872 struct usb_device *dev = ps->dev;
51873 ssize_t ret = 0;
51874 - unsigned len;
51875 + size_t len;
51876 loff_t pos;
51877 int i;
51878
51879 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51880 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51881 struct usb_config_descriptor *config =
51882 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51883 - unsigned int length = le16_to_cpu(config->wTotalLength);
51884 + size_t length = le16_to_cpu(config->wTotalLength);
51885
51886 if (*ppos < pos + length) {
51887
51888 /* The descriptor may claim to be longer than it
51889 * really is. Here is the actual allocated length. */
51890 - unsigned alloclen =
51891 + size_t alloclen =
51892 le16_to_cpu(dev->config[i].desc.wTotalLength);
51893
51894 - len = length - (*ppos - pos);
51895 + len = length + pos - *ppos;
51896 if (len > nbytes)
51897 len = nbytes;
51898
51899 /* Simply don't write (skip over) unallocated parts */
51900 if (alloclen > (*ppos - pos)) {
51901 - alloclen -= (*ppos - pos);
51902 + alloclen = alloclen + pos - *ppos;
51903 if (copy_to_user(buf,
51904 dev->rawdescriptors[i] + (*ppos - pos),
51905 min(len, alloclen))) {
51906 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51907 index 9c4e292..b89877f 100644
51908 --- a/drivers/usb/core/hcd.c
51909 +++ b/drivers/usb/core/hcd.c
51910 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51911 */
51912 usb_get_urb(urb);
51913 atomic_inc(&urb->use_count);
51914 - atomic_inc(&urb->dev->urbnum);
51915 + atomic_inc_unchecked(&urb->dev->urbnum);
51916 usbmon_urb_submit(&hcd->self, urb);
51917
51918 /* NOTE requirements on root-hub callers (usbfs and the hub
51919 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51920 urb->hcpriv = NULL;
51921 INIT_LIST_HEAD(&urb->urb_list);
51922 atomic_dec(&urb->use_count);
51923 - atomic_dec(&urb->dev->urbnum);
51924 + atomic_dec_unchecked(&urb->dev->urbnum);
51925 if (atomic_read(&urb->reject))
51926 wake_up(&usb_kill_urb_queue);
51927 usb_put_urb(urb);
51928 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51929 index 229a73f..ef86f98 100644
51930 --- a/drivers/usb/core/hub.c
51931 +++ b/drivers/usb/core/hub.c
51932 @@ -27,6 +27,7 @@
51933 #include <linux/freezer.h>
51934 #include <linux/random.h>
51935 #include <linux/pm_qos.h>
51936 +#include <linux/grsecurity.h>
51937
51938 #include <asm/uaccess.h>
51939 #include <asm/byteorder.h>
51940 @@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51941 goto done;
51942 return;
51943 }
51944 +
51945 + if (gr_handle_new_usb())
51946 + goto done;
51947 +
51948 if (hub_is_superspeed(hub->hdev))
51949 unit_load = 150;
51950 else
51951 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51952 index 0c8a7fc..c45b40a 100644
51953 --- a/drivers/usb/core/message.c
51954 +++ b/drivers/usb/core/message.c
51955 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51956 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51957 * error number.
51958 */
51959 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51960 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51961 __u8 requesttype, __u16 value, __u16 index, void *data,
51962 __u16 size, int timeout)
51963 {
51964 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51965 * If successful, 0. Otherwise a negative error number. The number of actual
51966 * bytes transferred will be stored in the @actual_length parameter.
51967 */
51968 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51969 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51970 void *data, int len, int *actual_length, int timeout)
51971 {
51972 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51973 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51974 * bytes transferred will be stored in the @actual_length parameter.
51975 *
51976 */
51977 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51978 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51979 void *data, int len, int *actual_length, int timeout)
51980 {
51981 struct urb *urb;
51982 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51983 index 1236c60..d47a51c 100644
51984 --- a/drivers/usb/core/sysfs.c
51985 +++ b/drivers/usb/core/sysfs.c
51986 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51987 struct usb_device *udev;
51988
51989 udev = to_usb_device(dev);
51990 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51991 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51992 }
51993 static DEVICE_ATTR_RO(urbnum);
51994
51995 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51996 index 4d11449..f4ccabf 100644
51997 --- a/drivers/usb/core/usb.c
51998 +++ b/drivers/usb/core/usb.c
51999 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52000 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52001 dev->state = USB_STATE_ATTACHED;
52002 dev->lpm_disable_count = 1;
52003 - atomic_set(&dev->urbnum, 0);
52004 + atomic_set_unchecked(&dev->urbnum, 0);
52005
52006 INIT_LIST_HEAD(&dev->ep0.urb_list);
52007 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52008 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52009 index 85f398d..d375bbe 100644
52010 --- a/drivers/usb/dwc3/gadget.c
52011 +++ b/drivers/usb/dwc3/gadget.c
52012 @@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52013 if (!usb_endpoint_xfer_isoc(desc))
52014 return 0;
52015
52016 - memset(&trb_link, 0, sizeof(trb_link));
52017 -
52018 /* Link TRB for ISOC. The HWO bit is never reset */
52019 trb_st_hw = &dep->trb_pool[0];
52020
52021 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52022 index 8cfc319..4868255 100644
52023 --- a/drivers/usb/early/ehci-dbgp.c
52024 +++ b/drivers/usb/early/ehci-dbgp.c
52025 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52026
52027 #ifdef CONFIG_KGDB
52028 static struct kgdb_io kgdbdbgp_io_ops;
52029 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52030 +static struct kgdb_io kgdbdbgp_io_ops_console;
52031 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52032 #else
52033 #define dbgp_kgdb_mode (0)
52034 #endif
52035 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52036 .write_char = kgdbdbgp_write_char,
52037 };
52038
52039 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52040 + .name = "kgdbdbgp",
52041 + .read_char = kgdbdbgp_read_char,
52042 + .write_char = kgdbdbgp_write_char,
52043 + .is_console = 1
52044 +};
52045 +
52046 static int kgdbdbgp_wait_time;
52047
52048 static int __init kgdbdbgp_parse_config(char *str)
52049 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52050 ptr++;
52051 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52052 }
52053 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52054 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52055 + if (early_dbgp_console.index != -1)
52056 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52057 + else
52058 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52059
52060 return 0;
52061 }
52062 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52063 index 2b4c82d..06a8ee6 100644
52064 --- a/drivers/usb/gadget/f_uac1.c
52065 +++ b/drivers/usb/gadget/f_uac1.c
52066 @@ -13,6 +13,7 @@
52067 #include <linux/kernel.h>
52068 #include <linux/device.h>
52069 #include <linux/atomic.h>
52070 +#include <linux/module.h>
52071
52072 #include "u_uac1.h"
52073
52074 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52075 index ad0aca8..8ff84865 100644
52076 --- a/drivers/usb/gadget/u_serial.c
52077 +++ b/drivers/usb/gadget/u_serial.c
52078 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52079 spin_lock_irq(&port->port_lock);
52080
52081 /* already open? Great. */
52082 - if (port->port.count) {
52083 + if (atomic_read(&port->port.count)) {
52084 status = 0;
52085 - port->port.count++;
52086 + atomic_inc(&port->port.count);
52087
52088 /* currently opening/closing? wait ... */
52089 } else if (port->openclose) {
52090 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52091 tty->driver_data = port;
52092 port->port.tty = tty;
52093
52094 - port->port.count = 1;
52095 + atomic_set(&port->port.count, 1);
52096 port->openclose = false;
52097
52098 /* if connected, start the I/O stream */
52099 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52100
52101 spin_lock_irq(&port->port_lock);
52102
52103 - if (port->port.count != 1) {
52104 - if (port->port.count == 0)
52105 + if (atomic_read(&port->port.count) != 1) {
52106 + if (atomic_read(&port->port.count) == 0)
52107 WARN_ON(1);
52108 else
52109 - --port->port.count;
52110 + atomic_dec(&port->port.count);
52111 goto exit;
52112 }
52113
52114 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52115 * and sleep if necessary
52116 */
52117 port->openclose = true;
52118 - port->port.count = 0;
52119 + atomic_set(&port->port.count, 0);
52120
52121 gser = port->port_usb;
52122 if (gser && gser->disconnect)
52123 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52124 int cond;
52125
52126 spin_lock_irq(&port->port_lock);
52127 - cond = (port->port.count == 0) && !port->openclose;
52128 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52129 spin_unlock_irq(&port->port_lock);
52130 return cond;
52131 }
52132 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52133 /* if it's already open, start I/O ... and notify the serial
52134 * protocol about open/close status (connect/disconnect).
52135 */
52136 - if (port->port.count) {
52137 + if (atomic_read(&port->port.count)) {
52138 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52139 gs_start_io(port);
52140 if (gser->connect)
52141 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52142
52143 port->port_usb = NULL;
52144 gser->ioport = NULL;
52145 - if (port->port.count > 0 || port->openclose) {
52146 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52147 wake_up_interruptible(&port->drain_wait);
52148 if (port->port.tty)
52149 tty_hangup(port->port.tty);
52150 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52151
52152 /* finally, free any unused/unusable I/O buffers */
52153 spin_lock_irqsave(&port->port_lock, flags);
52154 - if (port->port.count == 0 && !port->openclose)
52155 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52156 gs_buf_free(&port->port_write_buf);
52157 gs_free_requests(gser->out, &port->read_pool, NULL);
52158 gs_free_requests(gser->out, &port->read_queue, NULL);
52159 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52160 index 7a55fea..cc0ed4f 100644
52161 --- a/drivers/usb/gadget/u_uac1.c
52162 +++ b/drivers/usb/gadget/u_uac1.c
52163 @@ -16,6 +16,7 @@
52164 #include <linux/ctype.h>
52165 #include <linux/random.h>
52166 #include <linux/syscalls.h>
52167 +#include <linux/module.h>
52168
52169 #include "u_uac1.h"
52170
52171 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52172 index 7ae0c4d..35521b7 100644
52173 --- a/drivers/usb/host/ehci-hub.c
52174 +++ b/drivers/usb/host/ehci-hub.c
52175 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52176 urb->transfer_flags = URB_DIR_IN;
52177 usb_get_urb(urb);
52178 atomic_inc(&urb->use_count);
52179 - atomic_inc(&urb->dev->urbnum);
52180 + atomic_inc_unchecked(&urb->dev->urbnum);
52181 urb->setup_dma = dma_map_single(
52182 hcd->self.controller,
52183 urb->setup_packet,
52184 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52185 urb->status = -EINPROGRESS;
52186 usb_get_urb(urb);
52187 atomic_inc(&urb->use_count);
52188 - atomic_inc(&urb->dev->urbnum);
52189 + atomic_inc_unchecked(&urb->dev->urbnum);
52190 retval = submit_single_step_set_feature(hcd, urb, 0);
52191 if (!retval && !wait_for_completion_timeout(&done,
52192 msecs_to_jiffies(2000))) {
52193 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52194 index ba6a5d6..f88f7f3 100644
52195 --- a/drivers/usb/misc/appledisplay.c
52196 +++ b/drivers/usb/misc/appledisplay.c
52197 @@ -83,7 +83,7 @@ struct appledisplay {
52198 spinlock_t lock;
52199 };
52200
52201 -static atomic_t count_displays = ATOMIC_INIT(0);
52202 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52203 static struct workqueue_struct *wq;
52204
52205 static void appledisplay_complete(struct urb *urb)
52206 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52207
52208 /* Register backlight device */
52209 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52210 - atomic_inc_return(&count_displays) - 1);
52211 + atomic_inc_return_unchecked(&count_displays) - 1);
52212 memset(&props, 0, sizeof(struct backlight_properties));
52213 props.type = BACKLIGHT_RAW;
52214 props.max_brightness = 0xff;
52215 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52216 index 8d7fc48..01c4986 100644
52217 --- a/drivers/usb/serial/console.c
52218 +++ b/drivers/usb/serial/console.c
52219 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52220
52221 info->port = port;
52222
52223 - ++port->port.count;
52224 + atomic_inc(&port->port.count);
52225 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52226 if (serial->type->set_termios) {
52227 /*
52228 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52229 }
52230 /* Now that any required fake tty operations are completed restore
52231 * the tty port count */
52232 - --port->port.count;
52233 + atomic_dec(&port->port.count);
52234 /* The console is special in terms of closing the device so
52235 * indicate this port is now acting as a system console. */
52236 port->port.console = 1;
52237 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52238 free_tty:
52239 kfree(tty);
52240 reset_open_count:
52241 - port->port.count = 0;
52242 + atomic_set(&port->port.count, 0);
52243 usb_autopm_put_interface(serial->interface);
52244 error_get_interface:
52245 usb_serial_put(serial);
52246 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52247 static void usb_console_write(struct console *co,
52248 const char *buf, unsigned count)
52249 {
52250 - static struct usbcons_info *info = &usbcons_info;
52251 + struct usbcons_info *info = &usbcons_info;
52252 struct usb_serial_port *port = info->port;
52253 struct usb_serial *serial;
52254 int retval = -ENODEV;
52255 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52256 index 307e339..6aa97cb 100644
52257 --- a/drivers/usb/storage/usb.h
52258 +++ b/drivers/usb/storage/usb.h
52259 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52260 __u8 useProtocol;
52261 __u8 useTransport;
52262 int (*initFunction)(struct us_data *);
52263 -};
52264 +} __do_const;
52265
52266
52267 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52268 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52269 index f2a8d29..7bc3fe7 100644
52270 --- a/drivers/usb/wusbcore/wa-hc.h
52271 +++ b/drivers/usb/wusbcore/wa-hc.h
52272 @@ -240,7 +240,7 @@ struct wahc {
52273 spinlock_t xfer_list_lock;
52274 struct work_struct xfer_enqueue_work;
52275 struct work_struct xfer_error_work;
52276 - atomic_t xfer_id_count;
52277 + atomic_unchecked_t xfer_id_count;
52278
52279 kernel_ulong_t quirks;
52280 };
52281 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52282 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52283 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52284 wa->dto_in_use = 0;
52285 - atomic_set(&wa->xfer_id_count, 1);
52286 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52287 /* init the buf in URBs */
52288 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52289 usb_init_urb(&(wa->buf_in_urbs[index]));
52290 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52291 index 3e2e4ed..060c9b8 100644
52292 --- a/drivers/usb/wusbcore/wa-xfer.c
52293 +++ b/drivers/usb/wusbcore/wa-xfer.c
52294 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52295 */
52296 static void wa_xfer_id_init(struct wa_xfer *xfer)
52297 {
52298 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52299 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52300 }
52301
52302 /* Return the xfer's ID. */
52303 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52304 index 512f479..7e041d0 100644
52305 --- a/drivers/vfio/vfio.c
52306 +++ b/drivers/vfio/vfio.c
52307 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52308 return 0;
52309
52310 /* TODO Prevent device auto probing */
52311 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52312 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52313 iommu_group_id(group->iommu_group));
52314
52315 return 0;
52316 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52317 index 5174eba..451e6bc 100644
52318 --- a/drivers/vhost/vringh.c
52319 +++ b/drivers/vhost/vringh.c
52320 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52321 /* Userspace access helpers: in this case, addresses are really userspace. */
52322 static inline int getu16_user(u16 *val, const u16 *p)
52323 {
52324 - return get_user(*val, (__force u16 __user *)p);
52325 + return get_user(*val, (u16 __force_user *)p);
52326 }
52327
52328 static inline int putu16_user(u16 *p, u16 val)
52329 {
52330 - return put_user(val, (__force u16 __user *)p);
52331 + return put_user(val, (u16 __force_user *)p);
52332 }
52333
52334 static inline int copydesc_user(void *dst, const void *src, size_t len)
52335 {
52336 - return copy_from_user(dst, (__force void __user *)src, len) ?
52337 + return copy_from_user(dst, (void __force_user *)src, len) ?
52338 -EFAULT : 0;
52339 }
52340
52341 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52342 const struct vring_used_elem *src,
52343 unsigned int num)
52344 {
52345 - return copy_to_user((__force void __user *)dst, src,
52346 + return copy_to_user((void __force_user *)dst, src,
52347 sizeof(*dst) * num) ? -EFAULT : 0;
52348 }
52349
52350 static inline int xfer_from_user(void *src, void *dst, size_t len)
52351 {
52352 - return copy_from_user(dst, (__force void __user *)src, len) ?
52353 + return copy_from_user(dst, (void __force_user *)src, len) ?
52354 -EFAULT : 0;
52355 }
52356
52357 static inline int xfer_to_user(void *dst, void *src, size_t len)
52358 {
52359 - return copy_to_user((__force void __user *)dst, src, len) ?
52360 + return copy_to_user((void __force_user *)dst, src, len) ?
52361 -EFAULT : 0;
52362 }
52363
52364 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52365 vrh->last_used_idx = 0;
52366 vrh->vring.num = num;
52367 /* vring expects kernel addresses, but only used via accessors. */
52368 - vrh->vring.desc = (__force struct vring_desc *)desc;
52369 - vrh->vring.avail = (__force struct vring_avail *)avail;
52370 - vrh->vring.used = (__force struct vring_used *)used;
52371 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52372 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52373 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52374 return 0;
52375 }
52376 EXPORT_SYMBOL(vringh_init_user);
52377 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52378
52379 static inline int putu16_kern(u16 *p, u16 val)
52380 {
52381 - ACCESS_ONCE(*p) = val;
52382 + ACCESS_ONCE_RW(*p) = val;
52383 return 0;
52384 }
52385
52386 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52387 index 84a110a..96312c3 100644
52388 --- a/drivers/video/backlight/kb3886_bl.c
52389 +++ b/drivers/video/backlight/kb3886_bl.c
52390 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52391 static unsigned long kb3886bl_flags;
52392 #define KB3886BL_SUSPENDED 0x01
52393
52394 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52395 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52396 {
52397 .ident = "Sahara Touch-iT",
52398 .matches = {
52399 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52400 index 1b0b233..6f34c2c 100644
52401 --- a/drivers/video/fbdev/arcfb.c
52402 +++ b/drivers/video/fbdev/arcfb.c
52403 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52404 return -ENOSPC;
52405
52406 err = 0;
52407 - if ((count + p) > fbmemlength) {
52408 + if (count > (fbmemlength - p)) {
52409 count = fbmemlength - p;
52410 err = -ENOSPC;
52411 }
52412 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52413 index 52108be..c7c110d 100644
52414 --- a/drivers/video/fbdev/aty/aty128fb.c
52415 +++ b/drivers/video/fbdev/aty/aty128fb.c
52416 @@ -149,7 +149,7 @@ enum {
52417 };
52418
52419 /* Must match above enum */
52420 -static char * const r128_family[] = {
52421 +static const char * const r128_family[] = {
52422 "AGP",
52423 "PCI",
52424 "PRO AGP",
52425 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52426 index c3d0074..0b9077e 100644
52427 --- a/drivers/video/fbdev/aty/atyfb_base.c
52428 +++ b/drivers/video/fbdev/aty/atyfb_base.c
52429 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52430 par->accel_flags = var->accel_flags; /* hack */
52431
52432 if (var->accel_flags) {
52433 - info->fbops->fb_sync = atyfb_sync;
52434 + pax_open_kernel();
52435 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52436 + pax_close_kernel();
52437 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52438 } else {
52439 - info->fbops->fb_sync = NULL;
52440 + pax_open_kernel();
52441 + *(void **)&info->fbops->fb_sync = NULL;
52442 + pax_close_kernel();
52443 info->flags |= FBINFO_HWACCEL_DISABLED;
52444 }
52445
52446 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52447 index 2fa0317..4983f2a 100644
52448 --- a/drivers/video/fbdev/aty/mach64_cursor.c
52449 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
52450 @@ -8,6 +8,7 @@
52451 #include "../core/fb_draw.h"
52452
52453 #include <asm/io.h>
52454 +#include <asm/pgtable.h>
52455
52456 #ifdef __sparc__
52457 #include <asm/fbio.h>
52458 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52459 info->sprite.buf_align = 16; /* and 64 lines tall. */
52460 info->sprite.flags = FB_PIXMAP_IO;
52461
52462 - info->fbops->fb_cursor = atyfb_cursor;
52463 + pax_open_kernel();
52464 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52465 + pax_close_kernel();
52466
52467 return 0;
52468 }
52469 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52470 index 900aa4e..6d49418 100644
52471 --- a/drivers/video/fbdev/core/fb_defio.c
52472 +++ b/drivers/video/fbdev/core/fb_defio.c
52473 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52474
52475 BUG_ON(!fbdefio);
52476 mutex_init(&fbdefio->lock);
52477 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52478 + pax_open_kernel();
52479 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52480 + pax_close_kernel();
52481 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52482 INIT_LIST_HEAD(&fbdefio->pagelist);
52483 if (fbdefio->delay == 0) /* set a default of 1 s */
52484 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52485 page->mapping = NULL;
52486 }
52487
52488 - info->fbops->fb_mmap = NULL;
52489 + *(void **)&info->fbops->fb_mmap = NULL;
52490 mutex_destroy(&fbdefio->lock);
52491 }
52492 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52493 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52494 index b6d5008..5bca7bf 100644
52495 --- a/drivers/video/fbdev/core/fbmem.c
52496 +++ b/drivers/video/fbdev/core/fbmem.c
52497 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52498 image->dx += image->width + 8;
52499 }
52500 } else if (rotate == FB_ROTATE_UD) {
52501 - for (x = 0; x < num && image->dx >= 0; x++) {
52502 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52503 info->fbops->fb_imageblit(info, image);
52504 image->dx -= image->width + 8;
52505 }
52506 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52507 image->dy += image->height + 8;
52508 }
52509 } else if (rotate == FB_ROTATE_CCW) {
52510 - for (x = 0; x < num && image->dy >= 0; x++) {
52511 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52512 info->fbops->fb_imageblit(info, image);
52513 image->dy -= image->height + 8;
52514 }
52515 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52516 return -EFAULT;
52517 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52518 return -EINVAL;
52519 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52520 + if (con2fb.framebuffer >= FB_MAX)
52521 return -EINVAL;
52522 if (!registered_fb[con2fb.framebuffer])
52523 request_module("fb%d", con2fb.framebuffer);
52524 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52525 __u32 data;
52526 int err;
52527
52528 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52529 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52530
52531 data = (__u32) (unsigned long) fix->smem_start;
52532 err |= put_user(data, &fix32->smem_start);
52533 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52534 index e23392e..8a77540 100644
52535 --- a/drivers/video/fbdev/hyperv_fb.c
52536 +++ b/drivers/video/fbdev/hyperv_fb.c
52537 @@ -235,7 +235,7 @@ static uint screen_fb_size;
52538 static inline int synthvid_send(struct hv_device *hdev,
52539 struct synthvid_msg *msg)
52540 {
52541 - static atomic64_t request_id = ATOMIC64_INIT(0);
52542 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52543 int ret;
52544
52545 msg->pipe_hdr.type = PIPE_MSG_DATA;
52546 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52547
52548 ret = vmbus_sendpacket(hdev->channel, msg,
52549 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52550 - atomic64_inc_return(&request_id),
52551 + atomic64_inc_return_unchecked(&request_id),
52552 VM_PKT_DATA_INBAND, 0);
52553
52554 if (ret)
52555 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52556 index 7672d2e..b56437f 100644
52557 --- a/drivers/video/fbdev/i810/i810_accel.c
52558 +++ b/drivers/video/fbdev/i810/i810_accel.c
52559 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52560 }
52561 }
52562 printk("ringbuffer lockup!!!\n");
52563 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52564 i810_report_error(mmio);
52565 par->dev_flags |= LOCKUP;
52566 info->pixmap.scan_align = 1;
52567 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52568 index a01147f..5d896f8 100644
52569 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52570 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52571 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52572
52573 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52574 struct matrox_switch matrox_mystique = {
52575 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52576 + .preinit = MGA1064_preinit,
52577 + .reset = MGA1064_reset,
52578 + .init = MGA1064_init,
52579 + .restore = MGA1064_restore,
52580 };
52581 EXPORT_SYMBOL(matrox_mystique);
52582 #endif
52583
52584 #ifdef CONFIG_FB_MATROX_G
52585 struct matrox_switch matrox_G100 = {
52586 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52587 + .preinit = MGAG100_preinit,
52588 + .reset = MGAG100_reset,
52589 + .init = MGAG100_init,
52590 + .restore = MGAG100_restore,
52591 };
52592 EXPORT_SYMBOL(matrox_G100);
52593 #endif
52594 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52595 index 195ad7c..09743fc 100644
52596 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52597 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52598 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52599 }
52600
52601 struct matrox_switch matrox_millennium = {
52602 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52603 + .preinit = Ti3026_preinit,
52604 + .reset = Ti3026_reset,
52605 + .init = Ti3026_init,
52606 + .restore = Ti3026_restore
52607 };
52608 EXPORT_SYMBOL(matrox_millennium);
52609 #endif
52610 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52611 index fe92eed..106e085 100644
52612 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52613 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52614 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52615 struct mb862xxfb_par *par = info->par;
52616
52617 if (info->var.bits_per_pixel == 32) {
52618 - info->fbops->fb_fillrect = cfb_fillrect;
52619 - info->fbops->fb_copyarea = cfb_copyarea;
52620 - info->fbops->fb_imageblit = cfb_imageblit;
52621 + pax_open_kernel();
52622 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52623 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52624 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52625 + pax_close_kernel();
52626 } else {
52627 outreg(disp, GC_L0EM, 3);
52628 - info->fbops->fb_fillrect = mb86290fb_fillrect;
52629 - info->fbops->fb_copyarea = mb86290fb_copyarea;
52630 - info->fbops->fb_imageblit = mb86290fb_imageblit;
52631 + pax_open_kernel();
52632 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52633 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52634 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52635 + pax_close_kernel();
52636 }
52637 outreg(draw, GDC_REG_DRAW_BASE, 0);
52638 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52639 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
52640 index def0412..fed6529 100644
52641 --- a/drivers/video/fbdev/nvidia/nvidia.c
52642 +++ b/drivers/video/fbdev/nvidia/nvidia.c
52643 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52644 info->fix.line_length = (info->var.xres_virtual *
52645 info->var.bits_per_pixel) >> 3;
52646 if (info->var.accel_flags) {
52647 - info->fbops->fb_imageblit = nvidiafb_imageblit;
52648 - info->fbops->fb_fillrect = nvidiafb_fillrect;
52649 - info->fbops->fb_copyarea = nvidiafb_copyarea;
52650 - info->fbops->fb_sync = nvidiafb_sync;
52651 + pax_open_kernel();
52652 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52653 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52654 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52655 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52656 + pax_close_kernel();
52657 info->pixmap.scan_align = 4;
52658 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52659 info->flags |= FBINFO_READS_FAST;
52660 NVResetGraphics(info);
52661 } else {
52662 - info->fbops->fb_imageblit = cfb_imageblit;
52663 - info->fbops->fb_fillrect = cfb_fillrect;
52664 - info->fbops->fb_copyarea = cfb_copyarea;
52665 - info->fbops->fb_sync = NULL;
52666 + pax_open_kernel();
52667 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52668 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52669 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52670 + *(void **)&info->fbops->fb_sync = NULL;
52671 + pax_close_kernel();
52672 info->pixmap.scan_align = 1;
52673 info->flags |= FBINFO_HWACCEL_DISABLED;
52674 info->flags &= ~FBINFO_READS_FAST;
52675 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52676 info->pixmap.size = 8 * 1024;
52677 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52678
52679 - if (!hwcur)
52680 - info->fbops->fb_cursor = NULL;
52681 + if (!hwcur) {
52682 + pax_open_kernel();
52683 + *(void **)&info->fbops->fb_cursor = NULL;
52684 + pax_close_kernel();
52685 + }
52686
52687 info->var.accel_flags = (!noaccel);
52688
52689 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
52690 index 2412a0d..294215b 100644
52691 --- a/drivers/video/fbdev/omap2/dss/display.c
52692 +++ b/drivers/video/fbdev/omap2/dss/display.c
52693 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52694 if (dssdev->name == NULL)
52695 dssdev->name = dssdev->alias;
52696
52697 + pax_open_kernel();
52698 if (drv && drv->get_resolution == NULL)
52699 - drv->get_resolution = omapdss_default_get_resolution;
52700 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52701 if (drv && drv->get_recommended_bpp == NULL)
52702 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52703 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52704 if (drv && drv->get_timings == NULL)
52705 - drv->get_timings = omapdss_default_get_timings;
52706 + *(void **)&drv->get_timings = omapdss_default_get_timings;
52707 + pax_close_kernel();
52708
52709 mutex_lock(&panel_list_mutex);
52710 list_add_tail(&dssdev->panel_list, &panel_list);
52711 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
52712 index 83433cb..71e9b98 100644
52713 --- a/drivers/video/fbdev/s1d13xxxfb.c
52714 +++ b/drivers/video/fbdev/s1d13xxxfb.c
52715 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52716
52717 switch(prod_id) {
52718 case S1D13506_PROD_ID: /* activate acceleration */
52719 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52720 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52721 + pax_open_kernel();
52722 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52723 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52724 + pax_close_kernel();
52725 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52726 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52727 break;
52728 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52729 index 2bcc84a..29dd1ea 100644
52730 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
52731 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52732 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
52733 }
52734
52735 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
52736 - lcdc_sys_write_index,
52737 - lcdc_sys_write_data,
52738 - lcdc_sys_read_data,
52739 + .write_index = lcdc_sys_write_index,
52740 + .write_data = lcdc_sys_write_data,
52741 + .read_data = lcdc_sys_read_data,
52742 };
52743
52744 static int sh_mobile_lcdc_sginit(struct fb_info *info,
52745 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
52746 index d513ed6..90b0de9 100644
52747 --- a/drivers/video/fbdev/smscufx.c
52748 +++ b/drivers/video/fbdev/smscufx.c
52749 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52750 fb_deferred_io_cleanup(info);
52751 kfree(info->fbdefio);
52752 info->fbdefio = NULL;
52753 - info->fbops->fb_mmap = ufx_ops_mmap;
52754 + pax_open_kernel();
52755 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52756 + pax_close_kernel();
52757 }
52758
52759 pr_debug("released /dev/fb%d user=%d count=%d",
52760 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
52761 index 77b890e..458e666 100644
52762 --- a/drivers/video/fbdev/udlfb.c
52763 +++ b/drivers/video/fbdev/udlfb.c
52764 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52765 dlfb_urb_completion(urb);
52766
52767 error:
52768 - atomic_add(bytes_sent, &dev->bytes_sent);
52769 - atomic_add(bytes_identical, &dev->bytes_identical);
52770 - atomic_add(width*height*2, &dev->bytes_rendered);
52771 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52772 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52773 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52774 end_cycles = get_cycles();
52775 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
52776 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52777 >> 10)), /* Kcycles */
52778 &dev->cpu_kcycles_used);
52779
52780 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52781 dlfb_urb_completion(urb);
52782
52783 error:
52784 - atomic_add(bytes_sent, &dev->bytes_sent);
52785 - atomic_add(bytes_identical, &dev->bytes_identical);
52786 - atomic_add(bytes_rendered, &dev->bytes_rendered);
52787 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52788 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52789 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52790 end_cycles = get_cycles();
52791 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
52792 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52793 >> 10)), /* Kcycles */
52794 &dev->cpu_kcycles_used);
52795 }
52796 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52797 fb_deferred_io_cleanup(info);
52798 kfree(info->fbdefio);
52799 info->fbdefio = NULL;
52800 - info->fbops->fb_mmap = dlfb_ops_mmap;
52801 + pax_open_kernel();
52802 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52803 + pax_close_kernel();
52804 }
52805
52806 pr_warn("released /dev/fb%d user=%d count=%d\n",
52807 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52808 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52809 struct dlfb_data *dev = fb_info->par;
52810 return snprintf(buf, PAGE_SIZE, "%u\n",
52811 - atomic_read(&dev->bytes_rendered));
52812 + atomic_read_unchecked(&dev->bytes_rendered));
52813 }
52814
52815 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52816 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52817 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52818 struct dlfb_data *dev = fb_info->par;
52819 return snprintf(buf, PAGE_SIZE, "%u\n",
52820 - atomic_read(&dev->bytes_identical));
52821 + atomic_read_unchecked(&dev->bytes_identical));
52822 }
52823
52824 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52825 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52826 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52827 struct dlfb_data *dev = fb_info->par;
52828 return snprintf(buf, PAGE_SIZE, "%u\n",
52829 - atomic_read(&dev->bytes_sent));
52830 + atomic_read_unchecked(&dev->bytes_sent));
52831 }
52832
52833 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52834 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52835 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52836 struct dlfb_data *dev = fb_info->par;
52837 return snprintf(buf, PAGE_SIZE, "%u\n",
52838 - atomic_read(&dev->cpu_kcycles_used));
52839 + atomic_read_unchecked(&dev->cpu_kcycles_used));
52840 }
52841
52842 static ssize_t edid_show(
52843 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52844 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52845 struct dlfb_data *dev = fb_info->par;
52846
52847 - atomic_set(&dev->bytes_rendered, 0);
52848 - atomic_set(&dev->bytes_identical, 0);
52849 - atomic_set(&dev->bytes_sent, 0);
52850 - atomic_set(&dev->cpu_kcycles_used, 0);
52851 + atomic_set_unchecked(&dev->bytes_rendered, 0);
52852 + atomic_set_unchecked(&dev->bytes_identical, 0);
52853 + atomic_set_unchecked(&dev->bytes_sent, 0);
52854 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52855
52856 return count;
52857 }
52858 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
52859 index 509d452..7c9d2de 100644
52860 --- a/drivers/video/fbdev/uvesafb.c
52861 +++ b/drivers/video/fbdev/uvesafb.c
52862 @@ -19,6 +19,7 @@
52863 #include <linux/io.h>
52864 #include <linux/mutex.h>
52865 #include <linux/slab.h>
52866 +#include <linux/moduleloader.h>
52867 #include <video/edid.h>
52868 #include <video/uvesafb.h>
52869 #ifdef CONFIG_X86
52870 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52871 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52872 par->pmi_setpal = par->ypan = 0;
52873 } else {
52874 +
52875 +#ifdef CONFIG_PAX_KERNEXEC
52876 +#ifdef CONFIG_MODULES
52877 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52878 +#endif
52879 + if (!par->pmi_code) {
52880 + par->pmi_setpal = par->ypan = 0;
52881 + return 0;
52882 + }
52883 +#endif
52884 +
52885 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52886 + task->t.regs.edi);
52887 +
52888 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52889 + pax_open_kernel();
52890 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52891 + pax_close_kernel();
52892 +
52893 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52894 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52895 +#else
52896 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52897 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52898 +#endif
52899 +
52900 printk(KERN_INFO "uvesafb: protected mode interface info at "
52901 "%04x:%04x\n",
52902 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52903 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52904 par->ypan = ypan;
52905
52906 if (par->pmi_setpal || par->ypan) {
52907 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52908 if (__supported_pte_mask & _PAGE_NX) {
52909 par->pmi_setpal = par->ypan = 0;
52910 printk(KERN_WARNING "uvesafb: NX protection is active, "
52911 "better not use the PMI.\n");
52912 - } else {
52913 + } else
52914 +#endif
52915 uvesafb_vbe_getpmi(task, par);
52916 - }
52917 }
52918 #else
52919 /* The protected mode interface is not available on non-x86. */
52920 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52921 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52922
52923 /* Disable blanking if the user requested so. */
52924 - if (!blank)
52925 - info->fbops->fb_blank = NULL;
52926 + if (!blank) {
52927 + pax_open_kernel();
52928 + *(void **)&info->fbops->fb_blank = NULL;
52929 + pax_close_kernel();
52930 + }
52931
52932 /*
52933 * Find out how much IO memory is required for the mode with
52934 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52935 info->flags = FBINFO_FLAG_DEFAULT |
52936 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52937
52938 - if (!par->ypan)
52939 - info->fbops->fb_pan_display = NULL;
52940 + if (!par->ypan) {
52941 + pax_open_kernel();
52942 + *(void **)&info->fbops->fb_pan_display = NULL;
52943 + pax_close_kernel();
52944 + }
52945 }
52946
52947 static void uvesafb_init_mtrr(struct fb_info *info)
52948 @@ -1787,6 +1817,11 @@ out_mode:
52949 out:
52950 kfree(par->vbe_modes);
52951
52952 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52953 + if (par->pmi_code)
52954 + module_free_exec(NULL, par->pmi_code);
52955 +#endif
52956 +
52957 framebuffer_release(info);
52958 return err;
52959 }
52960 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
52961 kfree(par->vbe_state_orig);
52962 kfree(par->vbe_state_saved);
52963
52964 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52965 + if (par->pmi_code)
52966 + module_free_exec(NULL, par->pmi_code);
52967 +#endif
52968 +
52969 framebuffer_release(info);
52970 }
52971 return 0;
52972 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
52973 index 6170e7f..dd63031 100644
52974 --- a/drivers/video/fbdev/vesafb.c
52975 +++ b/drivers/video/fbdev/vesafb.c
52976 @@ -9,6 +9,7 @@
52977 */
52978
52979 #include <linux/module.h>
52980 +#include <linux/moduleloader.h>
52981 #include <linux/kernel.h>
52982 #include <linux/errno.h>
52983 #include <linux/string.h>
52984 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
52985 static int vram_total; /* Set total amount of memory */
52986 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52987 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52988 -static void (*pmi_start)(void) __read_mostly;
52989 -static void (*pmi_pal) (void) __read_mostly;
52990 +static void (*pmi_start)(void) __read_only;
52991 +static void (*pmi_pal) (void) __read_only;
52992 static int depth __read_mostly;
52993 static int vga_compat __read_mostly;
52994 /* --------------------------------------------------------------------- */
52995 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
52996 unsigned int size_remap;
52997 unsigned int size_total;
52998 char *option = NULL;
52999 + void *pmi_code = NULL;
53000
53001 /* ignore error return of fb_get_options */
53002 fb_get_options("vesafb", &option);
53003 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53004 size_remap = size_total;
53005 vesafb_fix.smem_len = size_remap;
53006
53007 -#ifndef __i386__
53008 - screen_info.vesapm_seg = 0;
53009 -#endif
53010 -
53011 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53012 printk(KERN_WARNING
53013 "vesafb: cannot reserve video memory at 0x%lx\n",
53014 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53015 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53016 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53017
53018 +#ifdef __i386__
53019 +
53020 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53021 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
53022 + if (!pmi_code)
53023 +#elif !defined(CONFIG_PAX_KERNEXEC)
53024 + if (0)
53025 +#endif
53026 +
53027 +#endif
53028 + screen_info.vesapm_seg = 0;
53029 +
53030 if (screen_info.vesapm_seg) {
53031 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53032 - screen_info.vesapm_seg,screen_info.vesapm_off);
53033 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53034 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53035 }
53036
53037 if (screen_info.vesapm_seg < 0xc000)
53038 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53039
53040 if (ypan || pmi_setpal) {
53041 unsigned short *pmi_base;
53042 +
53043 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53044 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53045 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53046 +
53047 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53048 + pax_open_kernel();
53049 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53050 +#else
53051 + pmi_code = pmi_base;
53052 +#endif
53053 +
53054 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53055 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53056 +
53057 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53058 + pmi_start = ktva_ktla(pmi_start);
53059 + pmi_pal = ktva_ktla(pmi_pal);
53060 + pax_close_kernel();
53061 +#endif
53062 +
53063 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53064 if (pmi_base[3]) {
53065 printk(KERN_INFO "vesafb: pmi: ports = ");
53066 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53067 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53068 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53069
53070 - if (!ypan)
53071 - info->fbops->fb_pan_display = NULL;
53072 + if (!ypan) {
53073 + pax_open_kernel();
53074 + *(void **)&info->fbops->fb_pan_display = NULL;
53075 + pax_close_kernel();
53076 + }
53077
53078 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53079 err = -ENOMEM;
53080 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53081 fb_info(info, "%s frame buffer device\n", info->fix.id);
53082 return 0;
53083 err:
53084 +
53085 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53086 + module_free_exec(NULL, pmi_code);
53087 +#endif
53088 +
53089 if (info->screen_base)
53090 iounmap(info->screen_base);
53091 framebuffer_release(info);
53092 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53093 index 88714ae..16c2e11 100644
53094 --- a/drivers/video/fbdev/via/via_clock.h
53095 +++ b/drivers/video/fbdev/via/via_clock.h
53096 @@ -56,7 +56,7 @@ struct via_clock {
53097
53098 void (*set_engine_pll_state)(u8 state);
53099 void (*set_engine_pll)(struct via_pll_config config);
53100 -};
53101 +} __no_const;
53102
53103
53104 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53105 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53106 index 3c14e43..2630570 100644
53107 --- a/drivers/video/logo/logo_linux_clut224.ppm
53108 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53109 @@ -2,1603 +2,1123 @@ P3
53110 # Standard 224-color Linux logo
53111 80 80
53112 255
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 0 0 0
53115 - 0 0 0 0 0 0 0 0 0 0 0 0
53116 - 0 0 0 0 0 0 0 0 0 0 0 0
53117 - 0 0 0 0 0 0 0 0 0 0 0 0
53118 - 0 0 0 0 0 0 0 0 0 0 0 0
53119 - 0 0 0 0 0 0 0 0 0 0 0 0
53120 - 0 0 0 0 0 0 0 0 0 0 0 0
53121 - 0 0 0 0 0 0 0 0 0 0 0 0
53122 - 6 6 6 6 6 6 10 10 10 10 10 10
53123 - 10 10 10 6 6 6 6 6 6 6 6 6
53124 - 0 0 0 0 0 0 0 0 0 0 0 0
53125 - 0 0 0 0 0 0 0 0 0 0 0 0
53126 - 0 0 0 0 0 0 0 0 0 0 0 0
53127 - 0 0 0 0 0 0 0 0 0 0 0 0
53128 - 0 0 0 0 0 0 0 0 0 0 0 0
53129 - 0 0 0 0 0 0 0 0 0 0 0 0
53130 - 0 0 0 0 0 0 0 0 0 0 0 0
53131 - 0 0 0 0 0 0 0 0 0 0 0 0
53132 - 0 0 0 0 0 0 0 0 0 0 0 0
53133 - 0 0 0 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 0 0 0 0 0 0
53135 - 0 0 0 0 0 0 0 0 0 0 0 0
53136 - 0 0 0 0 0 0 0 0 0 0 0 0
53137 - 0 0 0 0 0 0 0 0 0 0 0 0
53138 - 0 0 0 0 0 0 0 0 0 0 0 0
53139 - 0 0 0 0 0 0 0 0 0 0 0 0
53140 - 0 0 0 0 0 0 0 0 0 0 0 0
53141 - 0 0 0 6 6 6 10 10 10 14 14 14
53142 - 22 22 22 26 26 26 30 30 30 34 34 34
53143 - 30 30 30 30 30 30 26 26 26 18 18 18
53144 - 14 14 14 10 10 10 6 6 6 0 0 0
53145 - 0 0 0 0 0 0 0 0 0 0 0 0
53146 - 0 0 0 0 0 0 0 0 0 0 0 0
53147 - 0 0 0 0 0 0 0 0 0 0 0 0
53148 - 0 0 0 0 0 0 0 0 0 0 0 0
53149 - 0 0 0 0 0 0 0 0 0 0 0 0
53150 - 0 0 0 0 0 0 0 0 0 0 0 0
53151 - 0 0 0 0 0 0 0 0 0 0 0 0
53152 - 0 0 0 0 0 0 0 0 0 0 0 0
53153 - 0 0 0 0 0 0 0 0 0 0 0 0
53154 - 0 0 0 0 0 1 0 0 1 0 0 0
53155 - 0 0 0 0 0 0 0 0 0 0 0 0
53156 - 0 0 0 0 0 0 0 0 0 0 0 0
53157 - 0 0 0 0 0 0 0 0 0 0 0 0
53158 - 0 0 0 0 0 0 0 0 0 0 0 0
53159 - 0 0 0 0 0 0 0 0 0 0 0 0
53160 - 0 0 0 0 0 0 0 0 0 0 0 0
53161 - 6 6 6 14 14 14 26 26 26 42 42 42
53162 - 54 54 54 66 66 66 78 78 78 78 78 78
53163 - 78 78 78 74 74 74 66 66 66 54 54 54
53164 - 42 42 42 26 26 26 18 18 18 10 10 10
53165 - 6 6 6 0 0 0 0 0 0 0 0 0
53166 - 0 0 0 0 0 0 0 0 0 0 0 0
53167 - 0 0 0 0 0 0 0 0 0 0 0 0
53168 - 0 0 0 0 0 0 0 0 0 0 0 0
53169 - 0 0 0 0 0 0 0 0 0 0 0 0
53170 - 0 0 0 0 0 0 0 0 0 0 0 0
53171 - 0 0 0 0 0 0 0 0 0 0 0 0
53172 - 0 0 0 0 0 0 0 0 0 0 0 0
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 0 0 1 0 0 0 0 0 0 0 0 0
53175 - 0 0 0 0 0 0 0 0 0 0 0 0
53176 - 0 0 0 0 0 0 0 0 0 0 0 0
53177 - 0 0 0 0 0 0 0 0 0 0 0 0
53178 - 0 0 0 0 0 0 0 0 0 0 0 0
53179 - 0 0 0 0 0 0 0 0 0 0 0 0
53180 - 0 0 0 0 0 0 0 0 0 10 10 10
53181 - 22 22 22 42 42 42 66 66 66 86 86 86
53182 - 66 66 66 38 38 38 38 38 38 22 22 22
53183 - 26 26 26 34 34 34 54 54 54 66 66 66
53184 - 86 86 86 70 70 70 46 46 46 26 26 26
53185 - 14 14 14 6 6 6 0 0 0 0 0 0
53186 - 0 0 0 0 0 0 0 0 0 0 0 0
53187 - 0 0 0 0 0 0 0 0 0 0 0 0
53188 - 0 0 0 0 0 0 0 0 0 0 0 0
53189 - 0 0 0 0 0 0 0 0 0 0 0 0
53190 - 0 0 0 0 0 0 0 0 0 0 0 0
53191 - 0 0 0 0 0 0 0 0 0 0 0 0
53192 - 0 0 0 0 0 0 0 0 0 0 0 0
53193 - 0 0 0 0 0 0 0 0 0 0 0 0
53194 - 0 0 1 0 0 1 0 0 1 0 0 0
53195 - 0 0 0 0 0 0 0 0 0 0 0 0
53196 - 0 0 0 0 0 0 0 0 0 0 0 0
53197 - 0 0 0 0 0 0 0 0 0 0 0 0
53198 - 0 0 0 0 0 0 0 0 0 0 0 0
53199 - 0 0 0 0 0 0 0 0 0 0 0 0
53200 - 0 0 0 0 0 0 10 10 10 26 26 26
53201 - 50 50 50 82 82 82 58 58 58 6 6 6
53202 - 2 2 6 2 2 6 2 2 6 2 2 6
53203 - 2 2 6 2 2 6 2 2 6 2 2 6
53204 - 6 6 6 54 54 54 86 86 86 66 66 66
53205 - 38 38 38 18 18 18 6 6 6 0 0 0
53206 - 0 0 0 0 0 0 0 0 0 0 0 0
53207 - 0 0 0 0 0 0 0 0 0 0 0 0
53208 - 0 0 0 0 0 0 0 0 0 0 0 0
53209 - 0 0 0 0 0 0 0 0 0 0 0 0
53210 - 0 0 0 0 0 0 0 0 0 0 0 0
53211 - 0 0 0 0 0 0 0 0 0 0 0 0
53212 - 0 0 0 0 0 0 0 0 0 0 0 0
53213 - 0 0 0 0 0 0 0 0 0 0 0 0
53214 - 0 0 0 0 0 0 0 0 0 0 0 0
53215 - 0 0 0 0 0 0 0 0 0 0 0 0
53216 - 0 0 0 0 0 0 0 0 0 0 0 0
53217 - 0 0 0 0 0 0 0 0 0 0 0 0
53218 - 0 0 0 0 0 0 0 0 0 0 0 0
53219 - 0 0 0 0 0 0 0 0 0 0 0 0
53220 - 0 0 0 6 6 6 22 22 22 50 50 50
53221 - 78 78 78 34 34 34 2 2 6 2 2 6
53222 - 2 2 6 2 2 6 2 2 6 2 2 6
53223 - 2 2 6 2 2 6 2 2 6 2 2 6
53224 - 2 2 6 2 2 6 6 6 6 70 70 70
53225 - 78 78 78 46 46 46 22 22 22 6 6 6
53226 - 0 0 0 0 0 0 0 0 0 0 0 0
53227 - 0 0 0 0 0 0 0 0 0 0 0 0
53228 - 0 0 0 0 0 0 0 0 0 0 0 0
53229 - 0 0 0 0 0 0 0 0 0 0 0 0
53230 - 0 0 0 0 0 0 0 0 0 0 0 0
53231 - 0 0 0 0 0 0 0 0 0 0 0 0
53232 - 0 0 0 0 0 0 0 0 0 0 0 0
53233 - 0 0 0 0 0 0 0 0 0 0 0 0
53234 - 0 0 1 0 0 1 0 0 1 0 0 0
53235 - 0 0 0 0 0 0 0 0 0 0 0 0
53236 - 0 0 0 0 0 0 0 0 0 0 0 0
53237 - 0 0 0 0 0 0 0 0 0 0 0 0
53238 - 0 0 0 0 0 0 0 0 0 0 0 0
53239 - 0 0 0 0 0 0 0 0 0 0 0 0
53240 - 6 6 6 18 18 18 42 42 42 82 82 82
53241 - 26 26 26 2 2 6 2 2 6 2 2 6
53242 - 2 2 6 2 2 6 2 2 6 2 2 6
53243 - 2 2 6 2 2 6 2 2 6 14 14 14
53244 - 46 46 46 34 34 34 6 6 6 2 2 6
53245 - 42 42 42 78 78 78 42 42 42 18 18 18
53246 - 6 6 6 0 0 0 0 0 0 0 0 0
53247 - 0 0 0 0 0 0 0 0 0 0 0 0
53248 - 0 0 0 0 0 0 0 0 0 0 0 0
53249 - 0 0 0 0 0 0 0 0 0 0 0 0
53250 - 0 0 0 0 0 0 0 0 0 0 0 0
53251 - 0 0 0 0 0 0 0 0 0 0 0 0
53252 - 0 0 0 0 0 0 0 0 0 0 0 0
53253 - 0 0 0 0 0 0 0 0 0 0 0 0
53254 - 0 0 1 0 0 0 0 0 1 0 0 0
53255 - 0 0 0 0 0 0 0 0 0 0 0 0
53256 - 0 0 0 0 0 0 0 0 0 0 0 0
53257 - 0 0 0 0 0 0 0 0 0 0 0 0
53258 - 0 0 0 0 0 0 0 0 0 0 0 0
53259 - 0 0 0 0 0 0 0 0 0 0 0 0
53260 - 10 10 10 30 30 30 66 66 66 58 58 58
53261 - 2 2 6 2 2 6 2 2 6 2 2 6
53262 - 2 2 6 2 2 6 2 2 6 2 2 6
53263 - 2 2 6 2 2 6 2 2 6 26 26 26
53264 - 86 86 86 101 101 101 46 46 46 10 10 10
53265 - 2 2 6 58 58 58 70 70 70 34 34 34
53266 - 10 10 10 0 0 0 0 0 0 0 0 0
53267 - 0 0 0 0 0 0 0 0 0 0 0 0
53268 - 0 0 0 0 0 0 0 0 0 0 0 0
53269 - 0 0 0 0 0 0 0 0 0 0 0 0
53270 - 0 0 0 0 0 0 0 0 0 0 0 0
53271 - 0 0 0 0 0 0 0 0 0 0 0 0
53272 - 0 0 0 0 0 0 0 0 0 0 0 0
53273 - 0 0 0 0 0 0 0 0 0 0 0 0
53274 - 0 0 1 0 0 1 0 0 1 0 0 0
53275 - 0 0 0 0 0 0 0 0 0 0 0 0
53276 - 0 0 0 0 0 0 0 0 0 0 0 0
53277 - 0 0 0 0 0 0 0 0 0 0 0 0
53278 - 0 0 0 0 0 0 0 0 0 0 0 0
53279 - 0 0 0 0 0 0 0 0 0 0 0 0
53280 - 14 14 14 42 42 42 86 86 86 10 10 10
53281 - 2 2 6 2 2 6 2 2 6 2 2 6
53282 - 2 2 6 2 2 6 2 2 6 2 2 6
53283 - 2 2 6 2 2 6 2 2 6 30 30 30
53284 - 94 94 94 94 94 94 58 58 58 26 26 26
53285 - 2 2 6 6 6 6 78 78 78 54 54 54
53286 - 22 22 22 6 6 6 0 0 0 0 0 0
53287 - 0 0 0 0 0 0 0 0 0 0 0 0
53288 - 0 0 0 0 0 0 0 0 0 0 0 0
53289 - 0 0 0 0 0 0 0 0 0 0 0 0
53290 - 0 0 0 0 0 0 0 0 0 0 0 0
53291 - 0 0 0 0 0 0 0 0 0 0 0 0
53292 - 0 0 0 0 0 0 0 0 0 0 0 0
53293 - 0 0 0 0 0 0 0 0 0 0 0 0
53294 - 0 0 0 0 0 0 0 0 0 0 0 0
53295 - 0 0 0 0 0 0 0 0 0 0 0 0
53296 - 0 0 0 0 0 0 0 0 0 0 0 0
53297 - 0 0 0 0 0 0 0 0 0 0 0 0
53298 - 0 0 0 0 0 0 0 0 0 0 0 0
53299 - 0 0 0 0 0 0 0 0 0 6 6 6
53300 - 22 22 22 62 62 62 62 62 62 2 2 6
53301 - 2 2 6 2 2 6 2 2 6 2 2 6
53302 - 2 2 6 2 2 6 2 2 6 2 2 6
53303 - 2 2 6 2 2 6 2 2 6 26 26 26
53304 - 54 54 54 38 38 38 18 18 18 10 10 10
53305 - 2 2 6 2 2 6 34 34 34 82 82 82
53306 - 38 38 38 14 14 14 0 0 0 0 0 0
53307 - 0 0 0 0 0 0 0 0 0 0 0 0
53308 - 0 0 0 0 0 0 0 0 0 0 0 0
53309 - 0 0 0 0 0 0 0 0 0 0 0 0
53310 - 0 0 0 0 0 0 0 0 0 0 0 0
53311 - 0 0 0 0 0 0 0 0 0 0 0 0
53312 - 0 0 0 0 0 0 0 0 0 0 0 0
53313 - 0 0 0 0 0 0 0 0 0 0 0 0
53314 - 0 0 0 0 0 1 0 0 1 0 0 0
53315 - 0 0 0 0 0 0 0 0 0 0 0 0
53316 - 0 0 0 0 0 0 0 0 0 0 0 0
53317 - 0 0 0 0 0 0 0 0 0 0 0 0
53318 - 0 0 0 0 0 0 0 0 0 0 0 0
53319 - 0 0 0 0 0 0 0 0 0 6 6 6
53320 - 30 30 30 78 78 78 30 30 30 2 2 6
53321 - 2 2 6 2 2 6 2 2 6 2 2 6
53322 - 2 2 6 2 2 6 2 2 6 2 2 6
53323 - 2 2 6 2 2 6 2 2 6 10 10 10
53324 - 10 10 10 2 2 6 2 2 6 2 2 6
53325 - 2 2 6 2 2 6 2 2 6 78 78 78
53326 - 50 50 50 18 18 18 6 6 6 0 0 0
53327 - 0 0 0 0 0 0 0 0 0 0 0 0
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 0 0 0
53330 - 0 0 0 0 0 0 0 0 0 0 0 0
53331 - 0 0 0 0 0 0 0 0 0 0 0 0
53332 - 0 0 0 0 0 0 0 0 0 0 0 0
53333 - 0 0 0 0 0 0 0 0 0 0 0 0
53334 - 0 0 1 0 0 0 0 0 0 0 0 0
53335 - 0 0 0 0 0 0 0 0 0 0 0 0
53336 - 0 0 0 0 0 0 0 0 0 0 0 0
53337 - 0 0 0 0 0 0 0 0 0 0 0 0
53338 - 0 0 0 0 0 0 0 0 0 0 0 0
53339 - 0 0 0 0 0 0 0 0 0 10 10 10
53340 - 38 38 38 86 86 86 14 14 14 2 2 6
53341 - 2 2 6 2 2 6 2 2 6 2 2 6
53342 - 2 2 6 2 2 6 2 2 6 2 2 6
53343 - 2 2 6 2 2 6 2 2 6 2 2 6
53344 - 2 2 6 2 2 6 2 2 6 2 2 6
53345 - 2 2 6 2 2 6 2 2 6 54 54 54
53346 - 66 66 66 26 26 26 6 6 6 0 0 0
53347 - 0 0 0 0 0 0 0 0 0 0 0 0
53348 - 0 0 0 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 0 0 0
53350 - 0 0 0 0 0 0 0 0 0 0 0 0
53351 - 0 0 0 0 0 0 0 0 0 0 0 0
53352 - 0 0 0 0 0 0 0 0 0 0 0 0
53353 - 0 0 0 0 0 0 0 0 0 0 0 0
53354 - 0 0 0 0 0 1 0 0 1 0 0 0
53355 - 0 0 0 0 0 0 0 0 0 0 0 0
53356 - 0 0 0 0 0 0 0 0 0 0 0 0
53357 - 0 0 0 0 0 0 0 0 0 0 0 0
53358 - 0 0 0 0 0 0 0 0 0 0 0 0
53359 - 0 0 0 0 0 0 0 0 0 14 14 14
53360 - 42 42 42 82 82 82 2 2 6 2 2 6
53361 - 2 2 6 6 6 6 10 10 10 2 2 6
53362 - 2 2 6 2 2 6 2 2 6 2 2 6
53363 - 2 2 6 2 2 6 2 2 6 6 6 6
53364 - 14 14 14 10 10 10 2 2 6 2 2 6
53365 - 2 2 6 2 2 6 2 2 6 18 18 18
53366 - 82 82 82 34 34 34 10 10 10 0 0 0
53367 - 0 0 0 0 0 0 0 0 0 0 0 0
53368 - 0 0 0 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 0 0 0 0 0 0
53370 - 0 0 0 0 0 0 0 0 0 0 0 0
53371 - 0 0 0 0 0 0 0 0 0 0 0 0
53372 - 0 0 0 0 0 0 0 0 0 0 0 0
53373 - 0 0 0 0 0 0 0 0 0 0 0 0
53374 - 0 0 1 0 0 0 0 0 0 0 0 0
53375 - 0 0 0 0 0 0 0 0 0 0 0 0
53376 - 0 0 0 0 0 0 0 0 0 0 0 0
53377 - 0 0 0 0 0 0 0 0 0 0 0 0
53378 - 0 0 0 0 0 0 0 0 0 0 0 0
53379 - 0 0 0 0 0 0 0 0 0 14 14 14
53380 - 46 46 46 86 86 86 2 2 6 2 2 6
53381 - 6 6 6 6 6 6 22 22 22 34 34 34
53382 - 6 6 6 2 2 6 2 2 6 2 2 6
53383 - 2 2 6 2 2 6 18 18 18 34 34 34
53384 - 10 10 10 50 50 50 22 22 22 2 2 6
53385 - 2 2 6 2 2 6 2 2 6 10 10 10
53386 - 86 86 86 42 42 42 14 14 14 0 0 0
53387 - 0 0 0 0 0 0 0 0 0 0 0 0
53388 - 0 0 0 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 0 0 0 0 0 0
53390 - 0 0 0 0 0 0 0 0 0 0 0 0
53391 - 0 0 0 0 0 0 0 0 0 0 0 0
53392 - 0 0 0 0 0 0 0 0 0 0 0 0
53393 - 0 0 0 0 0 0 0 0 0 0 0 0
53394 - 0 0 1 0 0 1 0 0 1 0 0 0
53395 - 0 0 0 0 0 0 0 0 0 0 0 0
53396 - 0 0 0 0 0 0 0 0 0 0 0 0
53397 - 0 0 0 0 0 0 0 0 0 0 0 0
53398 - 0 0 0 0 0 0 0 0 0 0 0 0
53399 - 0 0 0 0 0 0 0 0 0 14 14 14
53400 - 46 46 46 86 86 86 2 2 6 2 2 6
53401 - 38 38 38 116 116 116 94 94 94 22 22 22
53402 - 22 22 22 2 2 6 2 2 6 2 2 6
53403 - 14 14 14 86 86 86 138 138 138 162 162 162
53404 -154 154 154 38 38 38 26 26 26 6 6 6
53405 - 2 2 6 2 2 6 2 2 6 2 2 6
53406 - 86 86 86 46 46 46 14 14 14 0 0 0
53407 - 0 0 0 0 0 0 0 0 0 0 0 0
53408 - 0 0 0 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 0 0 0 0 0 0
53410 - 0 0 0 0 0 0 0 0 0 0 0 0
53411 - 0 0 0 0 0 0 0 0 0 0 0 0
53412 - 0 0 0 0 0 0 0 0 0 0 0 0
53413 - 0 0 0 0 0 0 0 0 0 0 0 0
53414 - 0 0 0 0 0 0 0 0 0 0 0 0
53415 - 0 0 0 0 0 0 0 0 0 0 0 0
53416 - 0 0 0 0 0 0 0 0 0 0 0 0
53417 - 0 0 0 0 0 0 0 0 0 0 0 0
53418 - 0 0 0 0 0 0 0 0 0 0 0 0
53419 - 0 0 0 0 0 0 0 0 0 14 14 14
53420 - 46 46 46 86 86 86 2 2 6 14 14 14
53421 -134 134 134 198 198 198 195 195 195 116 116 116
53422 - 10 10 10 2 2 6 2 2 6 6 6 6
53423 -101 98 89 187 187 187 210 210 210 218 218 218
53424 -214 214 214 134 134 134 14 14 14 6 6 6
53425 - 2 2 6 2 2 6 2 2 6 2 2 6
53426 - 86 86 86 50 50 50 18 18 18 6 6 6
53427 - 0 0 0 0 0 0 0 0 0 0 0 0
53428 - 0 0 0 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 0 0 0 0 0 0
53430 - 0 0 0 0 0 0 0 0 0 0 0 0
53431 - 0 0 0 0 0 0 0 0 0 0 0 0
53432 - 0 0 0 0 0 0 0 0 0 0 0 0
53433 - 0 0 0 0 0 0 0 0 1 0 0 0
53434 - 0 0 1 0 0 1 0 0 1 0 0 0
53435 - 0 0 0 0 0 0 0 0 0 0 0 0
53436 - 0 0 0 0 0 0 0 0 0 0 0 0
53437 - 0 0 0 0 0 0 0 0 0 0 0 0
53438 - 0 0 0 0 0 0 0 0 0 0 0 0
53439 - 0 0 0 0 0 0 0 0 0 14 14 14
53440 - 46 46 46 86 86 86 2 2 6 54 54 54
53441 -218 218 218 195 195 195 226 226 226 246 246 246
53442 - 58 58 58 2 2 6 2 2 6 30 30 30
53443 -210 210 210 253 253 253 174 174 174 123 123 123
53444 -221 221 221 234 234 234 74 74 74 2 2 6
53445 - 2 2 6 2 2 6 2 2 6 2 2 6
53446 - 70 70 70 58 58 58 22 22 22 6 6 6
53447 - 0 0 0 0 0 0 0 0 0 0 0 0
53448 - 0 0 0 0 0 0 0 0 0 0 0 0
53449 - 0 0 0 0 0 0 0 0 0 0 0 0
53450 - 0 0 0 0 0 0 0 0 0 0 0 0
53451 - 0 0 0 0 0 0 0 0 0 0 0 0
53452 - 0 0 0 0 0 0 0 0 0 0 0 0
53453 - 0 0 0 0 0 0 0 0 0 0 0 0
53454 - 0 0 0 0 0 0 0 0 0 0 0 0
53455 - 0 0 0 0 0 0 0 0 0 0 0 0
53456 - 0 0 0 0 0 0 0 0 0 0 0 0
53457 - 0 0 0 0 0 0 0 0 0 0 0 0
53458 - 0 0 0 0 0 0 0 0 0 0 0 0
53459 - 0 0 0 0 0 0 0 0 0 14 14 14
53460 - 46 46 46 82 82 82 2 2 6 106 106 106
53461 -170 170 170 26 26 26 86 86 86 226 226 226
53462 -123 123 123 10 10 10 14 14 14 46 46 46
53463 -231 231 231 190 190 190 6 6 6 70 70 70
53464 - 90 90 90 238 238 238 158 158 158 2 2 6
53465 - 2 2 6 2 2 6 2 2 6 2 2 6
53466 - 70 70 70 58 58 58 22 22 22 6 6 6
53467 - 0 0 0 0 0 0 0 0 0 0 0 0
53468 - 0 0 0 0 0 0 0 0 0 0 0 0
53469 - 0 0 0 0 0 0 0 0 0 0 0 0
53470 - 0 0 0 0 0 0 0 0 0 0 0 0
53471 - 0 0 0 0 0 0 0 0 0 0 0 0
53472 - 0 0 0 0 0 0 0 0 0 0 0 0
53473 - 0 0 0 0 0 0 0 0 1 0 0 0
53474 - 0 0 1 0 0 1 0 0 1 0 0 0
53475 - 0 0 0 0 0 0 0 0 0 0 0 0
53476 - 0 0 0 0 0 0 0 0 0 0 0 0
53477 - 0 0 0 0 0 0 0 0 0 0 0 0
53478 - 0 0 0 0 0 0 0 0 0 0 0 0
53479 - 0 0 0 0 0 0 0 0 0 14 14 14
53480 - 42 42 42 86 86 86 6 6 6 116 116 116
53481 -106 106 106 6 6 6 70 70 70 149 149 149
53482 -128 128 128 18 18 18 38 38 38 54 54 54
53483 -221 221 221 106 106 106 2 2 6 14 14 14
53484 - 46 46 46 190 190 190 198 198 198 2 2 6
53485 - 2 2 6 2 2 6 2 2 6 2 2 6
53486 - 74 74 74 62 62 62 22 22 22 6 6 6
53487 - 0 0 0 0 0 0 0 0 0 0 0 0
53488 - 0 0 0 0 0 0 0 0 0 0 0 0
53489 - 0 0 0 0 0 0 0 0 0 0 0 0
53490 - 0 0 0 0 0 0 0 0 0 0 0 0
53491 - 0 0 0 0 0 0 0 0 0 0 0 0
53492 - 0 0 0 0 0 0 0 0 0 0 0 0
53493 - 0 0 0 0 0 0 0 0 1 0 0 0
53494 - 0 0 1 0 0 0 0 0 1 0 0 0
53495 - 0 0 0 0 0 0 0 0 0 0 0 0
53496 - 0 0 0 0 0 0 0 0 0 0 0 0
53497 - 0 0 0 0 0 0 0 0 0 0 0 0
53498 - 0 0 0 0 0 0 0 0 0 0 0 0
53499 - 0 0 0 0 0 0 0 0 0 14 14 14
53500 - 42 42 42 94 94 94 14 14 14 101 101 101
53501 -128 128 128 2 2 6 18 18 18 116 116 116
53502 -118 98 46 121 92 8 121 92 8 98 78 10
53503 -162 162 162 106 106 106 2 2 6 2 2 6
53504 - 2 2 6 195 195 195 195 195 195 6 6 6
53505 - 2 2 6 2 2 6 2 2 6 2 2 6
53506 - 74 74 74 62 62 62 22 22 22 6 6 6
53507 - 0 0 0 0 0 0 0 0 0 0 0 0
53508 - 0 0 0 0 0 0 0 0 0 0 0 0
53509 - 0 0 0 0 0 0 0 0 0 0 0 0
53510 - 0 0 0 0 0 0 0 0 0 0 0 0
53511 - 0 0 0 0 0 0 0 0 0 0 0 0
53512 - 0 0 0 0 0 0 0 0 0 0 0 0
53513 - 0 0 0 0 0 0 0 0 1 0 0 1
53514 - 0 0 1 0 0 0 0 0 1 0 0 0
53515 - 0 0 0 0 0 0 0 0 0 0 0 0
53516 - 0 0 0 0 0 0 0 0 0 0 0 0
53517 - 0 0 0 0 0 0 0 0 0 0 0 0
53518 - 0 0 0 0 0 0 0 0 0 0 0 0
53519 - 0 0 0 0 0 0 0 0 0 10 10 10
53520 - 38 38 38 90 90 90 14 14 14 58 58 58
53521 -210 210 210 26 26 26 54 38 6 154 114 10
53522 -226 170 11 236 186 11 225 175 15 184 144 12
53523 -215 174 15 175 146 61 37 26 9 2 2 6
53524 - 70 70 70 246 246 246 138 138 138 2 2 6
53525 - 2 2 6 2 2 6 2 2 6 2 2 6
53526 - 70 70 70 66 66 66 26 26 26 6 6 6
53527 - 0 0 0 0 0 0 0 0 0 0 0 0
53528 - 0 0 0 0 0 0 0 0 0 0 0 0
53529 - 0 0 0 0 0 0 0 0 0 0 0 0
53530 - 0 0 0 0 0 0 0 0 0 0 0 0
53531 - 0 0 0 0 0 0 0 0 0 0 0 0
53532 - 0 0 0 0 0 0 0 0 0 0 0 0
53533 - 0 0 0 0 0 0 0 0 0 0 0 0
53534 - 0 0 0 0 0 0 0 0 0 0 0 0
53535 - 0 0 0 0 0 0 0 0 0 0 0 0
53536 - 0 0 0 0 0 0 0 0 0 0 0 0
53537 - 0 0 0 0 0 0 0 0 0 0 0 0
53538 - 0 0 0 0 0 0 0 0 0 0 0 0
53539 - 0 0 0 0 0 0 0 0 0 10 10 10
53540 - 38 38 38 86 86 86 14 14 14 10 10 10
53541 -195 195 195 188 164 115 192 133 9 225 175 15
53542 -239 182 13 234 190 10 232 195 16 232 200 30
53543 -245 207 45 241 208 19 232 195 16 184 144 12
53544 -218 194 134 211 206 186 42 42 42 2 2 6
53545 - 2 2 6 2 2 6 2 2 6 2 2 6
53546 - 50 50 50 74 74 74 30 30 30 6 6 6
53547 - 0 0 0 0 0 0 0 0 0 0 0 0
53548 - 0 0 0 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 0 0 0
53550 - 0 0 0 0 0 0 0 0 0 0 0 0
53551 - 0 0 0 0 0 0 0 0 0 0 0 0
53552 - 0 0 0 0 0 0 0 0 0 0 0 0
53553 - 0 0 0 0 0 0 0 0 0 0 0 0
53554 - 0 0 0 0 0 0 0 0 0 0 0 0
53555 - 0 0 0 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 0 0 0
53558 - 0 0 0 0 0 0 0 0 0 0 0 0
53559 - 0 0 0 0 0 0 0 0 0 10 10 10
53560 - 34 34 34 86 86 86 14 14 14 2 2 6
53561 -121 87 25 192 133 9 219 162 10 239 182 13
53562 -236 186 11 232 195 16 241 208 19 244 214 54
53563 -246 218 60 246 218 38 246 215 20 241 208 19
53564 -241 208 19 226 184 13 121 87 25 2 2 6
53565 - 2 2 6 2 2 6 2 2 6 2 2 6
53566 - 50 50 50 82 82 82 34 34 34 10 10 10
53567 - 0 0 0 0 0 0 0 0 0 0 0 0
53568 - 0 0 0 0 0 0 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 0 0 0
53570 - 0 0 0 0 0 0 0 0 0 0 0 0
53571 - 0 0 0 0 0 0 0 0 0 0 0 0
53572 - 0 0 0 0 0 0 0 0 0 0 0 0
53573 - 0 0 0 0 0 0 0 0 0 0 0 0
53574 - 0 0 0 0 0 0 0 0 0 0 0 0
53575 - 0 0 0 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 0 0 0
53578 - 0 0 0 0 0 0 0 0 0 0 0 0
53579 - 0 0 0 0 0 0 0 0 0 10 10 10
53580 - 34 34 34 82 82 82 30 30 30 61 42 6
53581 -180 123 7 206 145 10 230 174 11 239 182 13
53582 -234 190 10 238 202 15 241 208 19 246 218 74
53583 -246 218 38 246 215 20 246 215 20 246 215 20
53584 -226 184 13 215 174 15 184 144 12 6 6 6
53585 - 2 2 6 2 2 6 2 2 6 2 2 6
53586 - 26 26 26 94 94 94 42 42 42 14 14 14
53587 - 0 0 0 0 0 0 0 0 0 0 0 0
53588 - 0 0 0 0 0 0 0 0 0 0 0 0
53589 - 0 0 0 0 0 0 0 0 0 0 0 0
53590 - 0 0 0 0 0 0 0 0 0 0 0 0
53591 - 0 0 0 0 0 0 0 0 0 0 0 0
53592 - 0 0 0 0 0 0 0 0 0 0 0 0
53593 - 0 0 0 0 0 0 0 0 0 0 0 0
53594 - 0 0 0 0 0 0 0 0 0 0 0 0
53595 - 0 0 0 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 0 0 0
53598 - 0 0 0 0 0 0 0 0 0 0 0 0
53599 - 0 0 0 0 0 0 0 0 0 10 10 10
53600 - 30 30 30 78 78 78 50 50 50 104 69 6
53601 -192 133 9 216 158 10 236 178 12 236 186 11
53602 -232 195 16 241 208 19 244 214 54 245 215 43
53603 -246 215 20 246 215 20 241 208 19 198 155 10
53604 -200 144 11 216 158 10 156 118 10 2 2 6
53605 - 2 2 6 2 2 6 2 2 6 2 2 6
53606 - 6 6 6 90 90 90 54 54 54 18 18 18
53607 - 6 6 6 0 0 0 0 0 0 0 0 0
53608 - 0 0 0 0 0 0 0 0 0 0 0 0
53609 - 0 0 0 0 0 0 0 0 0 0 0 0
53610 - 0 0 0 0 0 0 0 0 0 0 0 0
53611 - 0 0 0 0 0 0 0 0 0 0 0 0
53612 - 0 0 0 0 0 0 0 0 0 0 0 0
53613 - 0 0 0 0 0 0 0 0 0 0 0 0
53614 - 0 0 0 0 0 0 0 0 0 0 0 0
53615 - 0 0 0 0 0 0 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 0 0 0
53618 - 0 0 0 0 0 0 0 0 0 0 0 0
53619 - 0 0 0 0 0 0 0 0 0 10 10 10
53620 - 30 30 30 78 78 78 46 46 46 22 22 22
53621 -137 92 6 210 162 10 239 182 13 238 190 10
53622 -238 202 15 241 208 19 246 215 20 246 215 20
53623 -241 208 19 203 166 17 185 133 11 210 150 10
53624 -216 158 10 210 150 10 102 78 10 2 2 6
53625 - 6 6 6 54 54 54 14 14 14 2 2 6
53626 - 2 2 6 62 62 62 74 74 74 30 30 30
53627 - 10 10 10 0 0 0 0 0 0 0 0 0
53628 - 0 0 0 0 0 0 0 0 0 0 0 0
53629 - 0 0 0 0 0 0 0 0 0 0 0 0
53630 - 0 0 0 0 0 0 0 0 0 0 0 0
53631 - 0 0 0 0 0 0 0 0 0 0 0 0
53632 - 0 0 0 0 0 0 0 0 0 0 0 0
53633 - 0 0 0 0 0 0 0 0 0 0 0 0
53634 - 0 0 0 0 0 0 0 0 0 0 0 0
53635 - 0 0 0 0 0 0 0 0 0 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 0 0 0
53638 - 0 0 0 0 0 0 0 0 0 0 0 0
53639 - 0 0 0 0 0 0 0 0 0 10 10 10
53640 - 34 34 34 78 78 78 50 50 50 6 6 6
53641 - 94 70 30 139 102 15 190 146 13 226 184 13
53642 -232 200 30 232 195 16 215 174 15 190 146 13
53643 -168 122 10 192 133 9 210 150 10 213 154 11
53644 -202 150 34 182 157 106 101 98 89 2 2 6
53645 - 2 2 6 78 78 78 116 116 116 58 58 58
53646 - 2 2 6 22 22 22 90 90 90 46 46 46
53647 - 18 18 18 6 6 6 0 0 0 0 0 0
53648 - 0 0 0 0 0 0 0 0 0 0 0 0
53649 - 0 0 0 0 0 0 0 0 0 0 0 0
53650 - 0 0 0 0 0 0 0 0 0 0 0 0
53651 - 0 0 0 0 0 0 0 0 0 0 0 0
53652 - 0 0 0 0 0 0 0 0 0 0 0 0
53653 - 0 0 0 0 0 0 0 0 0 0 0 0
53654 - 0 0 0 0 0 0 0 0 0 0 0 0
53655 - 0 0 0 0 0 0 0 0 0 0 0 0
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 0 0 0
53658 - 0 0 0 0 0 0 0 0 0 0 0 0
53659 - 0 0 0 0 0 0 0 0 0 10 10 10
53660 - 38 38 38 86 86 86 50 50 50 6 6 6
53661 -128 128 128 174 154 114 156 107 11 168 122 10
53662 -198 155 10 184 144 12 197 138 11 200 144 11
53663 -206 145 10 206 145 10 197 138 11 188 164 115
53664 -195 195 195 198 198 198 174 174 174 14 14 14
53665 - 2 2 6 22 22 22 116 116 116 116 116 116
53666 - 22 22 22 2 2 6 74 74 74 70 70 70
53667 - 30 30 30 10 10 10 0 0 0 0 0 0
53668 - 0 0 0 0 0 0 0 0 0 0 0 0
53669 - 0 0 0 0 0 0 0 0 0 0 0 0
53670 - 0 0 0 0 0 0 0 0 0 0 0 0
53671 - 0 0 0 0 0 0 0 0 0 0 0 0
53672 - 0 0 0 0 0 0 0 0 0 0 0 0
53673 - 0 0 0 0 0 0 0 0 0 0 0 0
53674 - 0 0 0 0 0 0 0 0 0 0 0 0
53675 - 0 0 0 0 0 0 0 0 0 0 0 0
53676 - 0 0 0 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 0 0 0
53678 - 0 0 0 0 0 0 0 0 0 0 0 0
53679 - 0 0 0 0 0 0 6 6 6 18 18 18
53680 - 50 50 50 101 101 101 26 26 26 10 10 10
53681 -138 138 138 190 190 190 174 154 114 156 107 11
53682 -197 138 11 200 144 11 197 138 11 192 133 9
53683 -180 123 7 190 142 34 190 178 144 187 187 187
53684 -202 202 202 221 221 221 214 214 214 66 66 66
53685 - 2 2 6 2 2 6 50 50 50 62 62 62
53686 - 6 6 6 2 2 6 10 10 10 90 90 90
53687 - 50 50 50 18 18 18 6 6 6 0 0 0
53688 - 0 0 0 0 0 0 0 0 0 0 0 0
53689 - 0 0 0 0 0 0 0 0 0 0 0 0
53690 - 0 0 0 0 0 0 0 0 0 0 0 0
53691 - 0 0 0 0 0 0 0 0 0 0 0 0
53692 - 0 0 0 0 0 0 0 0 0 0 0 0
53693 - 0 0 0 0 0 0 0 0 0 0 0 0
53694 - 0 0 0 0 0 0 0 0 0 0 0 0
53695 - 0 0 0 0 0 0 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 0 0 0 0 0 0 0
53699 - 0 0 0 0 0 0 10 10 10 34 34 34
53700 - 74 74 74 74 74 74 2 2 6 6 6 6
53701 -144 144 144 198 198 198 190 190 190 178 166 146
53702 -154 121 60 156 107 11 156 107 11 168 124 44
53703 -174 154 114 187 187 187 190 190 190 210 210 210
53704 -246 246 246 253 253 253 253 253 253 182 182 182
53705 - 6 6 6 2 2 6 2 2 6 2 2 6
53706 - 2 2 6 2 2 6 2 2 6 62 62 62
53707 - 74 74 74 34 34 34 14 14 14 0 0 0
53708 - 0 0 0 0 0 0 0 0 0 0 0 0
53709 - 0 0 0 0 0 0 0 0 0 0 0 0
53710 - 0 0 0 0 0 0 0 0 0 0 0 0
53711 - 0 0 0 0 0 0 0 0 0 0 0 0
53712 - 0 0 0 0 0 0 0 0 0 0 0 0
53713 - 0 0 0 0 0 0 0 0 0 0 0 0
53714 - 0 0 0 0 0 0 0 0 0 0 0 0
53715 - 0 0 0 0 0 0 0 0 0 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 0 0 0 0 0 0 0 0 0 0
53719 - 0 0 0 10 10 10 22 22 22 54 54 54
53720 - 94 94 94 18 18 18 2 2 6 46 46 46
53721 -234 234 234 221 221 221 190 190 190 190 190 190
53722 -190 190 190 187 187 187 187 187 187 190 190 190
53723 -190 190 190 195 195 195 214 214 214 242 242 242
53724 -253 253 253 253 253 253 253 253 253 253 253 253
53725 - 82 82 82 2 2 6 2 2 6 2 2 6
53726 - 2 2 6 2 2 6 2 2 6 14 14 14
53727 - 86 86 86 54 54 54 22 22 22 6 6 6
53728 - 0 0 0 0 0 0 0 0 0 0 0 0
53729 - 0 0 0 0 0 0 0 0 0 0 0 0
53730 - 0 0 0 0 0 0 0 0 0 0 0 0
53731 - 0 0 0 0 0 0 0 0 0 0 0 0
53732 - 0 0 0 0 0 0 0 0 0 0 0 0
53733 - 0 0 0 0 0 0 0 0 0 0 0 0
53734 - 0 0 0 0 0 0 0 0 0 0 0 0
53735 - 0 0 0 0 0 0 0 0 0 0 0 0
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 0 0 0 0 0 0 0 0 0 0
53739 - 6 6 6 18 18 18 46 46 46 90 90 90
53740 - 46 46 46 18 18 18 6 6 6 182 182 182
53741 -253 253 253 246 246 246 206 206 206 190 190 190
53742 -190 190 190 190 190 190 190 190 190 190 190 190
53743 -206 206 206 231 231 231 250 250 250 253 253 253
53744 -253 253 253 253 253 253 253 253 253 253 253 253
53745 -202 202 202 14 14 14 2 2 6 2 2 6
53746 - 2 2 6 2 2 6 2 2 6 2 2 6
53747 - 42 42 42 86 86 86 42 42 42 18 18 18
53748 - 6 6 6 0 0 0 0 0 0 0 0 0
53749 - 0 0 0 0 0 0 0 0 0 0 0 0
53750 - 0 0 0 0 0 0 0 0 0 0 0 0
53751 - 0 0 0 0 0 0 0 0 0 0 0 0
53752 - 0 0 0 0 0 0 0 0 0 0 0 0
53753 - 0 0 0 0 0 0 0 0 0 0 0 0
53754 - 0 0 0 0 0 0 0 0 0 0 0 0
53755 - 0 0 0 0 0 0 0 0 0 0 0 0
53756 - 0 0 0 0 0 0 0 0 0 0 0 0
53757 - 0 0 0 0 0 0 0 0 0 0 0 0
53758 - 0 0 0 0 0 0 0 0 0 6 6 6
53759 - 14 14 14 38 38 38 74 74 74 66 66 66
53760 - 2 2 6 6 6 6 90 90 90 250 250 250
53761 -253 253 253 253 253 253 238 238 238 198 198 198
53762 -190 190 190 190 190 190 195 195 195 221 221 221
53763 -246 246 246 253 253 253 253 253 253 253 253 253
53764 -253 253 253 253 253 253 253 253 253 253 253 253
53765 -253 253 253 82 82 82 2 2 6 2 2 6
53766 - 2 2 6 2 2 6 2 2 6 2 2 6
53767 - 2 2 6 78 78 78 70 70 70 34 34 34
53768 - 14 14 14 6 6 6 0 0 0 0 0 0
53769 - 0 0 0 0 0 0 0 0 0 0 0 0
53770 - 0 0 0 0 0 0 0 0 0 0 0 0
53771 - 0 0 0 0 0 0 0 0 0 0 0 0
53772 - 0 0 0 0 0 0 0 0 0 0 0 0
53773 - 0 0 0 0 0 0 0 0 0 0 0 0
53774 - 0 0 0 0 0 0 0 0 0 0 0 0
53775 - 0 0 0 0 0 0 0 0 0 0 0 0
53776 - 0 0 0 0 0 0 0 0 0 0 0 0
53777 - 0 0 0 0 0 0 0 0 0 0 0 0
53778 - 0 0 0 0 0 0 0 0 0 14 14 14
53779 - 34 34 34 66 66 66 78 78 78 6 6 6
53780 - 2 2 6 18 18 18 218 218 218 253 253 253
53781 -253 253 253 253 253 253 253 253 253 246 246 246
53782 -226 226 226 231 231 231 246 246 246 253 253 253
53783 -253 253 253 253 253 253 253 253 253 253 253 253
53784 -253 253 253 253 253 253 253 253 253 253 253 253
53785 -253 253 253 178 178 178 2 2 6 2 2 6
53786 - 2 2 6 2 2 6 2 2 6 2 2 6
53787 - 2 2 6 18 18 18 90 90 90 62 62 62
53788 - 30 30 30 10 10 10 0 0 0 0 0 0
53789 - 0 0 0 0 0 0 0 0 0 0 0 0
53790 - 0 0 0 0 0 0 0 0 0 0 0 0
53791 - 0 0 0 0 0 0 0 0 0 0 0 0
53792 - 0 0 0 0 0 0 0 0 0 0 0 0
53793 - 0 0 0 0 0 0 0 0 0 0 0 0
53794 - 0 0 0 0 0 0 0 0 0 0 0 0
53795 - 0 0 0 0 0 0 0 0 0 0 0 0
53796 - 0 0 0 0 0 0 0 0 0 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 0 0 0
53798 - 0 0 0 0 0 0 10 10 10 26 26 26
53799 - 58 58 58 90 90 90 18 18 18 2 2 6
53800 - 2 2 6 110 110 110 253 253 253 253 253 253
53801 -253 253 253 253 253 253 253 253 253 253 253 253
53802 -250 250 250 253 253 253 253 253 253 253 253 253
53803 -253 253 253 253 253 253 253 253 253 253 253 253
53804 -253 253 253 253 253 253 253 253 253 253 253 253
53805 -253 253 253 231 231 231 18 18 18 2 2 6
53806 - 2 2 6 2 2 6 2 2 6 2 2 6
53807 - 2 2 6 2 2 6 18 18 18 94 94 94
53808 - 54 54 54 26 26 26 10 10 10 0 0 0
53809 - 0 0 0 0 0 0 0 0 0 0 0 0
53810 - 0 0 0 0 0 0 0 0 0 0 0 0
53811 - 0 0 0 0 0 0 0 0 0 0 0 0
53812 - 0 0 0 0 0 0 0 0 0 0 0 0
53813 - 0 0 0 0 0 0 0 0 0 0 0 0
53814 - 0 0 0 0 0 0 0 0 0 0 0 0
53815 - 0 0 0 0 0 0 0 0 0 0 0 0
53816 - 0 0 0 0 0 0 0 0 0 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 0 0 0
53818 - 0 0 0 6 6 6 22 22 22 50 50 50
53819 - 90 90 90 26 26 26 2 2 6 2 2 6
53820 - 14 14 14 195 195 195 250 250 250 253 253 253
53821 -253 253 253 253 253 253 253 253 253 253 253 253
53822 -253 253 253 253 253 253 253 253 253 253 253 253
53823 -253 253 253 253 253 253 253 253 253 253 253 253
53824 -253 253 253 253 253 253 253 253 253 253 253 253
53825 -250 250 250 242 242 242 54 54 54 2 2 6
53826 - 2 2 6 2 2 6 2 2 6 2 2 6
53827 - 2 2 6 2 2 6 2 2 6 38 38 38
53828 - 86 86 86 50 50 50 22 22 22 6 6 6
53829 - 0 0 0 0 0 0 0 0 0 0 0 0
53830 - 0 0 0 0 0 0 0 0 0 0 0 0
53831 - 0 0 0 0 0 0 0 0 0 0 0 0
53832 - 0 0 0 0 0 0 0 0 0 0 0 0
53833 - 0 0 0 0 0 0 0 0 0 0 0 0
53834 - 0 0 0 0 0 0 0 0 0 0 0 0
53835 - 0 0 0 0 0 0 0 0 0 0 0 0
53836 - 0 0 0 0 0 0 0 0 0 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 6 6 6 14 14 14 38 38 38 82 82 82
53839 - 34 34 34 2 2 6 2 2 6 2 2 6
53840 - 42 42 42 195 195 195 246 246 246 253 253 253
53841 -253 253 253 253 253 253 253 253 253 250 250 250
53842 -242 242 242 242 242 242 250 250 250 253 253 253
53843 -253 253 253 253 253 253 253 253 253 253 253 253
53844 -253 253 253 250 250 250 246 246 246 238 238 238
53845 -226 226 226 231 231 231 101 101 101 6 6 6
53846 - 2 2 6 2 2 6 2 2 6 2 2 6
53847 - 2 2 6 2 2 6 2 2 6 2 2 6
53848 - 38 38 38 82 82 82 42 42 42 14 14 14
53849 - 6 6 6 0 0 0 0 0 0 0 0 0
53850 - 0 0 0 0 0 0 0 0 0 0 0 0
53851 - 0 0 0 0 0 0 0 0 0 0 0 0
53852 - 0 0 0 0 0 0 0 0 0 0 0 0
53853 - 0 0 0 0 0 0 0 0 0 0 0 0
53854 - 0 0 0 0 0 0 0 0 0 0 0 0
53855 - 0 0 0 0 0 0 0 0 0 0 0 0
53856 - 0 0 0 0 0 0 0 0 0 0 0 0
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 10 10 10 26 26 26 62 62 62 66 66 66
53859 - 2 2 6 2 2 6 2 2 6 6 6 6
53860 - 70 70 70 170 170 170 206 206 206 234 234 234
53861 -246 246 246 250 250 250 250 250 250 238 238 238
53862 -226 226 226 231 231 231 238 238 238 250 250 250
53863 -250 250 250 250 250 250 246 246 246 231 231 231
53864 -214 214 214 206 206 206 202 202 202 202 202 202
53865 -198 198 198 202 202 202 182 182 182 18 18 18
53866 - 2 2 6 2 2 6 2 2 6 2 2 6
53867 - 2 2 6 2 2 6 2 2 6 2 2 6
53868 - 2 2 6 62 62 62 66 66 66 30 30 30
53869 - 10 10 10 0 0 0 0 0 0 0 0 0
53870 - 0 0 0 0 0 0 0 0 0 0 0 0
53871 - 0 0 0 0 0 0 0 0 0 0 0 0
53872 - 0 0 0 0 0 0 0 0 0 0 0 0
53873 - 0 0 0 0 0 0 0 0 0 0 0 0
53874 - 0 0 0 0 0 0 0 0 0 0 0 0
53875 - 0 0 0 0 0 0 0 0 0 0 0 0
53876 - 0 0 0 0 0 0 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 14 14 14 42 42 42 82 82 82 18 18 18
53879 - 2 2 6 2 2 6 2 2 6 10 10 10
53880 - 94 94 94 182 182 182 218 218 218 242 242 242
53881 -250 250 250 253 253 253 253 253 253 250 250 250
53882 -234 234 234 253 253 253 253 253 253 253 253 253
53883 -253 253 253 253 253 253 253 253 253 246 246 246
53884 -238 238 238 226 226 226 210 210 210 202 202 202
53885 -195 195 195 195 195 195 210 210 210 158 158 158
53886 - 6 6 6 14 14 14 50 50 50 14 14 14
53887 - 2 2 6 2 2 6 2 2 6 2 2 6
53888 - 2 2 6 6 6 6 86 86 86 46 46 46
53889 - 18 18 18 6 6 6 0 0 0 0 0 0
53890 - 0 0 0 0 0 0 0 0 0 0 0 0
53891 - 0 0 0 0 0 0 0 0 0 0 0 0
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 0 0 0
53894 - 0 0 0 0 0 0 0 0 0 0 0 0
53895 - 0 0 0 0 0 0 0 0 0 0 0 0
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 6 6 6
53898 - 22 22 22 54 54 54 70 70 70 2 2 6
53899 - 2 2 6 10 10 10 2 2 6 22 22 22
53900 -166 166 166 231 231 231 250 250 250 253 253 253
53901 -253 253 253 253 253 253 253 253 253 250 250 250
53902 -242 242 242 253 253 253 253 253 253 253 253 253
53903 -253 253 253 253 253 253 253 253 253 253 253 253
53904 -253 253 253 253 253 253 253 253 253 246 246 246
53905 -231 231 231 206 206 206 198 198 198 226 226 226
53906 - 94 94 94 2 2 6 6 6 6 38 38 38
53907 - 30 30 30 2 2 6 2 2 6 2 2 6
53908 - 2 2 6 2 2 6 62 62 62 66 66 66
53909 - 26 26 26 10 10 10 0 0 0 0 0 0
53910 - 0 0 0 0 0 0 0 0 0 0 0 0
53911 - 0 0 0 0 0 0 0 0 0 0 0 0
53912 - 0 0 0 0 0 0 0 0 0 0 0 0
53913 - 0 0 0 0 0 0 0 0 0 0 0 0
53914 - 0 0 0 0 0 0 0 0 0 0 0 0
53915 - 0 0 0 0 0 0 0 0 0 0 0 0
53916 - 0 0 0 0 0 0 0 0 0 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 10 10 10
53918 - 30 30 30 74 74 74 50 50 50 2 2 6
53919 - 26 26 26 26 26 26 2 2 6 106 106 106
53920 -238 238 238 253 253 253 253 253 253 253 253 253
53921 -253 253 253 253 253 253 253 253 253 253 253 253
53922 -253 253 253 253 253 253 253 253 253 253 253 253
53923 -253 253 253 253 253 253 253 253 253 253 253 253
53924 -253 253 253 253 253 253 253 253 253 253 253 253
53925 -253 253 253 246 246 246 218 218 218 202 202 202
53926 -210 210 210 14 14 14 2 2 6 2 2 6
53927 - 30 30 30 22 22 22 2 2 6 2 2 6
53928 - 2 2 6 2 2 6 18 18 18 86 86 86
53929 - 42 42 42 14 14 14 0 0 0 0 0 0
53930 - 0 0 0 0 0 0 0 0 0 0 0 0
53931 - 0 0 0 0 0 0 0 0 0 0 0 0
53932 - 0 0 0 0 0 0 0 0 0 0 0 0
53933 - 0 0 0 0 0 0 0 0 0 0 0 0
53934 - 0 0 0 0 0 0 0 0 0 0 0 0
53935 - 0 0 0 0 0 0 0 0 0 0 0 0
53936 - 0 0 0 0 0 0 0 0 0 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 14 14 14
53938 - 42 42 42 90 90 90 22 22 22 2 2 6
53939 - 42 42 42 2 2 6 18 18 18 218 218 218
53940 -253 253 253 253 253 253 253 253 253 253 253 253
53941 -253 253 253 253 253 253 253 253 253 253 253 253
53942 -253 253 253 253 253 253 253 253 253 253 253 253
53943 -253 253 253 253 253 253 253 253 253 253 253 253
53944 -253 253 253 253 253 253 253 253 253 253 253 253
53945 -253 253 253 253 253 253 250 250 250 221 221 221
53946 -218 218 218 101 101 101 2 2 6 14 14 14
53947 - 18 18 18 38 38 38 10 10 10 2 2 6
53948 - 2 2 6 2 2 6 2 2 6 78 78 78
53949 - 58 58 58 22 22 22 6 6 6 0 0 0
53950 - 0 0 0 0 0 0 0 0 0 0 0 0
53951 - 0 0 0 0 0 0 0 0 0 0 0 0
53952 - 0 0 0 0 0 0 0 0 0 0 0 0
53953 - 0 0 0 0 0 0 0 0 0 0 0 0
53954 - 0 0 0 0 0 0 0 0 0 0 0 0
53955 - 0 0 0 0 0 0 0 0 0 0 0 0
53956 - 0 0 0 0 0 0 0 0 0 0 0 0
53957 - 0 0 0 0 0 0 6 6 6 18 18 18
53958 - 54 54 54 82 82 82 2 2 6 26 26 26
53959 - 22 22 22 2 2 6 123 123 123 253 253 253
53960 -253 253 253 253 253 253 253 253 253 253 253 253
53961 -253 253 253 253 253 253 253 253 253 253 253 253
53962 -253 253 253 253 253 253 253 253 253 253 253 253
53963 -253 253 253 253 253 253 253 253 253 253 253 253
53964 -253 253 253 253 253 253 253 253 253 253 253 253
53965 -253 253 253 253 253 253 253 253 253 250 250 250
53966 -238 238 238 198 198 198 6 6 6 38 38 38
53967 - 58 58 58 26 26 26 38 38 38 2 2 6
53968 - 2 2 6 2 2 6 2 2 6 46 46 46
53969 - 78 78 78 30 30 30 10 10 10 0 0 0
53970 - 0 0 0 0 0 0 0 0 0 0 0 0
53971 - 0 0 0 0 0 0 0 0 0 0 0 0
53972 - 0 0 0 0 0 0 0 0 0 0 0 0
53973 - 0 0 0 0 0 0 0 0 0 0 0 0
53974 - 0 0 0 0 0 0 0 0 0 0 0 0
53975 - 0 0 0 0 0 0 0 0 0 0 0 0
53976 - 0 0 0 0 0 0 0 0 0 0 0 0
53977 - 0 0 0 0 0 0 10 10 10 30 30 30
53978 - 74 74 74 58 58 58 2 2 6 42 42 42
53979 - 2 2 6 22 22 22 231 231 231 253 253 253
53980 -253 253 253 253 253 253 253 253 253 253 253 253
53981 -253 253 253 253 253 253 253 253 253 250 250 250
53982 -253 253 253 253 253 253 253 253 253 253 253 253
53983 -253 253 253 253 253 253 253 253 253 253 253 253
53984 -253 253 253 253 253 253 253 253 253 253 253 253
53985 -253 253 253 253 253 253 253 253 253 253 253 253
53986 -253 253 253 246 246 246 46 46 46 38 38 38
53987 - 42 42 42 14 14 14 38 38 38 14 14 14
53988 - 2 2 6 2 2 6 2 2 6 6 6 6
53989 - 86 86 86 46 46 46 14 14 14 0 0 0
53990 - 0 0 0 0 0 0 0 0 0 0 0 0
53991 - 0 0 0 0 0 0 0 0 0 0 0 0
53992 - 0 0 0 0 0 0 0 0 0 0 0 0
53993 - 0 0 0 0 0 0 0 0 0 0 0 0
53994 - 0 0 0 0 0 0 0 0 0 0 0 0
53995 - 0 0 0 0 0 0 0 0 0 0 0 0
53996 - 0 0 0 0 0 0 0 0 0 0 0 0
53997 - 0 0 0 6 6 6 14 14 14 42 42 42
53998 - 90 90 90 18 18 18 18 18 18 26 26 26
53999 - 2 2 6 116 116 116 253 253 253 253 253 253
54000 -253 253 253 253 253 253 253 253 253 253 253 253
54001 -253 253 253 253 253 253 250 250 250 238 238 238
54002 -253 253 253 253 253 253 253 253 253 253 253 253
54003 -253 253 253 253 253 253 253 253 253 253 253 253
54004 -253 253 253 253 253 253 253 253 253 253 253 253
54005 -253 253 253 253 253 253 253 253 253 253 253 253
54006 -253 253 253 253 253 253 94 94 94 6 6 6
54007 - 2 2 6 2 2 6 10 10 10 34 34 34
54008 - 2 2 6 2 2 6 2 2 6 2 2 6
54009 - 74 74 74 58 58 58 22 22 22 6 6 6
54010 - 0 0 0 0 0 0 0 0 0 0 0 0
54011 - 0 0 0 0 0 0 0 0 0 0 0 0
54012 - 0 0 0 0 0 0 0 0 0 0 0 0
54013 - 0 0 0 0 0 0 0 0 0 0 0 0
54014 - 0 0 0 0 0 0 0 0 0 0 0 0
54015 - 0 0 0 0 0 0 0 0 0 0 0 0
54016 - 0 0 0 0 0 0 0 0 0 0 0 0
54017 - 0 0 0 10 10 10 26 26 26 66 66 66
54018 - 82 82 82 2 2 6 38 38 38 6 6 6
54019 - 14 14 14 210 210 210 253 253 253 253 253 253
54020 -253 253 253 253 253 253 253 253 253 253 253 253
54021 -253 253 253 253 253 253 246 246 246 242 242 242
54022 -253 253 253 253 253 253 253 253 253 253 253 253
54023 -253 253 253 253 253 253 253 253 253 253 253 253
54024 -253 253 253 253 253 253 253 253 253 253 253 253
54025 -253 253 253 253 253 253 253 253 253 253 253 253
54026 -253 253 253 253 253 253 144 144 144 2 2 6
54027 - 2 2 6 2 2 6 2 2 6 46 46 46
54028 - 2 2 6 2 2 6 2 2 6 2 2 6
54029 - 42 42 42 74 74 74 30 30 30 10 10 10
54030 - 0 0 0 0 0 0 0 0 0 0 0 0
54031 - 0 0 0 0 0 0 0 0 0 0 0 0
54032 - 0 0 0 0 0 0 0 0 0 0 0 0
54033 - 0 0 0 0 0 0 0 0 0 0 0 0
54034 - 0 0 0 0 0 0 0 0 0 0 0 0
54035 - 0 0 0 0 0 0 0 0 0 0 0 0
54036 - 0 0 0 0 0 0 0 0 0 0 0 0
54037 - 6 6 6 14 14 14 42 42 42 90 90 90
54038 - 26 26 26 6 6 6 42 42 42 2 2 6
54039 - 74 74 74 250 250 250 253 253 253 253 253 253
54040 -253 253 253 253 253 253 253 253 253 253 253 253
54041 -253 253 253 253 253 253 242 242 242 242 242 242
54042 -253 253 253 253 253 253 253 253 253 253 253 253
54043 -253 253 253 253 253 253 253 253 253 253 253 253
54044 -253 253 253 253 253 253 253 253 253 253 253 253
54045 -253 253 253 253 253 253 253 253 253 253 253 253
54046 -253 253 253 253 253 253 182 182 182 2 2 6
54047 - 2 2 6 2 2 6 2 2 6 46 46 46
54048 - 2 2 6 2 2 6 2 2 6 2 2 6
54049 - 10 10 10 86 86 86 38 38 38 10 10 10
54050 - 0 0 0 0 0 0 0 0 0 0 0 0
54051 - 0 0 0 0 0 0 0 0 0 0 0 0
54052 - 0 0 0 0 0 0 0 0 0 0 0 0
54053 - 0 0 0 0 0 0 0 0 0 0 0 0
54054 - 0 0 0 0 0 0 0 0 0 0 0 0
54055 - 0 0 0 0 0 0 0 0 0 0 0 0
54056 - 0 0 0 0 0 0 0 0 0 0 0 0
54057 - 10 10 10 26 26 26 66 66 66 82 82 82
54058 - 2 2 6 22 22 22 18 18 18 2 2 6
54059 -149 149 149 253 253 253 253 253 253 253 253 253
54060 -253 253 253 253 253 253 253 253 253 253 253 253
54061 -253 253 253 253 253 253 234 234 234 242 242 242
54062 -253 253 253 253 253 253 253 253 253 253 253 253
54063 -253 253 253 253 253 253 253 253 253 253 253 253
54064 -253 253 253 253 253 253 253 253 253 253 253 253
54065 -253 253 253 253 253 253 253 253 253 253 253 253
54066 -253 253 253 253 253 253 206 206 206 2 2 6
54067 - 2 2 6 2 2 6 2 2 6 38 38 38
54068 - 2 2 6 2 2 6 2 2 6 2 2 6
54069 - 6 6 6 86 86 86 46 46 46 14 14 14
54070 - 0 0 0 0 0 0 0 0 0 0 0 0
54071 - 0 0 0 0 0 0 0 0 0 0 0 0
54072 - 0 0 0 0 0 0 0 0 0 0 0 0
54073 - 0 0 0 0 0 0 0 0 0 0 0 0
54074 - 0 0 0 0 0 0 0 0 0 0 0 0
54075 - 0 0 0 0 0 0 0 0 0 0 0 0
54076 - 0 0 0 0 0 0 0 0 0 6 6 6
54077 - 18 18 18 46 46 46 86 86 86 18 18 18
54078 - 2 2 6 34 34 34 10 10 10 6 6 6
54079 -210 210 210 253 253 253 253 253 253 253 253 253
54080 -253 253 253 253 253 253 253 253 253 253 253 253
54081 -253 253 253 253 253 253 234 234 234 242 242 242
54082 -253 253 253 253 253 253 253 253 253 253 253 253
54083 -253 253 253 253 253 253 253 253 253 253 253 253
54084 -253 253 253 253 253 253 253 253 253 253 253 253
54085 -253 253 253 253 253 253 253 253 253 253 253 253
54086 -253 253 253 253 253 253 221 221 221 6 6 6
54087 - 2 2 6 2 2 6 6 6 6 30 30 30
54088 - 2 2 6 2 2 6 2 2 6 2 2 6
54089 - 2 2 6 82 82 82 54 54 54 18 18 18
54090 - 6 6 6 0 0 0 0 0 0 0 0 0
54091 - 0 0 0 0 0 0 0 0 0 0 0 0
54092 - 0 0 0 0 0 0 0 0 0 0 0 0
54093 - 0 0 0 0 0 0 0 0 0 0 0 0
54094 - 0 0 0 0 0 0 0 0 0 0 0 0
54095 - 0 0 0 0 0 0 0 0 0 0 0 0
54096 - 0 0 0 0 0 0 0 0 0 10 10 10
54097 - 26 26 26 66 66 66 62 62 62 2 2 6
54098 - 2 2 6 38 38 38 10 10 10 26 26 26
54099 -238 238 238 253 253 253 253 253 253 253 253 253
54100 -253 253 253 253 253 253 253 253 253 253 253 253
54101 -253 253 253 253 253 253 231 231 231 238 238 238
54102 -253 253 253 253 253 253 253 253 253 253 253 253
54103 -253 253 253 253 253 253 253 253 253 253 253 253
54104 -253 253 253 253 253 253 253 253 253 253 253 253
54105 -253 253 253 253 253 253 253 253 253 253 253 253
54106 -253 253 253 253 253 253 231 231 231 6 6 6
54107 - 2 2 6 2 2 6 10 10 10 30 30 30
54108 - 2 2 6 2 2 6 2 2 6 2 2 6
54109 - 2 2 6 66 66 66 58 58 58 22 22 22
54110 - 6 6 6 0 0 0 0 0 0 0 0 0
54111 - 0 0 0 0 0 0 0 0 0 0 0 0
54112 - 0 0 0 0 0 0 0 0 0 0 0 0
54113 - 0 0 0 0 0 0 0 0 0 0 0 0
54114 - 0 0 0 0 0 0 0 0 0 0 0 0
54115 - 0 0 0 0 0 0 0 0 0 0 0 0
54116 - 0 0 0 0 0 0 0 0 0 10 10 10
54117 - 38 38 38 78 78 78 6 6 6 2 2 6
54118 - 2 2 6 46 46 46 14 14 14 42 42 42
54119 -246 246 246 253 253 253 253 253 253 253 253 253
54120 -253 253 253 253 253 253 253 253 253 253 253 253
54121 -253 253 253 253 253 253 231 231 231 242 242 242
54122 -253 253 253 253 253 253 253 253 253 253 253 253
54123 -253 253 253 253 253 253 253 253 253 253 253 253
54124 -253 253 253 253 253 253 253 253 253 253 253 253
54125 -253 253 253 253 253 253 253 253 253 253 253 253
54126 -253 253 253 253 253 253 234 234 234 10 10 10
54127 - 2 2 6 2 2 6 22 22 22 14 14 14
54128 - 2 2 6 2 2 6 2 2 6 2 2 6
54129 - 2 2 6 66 66 66 62 62 62 22 22 22
54130 - 6 6 6 0 0 0 0 0 0 0 0 0
54131 - 0 0 0 0 0 0 0 0 0 0 0 0
54132 - 0 0 0 0 0 0 0 0 0 0 0 0
54133 - 0 0 0 0 0 0 0 0 0 0 0 0
54134 - 0 0 0 0 0 0 0 0 0 0 0 0
54135 - 0 0 0 0 0 0 0 0 0 0 0 0
54136 - 0 0 0 0 0 0 6 6 6 18 18 18
54137 - 50 50 50 74 74 74 2 2 6 2 2 6
54138 - 14 14 14 70 70 70 34 34 34 62 62 62
54139 -250 250 250 253 253 253 253 253 253 253 253 253
54140 -253 253 253 253 253 253 253 253 253 253 253 253
54141 -253 253 253 253 253 253 231 231 231 246 246 246
54142 -253 253 253 253 253 253 253 253 253 253 253 253
54143 -253 253 253 253 253 253 253 253 253 253 253 253
54144 -253 253 253 253 253 253 253 253 253 253 253 253
54145 -253 253 253 253 253 253 253 253 253 253 253 253
54146 -253 253 253 253 253 253 234 234 234 14 14 14
54147 - 2 2 6 2 2 6 30 30 30 2 2 6
54148 - 2 2 6 2 2 6 2 2 6 2 2 6
54149 - 2 2 6 66 66 66 62 62 62 22 22 22
54150 - 6 6 6 0 0 0 0 0 0 0 0 0
54151 - 0 0 0 0 0 0 0 0 0 0 0 0
54152 - 0 0 0 0 0 0 0 0 0 0 0 0
54153 - 0 0 0 0 0 0 0 0 0 0 0 0
54154 - 0 0 0 0 0 0 0 0 0 0 0 0
54155 - 0 0 0 0 0 0 0 0 0 0 0 0
54156 - 0 0 0 0 0 0 6 6 6 18 18 18
54157 - 54 54 54 62 62 62 2 2 6 2 2 6
54158 - 2 2 6 30 30 30 46 46 46 70 70 70
54159 -250 250 250 253 253 253 253 253 253 253 253 253
54160 -253 253 253 253 253 253 253 253 253 253 253 253
54161 -253 253 253 253 253 253 231 231 231 246 246 246
54162 -253 253 253 253 253 253 253 253 253 253 253 253
54163 -253 253 253 253 253 253 253 253 253 253 253 253
54164 -253 253 253 253 253 253 253 253 253 253 253 253
54165 -253 253 253 253 253 253 253 253 253 253 253 253
54166 -253 253 253 253 253 253 226 226 226 10 10 10
54167 - 2 2 6 6 6 6 30 30 30 2 2 6
54168 - 2 2 6 2 2 6 2 2 6 2 2 6
54169 - 2 2 6 66 66 66 58 58 58 22 22 22
54170 - 6 6 6 0 0 0 0 0 0 0 0 0
54171 - 0 0 0 0 0 0 0 0 0 0 0 0
54172 - 0 0 0 0 0 0 0 0 0 0 0 0
54173 - 0 0 0 0 0 0 0 0 0 0 0 0
54174 - 0 0 0 0 0 0 0 0 0 0 0 0
54175 - 0 0 0 0 0 0 0 0 0 0 0 0
54176 - 0 0 0 0 0 0 6 6 6 22 22 22
54177 - 58 58 58 62 62 62 2 2 6 2 2 6
54178 - 2 2 6 2 2 6 30 30 30 78 78 78
54179 -250 250 250 253 253 253 253 253 253 253 253 253
54180 -253 253 253 253 253 253 253 253 253 253 253 253
54181 -253 253 253 253 253 253 231 231 231 246 246 246
54182 -253 253 253 253 253 253 253 253 253 253 253 253
54183 -253 253 253 253 253 253 253 253 253 253 253 253
54184 -253 253 253 253 253 253 253 253 253 253 253 253
54185 -253 253 253 253 253 253 253 253 253 253 253 253
54186 -253 253 253 253 253 253 206 206 206 2 2 6
54187 - 22 22 22 34 34 34 18 14 6 22 22 22
54188 - 26 26 26 18 18 18 6 6 6 2 2 6
54189 - 2 2 6 82 82 82 54 54 54 18 18 18
54190 - 6 6 6 0 0 0 0 0 0 0 0 0
54191 - 0 0 0 0 0 0 0 0 0 0 0 0
54192 - 0 0 0 0 0 0 0 0 0 0 0 0
54193 - 0 0 0 0 0 0 0 0 0 0 0 0
54194 - 0 0 0 0 0 0 0 0 0 0 0 0
54195 - 0 0 0 0 0 0 0 0 0 0 0 0
54196 - 0 0 0 0 0 0 6 6 6 26 26 26
54197 - 62 62 62 106 106 106 74 54 14 185 133 11
54198 -210 162 10 121 92 8 6 6 6 62 62 62
54199 -238 238 238 253 253 253 253 253 253 253 253 253
54200 -253 253 253 253 253 253 253 253 253 253 253 253
54201 -253 253 253 253 253 253 231 231 231 246 246 246
54202 -253 253 253 253 253 253 253 253 253 253 253 253
54203 -253 253 253 253 253 253 253 253 253 253 253 253
54204 -253 253 253 253 253 253 253 253 253 253 253 253
54205 -253 253 253 253 253 253 253 253 253 253 253 253
54206 -253 253 253 253 253 253 158 158 158 18 18 18
54207 - 14 14 14 2 2 6 2 2 6 2 2 6
54208 - 6 6 6 18 18 18 66 66 66 38 38 38
54209 - 6 6 6 94 94 94 50 50 50 18 18 18
54210 - 6 6 6 0 0 0 0 0 0 0 0 0
54211 - 0 0 0 0 0 0 0 0 0 0 0 0
54212 - 0 0 0 0 0 0 0 0 0 0 0 0
54213 - 0 0 0 0 0 0 0 0 0 0 0 0
54214 - 0 0 0 0 0 0 0 0 0 0 0 0
54215 - 0 0 0 0 0 0 0 0 0 6 6 6
54216 - 10 10 10 10 10 10 18 18 18 38 38 38
54217 - 78 78 78 142 134 106 216 158 10 242 186 14
54218 -246 190 14 246 190 14 156 118 10 10 10 10
54219 - 90 90 90 238 238 238 253 253 253 253 253 253
54220 -253 253 253 253 253 253 253 253 253 253 253 253
54221 -253 253 253 253 253 253 231 231 231 250 250 250
54222 -253 253 253 253 253 253 253 253 253 253 253 253
54223 -253 253 253 253 253 253 253 253 253 253 253 253
54224 -253 253 253 253 253 253 253 253 253 253 253 253
54225 -253 253 253 253 253 253 253 253 253 246 230 190
54226 -238 204 91 238 204 91 181 142 44 37 26 9
54227 - 2 2 6 2 2 6 2 2 6 2 2 6
54228 - 2 2 6 2 2 6 38 38 38 46 46 46
54229 - 26 26 26 106 106 106 54 54 54 18 18 18
54230 - 6 6 6 0 0 0 0 0 0 0 0 0
54231 - 0 0 0 0 0 0 0 0 0 0 0 0
54232 - 0 0 0 0 0 0 0 0 0 0 0 0
54233 - 0 0 0 0 0 0 0 0 0 0 0 0
54234 - 0 0 0 0 0 0 0 0 0 0 0 0
54235 - 0 0 0 6 6 6 14 14 14 22 22 22
54236 - 30 30 30 38 38 38 50 50 50 70 70 70
54237 -106 106 106 190 142 34 226 170 11 242 186 14
54238 -246 190 14 246 190 14 246 190 14 154 114 10
54239 - 6 6 6 74 74 74 226 226 226 253 253 253
54240 -253 253 253 253 253 253 253 253 253 253 253 253
54241 -253 253 253 253 253 253 231 231 231 250 250 250
54242 -253 253 253 253 253 253 253 253 253 253 253 253
54243 -253 253 253 253 253 253 253 253 253 253 253 253
54244 -253 253 253 253 253 253 253 253 253 253 253 253
54245 -253 253 253 253 253 253 253 253 253 228 184 62
54246 -241 196 14 241 208 19 232 195 16 38 30 10
54247 - 2 2 6 2 2 6 2 2 6 2 2 6
54248 - 2 2 6 6 6 6 30 30 30 26 26 26
54249 -203 166 17 154 142 90 66 66 66 26 26 26
54250 - 6 6 6 0 0 0 0 0 0 0 0 0
54251 - 0 0 0 0 0 0 0 0 0 0 0 0
54252 - 0 0 0 0 0 0 0 0 0 0 0 0
54253 - 0 0 0 0 0 0 0 0 0 0 0 0
54254 - 0 0 0 0 0 0 0 0 0 0 0 0
54255 - 6 6 6 18 18 18 38 38 38 58 58 58
54256 - 78 78 78 86 86 86 101 101 101 123 123 123
54257 -175 146 61 210 150 10 234 174 13 246 186 14
54258 -246 190 14 246 190 14 246 190 14 238 190 10
54259 -102 78 10 2 2 6 46 46 46 198 198 198
54260 -253 253 253 253 253 253 253 253 253 253 253 253
54261 -253 253 253 253 253 253 234 234 234 242 242 242
54262 -253 253 253 253 253 253 253 253 253 253 253 253
54263 -253 253 253 253 253 253 253 253 253 253 253 253
54264 -253 253 253 253 253 253 253 253 253 253 253 253
54265 -253 253 253 253 253 253 253 253 253 224 178 62
54266 -242 186 14 241 196 14 210 166 10 22 18 6
54267 - 2 2 6 2 2 6 2 2 6 2 2 6
54268 - 2 2 6 2 2 6 6 6 6 121 92 8
54269 -238 202 15 232 195 16 82 82 82 34 34 34
54270 - 10 10 10 0 0 0 0 0 0 0 0 0
54271 - 0 0 0 0 0 0 0 0 0 0 0 0
54272 - 0 0 0 0 0 0 0 0 0 0 0 0
54273 - 0 0 0 0 0 0 0 0 0 0 0 0
54274 - 0 0 0 0 0 0 0 0 0 0 0 0
54275 - 14 14 14 38 38 38 70 70 70 154 122 46
54276 -190 142 34 200 144 11 197 138 11 197 138 11
54277 -213 154 11 226 170 11 242 186 14 246 190 14
54278 -246 190 14 246 190 14 246 190 14 246 190 14
54279 -225 175 15 46 32 6 2 2 6 22 22 22
54280 -158 158 158 250 250 250 253 253 253 253 253 253
54281 -253 253 253 253 253 253 253 253 253 253 253 253
54282 -253 253 253 253 253 253 253 253 253 253 253 253
54283 -253 253 253 253 253 253 253 253 253 253 253 253
54284 -253 253 253 253 253 253 253 253 253 253 253 253
54285 -253 253 253 250 250 250 242 242 242 224 178 62
54286 -239 182 13 236 186 11 213 154 11 46 32 6
54287 - 2 2 6 2 2 6 2 2 6 2 2 6
54288 - 2 2 6 2 2 6 61 42 6 225 175 15
54289 -238 190 10 236 186 11 112 100 78 42 42 42
54290 - 14 14 14 0 0 0 0 0 0 0 0 0
54291 - 0 0 0 0 0 0 0 0 0 0 0 0
54292 - 0 0 0 0 0 0 0 0 0 0 0 0
54293 - 0 0 0 0 0 0 0 0 0 0 0 0
54294 - 0 0 0 0 0 0 0 0 0 6 6 6
54295 - 22 22 22 54 54 54 154 122 46 213 154 11
54296 -226 170 11 230 174 11 226 170 11 226 170 11
54297 -236 178 12 242 186 14 246 190 14 246 190 14
54298 -246 190 14 246 190 14 246 190 14 246 190 14
54299 -241 196 14 184 144 12 10 10 10 2 2 6
54300 - 6 6 6 116 116 116 242 242 242 253 253 253
54301 -253 253 253 253 253 253 253 253 253 253 253 253
54302 -253 253 253 253 253 253 253 253 253 253 253 253
54303 -253 253 253 253 253 253 253 253 253 253 253 253
54304 -253 253 253 253 253 253 253 253 253 253 253 253
54305 -253 253 253 231 231 231 198 198 198 214 170 54
54306 -236 178 12 236 178 12 210 150 10 137 92 6
54307 - 18 14 6 2 2 6 2 2 6 2 2 6
54308 - 6 6 6 70 47 6 200 144 11 236 178 12
54309 -239 182 13 239 182 13 124 112 88 58 58 58
54310 - 22 22 22 6 6 6 0 0 0 0 0 0
54311 - 0 0 0 0 0 0 0 0 0 0 0 0
54312 - 0 0 0 0 0 0 0 0 0 0 0 0
54313 - 0 0 0 0 0 0 0 0 0 0 0 0
54314 - 0 0 0 0 0 0 0 0 0 10 10 10
54315 - 30 30 30 70 70 70 180 133 36 226 170 11
54316 -239 182 13 242 186 14 242 186 14 246 186 14
54317 -246 190 14 246 190 14 246 190 14 246 190 14
54318 -246 190 14 246 190 14 246 190 14 246 190 14
54319 -246 190 14 232 195 16 98 70 6 2 2 6
54320 - 2 2 6 2 2 6 66 66 66 221 221 221
54321 -253 253 253 253 253 253 253 253 253 253 253 253
54322 -253 253 253 253 253 253 253 253 253 253 253 253
54323 -253 253 253 253 253 253 253 253 253 253 253 253
54324 -253 253 253 253 253 253 253 253 253 253 253 253
54325 -253 253 253 206 206 206 198 198 198 214 166 58
54326 -230 174 11 230 174 11 216 158 10 192 133 9
54327 -163 110 8 116 81 8 102 78 10 116 81 8
54328 -167 114 7 197 138 11 226 170 11 239 182 13
54329 -242 186 14 242 186 14 162 146 94 78 78 78
54330 - 34 34 34 14 14 14 6 6 6 0 0 0
54331 - 0 0 0 0 0 0 0 0 0 0 0 0
54332 - 0 0 0 0 0 0 0 0 0 0 0 0
54333 - 0 0 0 0 0 0 0 0 0 0 0 0
54334 - 0 0 0 0 0 0 0 0 0 6 6 6
54335 - 30 30 30 78 78 78 190 142 34 226 170 11
54336 -239 182 13 246 190 14 246 190 14 246 190 14
54337 -246 190 14 246 190 14 246 190 14 246 190 14
54338 -246 190 14 246 190 14 246 190 14 246 190 14
54339 -246 190 14 241 196 14 203 166 17 22 18 6
54340 - 2 2 6 2 2 6 2 2 6 38 38 38
54341 -218 218 218 253 253 253 253 253 253 253 253 253
54342 -253 253 253 253 253 253 253 253 253 253 253 253
54343 -253 253 253 253 253 253 253 253 253 253 253 253
54344 -253 253 253 253 253 253 253 253 253 253 253 253
54345 -250 250 250 206 206 206 198 198 198 202 162 69
54346 -226 170 11 236 178 12 224 166 10 210 150 10
54347 -200 144 11 197 138 11 192 133 9 197 138 11
54348 -210 150 10 226 170 11 242 186 14 246 190 14
54349 -246 190 14 246 186 14 225 175 15 124 112 88
54350 - 62 62 62 30 30 30 14 14 14 6 6 6
54351 - 0 0 0 0 0 0 0 0 0 0 0 0
54352 - 0 0 0 0 0 0 0 0 0 0 0 0
54353 - 0 0 0 0 0 0 0 0 0 0 0 0
54354 - 0 0 0 0 0 0 0 0 0 10 10 10
54355 - 30 30 30 78 78 78 174 135 50 224 166 10
54356 -239 182 13 246 190 14 246 190 14 246 190 14
54357 -246 190 14 246 190 14 246 190 14 246 190 14
54358 -246 190 14 246 190 14 246 190 14 246 190 14
54359 -246 190 14 246 190 14 241 196 14 139 102 15
54360 - 2 2 6 2 2 6 2 2 6 2 2 6
54361 - 78 78 78 250 250 250 253 253 253 253 253 253
54362 -253 253 253 253 253 253 253 253 253 253 253 253
54363 -253 253 253 253 253 253 253 253 253 253 253 253
54364 -253 253 253 253 253 253 253 253 253 253 253 253
54365 -250 250 250 214 214 214 198 198 198 190 150 46
54366 -219 162 10 236 178 12 234 174 13 224 166 10
54367 -216 158 10 213 154 11 213 154 11 216 158 10
54368 -226 170 11 239 182 13 246 190 14 246 190 14
54369 -246 190 14 246 190 14 242 186 14 206 162 42
54370 -101 101 101 58 58 58 30 30 30 14 14 14
54371 - 6 6 6 0 0 0 0 0 0 0 0 0
54372 - 0 0 0 0 0 0 0 0 0 0 0 0
54373 - 0 0 0 0 0 0 0 0 0 0 0 0
54374 - 0 0 0 0 0 0 0 0 0 10 10 10
54375 - 30 30 30 74 74 74 174 135 50 216 158 10
54376 -236 178 12 246 190 14 246 190 14 246 190 14
54377 -246 190 14 246 190 14 246 190 14 246 190 14
54378 -246 190 14 246 190 14 246 190 14 246 190 14
54379 -246 190 14 246 190 14 241 196 14 226 184 13
54380 - 61 42 6 2 2 6 2 2 6 2 2 6
54381 - 22 22 22 238 238 238 253 253 253 253 253 253
54382 -253 253 253 253 253 253 253 253 253 253 253 253
54383 -253 253 253 253 253 253 253 253 253 253 253 253
54384 -253 253 253 253 253 253 253 253 253 253 253 253
54385 -253 253 253 226 226 226 187 187 187 180 133 36
54386 -216 158 10 236 178 12 239 182 13 236 178 12
54387 -230 174 11 226 170 11 226 170 11 230 174 11
54388 -236 178 12 242 186 14 246 190 14 246 190 14
54389 -246 190 14 246 190 14 246 186 14 239 182 13
54390 -206 162 42 106 106 106 66 66 66 34 34 34
54391 - 14 14 14 6 6 6 0 0 0 0 0 0
54392 - 0 0 0 0 0 0 0 0 0 0 0 0
54393 - 0 0 0 0 0 0 0 0 0 0 0 0
54394 - 0 0 0 0 0 0 0 0 0 6 6 6
54395 - 26 26 26 70 70 70 163 133 67 213 154 11
54396 -236 178 12 246 190 14 246 190 14 246 190 14
54397 -246 190 14 246 190 14 246 190 14 246 190 14
54398 -246 190 14 246 190 14 246 190 14 246 190 14
54399 -246 190 14 246 190 14 246 190 14 241 196 14
54400 -190 146 13 18 14 6 2 2 6 2 2 6
54401 - 46 46 46 246 246 246 253 253 253 253 253 253
54402 -253 253 253 253 253 253 253 253 253 253 253 253
54403 -253 253 253 253 253 253 253 253 253 253 253 253
54404 -253 253 253 253 253 253 253 253 253 253 253 253
54405 -253 253 253 221 221 221 86 86 86 156 107 11
54406 -216 158 10 236 178 12 242 186 14 246 186 14
54407 -242 186 14 239 182 13 239 182 13 242 186 14
54408 -242 186 14 246 186 14 246 190 14 246 190 14
54409 -246 190 14 246 190 14 246 190 14 246 190 14
54410 -242 186 14 225 175 15 142 122 72 66 66 66
54411 - 30 30 30 10 10 10 0 0 0 0 0 0
54412 - 0 0 0 0 0 0 0 0 0 0 0 0
54413 - 0 0 0 0 0 0 0 0 0 0 0 0
54414 - 0 0 0 0 0 0 0 0 0 6 6 6
54415 - 26 26 26 70 70 70 163 133 67 210 150 10
54416 -236 178 12 246 190 14 246 190 14 246 190 14
54417 -246 190 14 246 190 14 246 190 14 246 190 14
54418 -246 190 14 246 190 14 246 190 14 246 190 14
54419 -246 190 14 246 190 14 246 190 14 246 190 14
54420 -232 195 16 121 92 8 34 34 34 106 106 106
54421 -221 221 221 253 253 253 253 253 253 253 253 253
54422 -253 253 253 253 253 253 253 253 253 253 253 253
54423 -253 253 253 253 253 253 253 253 253 253 253 253
54424 -253 253 253 253 253 253 253 253 253 253 253 253
54425 -242 242 242 82 82 82 18 14 6 163 110 8
54426 -216 158 10 236 178 12 242 186 14 246 190 14
54427 -246 190 14 246 190 14 246 190 14 246 190 14
54428 -246 190 14 246 190 14 246 190 14 246 190 14
54429 -246 190 14 246 190 14 246 190 14 246 190 14
54430 -246 190 14 246 190 14 242 186 14 163 133 67
54431 - 46 46 46 18 18 18 6 6 6 0 0 0
54432 - 0 0 0 0 0 0 0 0 0 0 0 0
54433 - 0 0 0 0 0 0 0 0 0 0 0 0
54434 - 0 0 0 0 0 0 0 0 0 10 10 10
54435 - 30 30 30 78 78 78 163 133 67 210 150 10
54436 -236 178 12 246 186 14 246 190 14 246 190 14
54437 -246 190 14 246 190 14 246 190 14 246 190 14
54438 -246 190 14 246 190 14 246 190 14 246 190 14
54439 -246 190 14 246 190 14 246 190 14 246 190 14
54440 -241 196 14 215 174 15 190 178 144 253 253 253
54441 -253 253 253 253 253 253 253 253 253 253 253 253
54442 -253 253 253 253 253 253 253 253 253 253 253 253
54443 -253 253 253 253 253 253 253 253 253 253 253 253
54444 -253 253 253 253 253 253 253 253 253 218 218 218
54445 - 58 58 58 2 2 6 22 18 6 167 114 7
54446 -216 158 10 236 178 12 246 186 14 246 190 14
54447 -246 190 14 246 190 14 246 190 14 246 190 14
54448 -246 190 14 246 190 14 246 190 14 246 190 14
54449 -246 190 14 246 190 14 246 190 14 246 190 14
54450 -246 190 14 246 186 14 242 186 14 190 150 46
54451 - 54 54 54 22 22 22 6 6 6 0 0 0
54452 - 0 0 0 0 0 0 0 0 0 0 0 0
54453 - 0 0 0 0 0 0 0 0 0 0 0 0
54454 - 0 0 0 0 0 0 0 0 0 14 14 14
54455 - 38 38 38 86 86 86 180 133 36 213 154 11
54456 -236 178 12 246 186 14 246 190 14 246 190 14
54457 -246 190 14 246 190 14 246 190 14 246 190 14
54458 -246 190 14 246 190 14 246 190 14 246 190 14
54459 -246 190 14 246 190 14 246 190 14 246 190 14
54460 -246 190 14 232 195 16 190 146 13 214 214 214
54461 -253 253 253 253 253 253 253 253 253 253 253 253
54462 -253 253 253 253 253 253 253 253 253 253 253 253
54463 -253 253 253 253 253 253 253 253 253 253 253 253
54464 -253 253 253 250 250 250 170 170 170 26 26 26
54465 - 2 2 6 2 2 6 37 26 9 163 110 8
54466 -219 162 10 239 182 13 246 186 14 246 190 14
54467 -246 190 14 246 190 14 246 190 14 246 190 14
54468 -246 190 14 246 190 14 246 190 14 246 190 14
54469 -246 190 14 246 190 14 246 190 14 246 190 14
54470 -246 186 14 236 178 12 224 166 10 142 122 72
54471 - 46 46 46 18 18 18 6 6 6 0 0 0
54472 - 0 0 0 0 0 0 0 0 0 0 0 0
54473 - 0 0 0 0 0 0 0 0 0 0 0 0
54474 - 0 0 0 0 0 0 6 6 6 18 18 18
54475 - 50 50 50 109 106 95 192 133 9 224 166 10
54476 -242 186 14 246 190 14 246 190 14 246 190 14
54477 -246 190 14 246 190 14 246 190 14 246 190 14
54478 -246 190 14 246 190 14 246 190 14 246 190 14
54479 -246 190 14 246 190 14 246 190 14 246 190 14
54480 -242 186 14 226 184 13 210 162 10 142 110 46
54481 -226 226 226 253 253 253 253 253 253 253 253 253
54482 -253 253 253 253 253 253 253 253 253 253 253 253
54483 -253 253 253 253 253 253 253 253 253 253 253 253
54484 -198 198 198 66 66 66 2 2 6 2 2 6
54485 - 2 2 6 2 2 6 50 34 6 156 107 11
54486 -219 162 10 239 182 13 246 186 14 246 190 14
54487 -246 190 14 246 190 14 246 190 14 246 190 14
54488 -246 190 14 246 190 14 246 190 14 246 190 14
54489 -246 190 14 246 190 14 246 190 14 242 186 14
54490 -234 174 13 213 154 11 154 122 46 66 66 66
54491 - 30 30 30 10 10 10 0 0 0 0 0 0
54492 - 0 0 0 0 0 0 0 0 0 0 0 0
54493 - 0 0 0 0 0 0 0 0 0 0 0 0
54494 - 0 0 0 0 0 0 6 6 6 22 22 22
54495 - 58 58 58 154 121 60 206 145 10 234 174 13
54496 -242 186 14 246 186 14 246 190 14 246 190 14
54497 -246 190 14 246 190 14 246 190 14 246 190 14
54498 -246 190 14 246 190 14 246 190 14 246 190 14
54499 -246 190 14 246 190 14 246 190 14 246 190 14
54500 -246 186 14 236 178 12 210 162 10 163 110 8
54501 - 61 42 6 138 138 138 218 218 218 250 250 250
54502 -253 253 253 253 253 253 253 253 253 250 250 250
54503 -242 242 242 210 210 210 144 144 144 66 66 66
54504 - 6 6 6 2 2 6 2 2 6 2 2 6
54505 - 2 2 6 2 2 6 61 42 6 163 110 8
54506 -216 158 10 236 178 12 246 190 14 246 190 14
54507 -246 190 14 246 190 14 246 190 14 246 190 14
54508 -246 190 14 246 190 14 246 190 14 246 190 14
54509 -246 190 14 239 182 13 230 174 11 216 158 10
54510 -190 142 34 124 112 88 70 70 70 38 38 38
54511 - 18 18 18 6 6 6 0 0 0 0 0 0
54512 - 0 0 0 0 0 0 0 0 0 0 0 0
54513 - 0 0 0 0 0 0 0 0 0 0 0 0
54514 - 0 0 0 0 0 0 6 6 6 22 22 22
54515 - 62 62 62 168 124 44 206 145 10 224 166 10
54516 -236 178 12 239 182 13 242 186 14 242 186 14
54517 -246 186 14 246 190 14 246 190 14 246 190 14
54518 -246 190 14 246 190 14 246 190 14 246 190 14
54519 -246 190 14 246 190 14 246 190 14 246 190 14
54520 -246 190 14 236 178 12 216 158 10 175 118 6
54521 - 80 54 7 2 2 6 6 6 6 30 30 30
54522 - 54 54 54 62 62 62 50 50 50 38 38 38
54523 - 14 14 14 2 2 6 2 2 6 2 2 6
54524 - 2 2 6 2 2 6 2 2 6 2 2 6
54525 - 2 2 6 6 6 6 80 54 7 167 114 7
54526 -213 154 11 236 178 12 246 190 14 246 190 14
54527 -246 190 14 246 190 14 246 190 14 246 190 14
54528 -246 190 14 242 186 14 239 182 13 239 182 13
54529 -230 174 11 210 150 10 174 135 50 124 112 88
54530 - 82 82 82 54 54 54 34 34 34 18 18 18
54531 - 6 6 6 0 0 0 0 0 0 0 0 0
54532 - 0 0 0 0 0 0 0 0 0 0 0 0
54533 - 0 0 0 0 0 0 0 0 0 0 0 0
54534 - 0 0 0 0 0 0 6 6 6 18 18 18
54535 - 50 50 50 158 118 36 192 133 9 200 144 11
54536 -216 158 10 219 162 10 224 166 10 226 170 11
54537 -230 174 11 236 178 12 239 182 13 239 182 13
54538 -242 186 14 246 186 14 246 190 14 246 190 14
54539 -246 190 14 246 190 14 246 190 14 246 190 14
54540 -246 186 14 230 174 11 210 150 10 163 110 8
54541 -104 69 6 10 10 10 2 2 6 2 2 6
54542 - 2 2 6 2 2 6 2 2 6 2 2 6
54543 - 2 2 6 2 2 6 2 2 6 2 2 6
54544 - 2 2 6 2 2 6 2 2 6 2 2 6
54545 - 2 2 6 6 6 6 91 60 6 167 114 7
54546 -206 145 10 230 174 11 242 186 14 246 190 14
54547 -246 190 14 246 190 14 246 186 14 242 186 14
54548 -239 182 13 230 174 11 224 166 10 213 154 11
54549 -180 133 36 124 112 88 86 86 86 58 58 58
54550 - 38 38 38 22 22 22 10 10 10 6 6 6
54551 - 0 0 0 0 0 0 0 0 0 0 0 0
54552 - 0 0 0 0 0 0 0 0 0 0 0 0
54553 - 0 0 0 0 0 0 0 0 0 0 0 0
54554 - 0 0 0 0 0 0 0 0 0 14 14 14
54555 - 34 34 34 70 70 70 138 110 50 158 118 36
54556 -167 114 7 180 123 7 192 133 9 197 138 11
54557 -200 144 11 206 145 10 213 154 11 219 162 10
54558 -224 166 10 230 174 11 239 182 13 242 186 14
54559 -246 186 14 246 186 14 246 186 14 246 186 14
54560 -239 182 13 216 158 10 185 133 11 152 99 6
54561 -104 69 6 18 14 6 2 2 6 2 2 6
54562 - 2 2 6 2 2 6 2 2 6 2 2 6
54563 - 2 2 6 2 2 6 2 2 6 2 2 6
54564 - 2 2 6 2 2 6 2 2 6 2 2 6
54565 - 2 2 6 6 6 6 80 54 7 152 99 6
54566 -192 133 9 219 162 10 236 178 12 239 182 13
54567 -246 186 14 242 186 14 239 182 13 236 178 12
54568 -224 166 10 206 145 10 192 133 9 154 121 60
54569 - 94 94 94 62 62 62 42 42 42 22 22 22
54570 - 14 14 14 6 6 6 0 0 0 0 0 0
54571 - 0 0 0 0 0 0 0 0 0 0 0 0
54572 - 0 0 0 0 0 0 0 0 0 0 0 0
54573 - 0 0 0 0 0 0 0 0 0 0 0 0
54574 - 0 0 0 0 0 0 0 0 0 6 6 6
54575 - 18 18 18 34 34 34 58 58 58 78 78 78
54576 -101 98 89 124 112 88 142 110 46 156 107 11
54577 -163 110 8 167 114 7 175 118 6 180 123 7
54578 -185 133 11 197 138 11 210 150 10 219 162 10
54579 -226 170 11 236 178 12 236 178 12 234 174 13
54580 -219 162 10 197 138 11 163 110 8 130 83 6
54581 - 91 60 6 10 10 10 2 2 6 2 2 6
54582 - 18 18 18 38 38 38 38 38 38 38 38 38
54583 - 38 38 38 38 38 38 38 38 38 38 38 38
54584 - 38 38 38 38 38 38 26 26 26 2 2 6
54585 - 2 2 6 6 6 6 70 47 6 137 92 6
54586 -175 118 6 200 144 11 219 162 10 230 174 11
54587 -234 174 13 230 174 11 219 162 10 210 150 10
54588 -192 133 9 163 110 8 124 112 88 82 82 82
54589 - 50 50 50 30 30 30 14 14 14 6 6 6
54590 - 0 0 0 0 0 0 0 0 0 0 0 0
54591 - 0 0 0 0 0 0 0 0 0 0 0 0
54592 - 0 0 0 0 0 0 0 0 0 0 0 0
54593 - 0 0 0 0 0 0 0 0 0 0 0 0
54594 - 0 0 0 0 0 0 0 0 0 0 0 0
54595 - 6 6 6 14 14 14 22 22 22 34 34 34
54596 - 42 42 42 58 58 58 74 74 74 86 86 86
54597 -101 98 89 122 102 70 130 98 46 121 87 25
54598 -137 92 6 152 99 6 163 110 8 180 123 7
54599 -185 133 11 197 138 11 206 145 10 200 144 11
54600 -180 123 7 156 107 11 130 83 6 104 69 6
54601 - 50 34 6 54 54 54 110 110 110 101 98 89
54602 - 86 86 86 82 82 82 78 78 78 78 78 78
54603 - 78 78 78 78 78 78 78 78 78 78 78 78
54604 - 78 78 78 82 82 82 86 86 86 94 94 94
54605 -106 106 106 101 101 101 86 66 34 124 80 6
54606 -156 107 11 180 123 7 192 133 9 200 144 11
54607 -206 145 10 200 144 11 192 133 9 175 118 6
54608 -139 102 15 109 106 95 70 70 70 42 42 42
54609 - 22 22 22 10 10 10 0 0 0 0 0 0
54610 - 0 0 0 0 0 0 0 0 0 0 0 0
54611 - 0 0 0 0 0 0 0 0 0 0 0 0
54612 - 0 0 0 0 0 0 0 0 0 0 0 0
54613 - 0 0 0 0 0 0 0 0 0 0 0 0
54614 - 0 0 0 0 0 0 0 0 0 0 0 0
54615 - 0 0 0 0 0 0 6 6 6 10 10 10
54616 - 14 14 14 22 22 22 30 30 30 38 38 38
54617 - 50 50 50 62 62 62 74 74 74 90 90 90
54618 -101 98 89 112 100 78 121 87 25 124 80 6
54619 -137 92 6 152 99 6 152 99 6 152 99 6
54620 -138 86 6 124 80 6 98 70 6 86 66 30
54621 -101 98 89 82 82 82 58 58 58 46 46 46
54622 - 38 38 38 34 34 34 34 34 34 34 34 34
54623 - 34 34 34 34 34 34 34 34 34 34 34 34
54624 - 34 34 34 34 34 34 38 38 38 42 42 42
54625 - 54 54 54 82 82 82 94 86 76 91 60 6
54626 -134 86 6 156 107 11 167 114 7 175 118 6
54627 -175 118 6 167 114 7 152 99 6 121 87 25
54628 -101 98 89 62 62 62 34 34 34 18 18 18
54629 - 6 6 6 0 0 0 0 0 0 0 0 0
54630 - 0 0 0 0 0 0 0 0 0 0 0 0
54631 - 0 0 0 0 0 0 0 0 0 0 0 0
54632 - 0 0 0 0 0 0 0 0 0 0 0 0
54633 - 0 0 0 0 0 0 0 0 0 0 0 0
54634 - 0 0 0 0 0 0 0 0 0 0 0 0
54635 - 0 0 0 0 0 0 0 0 0 0 0 0
54636 - 0 0 0 6 6 6 6 6 6 10 10 10
54637 - 18 18 18 22 22 22 30 30 30 42 42 42
54638 - 50 50 50 66 66 66 86 86 86 101 98 89
54639 -106 86 58 98 70 6 104 69 6 104 69 6
54640 -104 69 6 91 60 6 82 62 34 90 90 90
54641 - 62 62 62 38 38 38 22 22 22 14 14 14
54642 - 10 10 10 10 10 10 10 10 10 10 10 10
54643 - 10 10 10 10 10 10 6 6 6 10 10 10
54644 - 10 10 10 10 10 10 10 10 10 14 14 14
54645 - 22 22 22 42 42 42 70 70 70 89 81 66
54646 - 80 54 7 104 69 6 124 80 6 137 92 6
54647 -134 86 6 116 81 8 100 82 52 86 86 86
54648 - 58 58 58 30 30 30 14 14 14 6 6 6
54649 - 0 0 0 0 0 0 0 0 0 0 0 0
54650 - 0 0 0 0 0 0 0 0 0 0 0 0
54651 - 0 0 0 0 0 0 0 0 0 0 0 0
54652 - 0 0 0 0 0 0 0 0 0 0 0 0
54653 - 0 0 0 0 0 0 0 0 0 0 0 0
54654 - 0 0 0 0 0 0 0 0 0 0 0 0
54655 - 0 0 0 0 0 0 0 0 0 0 0 0
54656 - 0 0 0 0 0 0 0 0 0 0 0 0
54657 - 0 0 0 6 6 6 10 10 10 14 14 14
54658 - 18 18 18 26 26 26 38 38 38 54 54 54
54659 - 70 70 70 86 86 86 94 86 76 89 81 66
54660 - 89 81 66 86 86 86 74 74 74 50 50 50
54661 - 30 30 30 14 14 14 6 6 6 0 0 0
54662 - 0 0 0 0 0 0 0 0 0 0 0 0
54663 - 0 0 0 0 0 0 0 0 0 0 0 0
54664 - 0 0 0 0 0 0 0 0 0 0 0 0
54665 - 6 6 6 18 18 18 34 34 34 58 58 58
54666 - 82 82 82 89 81 66 89 81 66 89 81 66
54667 - 94 86 66 94 86 76 74 74 74 50 50 50
54668 - 26 26 26 14 14 14 6 6 6 0 0 0
54669 - 0 0 0 0 0 0 0 0 0 0 0 0
54670 - 0 0 0 0 0 0 0 0 0 0 0 0
54671 - 0 0 0 0 0 0 0 0 0 0 0 0
54672 - 0 0 0 0 0 0 0 0 0 0 0 0
54673 - 0 0 0 0 0 0 0 0 0 0 0 0
54674 - 0 0 0 0 0 0 0 0 0 0 0 0
54675 - 0 0 0 0 0 0 0 0 0 0 0 0
54676 - 0 0 0 0 0 0 0 0 0 0 0 0
54677 - 0 0 0 0 0 0 0 0 0 0 0 0
54678 - 6 6 6 6 6 6 14 14 14 18 18 18
54679 - 30 30 30 38 38 38 46 46 46 54 54 54
54680 - 50 50 50 42 42 42 30 30 30 18 18 18
54681 - 10 10 10 0 0 0 0 0 0 0 0 0
54682 - 0 0 0 0 0 0 0 0 0 0 0 0
54683 - 0 0 0 0 0 0 0 0 0 0 0 0
54684 - 0 0 0 0 0 0 0 0 0 0 0 0
54685 - 0 0 0 6 6 6 14 14 14 26 26 26
54686 - 38 38 38 50 50 50 58 58 58 58 58 58
54687 - 54 54 54 42 42 42 30 30 30 18 18 18
54688 - 10 10 10 0 0 0 0 0 0 0 0 0
54689 - 0 0 0 0 0 0 0 0 0 0 0 0
54690 - 0 0 0 0 0 0 0 0 0 0 0 0
54691 - 0 0 0 0 0 0 0 0 0 0 0 0
54692 - 0 0 0 0 0 0 0 0 0 0 0 0
54693 - 0 0 0 0 0 0 0 0 0 0 0 0
54694 - 0 0 0 0 0 0 0 0 0 0 0 0
54695 - 0 0 0 0 0 0 0 0 0 0 0 0
54696 - 0 0 0 0 0 0 0 0 0 0 0 0
54697 - 0 0 0 0 0 0 0 0 0 0 0 0
54698 - 0 0 0 0 0 0 0 0 0 6 6 6
54699 - 6 6 6 10 10 10 14 14 14 18 18 18
54700 - 18 18 18 14 14 14 10 10 10 6 6 6
54701 - 0 0 0 0 0 0 0 0 0 0 0 0
54702 - 0 0 0 0 0 0 0 0 0 0 0 0
54703 - 0 0 0 0 0 0 0 0 0 0 0 0
54704 - 0 0 0 0 0 0 0 0 0 0 0 0
54705 - 0 0 0 0 0 0 0 0 0 6 6 6
54706 - 14 14 14 18 18 18 22 22 22 22 22 22
54707 - 18 18 18 14 14 14 10 10 10 6 6 6
54708 - 0 0 0 0 0 0 0 0 0 0 0 0
54709 - 0 0 0 0 0 0 0 0 0 0 0 0
54710 - 0 0 0 0 0 0 0 0 0 0 0 0
54711 - 0 0 0 0 0 0 0 0 0 0 0 0
54712 - 0 0 0 0 0 0 0 0 0 0 0 0
54713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726 +4 4 4 4 4 4
54727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740 +4 4 4 4 4 4
54741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754 +4 4 4 4 4 4
54755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768 +4 4 4 4 4 4
54769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782 +4 4 4 4 4 4
54783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796 +4 4 4 4 4 4
54797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54802 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54806 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54807 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54808 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810 +4 4 4 4 4 4
54811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54816 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54817 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54820 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54821 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54822 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54823 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824 +4 4 4 4 4 4
54825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54829 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54830 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54831 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54834 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54835 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54836 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54837 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54838 +4 4 4 4 4 4
54839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54842 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54843 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54844 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54845 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54847 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54848 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54849 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54850 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54851 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54852 +4 4 4 4 4 4
54853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54856 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54857 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54858 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54859 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54860 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54861 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54862 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54863 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54864 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54865 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54866 +4 4 4 4 4 4
54867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54870 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54871 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54872 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54873 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54874 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54875 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54876 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54877 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54878 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54879 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54880 +4 4 4 4 4 4
54881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54883 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54884 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54885 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54886 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54887 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54888 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54889 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54890 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54891 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54892 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54893 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54894 +4 4 4 4 4 4
54895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54897 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54898 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54899 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54900 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54901 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54902 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54903 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54904 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54905 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54906 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54907 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54908 +4 4 4 4 4 4
54909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54911 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54912 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54913 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54914 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54915 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54916 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54917 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54918 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54919 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54920 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54921 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4
54923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54925 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54926 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54927 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54928 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54929 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54930 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54931 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54932 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54933 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54934 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54935 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54936 +4 4 4 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54939 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54940 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54941 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54942 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54943 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54944 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54945 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54946 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54947 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54948 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54949 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54950 +4 4 4 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54953 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54954 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54955 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54956 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54957 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54958 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54959 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54960 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54961 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54962 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54963 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54964 +0 0 0 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54966 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54967 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54968 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54969 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54970 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54971 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54972 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54973 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54974 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54975 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54976 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54977 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54978 +2 0 0 0 0 0
54979 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54980 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54981 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54982 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54983 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54984 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54985 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54986 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54987 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54988 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54989 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54990 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54991 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54992 +37 38 37 0 0 0
54993 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54994 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54995 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54996 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54997 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54998 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54999 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55000 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55001 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55002 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55003 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55004 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55005 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55006 +85 115 134 4 0 0
55007 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55008 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55009 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55010 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55011 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55012 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55013 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55014 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55015 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55016 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55017 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55018 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55019 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55020 +60 73 81 4 0 0
55021 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55022 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55023 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55024 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55025 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55026 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55027 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55028 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55029 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55030 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55031 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55032 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55033 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55034 +16 19 21 4 0 0
55035 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55036 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55037 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55038 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55039 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55040 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55041 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55042 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55043 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55044 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55045 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55046 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55047 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55048 +4 0 0 4 3 3
55049 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55050 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55051 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55053 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55054 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55055 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55056 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55057 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55058 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55059 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55060 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55061 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55062 +3 2 2 4 4 4
55063 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55064 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55065 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55066 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55067 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55068 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55069 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55070 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55071 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55072 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55073 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55074 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55075 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55076 +4 4 4 4 4 4
55077 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55078 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55079 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55080 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55081 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55082 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55083 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55084 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55085 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55086 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55087 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55088 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55089 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55090 +4 4 4 4 4 4
55091 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55092 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55093 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55094 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55095 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55096 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55097 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55098 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55099 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55100 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55101 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55102 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55103 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55104 +5 5 5 5 5 5
55105 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55106 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55107 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55108 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55109 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55110 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55111 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55112 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55113 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55114 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55115 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55116 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55117 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55118 +5 5 5 4 4 4
55119 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55120 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55121 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55122 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55123 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55124 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55125 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55126 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55127 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55128 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55129 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55130 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55132 +4 4 4 4 4 4
55133 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55134 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55135 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55136 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55137 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55138 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55139 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55140 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55141 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55142 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55143 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55144 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55146 +4 4 4 4 4 4
55147 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55148 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55149 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55150 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55151 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55152 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55153 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55154 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55155 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55156 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55157 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55160 +4 4 4 4 4 4
55161 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55162 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55163 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55164 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55165 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55166 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55167 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55168 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55169 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55170 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55171 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174 +4 4 4 4 4 4
55175 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55176 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55177 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55178 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55179 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55180 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55181 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55182 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55183 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55184 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55185 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188 +4 4 4 4 4 4
55189 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55190 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55191 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55192 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55193 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55194 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55195 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55196 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55197 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55198 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55199 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202 +4 4 4 4 4 4
55203 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55204 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55205 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55206 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55207 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55208 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55209 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55210 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55211 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55212 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55213 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216 +4 4 4 4 4 4
55217 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55218 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55219 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55220 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55221 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55222 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55223 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55224 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55225 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55226 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55227 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55230 +4 4 4 4 4 4
55231 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55232 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55233 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55234 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55235 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55236 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55237 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55238 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55239 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55240 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55241 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55244 +4 4 4 4 4 4
55245 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55246 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55247 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55248 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55249 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55250 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55251 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55252 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55253 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55254 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55255 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55258 +4 4 4 4 4 4
55259 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55260 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55261 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55262 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55263 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55264 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55265 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55266 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55267 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55268 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55269 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55272 +4 4 4 4 4 4
55273 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55274 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55275 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55276 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55277 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55278 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55279 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55280 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55281 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55282 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55283 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286 +4 4 4 4 4 4
55287 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55288 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55289 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55290 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55291 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55292 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55293 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55294 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55295 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55296 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55297 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55300 +4 4 4 4 4 4
55301 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55302 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55303 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55304 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55305 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55306 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55307 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55308 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55309 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55310 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55311 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55314 +4 4 4 4 4 4
55315 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55316 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55317 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55318 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55319 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55320 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55321 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55322 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55323 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55324 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55325 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55328 +4 4 4 4 4 4
55329 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55330 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55331 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55332 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55333 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55334 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55335 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55336 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55337 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55338 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55339 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55342 +4 4 4 4 4 4
55343 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55344 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55345 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55346 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55347 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55348 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55349 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55350 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55351 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55352 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55353 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55356 +4 4 4 4 4 4
55357 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55358 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55359 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55360 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55361 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55362 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55363 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55364 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55365 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55366 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55367 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55370 +4 4 4 4 4 4
55371 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55372 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55373 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55374 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55375 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55376 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55377 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55378 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55379 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55380 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55381 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55384 +4 4 4 4 4 4
55385 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55386 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55387 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55388 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55389 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55390 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55391 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55392 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55393 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55394 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55395 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55398 +4 4 4 4 4 4
55399 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55400 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55401 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55402 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55403 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55404 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55405 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55406 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55407 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55408 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55409 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55412 +4 4 4 4 4 4
55413 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55414 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55415 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55416 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55417 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55418 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55419 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55420 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55421 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55422 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55423 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55426 +4 4 4 4 4 4
55427 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55428 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55429 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55430 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55431 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55432 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55433 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55434 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55435 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55436 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55437 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55440 +4 4 4 4 4 4
55441 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55442 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55443 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55444 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55445 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55446 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55447 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55448 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55449 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55450 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55451 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55454 +4 4 4 4 4 4
55455 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55456 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55457 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55458 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55459 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55460 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55461 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55462 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55463 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55464 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55465 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55468 +4 4 4 4 4 4
55469 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55470 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55471 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55472 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55473 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55474 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55475 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55476 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55477 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55478 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55479 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55482 +4 4 4 4 4 4
55483 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55484 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55485 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55486 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55487 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55488 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55489 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55490 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55491 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55492 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55493 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55496 +4 4 4 4 4 4
55497 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55498 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55499 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55500 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55501 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55502 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55503 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55504 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55505 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55506 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55507 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55510 +4 4 4 4 4 4
55511 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55512 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55513 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55514 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55515 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55516 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55517 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55518 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55519 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55520 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55521 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55524 +4 4 4 4 4 4
55525 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55526 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55527 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55528 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55529 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55530 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55531 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55532 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55533 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55534 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55538 +4 4 4 4 4 4
55539 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55540 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55541 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55542 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55543 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55544 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55545 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55546 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55547 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55548 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55552 +4 4 4 4 4 4
55553 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55554 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55555 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55556 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55557 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55558 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55559 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55560 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55561 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55562 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55566 +4 4 4 4 4 4
55567 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55568 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55569 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55570 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55571 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55572 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55573 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55574 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55575 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55576 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55580 +4 4 4 4 4 4
55581 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55582 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55583 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55584 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55585 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55586 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55587 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55588 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55589 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55594 +4 4 4 4 4 4
55595 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55596 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55597 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55598 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55599 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55600 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55601 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55602 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55603 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55608 +4 4 4 4 4 4
55609 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55610 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55611 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55612 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55613 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55614 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55615 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55616 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55617 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55622 +4 4 4 4 4 4
55623 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55624 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55625 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55626 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55627 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55628 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55629 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55630 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636 +4 4 4 4 4 4
55637 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55638 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55639 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55640 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55641 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55642 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55643 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55644 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650 +4 4 4 4 4 4
55651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55652 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55653 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55654 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55655 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55656 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55657 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55658 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664 +4 4 4 4 4 4
55665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55667 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55668 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55669 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55670 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55671 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55672 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678 +4 4 4 4 4 4
55679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55681 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55682 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55683 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55684 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55685 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55686 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692 +4 4 4 4 4 4
55693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55696 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55697 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55698 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55699 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55700 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706 +4 4 4 4 4 4
55707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55710 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55711 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55712 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55713 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720 +4 4 4 4 4 4
55721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55724 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55725 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55726 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55727 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55734 +4 4 4 4 4 4
55735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55738 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55739 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55740 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55741 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55748 +4 4 4 4 4 4
55749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55752 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55753 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55754 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55755 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55762 +4 4 4 4 4 4
55763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55767 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55768 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55769 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55776 +4 4 4 4 4 4
55777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55781 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55782 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55783 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55790 +4 4 4 4 4 4
55791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55795 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55796 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55797 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55804 +4 4 4 4 4 4
55805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55809 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55810 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55818 +4 4 4 4 4 4
55819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55823 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55824 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55832 +4 4 4 4 4 4
55833 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55834 index fef20db..d28b1ab 100644
55835 --- a/drivers/xen/xenfs/xenstored.c
55836 +++ b/drivers/xen/xenfs/xenstored.c
55837 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55838 static int xsd_kva_open(struct inode *inode, struct file *file)
55839 {
55840 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55842 + NULL);
55843 +#else
55844 xen_store_interface);
55845 +#endif
55846 +
55847 if (!file->private_data)
55848 return -ENOMEM;
55849 return 0;
55850 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55851 index c71e886..61d3d44b 100644
55852 --- a/fs/9p/vfs_addr.c
55853 +++ b/fs/9p/vfs_addr.c
55854 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55855
55856 retval = v9fs_file_write_internal(inode,
55857 v9inode->writeback_fid,
55858 - (__force const char __user *)buffer,
55859 + (const char __force_user *)buffer,
55860 len, &offset, 0);
55861 if (retval > 0)
55862 retval = 0;
55863 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55864 index 53161ec..e261d8a 100644
55865 --- a/fs/9p/vfs_inode.c
55866 +++ b/fs/9p/vfs_inode.c
55867 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55868 void
55869 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55870 {
55871 - char *s = nd_get_link(nd);
55872 + const char *s = nd_get_link(nd);
55873
55874 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55875 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55876 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55877 index 370b24c..ff0be7b 100644
55878 --- a/fs/Kconfig.binfmt
55879 +++ b/fs/Kconfig.binfmt
55880 @@ -103,7 +103,7 @@ config HAVE_AOUT
55881
55882 config BINFMT_AOUT
55883 tristate "Kernel support for a.out and ECOFF binaries"
55884 - depends on HAVE_AOUT
55885 + depends on HAVE_AOUT && BROKEN
55886 ---help---
55887 A.out (Assembler.OUTput) is a set of formats for libraries and
55888 executables used in the earliest versions of UNIX. Linux used
55889 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55890 index 2946712..f737435 100644
55891 --- a/fs/afs/inode.c
55892 +++ b/fs/afs/inode.c
55893 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55894 struct afs_vnode *vnode;
55895 struct super_block *sb;
55896 struct inode *inode;
55897 - static atomic_t afs_autocell_ino;
55898 + static atomic_unchecked_t afs_autocell_ino;
55899
55900 _enter("{%x:%u},%*.*s,",
55901 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55902 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55903 data.fid.unique = 0;
55904 data.fid.vnode = 0;
55905
55906 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55907 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55908 afs_iget5_autocell_test, afs_iget5_set,
55909 &data);
55910 if (!inode) {
55911 diff --git a/fs/aio.c b/fs/aio.c
55912 index e609e15..c9fcd97 100644
55913 --- a/fs/aio.c
55914 +++ b/fs/aio.c
55915 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55916 size += sizeof(struct io_event) * nr_events;
55917
55918 nr_pages = PFN_UP(size);
55919 - if (nr_pages < 0)
55920 + if (nr_pages <= 0)
55921 return -EINVAL;
55922
55923 file = aio_private_file(ctx, nr_pages);
55924 diff --git a/fs/attr.c b/fs/attr.c
55925 index 6530ced..4a827e2 100644
55926 --- a/fs/attr.c
55927 +++ b/fs/attr.c
55928 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55929 unsigned long limit;
55930
55931 limit = rlimit(RLIMIT_FSIZE);
55932 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55933 if (limit != RLIM_INFINITY && offset > limit)
55934 goto out_sig;
55935 if (offset > inode->i_sb->s_maxbytes)
55936 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55937 index 116fd38..c04182da 100644
55938 --- a/fs/autofs4/waitq.c
55939 +++ b/fs/autofs4/waitq.c
55940 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55941 {
55942 unsigned long sigpipe, flags;
55943 mm_segment_t fs;
55944 - const char *data = (const char *)addr;
55945 + const char __user *data = (const char __force_user *)addr;
55946 ssize_t wr = 0;
55947
55948 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55949 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55950 return 1;
55951 }
55952
55953 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55954 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55955 +#endif
55956 +
55957 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55958 enum autofs_notify notify)
55959 {
55960 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55961
55962 /* If this is a direct mount request create a dummy name */
55963 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55964 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55965 + /* this name does get written to userland via autofs4_write() */
55966 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55967 +#else
55968 qstr.len = sprintf(name, "%p", dentry);
55969 +#endif
55970 else {
55971 qstr.len = autofs4_getpath(sbi, dentry, &name);
55972 if (!qstr.len) {
55973 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55974 index 2722387..56059b5 100644
55975 --- a/fs/befs/endian.h
55976 +++ b/fs/befs/endian.h
55977 @@ -11,7 +11,7 @@
55978
55979 #include <asm/byteorder.h>
55980
55981 -static inline u64
55982 +static inline u64 __intentional_overflow(-1)
55983 fs64_to_cpu(const struct super_block *sb, fs64 n)
55984 {
55985 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55986 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55987 return (__force fs64)cpu_to_be64(n);
55988 }
55989
55990 -static inline u32
55991 +static inline u32 __intentional_overflow(-1)
55992 fs32_to_cpu(const struct super_block *sb, fs32 n)
55993 {
55994 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55995 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55996 return (__force fs32)cpu_to_be32(n);
55997 }
55998
55999 -static inline u16
56000 +static inline u16 __intentional_overflow(-1)
56001 fs16_to_cpu(const struct super_block *sb, fs16 n)
56002 {
56003 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56004 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56005 index ca0ba15..0fa3257 100644
56006 --- a/fs/binfmt_aout.c
56007 +++ b/fs/binfmt_aout.c
56008 @@ -16,6 +16,7 @@
56009 #include <linux/string.h>
56010 #include <linux/fs.h>
56011 #include <linux/file.h>
56012 +#include <linux/security.h>
56013 #include <linux/stat.h>
56014 #include <linux/fcntl.h>
56015 #include <linux/ptrace.h>
56016 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56017 #endif
56018 # define START_STACK(u) ((void __user *)u.start_stack)
56019
56020 + memset(&dump, 0, sizeof(dump));
56021 +
56022 fs = get_fs();
56023 set_fs(KERNEL_DS);
56024 has_dumped = 1;
56025 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56026
56027 /* If the size of the dump file exceeds the rlimit, then see what would happen
56028 if we wrote the stack, but not the data area. */
56029 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56030 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56031 dump.u_dsize = 0;
56032
56033 /* Make sure we have enough room to write the stack and data areas. */
56034 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56035 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56036 dump.u_ssize = 0;
56037
56038 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56039 rlim = rlimit(RLIMIT_DATA);
56040 if (rlim >= RLIM_INFINITY)
56041 rlim = ~0;
56042 +
56043 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56044 if (ex.a_data + ex.a_bss > rlim)
56045 return -ENOMEM;
56046
56047 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56048
56049 install_exec_creds(bprm);
56050
56051 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56052 + current->mm->pax_flags = 0UL;
56053 +#endif
56054 +
56055 +#ifdef CONFIG_PAX_PAGEEXEC
56056 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56057 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56058 +
56059 +#ifdef CONFIG_PAX_EMUTRAMP
56060 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56061 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56062 +#endif
56063 +
56064 +#ifdef CONFIG_PAX_MPROTECT
56065 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56066 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56067 +#endif
56068 +
56069 + }
56070 +#endif
56071 +
56072 if (N_MAGIC(ex) == OMAGIC) {
56073 unsigned long text_addr, map_size;
56074 loff_t pos;
56075 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56076 }
56077
56078 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56079 - PROT_READ | PROT_WRITE | PROT_EXEC,
56080 + PROT_READ | PROT_WRITE,
56081 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56082 fd_offset + ex.a_text);
56083 if (error != N_DATADDR(ex)) {
56084 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56085 index aa3cb62..bc53934 100644
56086 --- a/fs/binfmt_elf.c
56087 +++ b/fs/binfmt_elf.c
56088 @@ -34,6 +34,7 @@
56089 #include <linux/utsname.h>
56090 #include <linux/coredump.h>
56091 #include <linux/sched.h>
56092 +#include <linux/xattr.h>
56093 #include <asm/uaccess.h>
56094 #include <asm/param.h>
56095 #include <asm/page.h>
56096 @@ -47,7 +48,7 @@
56097
56098 static int load_elf_binary(struct linux_binprm *bprm);
56099 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56100 - int, int, unsigned long);
56101 + int, int, unsigned long) __intentional_overflow(-1);
56102
56103 #ifdef CONFIG_USELIB
56104 static int load_elf_library(struct file *);
56105 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56106 #define elf_core_dump NULL
56107 #endif
56108
56109 +#ifdef CONFIG_PAX_MPROTECT
56110 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56111 +#endif
56112 +
56113 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56114 +static void elf_handle_mmap(struct file *file);
56115 +#endif
56116 +
56117 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56118 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56119 #else
56120 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56121 .load_binary = load_elf_binary,
56122 .load_shlib = load_elf_library,
56123 .core_dump = elf_core_dump,
56124 +
56125 +#ifdef CONFIG_PAX_MPROTECT
56126 + .handle_mprotect= elf_handle_mprotect,
56127 +#endif
56128 +
56129 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56130 + .handle_mmap = elf_handle_mmap,
56131 +#endif
56132 +
56133 .min_coredump = ELF_EXEC_PAGESIZE,
56134 };
56135
56136 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56137
56138 static int set_brk(unsigned long start, unsigned long end)
56139 {
56140 + unsigned long e = end;
56141 +
56142 start = ELF_PAGEALIGN(start);
56143 end = ELF_PAGEALIGN(end);
56144 if (end > start) {
56145 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56146 if (BAD_ADDR(addr))
56147 return addr;
56148 }
56149 - current->mm->start_brk = current->mm->brk = end;
56150 + current->mm->start_brk = current->mm->brk = e;
56151 return 0;
56152 }
56153
56154 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56155 elf_addr_t __user *u_rand_bytes;
56156 const char *k_platform = ELF_PLATFORM;
56157 const char *k_base_platform = ELF_BASE_PLATFORM;
56158 - unsigned char k_rand_bytes[16];
56159 + u32 k_rand_bytes[4];
56160 int items;
56161 elf_addr_t *elf_info;
56162 int ei_index = 0;
56163 const struct cred *cred = current_cred();
56164 struct vm_area_struct *vma;
56165 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56166
56167 /*
56168 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56169 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56170 * Generate 16 random bytes for userspace PRNG seeding.
56171 */
56172 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56173 - u_rand_bytes = (elf_addr_t __user *)
56174 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56175 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56176 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56177 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56178 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56179 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56180 + u_rand_bytes = (elf_addr_t __user *) p;
56181 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56182 return -EFAULT;
56183
56184 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56185 return -EFAULT;
56186 current->mm->env_end = p;
56187
56188 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56189 +
56190 /* Put the elf_info on the stack in the right place. */
56191 sp = (elf_addr_t __user *)envp + 1;
56192 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56193 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56194 return -EFAULT;
56195 return 0;
56196 }
56197 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56198 an ELF header */
56199
56200 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56201 - struct file *interpreter, unsigned long *interp_map_addr,
56202 - unsigned long no_base)
56203 + struct file *interpreter, unsigned long no_base)
56204 {
56205 struct elf_phdr *elf_phdata;
56206 struct elf_phdr *eppnt;
56207 - unsigned long load_addr = 0;
56208 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56209 int load_addr_set = 0;
56210 unsigned long last_bss = 0, elf_bss = 0;
56211 - unsigned long error = ~0UL;
56212 + unsigned long error = -EINVAL;
56213 unsigned long total_size;
56214 int retval, i, size;
56215
56216 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56217 goto out_close;
56218 }
56219
56220 +#ifdef CONFIG_PAX_SEGMEXEC
56221 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56222 + pax_task_size = SEGMEXEC_TASK_SIZE;
56223 +#endif
56224 +
56225 eppnt = elf_phdata;
56226 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56227 if (eppnt->p_type == PT_LOAD) {
56228 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56229 map_addr = elf_map(interpreter, load_addr + vaddr,
56230 eppnt, elf_prot, elf_type, total_size);
56231 total_size = 0;
56232 - if (!*interp_map_addr)
56233 - *interp_map_addr = map_addr;
56234 error = map_addr;
56235 if (BAD_ADDR(map_addr))
56236 goto out_close;
56237 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56238 k = load_addr + eppnt->p_vaddr;
56239 if (BAD_ADDR(k) ||
56240 eppnt->p_filesz > eppnt->p_memsz ||
56241 - eppnt->p_memsz > TASK_SIZE ||
56242 - TASK_SIZE - eppnt->p_memsz < k) {
56243 + eppnt->p_memsz > pax_task_size ||
56244 + pax_task_size - eppnt->p_memsz < k) {
56245 error = -ENOMEM;
56246 goto out_close;
56247 }
56248 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56249 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56250
56251 /* Map the last of the bss segment */
56252 - error = vm_brk(elf_bss, last_bss - elf_bss);
56253 - if (BAD_ADDR(error))
56254 - goto out_close;
56255 + if (last_bss > elf_bss) {
56256 + error = vm_brk(elf_bss, last_bss - elf_bss);
56257 + if (BAD_ADDR(error))
56258 + goto out_close;
56259 + }
56260 }
56261
56262 error = load_addr;
56263 @@ -543,6 +574,336 @@ out:
56264 return error;
56265 }
56266
56267 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56268 +#ifdef CONFIG_PAX_SOFTMODE
56269 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56270 +{
56271 + unsigned long pax_flags = 0UL;
56272 +
56273 +#ifdef CONFIG_PAX_PAGEEXEC
56274 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56275 + pax_flags |= MF_PAX_PAGEEXEC;
56276 +#endif
56277 +
56278 +#ifdef CONFIG_PAX_SEGMEXEC
56279 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56280 + pax_flags |= MF_PAX_SEGMEXEC;
56281 +#endif
56282 +
56283 +#ifdef CONFIG_PAX_EMUTRAMP
56284 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56285 + pax_flags |= MF_PAX_EMUTRAMP;
56286 +#endif
56287 +
56288 +#ifdef CONFIG_PAX_MPROTECT
56289 + if (elf_phdata->p_flags & PF_MPROTECT)
56290 + pax_flags |= MF_PAX_MPROTECT;
56291 +#endif
56292 +
56293 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56294 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56295 + pax_flags |= MF_PAX_RANDMMAP;
56296 +#endif
56297 +
56298 + return pax_flags;
56299 +}
56300 +#endif
56301 +
56302 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56303 +{
56304 + unsigned long pax_flags = 0UL;
56305 +
56306 +#ifdef CONFIG_PAX_PAGEEXEC
56307 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56308 + pax_flags |= MF_PAX_PAGEEXEC;
56309 +#endif
56310 +
56311 +#ifdef CONFIG_PAX_SEGMEXEC
56312 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56313 + pax_flags |= MF_PAX_SEGMEXEC;
56314 +#endif
56315 +
56316 +#ifdef CONFIG_PAX_EMUTRAMP
56317 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56318 + pax_flags |= MF_PAX_EMUTRAMP;
56319 +#endif
56320 +
56321 +#ifdef CONFIG_PAX_MPROTECT
56322 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56323 + pax_flags |= MF_PAX_MPROTECT;
56324 +#endif
56325 +
56326 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56327 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56328 + pax_flags |= MF_PAX_RANDMMAP;
56329 +#endif
56330 +
56331 + return pax_flags;
56332 +}
56333 +#endif
56334 +
56335 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56336 +#ifdef CONFIG_PAX_SOFTMODE
56337 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56338 +{
56339 + unsigned long pax_flags = 0UL;
56340 +
56341 +#ifdef CONFIG_PAX_PAGEEXEC
56342 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56343 + pax_flags |= MF_PAX_PAGEEXEC;
56344 +#endif
56345 +
56346 +#ifdef CONFIG_PAX_SEGMEXEC
56347 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56348 + pax_flags |= MF_PAX_SEGMEXEC;
56349 +#endif
56350 +
56351 +#ifdef CONFIG_PAX_EMUTRAMP
56352 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56353 + pax_flags |= MF_PAX_EMUTRAMP;
56354 +#endif
56355 +
56356 +#ifdef CONFIG_PAX_MPROTECT
56357 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56358 + pax_flags |= MF_PAX_MPROTECT;
56359 +#endif
56360 +
56361 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56362 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56363 + pax_flags |= MF_PAX_RANDMMAP;
56364 +#endif
56365 +
56366 + return pax_flags;
56367 +}
56368 +#endif
56369 +
56370 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56371 +{
56372 + unsigned long pax_flags = 0UL;
56373 +
56374 +#ifdef CONFIG_PAX_PAGEEXEC
56375 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56376 + pax_flags |= MF_PAX_PAGEEXEC;
56377 +#endif
56378 +
56379 +#ifdef CONFIG_PAX_SEGMEXEC
56380 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56381 + pax_flags |= MF_PAX_SEGMEXEC;
56382 +#endif
56383 +
56384 +#ifdef CONFIG_PAX_EMUTRAMP
56385 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56386 + pax_flags |= MF_PAX_EMUTRAMP;
56387 +#endif
56388 +
56389 +#ifdef CONFIG_PAX_MPROTECT
56390 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56391 + pax_flags |= MF_PAX_MPROTECT;
56392 +#endif
56393 +
56394 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56395 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56396 + pax_flags |= MF_PAX_RANDMMAP;
56397 +#endif
56398 +
56399 + return pax_flags;
56400 +}
56401 +#endif
56402 +
56403 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56404 +static unsigned long pax_parse_defaults(void)
56405 +{
56406 + unsigned long pax_flags = 0UL;
56407 +
56408 +#ifdef CONFIG_PAX_SOFTMODE
56409 + if (pax_softmode)
56410 + return pax_flags;
56411 +#endif
56412 +
56413 +#ifdef CONFIG_PAX_PAGEEXEC
56414 + pax_flags |= MF_PAX_PAGEEXEC;
56415 +#endif
56416 +
56417 +#ifdef CONFIG_PAX_SEGMEXEC
56418 + pax_flags |= MF_PAX_SEGMEXEC;
56419 +#endif
56420 +
56421 +#ifdef CONFIG_PAX_MPROTECT
56422 + pax_flags |= MF_PAX_MPROTECT;
56423 +#endif
56424 +
56425 +#ifdef CONFIG_PAX_RANDMMAP
56426 + if (randomize_va_space)
56427 + pax_flags |= MF_PAX_RANDMMAP;
56428 +#endif
56429 +
56430 + return pax_flags;
56431 +}
56432 +
56433 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56434 +{
56435 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56436 +
56437 +#ifdef CONFIG_PAX_EI_PAX
56438 +
56439 +#ifdef CONFIG_PAX_SOFTMODE
56440 + if (pax_softmode)
56441 + return pax_flags;
56442 +#endif
56443 +
56444 + pax_flags = 0UL;
56445 +
56446 +#ifdef CONFIG_PAX_PAGEEXEC
56447 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56448 + pax_flags |= MF_PAX_PAGEEXEC;
56449 +#endif
56450 +
56451 +#ifdef CONFIG_PAX_SEGMEXEC
56452 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56453 + pax_flags |= MF_PAX_SEGMEXEC;
56454 +#endif
56455 +
56456 +#ifdef CONFIG_PAX_EMUTRAMP
56457 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56458 + pax_flags |= MF_PAX_EMUTRAMP;
56459 +#endif
56460 +
56461 +#ifdef CONFIG_PAX_MPROTECT
56462 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56463 + pax_flags |= MF_PAX_MPROTECT;
56464 +#endif
56465 +
56466 +#ifdef CONFIG_PAX_ASLR
56467 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56468 + pax_flags |= MF_PAX_RANDMMAP;
56469 +#endif
56470 +
56471 +#endif
56472 +
56473 + return pax_flags;
56474 +
56475 +}
56476 +
56477 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56478 +{
56479 +
56480 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56481 + unsigned long i;
56482 +
56483 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56484 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56485 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56486 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56487 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56488 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56489 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56490 + return PAX_PARSE_FLAGS_FALLBACK;
56491 +
56492 +#ifdef CONFIG_PAX_SOFTMODE
56493 + if (pax_softmode)
56494 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56495 + else
56496 +#endif
56497 +
56498 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56499 + break;
56500 + }
56501 +#endif
56502 +
56503 + return PAX_PARSE_FLAGS_FALLBACK;
56504 +}
56505 +
56506 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56507 +{
56508 +
56509 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56510 + ssize_t xattr_size, i;
56511 + unsigned char xattr_value[sizeof("pemrs") - 1];
56512 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56513 +
56514 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56515 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56516 + return PAX_PARSE_FLAGS_FALLBACK;
56517 +
56518 + for (i = 0; i < xattr_size; i++)
56519 + switch (xattr_value[i]) {
56520 + default:
56521 + return PAX_PARSE_FLAGS_FALLBACK;
56522 +
56523 +#define parse_flag(option1, option2, flag) \
56524 + case option1: \
56525 + if (pax_flags_hardmode & MF_PAX_##flag) \
56526 + return PAX_PARSE_FLAGS_FALLBACK;\
56527 + pax_flags_hardmode |= MF_PAX_##flag; \
56528 + break; \
56529 + case option2: \
56530 + if (pax_flags_softmode & MF_PAX_##flag) \
56531 + return PAX_PARSE_FLAGS_FALLBACK;\
56532 + pax_flags_softmode |= MF_PAX_##flag; \
56533 + break;
56534 +
56535 + parse_flag('p', 'P', PAGEEXEC);
56536 + parse_flag('e', 'E', EMUTRAMP);
56537 + parse_flag('m', 'M', MPROTECT);
56538 + parse_flag('r', 'R', RANDMMAP);
56539 + parse_flag('s', 'S', SEGMEXEC);
56540 +
56541 +#undef parse_flag
56542 + }
56543 +
56544 + if (pax_flags_hardmode & pax_flags_softmode)
56545 + return PAX_PARSE_FLAGS_FALLBACK;
56546 +
56547 +#ifdef CONFIG_PAX_SOFTMODE
56548 + if (pax_softmode)
56549 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56550 + else
56551 +#endif
56552 +
56553 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56554 +#else
56555 + return PAX_PARSE_FLAGS_FALLBACK;
56556 +#endif
56557 +
56558 +}
56559 +
56560 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56561 +{
56562 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56563 +
56564 + pax_flags = pax_parse_defaults();
56565 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56566 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56567 + xattr_pax_flags = pax_parse_xattr_pax(file);
56568 +
56569 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56570 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56571 + pt_pax_flags != xattr_pax_flags)
56572 + return -EINVAL;
56573 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56574 + pax_flags = xattr_pax_flags;
56575 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56576 + pax_flags = pt_pax_flags;
56577 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56578 + pax_flags = ei_pax_flags;
56579 +
56580 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56581 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56582 + if ((__supported_pte_mask & _PAGE_NX))
56583 + pax_flags &= ~MF_PAX_SEGMEXEC;
56584 + else
56585 + pax_flags &= ~MF_PAX_PAGEEXEC;
56586 + }
56587 +#endif
56588 +
56589 + if (0 > pax_check_flags(&pax_flags))
56590 + return -EINVAL;
56591 +
56592 + current->mm->pax_flags = pax_flags;
56593 + return 0;
56594 +}
56595 +#endif
56596 +
56597 /*
56598 * These are the functions used to load ELF style executables and shared
56599 * libraries. There is no binary dependent code anywhere else.
56600 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56601 {
56602 unsigned int random_variable = 0;
56603
56604 +#ifdef CONFIG_PAX_RANDUSTACK
56605 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56606 + return stack_top - current->mm->delta_stack;
56607 +#endif
56608 +
56609 if ((current->flags & PF_RANDOMIZE) &&
56610 !(current->personality & ADDR_NO_RANDOMIZE)) {
56611 random_variable = get_random_int() & STACK_RND_MASK;
56612 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56613 unsigned long load_addr = 0, load_bias = 0;
56614 int load_addr_set = 0;
56615 char * elf_interpreter = NULL;
56616 - unsigned long error;
56617 + unsigned long error = 0;
56618 struct elf_phdr *elf_ppnt, *elf_phdata;
56619 unsigned long elf_bss, elf_brk;
56620 int retval, i;
56621 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56622 struct elfhdr elf_ex;
56623 struct elfhdr interp_elf_ex;
56624 } *loc;
56625 + unsigned long pax_task_size;
56626
56627 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56628 if (!loc) {
56629 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
56630 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56631 may depend on the personality. */
56632 SET_PERSONALITY(loc->elf_ex);
56633 +
56634 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56635 + current->mm->pax_flags = 0UL;
56636 +#endif
56637 +
56638 +#ifdef CONFIG_PAX_DLRESOLVE
56639 + current->mm->call_dl_resolve = 0UL;
56640 +#endif
56641 +
56642 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56643 + current->mm->call_syscall = 0UL;
56644 +#endif
56645 +
56646 +#ifdef CONFIG_PAX_ASLR
56647 + current->mm->delta_mmap = 0UL;
56648 + current->mm->delta_stack = 0UL;
56649 +#endif
56650 +
56651 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56652 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56653 + send_sig(SIGKILL, current, 0);
56654 + goto out_free_dentry;
56655 + }
56656 +#endif
56657 +
56658 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56659 + pax_set_initial_flags(bprm);
56660 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56661 + if (pax_set_initial_flags_func)
56662 + (pax_set_initial_flags_func)(bprm);
56663 +#endif
56664 +
56665 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56666 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56667 + current->mm->context.user_cs_limit = PAGE_SIZE;
56668 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56669 + }
56670 +#endif
56671 +
56672 +#ifdef CONFIG_PAX_SEGMEXEC
56673 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56674 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56675 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56676 + pax_task_size = SEGMEXEC_TASK_SIZE;
56677 + current->mm->def_flags |= VM_NOHUGEPAGE;
56678 + } else
56679 +#endif
56680 +
56681 + pax_task_size = TASK_SIZE;
56682 +
56683 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56684 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56685 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56686 + put_cpu();
56687 + }
56688 +#endif
56689 +
56690 +#ifdef CONFIG_PAX_ASLR
56691 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56692 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56693 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56694 + }
56695 +#endif
56696 +
56697 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56698 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56699 + executable_stack = EXSTACK_DISABLE_X;
56700 + current->personality &= ~READ_IMPLIES_EXEC;
56701 + } else
56702 +#endif
56703 +
56704 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56705 current->personality |= READ_IMPLIES_EXEC;
56706
56707 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56708 #else
56709 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56710 #endif
56711 +
56712 +#ifdef CONFIG_PAX_RANDMMAP
56713 + /* PaX: randomize base address at the default exe base if requested */
56714 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56715 +#ifdef CONFIG_SPARC64
56716 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56717 +#else
56718 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56719 +#endif
56720 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56721 + elf_flags |= MAP_FIXED;
56722 + }
56723 +#endif
56724 +
56725 }
56726
56727 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56728 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56729 * allowed task size. Note that p_filesz must always be
56730 * <= p_memsz so it is only necessary to check p_memsz.
56731 */
56732 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56733 - elf_ppnt->p_memsz > TASK_SIZE ||
56734 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56735 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56736 + elf_ppnt->p_memsz > pax_task_size ||
56737 + pax_task_size - elf_ppnt->p_memsz < k) {
56738 /* set_brk can never work. Avoid overflows. */
56739 send_sig(SIGKILL, current, 0);
56740 retval = -EINVAL;
56741 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56742 goto out_free_dentry;
56743 }
56744 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56745 - send_sig(SIGSEGV, current, 0);
56746 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56747 - goto out_free_dentry;
56748 + /*
56749 + * This bss-zeroing can fail if the ELF
56750 + * file specifies odd protections. So
56751 + * we don't check the return value
56752 + */
56753 }
56754
56755 +#ifdef CONFIG_PAX_RANDMMAP
56756 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56757 + unsigned long start, size, flags;
56758 + vm_flags_t vm_flags;
56759 +
56760 + start = ELF_PAGEALIGN(elf_brk);
56761 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56762 + flags = MAP_FIXED | MAP_PRIVATE;
56763 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56764 +
56765 + down_write(&current->mm->mmap_sem);
56766 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56767 + retval = -ENOMEM;
56768 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56769 +// if (current->personality & ADDR_NO_RANDOMIZE)
56770 +// vm_flags |= VM_READ | VM_MAYREAD;
56771 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56772 + retval = IS_ERR_VALUE(start) ? start : 0;
56773 + }
56774 + up_write(&current->mm->mmap_sem);
56775 + if (retval == 0)
56776 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56777 + if (retval < 0) {
56778 + send_sig(SIGKILL, current, 0);
56779 + goto out_free_dentry;
56780 + }
56781 + }
56782 +#endif
56783 +
56784 if (elf_interpreter) {
56785 - unsigned long interp_map_addr = 0;
56786 -
56787 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56788 interpreter,
56789 - &interp_map_addr,
56790 load_bias);
56791 if (!IS_ERR((void *)elf_entry)) {
56792 /*
56793 @@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56794 * Decide what to dump of a segment, part, all or none.
56795 */
56796 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56797 - unsigned long mm_flags)
56798 + unsigned long mm_flags, long signr)
56799 {
56800 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56801
56802 @@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56803 if (vma->vm_file == NULL)
56804 return 0;
56805
56806 - if (FILTER(MAPPED_PRIVATE))
56807 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56808 goto whole;
56809
56810 /*
56811 @@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56812 {
56813 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56814 int i = 0;
56815 - do
56816 + do {
56817 i += 2;
56818 - while (auxv[i - 2] != AT_NULL);
56819 + } while (auxv[i - 2] != AT_NULL);
56820 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56821 }
56822
56823 @@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56824 {
56825 mm_segment_t old_fs = get_fs();
56826 set_fs(KERNEL_DS);
56827 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56828 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56829 set_fs(old_fs);
56830 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56831 }
56832 @@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56833 }
56834
56835 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56836 - unsigned long mm_flags)
56837 + struct coredump_params *cprm)
56838 {
56839 struct vm_area_struct *vma;
56840 size_t size = 0;
56841
56842 for (vma = first_vma(current, gate_vma); vma != NULL;
56843 vma = next_vma(vma, gate_vma))
56844 - size += vma_dump_size(vma, mm_flags);
56845 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56846 return size;
56847 }
56848
56849 @@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56850
56851 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56852
56853 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56854 + offset += elf_core_vma_data_size(gate_vma, cprm);
56855 offset += elf_core_extra_data_size();
56856 e_shoff = offset;
56857
56858 @@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56859 phdr.p_offset = offset;
56860 phdr.p_vaddr = vma->vm_start;
56861 phdr.p_paddr = 0;
56862 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56863 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56864 phdr.p_memsz = vma->vm_end - vma->vm_start;
56865 offset += phdr.p_filesz;
56866 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56867 @@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56868 unsigned long addr;
56869 unsigned long end;
56870
56871 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56872 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56873
56874 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56875 struct page *page;
56876 @@ -2202,6 +2682,167 @@ out:
56877
56878 #endif /* CONFIG_ELF_CORE */
56879
56880 +#ifdef CONFIG_PAX_MPROTECT
56881 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56882 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56883 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56884 + *
56885 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56886 + * basis because we want to allow the common case and not the special ones.
56887 + */
56888 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56889 +{
56890 + struct elfhdr elf_h;
56891 + struct elf_phdr elf_p;
56892 + unsigned long i;
56893 + unsigned long oldflags;
56894 + bool is_textrel_rw, is_textrel_rx, is_relro;
56895 +
56896 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56897 + return;
56898 +
56899 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56900 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56901 +
56902 +#ifdef CONFIG_PAX_ELFRELOCS
56903 + /* possible TEXTREL */
56904 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56905 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56906 +#else
56907 + is_textrel_rw = false;
56908 + is_textrel_rx = false;
56909 +#endif
56910 +
56911 + /* possible RELRO */
56912 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56913 +
56914 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56915 + return;
56916 +
56917 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56918 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56919 +
56920 +#ifdef CONFIG_PAX_ETEXECRELOCS
56921 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56922 +#else
56923 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56924 +#endif
56925 +
56926 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56927 + !elf_check_arch(&elf_h) ||
56928 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56929 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56930 + return;
56931 +
56932 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56933 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56934 + return;
56935 + switch (elf_p.p_type) {
56936 + case PT_DYNAMIC:
56937 + if (!is_textrel_rw && !is_textrel_rx)
56938 + continue;
56939 + i = 0UL;
56940 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56941 + elf_dyn dyn;
56942 +
56943 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56944 + break;
56945 + if (dyn.d_tag == DT_NULL)
56946 + break;
56947 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56948 + gr_log_textrel(vma);
56949 + if (is_textrel_rw)
56950 + vma->vm_flags |= VM_MAYWRITE;
56951 + else
56952 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56953 + vma->vm_flags &= ~VM_MAYWRITE;
56954 + break;
56955 + }
56956 + i++;
56957 + }
56958 + is_textrel_rw = false;
56959 + is_textrel_rx = false;
56960 + continue;
56961 +
56962 + case PT_GNU_RELRO:
56963 + if (!is_relro)
56964 + continue;
56965 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56966 + vma->vm_flags &= ~VM_MAYWRITE;
56967 + is_relro = false;
56968 + continue;
56969 +
56970 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56971 + case PT_PAX_FLAGS: {
56972 + const char *msg_mprotect = "", *msg_emutramp = "";
56973 + char *buffer_lib, *buffer_exe;
56974 +
56975 + if (elf_p.p_flags & PF_NOMPROTECT)
56976 + msg_mprotect = "MPROTECT disabled";
56977 +
56978 +#ifdef CONFIG_PAX_EMUTRAMP
56979 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56980 + msg_emutramp = "EMUTRAMP enabled";
56981 +#endif
56982 +
56983 + if (!msg_mprotect[0] && !msg_emutramp[0])
56984 + continue;
56985 +
56986 + if (!printk_ratelimit())
56987 + continue;
56988 +
56989 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56990 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56991 + if (buffer_lib && buffer_exe) {
56992 + char *path_lib, *path_exe;
56993 +
56994 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56995 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56996 +
56997 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56998 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56999 +
57000 + }
57001 + free_page((unsigned long)buffer_exe);
57002 + free_page((unsigned long)buffer_lib);
57003 + continue;
57004 + }
57005 +#endif
57006 +
57007 + }
57008 + }
57009 +}
57010 +#endif
57011 +
57012 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57013 +
57014 +extern int grsec_enable_log_rwxmaps;
57015 +
57016 +static void elf_handle_mmap(struct file *file)
57017 +{
57018 + struct elfhdr elf_h;
57019 + struct elf_phdr elf_p;
57020 + unsigned long i;
57021 +
57022 + if (!grsec_enable_log_rwxmaps)
57023 + return;
57024 +
57025 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57026 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57027 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57028 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57029 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57030 + return;
57031 +
57032 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57033 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57034 + return;
57035 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57036 + gr_log_ptgnustack(file);
57037 + }
57038 +}
57039 +#endif
57040 +
57041 static int __init init_elf_binfmt(void)
57042 {
57043 register_binfmt(&elf_format);
57044 diff --git a/fs/bio.c b/fs/bio.c
57045 index 6f0362b..26a7496 100644
57046 --- a/fs/bio.c
57047 +++ b/fs/bio.c
57048 @@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57049 /*
57050 * Overflow, abort
57051 */
57052 - if (end < start)
57053 + if (end < start || end - start > INT_MAX - nr_pages)
57054 return ERR_PTR(-EINVAL);
57055
57056 nr_pages += end - start;
57057 @@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57058 /*
57059 * Overflow, abort
57060 */
57061 - if (end < start)
57062 + if (end < start || end - start > INT_MAX - nr_pages)
57063 return ERR_PTR(-EINVAL);
57064
57065 nr_pages += end - start;
57066 @@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57067 const int read = bio_data_dir(bio) == READ;
57068 struct bio_map_data *bmd = bio->bi_private;
57069 int i;
57070 - char *p = bmd->sgvecs[0].iov_base;
57071 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57072
57073 bio_for_each_segment_all(bvec, bio, i) {
57074 char *addr = page_address(bvec->bv_page);
57075 diff --git a/fs/block_dev.c b/fs/block_dev.c
57076 index 552a8d1..d51ccf3 100644
57077 --- a/fs/block_dev.c
57078 +++ b/fs/block_dev.c
57079 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57080 else if (bdev->bd_contains == bdev)
57081 return true; /* is a whole device which isn't held */
57082
57083 - else if (whole->bd_holder == bd_may_claim)
57084 + else if (whole->bd_holder == (void *)bd_may_claim)
57085 return true; /* is a partition of a device that is being partitioned */
57086 else if (whole->bd_holder != NULL)
57087 return false; /* is a partition of a held device */
57088 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57089 index 1bcfcdb..e942132 100644
57090 --- a/fs/btrfs/ctree.c
57091 +++ b/fs/btrfs/ctree.c
57092 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57093 free_extent_buffer(buf);
57094 add_root_to_dirty_list(root);
57095 } else {
57096 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57097 - parent_start = parent->start;
57098 - else
57099 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57100 + if (parent)
57101 + parent_start = parent->start;
57102 + else
57103 + parent_start = 0;
57104 + } else
57105 parent_start = 0;
57106
57107 WARN_ON(trans->transid != btrfs_header_generation(parent));
57108 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57109 index 33e561a..16df7ae 100644
57110 --- a/fs/btrfs/delayed-inode.c
57111 +++ b/fs/btrfs/delayed-inode.c
57112 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57113
57114 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57115 {
57116 - int seq = atomic_inc_return(&delayed_root->items_seq);
57117 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57118 if ((atomic_dec_return(&delayed_root->items) <
57119 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57120 waitqueue_active(&delayed_root->wait))
57121 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57122
57123 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57124 {
57125 - int val = atomic_read(&delayed_root->items_seq);
57126 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57127
57128 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57129 return 1;
57130 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57131 int seq;
57132 int ret;
57133
57134 - seq = atomic_read(&delayed_root->items_seq);
57135 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57136
57137 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57138 if (ret)
57139 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57140 index f70119f..ab5894d 100644
57141 --- a/fs/btrfs/delayed-inode.h
57142 +++ b/fs/btrfs/delayed-inode.h
57143 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57144 */
57145 struct list_head prepare_list;
57146 atomic_t items; /* for delayed items */
57147 - atomic_t items_seq; /* for delayed items */
57148 + atomic_unchecked_t items_seq; /* for delayed items */
57149 int nodes; /* for delayed nodes */
57150 wait_queue_head_t wait;
57151 };
57152 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57153 struct btrfs_delayed_root *delayed_root)
57154 {
57155 atomic_set(&delayed_root->items, 0);
57156 - atomic_set(&delayed_root->items_seq, 0);
57157 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57158 delayed_root->nodes = 0;
57159 spin_lock_init(&delayed_root->lock);
57160 init_waitqueue_head(&delayed_root->wait);
57161 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57162 index 2f6d7b1..f186382 100644
57163 --- a/fs/btrfs/ioctl.c
57164 +++ b/fs/btrfs/ioctl.c
57165 @@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57166 for (i = 0; i < num_types; i++) {
57167 struct btrfs_space_info *tmp;
57168
57169 + /* Don't copy in more than we allocated */
57170 if (!slot_count)
57171 break;
57172
57173 + slot_count--;
57174 +
57175 info = NULL;
57176 rcu_read_lock();
57177 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57178 @@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57179 memcpy(dest, &space, sizeof(space));
57180 dest++;
57181 space_args.total_spaces++;
57182 - slot_count--;
57183 }
57184 - if (!slot_count)
57185 - break;
57186 }
57187 up_read(&info->groups_sem);
57188 }
57189 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57190 index 9601d25..2896d6c 100644
57191 --- a/fs/btrfs/super.c
57192 +++ b/fs/btrfs/super.c
57193 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57194 function, line, errstr);
57195 return;
57196 }
57197 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57198 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57199 /* Wake up anybody who may be waiting on this transaction */
57200 wake_up(&root->fs_info->transaction_wait);
57201 wake_up(&root->fs_info->transaction_blocked_wait);
57202 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57203 index 4825cd2..b2fe768 100644
57204 --- a/fs/btrfs/sysfs.c
57205 +++ b/fs/btrfs/sysfs.c
57206 @@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57207 for (set = 0; set < FEAT_MAX; set++) {
57208 int i;
57209 struct attribute *attrs[2];
57210 - struct attribute_group agroup = {
57211 + attribute_group_no_const agroup = {
57212 .name = "features",
57213 .attrs = attrs,
57214 };
57215 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57216 index e2f45fc..b036909 100644
57217 --- a/fs/btrfs/tree-log.c
57218 +++ b/fs/btrfs/tree-log.c
57219 @@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57220 blk_finish_plug(&plug);
57221 btrfs_abort_transaction(trans, root, ret);
57222 btrfs_free_logged_extents(log, log_transid);
57223 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57224 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57225 trans->transid;
57226 mutex_unlock(&root->log_mutex);
57227 goto out;
57228 @@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57229 list_del_init(&root_log_ctx.list);
57230
57231 blk_finish_plug(&plug);
57232 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57233 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57234 trans->transid;
57235 if (ret != -ENOSPC) {
57236 btrfs_abort_transaction(trans, root, ret);
57237 @@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57238 * now that we've moved on to the tree of log tree roots,
57239 * check the full commit flag again
57240 */
57241 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57242 + if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57243 trans->transid) {
57244 blk_finish_plug(&plug);
57245 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57246 @@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57247 EXTENT_DIRTY | EXTENT_NEW);
57248 blk_finish_plug(&plug);
57249 if (ret) {
57250 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57251 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57252 trans->transid;
57253 btrfs_abort_transaction(trans, root, ret);
57254 btrfs_free_logged_extents(log, log_transid);
57255 @@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57256 */
57257 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57258 if (ret) {
57259 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57260 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57261 trans->transid;
57262 btrfs_abort_transaction(trans, root, ret);
57263 goto out_wake_log_root;
57264 diff --git a/fs/buffer.c b/fs/buffer.c
57265 index 9ddb9fc..7aa2487 100644
57266 --- a/fs/buffer.c
57267 +++ b/fs/buffer.c
57268 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57269 bh_cachep = kmem_cache_create("buffer_head",
57270 sizeof(struct buffer_head), 0,
57271 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57272 - SLAB_MEM_SPREAD),
57273 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57274 NULL);
57275
57276 /*
57277 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57278 index 5b99baf..47fffb5 100644
57279 --- a/fs/cachefiles/bind.c
57280 +++ b/fs/cachefiles/bind.c
57281 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57282 args);
57283
57284 /* start by checking things over */
57285 - ASSERT(cache->fstop_percent >= 0 &&
57286 - cache->fstop_percent < cache->fcull_percent &&
57287 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57288 cache->fcull_percent < cache->frun_percent &&
57289 cache->frun_percent < 100);
57290
57291 - ASSERT(cache->bstop_percent >= 0 &&
57292 - cache->bstop_percent < cache->bcull_percent &&
57293 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57294 cache->bcull_percent < cache->brun_percent &&
57295 cache->brun_percent < 100);
57296
57297 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57298 index 0a1467b..6a53245 100644
57299 --- a/fs/cachefiles/daemon.c
57300 +++ b/fs/cachefiles/daemon.c
57301 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57302 if (n > buflen)
57303 return -EMSGSIZE;
57304
57305 - if (copy_to_user(_buffer, buffer, n) != 0)
57306 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57307 return -EFAULT;
57308
57309 return n;
57310 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57311 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57312 return -EIO;
57313
57314 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57315 + if (datalen > PAGE_SIZE - 1)
57316 return -EOPNOTSUPP;
57317
57318 /* drag the command string into the kernel so we can parse it */
57319 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57320 if (args[0] != '%' || args[1] != '\0')
57321 return -EINVAL;
57322
57323 - if (fstop < 0 || fstop >= cache->fcull_percent)
57324 + if (fstop >= cache->fcull_percent)
57325 return cachefiles_daemon_range_error(cache, args);
57326
57327 cache->fstop_percent = fstop;
57328 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57329 if (args[0] != '%' || args[1] != '\0')
57330 return -EINVAL;
57331
57332 - if (bstop < 0 || bstop >= cache->bcull_percent)
57333 + if (bstop >= cache->bcull_percent)
57334 return cachefiles_daemon_range_error(cache, args);
57335
57336 cache->bstop_percent = bstop;
57337 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57338 index 5349473..d6c0b93 100644
57339 --- a/fs/cachefiles/internal.h
57340 +++ b/fs/cachefiles/internal.h
57341 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57342 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57343 struct rb_root active_nodes; /* active nodes (can't be culled) */
57344 rwlock_t active_lock; /* lock for active_nodes */
57345 - atomic_t gravecounter; /* graveyard uniquifier */
57346 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57347 unsigned frun_percent; /* when to stop culling (% files) */
57348 unsigned fcull_percent; /* when to start culling (% files) */
57349 unsigned fstop_percent; /* when to stop allocating (% files) */
57350 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57351 * proc.c
57352 */
57353 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57354 -extern atomic_t cachefiles_lookup_histogram[HZ];
57355 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57356 -extern atomic_t cachefiles_create_histogram[HZ];
57357 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57358 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57359 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57360
57361 extern int __init cachefiles_proc_init(void);
57362 extern void cachefiles_proc_cleanup(void);
57363 static inline
57364 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57365 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57366 {
57367 unsigned long jif = jiffies - start_jif;
57368 if (jif >= HZ)
57369 jif = HZ - 1;
57370 - atomic_inc(&histogram[jif]);
57371 + atomic_inc_unchecked(&histogram[jif]);
57372 }
57373
57374 #else
57375 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57376 index c0a6817..ea811166 100644
57377 --- a/fs/cachefiles/namei.c
57378 +++ b/fs/cachefiles/namei.c
57379 @@ -317,7 +317,7 @@ try_again:
57380 /* first step is to make up a grave dentry in the graveyard */
57381 sprintf(nbuffer, "%08x%08x",
57382 (uint32_t) get_seconds(),
57383 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57384 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57385
57386 /* do the multiway lock magic */
57387 trap = lock_rename(cache->graveyard, dir);
57388 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57389 index eccd339..4c1d995 100644
57390 --- a/fs/cachefiles/proc.c
57391 +++ b/fs/cachefiles/proc.c
57392 @@ -14,9 +14,9 @@
57393 #include <linux/seq_file.h>
57394 #include "internal.h"
57395
57396 -atomic_t cachefiles_lookup_histogram[HZ];
57397 -atomic_t cachefiles_mkdir_histogram[HZ];
57398 -atomic_t cachefiles_create_histogram[HZ];
57399 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57400 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57401 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57402
57403 /*
57404 * display the latency histogram
57405 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57406 return 0;
57407 default:
57408 index = (unsigned long) v - 3;
57409 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57410 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57411 - z = atomic_read(&cachefiles_create_histogram[index]);
57412 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57413 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57414 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57415 if (x == 0 && y == 0 && z == 0)
57416 return 0;
57417
57418 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57419 index 4b1fb5c..0d2a699 100644
57420 --- a/fs/cachefiles/rdwr.c
57421 +++ b/fs/cachefiles/rdwr.c
57422 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57423 old_fs = get_fs();
57424 set_fs(KERNEL_DS);
57425 ret = file->f_op->write(
57426 - file, (const void __user *) data, len, &pos);
57427 + file, (const void __force_user *) data, len, &pos);
57428 set_fs(old_fs);
57429 kunmap(page);
57430 file_end_write(file);
57431 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57432 index c29d6ae..a56c4ae 100644
57433 --- a/fs/ceph/dir.c
57434 +++ b/fs/ceph/dir.c
57435 @@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57436 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57437 struct ceph_mds_client *mdsc = fsc->mdsc;
57438 unsigned frag = fpos_frag(ctx->pos);
57439 - int off = fpos_off(ctx->pos);
57440 + unsigned int off = fpos_off(ctx->pos);
57441 int err;
57442 u32 ftype;
57443 struct ceph_mds_reply_info_parsed *rinfo;
57444 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57445 index 06150fd..192061b 100644
57446 --- a/fs/ceph/super.c
57447 +++ b/fs/ceph/super.c
57448 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57449 /*
57450 * construct our own bdi so we can control readahead, etc.
57451 */
57452 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57453 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57454
57455 static int ceph_register_bdi(struct super_block *sb,
57456 struct ceph_fs_client *fsc)
57457 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57458 default_backing_dev_info.ra_pages;
57459
57460 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57461 - atomic_long_inc_return(&bdi_seq));
57462 + atomic_long_inc_return_unchecked(&bdi_seq));
57463 if (!err)
57464 sb->s_bdi = &fsc->backing_dev_info;
57465 return err;
57466 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57467 index f3ac415..3d2420c 100644
57468 --- a/fs/cifs/cifs_debug.c
57469 +++ b/fs/cifs/cifs_debug.c
57470 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57471
57472 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57473 #ifdef CONFIG_CIFS_STATS2
57474 - atomic_set(&totBufAllocCount, 0);
57475 - atomic_set(&totSmBufAllocCount, 0);
57476 + atomic_set_unchecked(&totBufAllocCount, 0);
57477 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57478 #endif /* CONFIG_CIFS_STATS2 */
57479 spin_lock(&cifs_tcp_ses_lock);
57480 list_for_each(tmp1, &cifs_tcp_ses_list) {
57481 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57482 tcon = list_entry(tmp3,
57483 struct cifs_tcon,
57484 tcon_list);
57485 - atomic_set(&tcon->num_smbs_sent, 0);
57486 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57487 if (server->ops->clear_stats)
57488 server->ops->clear_stats(tcon);
57489 }
57490 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57491 smBufAllocCount.counter, cifs_min_small);
57492 #ifdef CONFIG_CIFS_STATS2
57493 seq_printf(m, "Total Large %d Small %d Allocations\n",
57494 - atomic_read(&totBufAllocCount),
57495 - atomic_read(&totSmBufAllocCount));
57496 + atomic_read_unchecked(&totBufAllocCount),
57497 + atomic_read_unchecked(&totSmBufAllocCount));
57498 #endif /* CONFIG_CIFS_STATS2 */
57499
57500 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57501 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57502 if (tcon->need_reconnect)
57503 seq_puts(m, "\tDISCONNECTED ");
57504 seq_printf(m, "\nSMBs: %d",
57505 - atomic_read(&tcon->num_smbs_sent));
57506 + atomic_read_unchecked(&tcon->num_smbs_sent));
57507 if (server->ops->print_stats)
57508 server->ops->print_stats(m, tcon);
57509 }
57510 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57511 index 5be1f997..fa1015a1 100644
57512 --- a/fs/cifs/cifsfs.c
57513 +++ b/fs/cifs/cifsfs.c
57514 @@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57515 */
57516 cifs_req_cachep = kmem_cache_create("cifs_request",
57517 CIFSMaxBufSize + max_hdr_size, 0,
57518 - SLAB_HWCACHE_ALIGN, NULL);
57519 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57520 if (cifs_req_cachep == NULL)
57521 return -ENOMEM;
57522
57523 @@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57524 efficient to alloc 1 per page off the slab compared to 17K (5page)
57525 alloc of large cifs buffers even when page debugging is on */
57526 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57527 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57528 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57529 NULL);
57530 if (cifs_sm_req_cachep == NULL) {
57531 mempool_destroy(cifs_req_poolp);
57532 @@ -1180,8 +1180,8 @@ init_cifs(void)
57533 atomic_set(&bufAllocCount, 0);
57534 atomic_set(&smBufAllocCount, 0);
57535 #ifdef CONFIG_CIFS_STATS2
57536 - atomic_set(&totBufAllocCount, 0);
57537 - atomic_set(&totSmBufAllocCount, 0);
57538 + atomic_set_unchecked(&totBufAllocCount, 0);
57539 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57540 #endif /* CONFIG_CIFS_STATS2 */
57541
57542 atomic_set(&midCount, 0);
57543 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57544 index 30f6e92..e915ba5 100644
57545 --- a/fs/cifs/cifsglob.h
57546 +++ b/fs/cifs/cifsglob.h
57547 @@ -806,35 +806,35 @@ struct cifs_tcon {
57548 __u16 Flags; /* optional support bits */
57549 enum statusEnum tidStatus;
57550 #ifdef CONFIG_CIFS_STATS
57551 - atomic_t num_smbs_sent;
57552 + atomic_unchecked_t num_smbs_sent;
57553 union {
57554 struct {
57555 - atomic_t num_writes;
57556 - atomic_t num_reads;
57557 - atomic_t num_flushes;
57558 - atomic_t num_oplock_brks;
57559 - atomic_t num_opens;
57560 - atomic_t num_closes;
57561 - atomic_t num_deletes;
57562 - atomic_t num_mkdirs;
57563 - atomic_t num_posixopens;
57564 - atomic_t num_posixmkdirs;
57565 - atomic_t num_rmdirs;
57566 - atomic_t num_renames;
57567 - atomic_t num_t2renames;
57568 - atomic_t num_ffirst;
57569 - atomic_t num_fnext;
57570 - atomic_t num_fclose;
57571 - atomic_t num_hardlinks;
57572 - atomic_t num_symlinks;
57573 - atomic_t num_locks;
57574 - atomic_t num_acl_get;
57575 - atomic_t num_acl_set;
57576 + atomic_unchecked_t num_writes;
57577 + atomic_unchecked_t num_reads;
57578 + atomic_unchecked_t num_flushes;
57579 + atomic_unchecked_t num_oplock_brks;
57580 + atomic_unchecked_t num_opens;
57581 + atomic_unchecked_t num_closes;
57582 + atomic_unchecked_t num_deletes;
57583 + atomic_unchecked_t num_mkdirs;
57584 + atomic_unchecked_t num_posixopens;
57585 + atomic_unchecked_t num_posixmkdirs;
57586 + atomic_unchecked_t num_rmdirs;
57587 + atomic_unchecked_t num_renames;
57588 + atomic_unchecked_t num_t2renames;
57589 + atomic_unchecked_t num_ffirst;
57590 + atomic_unchecked_t num_fnext;
57591 + atomic_unchecked_t num_fclose;
57592 + atomic_unchecked_t num_hardlinks;
57593 + atomic_unchecked_t num_symlinks;
57594 + atomic_unchecked_t num_locks;
57595 + atomic_unchecked_t num_acl_get;
57596 + atomic_unchecked_t num_acl_set;
57597 } cifs_stats;
57598 #ifdef CONFIG_CIFS_SMB2
57599 struct {
57600 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57601 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57602 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57603 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57604 } smb2_stats;
57605 #endif /* CONFIG_CIFS_SMB2 */
57606 } stats;
57607 @@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57608 }
57609
57610 #ifdef CONFIG_CIFS_STATS
57611 -#define cifs_stats_inc atomic_inc
57612 +#define cifs_stats_inc atomic_inc_unchecked
57613
57614 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57615 unsigned int bytes)
57616 @@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57617 /* Various Debug counters */
57618 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57619 #ifdef CONFIG_CIFS_STATS2
57620 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57621 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57622 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57623 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57624 #endif
57625 GLOBAL_EXTERN atomic_t smBufAllocCount;
57626 GLOBAL_EXTERN atomic_t midCount;
57627 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57628 index 5ed03e0..e9a3a6c 100644
57629 --- a/fs/cifs/file.c
57630 +++ b/fs/cifs/file.c
57631 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57632 index = mapping->writeback_index; /* Start from prev offset */
57633 end = -1;
57634 } else {
57635 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57636 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57637 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57638 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57639 range_whole = true;
57640 + index = 0;
57641 + end = ULONG_MAX;
57642 + } else {
57643 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57644 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57645 + }
57646 scanned = true;
57647 }
57648 retry:
57649 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57650 index 3b0c62e..f7d090c 100644
57651 --- a/fs/cifs/misc.c
57652 +++ b/fs/cifs/misc.c
57653 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57654 memset(ret_buf, 0, buf_size + 3);
57655 atomic_inc(&bufAllocCount);
57656 #ifdef CONFIG_CIFS_STATS2
57657 - atomic_inc(&totBufAllocCount);
57658 + atomic_inc_unchecked(&totBufAllocCount);
57659 #endif /* CONFIG_CIFS_STATS2 */
57660 }
57661
57662 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57663 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57664 atomic_inc(&smBufAllocCount);
57665 #ifdef CONFIG_CIFS_STATS2
57666 - atomic_inc(&totSmBufAllocCount);
57667 + atomic_inc_unchecked(&totSmBufAllocCount);
57668 #endif /* CONFIG_CIFS_STATS2 */
57669
57670 }
57671 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57672 index d1fdfa8..94558f8 100644
57673 --- a/fs/cifs/smb1ops.c
57674 +++ b/fs/cifs/smb1ops.c
57675 @@ -626,27 +626,27 @@ static void
57676 cifs_clear_stats(struct cifs_tcon *tcon)
57677 {
57678 #ifdef CONFIG_CIFS_STATS
57679 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57680 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57681 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57682 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57683 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57684 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57685 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57686 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57687 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57688 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57689 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57690 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57691 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57692 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57693 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57694 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57695 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57696 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57697 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57698 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57699 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57700 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57701 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57702 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57703 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57704 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57705 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57706 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57707 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57708 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57709 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57710 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57711 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57712 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57713 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57714 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57715 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57716 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57717 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57718 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57719 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57720 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57721 #endif
57722 }
57723
57724 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57725 {
57726 #ifdef CONFIG_CIFS_STATS
57727 seq_printf(m, " Oplocks breaks: %d",
57728 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57729 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57730 seq_printf(m, "\nReads: %d Bytes: %llu",
57731 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57732 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57733 (long long)(tcon->bytes_read));
57734 seq_printf(m, "\nWrites: %d Bytes: %llu",
57735 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57736 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57737 (long long)(tcon->bytes_written));
57738 seq_printf(m, "\nFlushes: %d",
57739 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57740 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57741 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57742 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57743 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57744 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57745 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57746 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57747 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57748 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57749 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57750 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57751 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57752 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57753 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57754 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57755 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57756 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57757 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57758 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57759 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57760 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57761 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57762 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57763 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57764 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57765 seq_printf(m, "\nRenames: %d T2 Renames %d",
57766 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57767 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57768 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57769 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57770 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57771 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57772 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57773 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57774 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57775 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57776 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57777 #endif
57778 }
57779
57780 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57781 index 35ddc3e..563e809 100644
57782 --- a/fs/cifs/smb2ops.c
57783 +++ b/fs/cifs/smb2ops.c
57784 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57785 #ifdef CONFIG_CIFS_STATS
57786 int i;
57787 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57788 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57789 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57790 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57791 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57792 }
57793 #endif
57794 }
57795 @@ -405,65 +405,65 @@ static void
57796 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57797 {
57798 #ifdef CONFIG_CIFS_STATS
57799 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57800 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57801 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57802 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57803 seq_printf(m, "\nNegotiates: %d sent %d failed",
57804 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57805 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57806 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57807 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57808 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57809 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57810 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57811 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57812 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57813 seq_printf(m, "\nLogoffs: %d sent %d failed",
57814 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57815 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57816 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57817 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57818 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57819 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57820 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57821 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57822 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57823 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57824 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57825 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57826 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57827 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57828 seq_printf(m, "\nCreates: %d sent %d failed",
57829 - atomic_read(&sent[SMB2_CREATE_HE]),
57830 - atomic_read(&failed[SMB2_CREATE_HE]));
57831 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57832 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57833 seq_printf(m, "\nCloses: %d sent %d failed",
57834 - atomic_read(&sent[SMB2_CLOSE_HE]),
57835 - atomic_read(&failed[SMB2_CLOSE_HE]));
57836 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57837 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57838 seq_printf(m, "\nFlushes: %d sent %d failed",
57839 - atomic_read(&sent[SMB2_FLUSH_HE]),
57840 - atomic_read(&failed[SMB2_FLUSH_HE]));
57841 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57842 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57843 seq_printf(m, "\nReads: %d sent %d failed",
57844 - atomic_read(&sent[SMB2_READ_HE]),
57845 - atomic_read(&failed[SMB2_READ_HE]));
57846 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57847 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57848 seq_printf(m, "\nWrites: %d sent %d failed",
57849 - atomic_read(&sent[SMB2_WRITE_HE]),
57850 - atomic_read(&failed[SMB2_WRITE_HE]));
57851 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57852 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57853 seq_printf(m, "\nLocks: %d sent %d failed",
57854 - atomic_read(&sent[SMB2_LOCK_HE]),
57855 - atomic_read(&failed[SMB2_LOCK_HE]));
57856 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57857 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57858 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57859 - atomic_read(&sent[SMB2_IOCTL_HE]),
57860 - atomic_read(&failed[SMB2_IOCTL_HE]));
57861 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57862 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57863 seq_printf(m, "\nCancels: %d sent %d failed",
57864 - atomic_read(&sent[SMB2_CANCEL_HE]),
57865 - atomic_read(&failed[SMB2_CANCEL_HE]));
57866 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57867 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57868 seq_printf(m, "\nEchos: %d sent %d failed",
57869 - atomic_read(&sent[SMB2_ECHO_HE]),
57870 - atomic_read(&failed[SMB2_ECHO_HE]));
57871 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57872 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57873 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57874 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57875 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57876 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57877 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57878 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57879 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57880 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57881 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57882 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57883 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57884 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57885 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57886 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57887 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57888 seq_printf(m, "\nSetInfos: %d sent %d failed",
57889 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57890 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57891 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57892 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57893 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57894 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57895 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57896 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57897 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57898 #endif
57899 }
57900
57901 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57902 index 1fb6ad2..758e171 100644
57903 --- a/fs/cifs/smb2pdu.c
57904 +++ b/fs/cifs/smb2pdu.c
57905 @@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57906 default:
57907 cifs_dbg(VFS, "info level %u isn't supported\n",
57908 srch_inf->info_level);
57909 - rc = -EINVAL;
57910 - goto qdir_exit;
57911 + return -EINVAL;
57912 }
57913
57914 req->FileIndex = cpu_to_le32(index);
57915 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57916 index 1da168c..8bc7ff6 100644
57917 --- a/fs/coda/cache.c
57918 +++ b/fs/coda/cache.c
57919 @@ -24,7 +24,7 @@
57920 #include "coda_linux.h"
57921 #include "coda_cache.h"
57922
57923 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57924 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57925
57926 /* replace or extend an acl cache hit */
57927 void coda_cache_enter(struct inode *inode, int mask)
57928 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57929 struct coda_inode_info *cii = ITOC(inode);
57930
57931 spin_lock(&cii->c_lock);
57932 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57933 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57934 if (!uid_eq(cii->c_uid, current_fsuid())) {
57935 cii->c_uid = current_fsuid();
57936 cii->c_cached_perm = mask;
57937 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57938 {
57939 struct coda_inode_info *cii = ITOC(inode);
57940 spin_lock(&cii->c_lock);
57941 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57942 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57943 spin_unlock(&cii->c_lock);
57944 }
57945
57946 /* remove all acl caches */
57947 void coda_cache_clear_all(struct super_block *sb)
57948 {
57949 - atomic_inc(&permission_epoch);
57950 + atomic_inc_unchecked(&permission_epoch);
57951 }
57952
57953
57954 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57955 spin_lock(&cii->c_lock);
57956 hit = (mask & cii->c_cached_perm) == mask &&
57957 uid_eq(cii->c_uid, current_fsuid()) &&
57958 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57959 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57960 spin_unlock(&cii->c_lock);
57961
57962 return hit;
57963 diff --git a/fs/compat.c b/fs/compat.c
57964 index 66d3d3c..9c10175 100644
57965 --- a/fs/compat.c
57966 +++ b/fs/compat.c
57967 @@ -54,7 +54,7 @@
57968 #include <asm/ioctls.h>
57969 #include "internal.h"
57970
57971 -int compat_log = 1;
57972 +int compat_log = 0;
57973
57974 int compat_printk(const char *fmt, ...)
57975 {
57976 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
57977
57978 set_fs(KERNEL_DS);
57979 /* The __user pointer cast is valid because of the set_fs() */
57980 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57981 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57982 set_fs(oldfs);
57983 /* truncating is ok because it's a user address */
57984 if (!ret)
57985 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57986 goto out;
57987
57988 ret = -EINVAL;
57989 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57990 + if (nr_segs > UIO_MAXIOV)
57991 goto out;
57992 if (nr_segs > fast_segs) {
57993 ret = -ENOMEM;
57994 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
57995 struct compat_readdir_callback {
57996 struct dir_context ctx;
57997 struct compat_old_linux_dirent __user *dirent;
57998 + struct file * file;
57999 int result;
58000 };
58001
58002 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58003 buf->result = -EOVERFLOW;
58004 return -EOVERFLOW;
58005 }
58006 +
58007 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58008 + return 0;
58009 +
58010 buf->result++;
58011 dirent = buf->dirent;
58012 if (!access_ok(VERIFY_WRITE, dirent,
58013 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58014 if (!f.file)
58015 return -EBADF;
58016
58017 + buf.file = f.file;
58018 error = iterate_dir(f.file, &buf.ctx);
58019 if (buf.result)
58020 error = buf.result;
58021 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
58022 struct dir_context ctx;
58023 struct compat_linux_dirent __user *current_dir;
58024 struct compat_linux_dirent __user *previous;
58025 + struct file * file;
58026 int count;
58027 int error;
58028 };
58029 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58030 buf->error = -EOVERFLOW;
58031 return -EOVERFLOW;
58032 }
58033 +
58034 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58035 + return 0;
58036 +
58037 dirent = buf->previous;
58038 if (dirent) {
58039 if (__put_user(offset, &dirent->d_off))
58040 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58041 if (!f.file)
58042 return -EBADF;
58043
58044 + buf.file = f.file;
58045 error = iterate_dir(f.file, &buf.ctx);
58046 if (error >= 0)
58047 error = buf.error;
58048 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58049 struct dir_context ctx;
58050 struct linux_dirent64 __user *current_dir;
58051 struct linux_dirent64 __user *previous;
58052 + struct file * file;
58053 int count;
58054 int error;
58055 };
58056 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58057 buf->error = -EINVAL; /* only used if we fail.. */
58058 if (reclen > buf->count)
58059 return -EINVAL;
58060 +
58061 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58062 + return 0;
58063 +
58064 dirent = buf->previous;
58065
58066 if (dirent) {
58067 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58068 if (!f.file)
58069 return -EBADF;
58070
58071 + buf.file = f.file;
58072 error = iterate_dir(f.file, &buf.ctx);
58073 if (error >= 0)
58074 error = buf.error;
58075 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58076 index 4d24d17..4f8c09e 100644
58077 --- a/fs/compat_binfmt_elf.c
58078 +++ b/fs/compat_binfmt_elf.c
58079 @@ -30,11 +30,13 @@
58080 #undef elf_phdr
58081 #undef elf_shdr
58082 #undef elf_note
58083 +#undef elf_dyn
58084 #undef elf_addr_t
58085 #define elfhdr elf32_hdr
58086 #define elf_phdr elf32_phdr
58087 #define elf_shdr elf32_shdr
58088 #define elf_note elf32_note
58089 +#define elf_dyn Elf32_Dyn
58090 #define elf_addr_t Elf32_Addr
58091
58092 /*
58093 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58094 index e822890..59374d5 100644
58095 --- a/fs/compat_ioctl.c
58096 +++ b/fs/compat_ioctl.c
58097 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58098 return -EFAULT;
58099 if (__get_user(udata, &ss32->iomem_base))
58100 return -EFAULT;
58101 - ss.iomem_base = compat_ptr(udata);
58102 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58103 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58104 __get_user(ss.port_high, &ss32->port_high))
58105 return -EFAULT;
58106 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58107 for (i = 0; i < nmsgs; i++) {
58108 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58109 return -EFAULT;
58110 - if (get_user(datap, &umsgs[i].buf) ||
58111 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58112 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58113 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58114 return -EFAULT;
58115 }
58116 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58117 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58118 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58119 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58120 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58121 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58122 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58123 return -EFAULT;
58124
58125 return ioctl_preallocate(file, p);
58126 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58127 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58128 {
58129 unsigned int a, b;
58130 - a = *(unsigned int *)p;
58131 - b = *(unsigned int *)q;
58132 + a = *(const unsigned int *)p;
58133 + b = *(const unsigned int *)q;
58134 if (a > b)
58135 return 1;
58136 if (a < b)
58137 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58138 index e081acb..911df21 100644
58139 --- a/fs/configfs/dir.c
58140 +++ b/fs/configfs/dir.c
58141 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58142 }
58143 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58144 struct configfs_dirent *next;
58145 - const char *name;
58146 + const unsigned char * name;
58147 + char d_name[sizeof(next->s_dentry->d_iname)];
58148 int len;
58149 struct inode *inode = NULL;
58150
58151 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58152 continue;
58153
58154 name = configfs_get_name(next);
58155 - len = strlen(name);
58156 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58157 + len = next->s_dentry->d_name.len;
58158 + memcpy(d_name, name, len);
58159 + name = d_name;
58160 + } else
58161 + len = strlen(name);
58162
58163 /*
58164 * We'll have a dentry and an inode for
58165 diff --git a/fs/coredump.c b/fs/coredump.c
58166 index 0b2528f..836c55f 100644
58167 --- a/fs/coredump.c
58168 +++ b/fs/coredump.c
58169 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58170 struct pipe_inode_info *pipe = file->private_data;
58171
58172 pipe_lock(pipe);
58173 - pipe->readers++;
58174 - pipe->writers--;
58175 + atomic_inc(&pipe->readers);
58176 + atomic_dec(&pipe->writers);
58177 wake_up_interruptible_sync(&pipe->wait);
58178 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58179 pipe_unlock(pipe);
58180 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58181 * We actually want wait_event_freezable() but then we need
58182 * to clear TIF_SIGPENDING and improve dump_interrupted().
58183 */
58184 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58185 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58186
58187 pipe_lock(pipe);
58188 - pipe->readers--;
58189 - pipe->writers++;
58190 + atomic_dec(&pipe->readers);
58191 + atomic_inc(&pipe->writers);
58192 pipe_unlock(pipe);
58193 }
58194
58195 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58196 struct files_struct *displaced;
58197 bool need_nonrelative = false;
58198 bool core_dumped = false;
58199 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58200 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58201 + long signr = siginfo->si_signo;
58202 + int dumpable;
58203 struct coredump_params cprm = {
58204 .siginfo = siginfo,
58205 .regs = signal_pt_regs(),
58206 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58207 .mm_flags = mm->flags,
58208 };
58209
58210 - audit_core_dumps(siginfo->si_signo);
58211 + audit_core_dumps(signr);
58212 +
58213 + dumpable = __get_dumpable(cprm.mm_flags);
58214 +
58215 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58216 + gr_handle_brute_attach(dumpable);
58217
58218 binfmt = mm->binfmt;
58219 if (!binfmt || !binfmt->core_dump)
58220 goto fail;
58221 - if (!__get_dumpable(cprm.mm_flags))
58222 + if (!dumpable)
58223 goto fail;
58224
58225 cred = prepare_creds();
58226 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58227 need_nonrelative = true;
58228 }
58229
58230 - retval = coredump_wait(siginfo->si_signo, &core_state);
58231 + retval = coredump_wait(signr, &core_state);
58232 if (retval < 0)
58233 goto fail_creds;
58234
58235 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58236 }
58237 cprm.limit = RLIM_INFINITY;
58238
58239 - dump_count = atomic_inc_return(&core_dump_count);
58240 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58241 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58242 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58243 task_tgid_vnr(current), current->comm);
58244 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58245 } else {
58246 struct inode *inode;
58247
58248 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58249 +
58250 if (cprm.limit < binfmt->min_coredump)
58251 goto fail_unlock;
58252
58253 @@ -673,7 +682,7 @@ close_fail:
58254 filp_close(cprm.file, NULL);
58255 fail_dropcount:
58256 if (ispipe)
58257 - atomic_dec(&core_dump_count);
58258 + atomic_dec_unchecked(&core_dump_count);
58259 fail_unlock:
58260 kfree(cn.corename);
58261 coredump_finish(mm, core_dumped);
58262 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58263 struct file *file = cprm->file;
58264 loff_t pos = file->f_pos;
58265 ssize_t n;
58266 +
58267 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58268 if (cprm->written + nr > cprm->limit)
58269 return 0;
58270 while (nr) {
58271 diff --git a/fs/dcache.c b/fs/dcache.c
58272 index e99c6f5..2838bf58 100644
58273 --- a/fs/dcache.c
58274 +++ b/fs/dcache.c
58275 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58276 */
58277 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58278 if (name->len > DNAME_INLINE_LEN-1) {
58279 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58280 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58281 if (!dname) {
58282 kmem_cache_free(dentry_cache, dentry);
58283 return NULL;
58284 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58285 mempages -= reserve;
58286
58287 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58288 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58289 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58290 + SLAB_NO_SANITIZE, NULL);
58291
58292 dcache_init();
58293 inode_init();
58294 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58295 index 8c41b52..145b1b9 100644
58296 --- a/fs/debugfs/inode.c
58297 +++ b/fs/debugfs/inode.c
58298 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58299 */
58300 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58301 {
58302 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58303 + return __create_file(name, S_IFDIR | S_IRWXU,
58304 +#else
58305 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58306 +#endif
58307 parent, NULL, NULL);
58308 }
58309 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58310 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58311 index d4a9431..77f9b2e 100644
58312 --- a/fs/ecryptfs/inode.c
58313 +++ b/fs/ecryptfs/inode.c
58314 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58315 old_fs = get_fs();
58316 set_fs(get_ds());
58317 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58318 - (char __user *)lower_buf,
58319 + (char __force_user *)lower_buf,
58320 PATH_MAX);
58321 set_fs(old_fs);
58322 if (rc < 0)
58323 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58324 index e4141f2..d8263e8 100644
58325 --- a/fs/ecryptfs/miscdev.c
58326 +++ b/fs/ecryptfs/miscdev.c
58327 @@ -304,7 +304,7 @@ check_list:
58328 goto out_unlock_msg_ctx;
58329 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58330 if (msg_ctx->msg) {
58331 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58332 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58333 goto out_unlock_msg_ctx;
58334 i += packet_length_size;
58335 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58336 diff --git a/fs/exec.c b/fs/exec.c
58337 index 238b7aa..a421d91 100644
58338 --- a/fs/exec.c
58339 +++ b/fs/exec.c
58340 @@ -56,8 +56,20 @@
58341 #include <linux/pipe_fs_i.h>
58342 #include <linux/oom.h>
58343 #include <linux/compat.h>
58344 +#include <linux/random.h>
58345 +#include <linux/seq_file.h>
58346 +#include <linux/coredump.h>
58347 +#include <linux/mman.h>
58348 +
58349 +#ifdef CONFIG_PAX_REFCOUNT
58350 +#include <linux/kallsyms.h>
58351 +#include <linux/kdebug.h>
58352 +#endif
58353 +
58354 +#include <trace/events/fs.h>
58355
58356 #include <asm/uaccess.h>
58357 +#include <asm/sections.h>
58358 #include <asm/mmu_context.h>
58359 #include <asm/tlb.h>
58360
58361 @@ -66,19 +78,34 @@
58362
58363 #include <trace/events/sched.h>
58364
58365 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58366 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58367 +{
58368 + 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");
58369 +}
58370 +#endif
58371 +
58372 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58373 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58374 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58375 +#endif
58376 +
58377 int suid_dumpable = 0;
58378
58379 static LIST_HEAD(formats);
58380 static DEFINE_RWLOCK(binfmt_lock);
58381
58382 +extern int gr_process_kernel_exec_ban(void);
58383 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58384 +
58385 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58386 {
58387 BUG_ON(!fmt);
58388 if (WARN_ON(!fmt->load_binary))
58389 return;
58390 write_lock(&binfmt_lock);
58391 - insert ? list_add(&fmt->lh, &formats) :
58392 - list_add_tail(&fmt->lh, &formats);
58393 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58394 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58395 write_unlock(&binfmt_lock);
58396 }
58397
58398 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58399 void unregister_binfmt(struct linux_binfmt * fmt)
58400 {
58401 write_lock(&binfmt_lock);
58402 - list_del(&fmt->lh);
58403 + pax_list_del((struct list_head *)&fmt->lh);
58404 write_unlock(&binfmt_lock);
58405 }
58406
58407 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58408 int write)
58409 {
58410 struct page *page;
58411 - int ret;
58412
58413 -#ifdef CONFIG_STACK_GROWSUP
58414 - if (write) {
58415 - ret = expand_downwards(bprm->vma, pos);
58416 - if (ret < 0)
58417 - return NULL;
58418 - }
58419 -#endif
58420 - ret = get_user_pages(current, bprm->mm, pos,
58421 - 1, write, 1, &page, NULL);
58422 - if (ret <= 0)
58423 + if (0 > expand_downwards(bprm->vma, pos))
58424 + return NULL;
58425 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58426 return NULL;
58427
58428 if (write) {
58429 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58430 if (size <= ARG_MAX)
58431 return page;
58432
58433 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58434 + // only allow 512KB for argv+env on suid/sgid binaries
58435 + // to prevent easy ASLR exhaustion
58436 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58437 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58438 + (size > (512 * 1024))) {
58439 + put_page(page);
58440 + return NULL;
58441 + }
58442 +#endif
58443 +
58444 /*
58445 * Limit to 1/4-th the stack size for the argv+env strings.
58446 * This ensures that:
58447 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58448 vma->vm_end = STACK_TOP_MAX;
58449 vma->vm_start = vma->vm_end - PAGE_SIZE;
58450 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58451 +
58452 +#ifdef CONFIG_PAX_SEGMEXEC
58453 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58454 +#endif
58455 +
58456 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58457 INIT_LIST_HEAD(&vma->anon_vma_chain);
58458
58459 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58460 mm->stack_vm = mm->total_vm = 1;
58461 up_write(&mm->mmap_sem);
58462 bprm->p = vma->vm_end - sizeof(void *);
58463 +
58464 +#ifdef CONFIG_PAX_RANDUSTACK
58465 + if (randomize_va_space)
58466 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58467 +#endif
58468 +
58469 return 0;
58470 err:
58471 up_write(&mm->mmap_sem);
58472 @@ -399,7 +440,7 @@ struct user_arg_ptr {
58473 } ptr;
58474 };
58475
58476 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58477 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58478 {
58479 const char __user *native;
58480
58481 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58482 compat_uptr_t compat;
58483
58484 if (get_user(compat, argv.ptr.compat + nr))
58485 - return ERR_PTR(-EFAULT);
58486 + return (const char __force_user *)ERR_PTR(-EFAULT);
58487
58488 return compat_ptr(compat);
58489 }
58490 #endif
58491
58492 if (get_user(native, argv.ptr.native + nr))
58493 - return ERR_PTR(-EFAULT);
58494 + return (const char __force_user *)ERR_PTR(-EFAULT);
58495
58496 return native;
58497 }
58498 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58499 if (!p)
58500 break;
58501
58502 - if (IS_ERR(p))
58503 + if (IS_ERR((const char __force_kernel *)p))
58504 return -EFAULT;
58505
58506 if (i >= max)
58507 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58508
58509 ret = -EFAULT;
58510 str = get_user_arg_ptr(argv, argc);
58511 - if (IS_ERR(str))
58512 + if (IS_ERR((const char __force_kernel *)str))
58513 goto out;
58514
58515 len = strnlen_user(str, MAX_ARG_STRLEN);
58516 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58517 int r;
58518 mm_segment_t oldfs = get_fs();
58519 struct user_arg_ptr argv = {
58520 - .ptr.native = (const char __user *const __user *)__argv,
58521 + .ptr.native = (const char __user * const __force_user *)__argv,
58522 };
58523
58524 set_fs(KERNEL_DS);
58525 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58526 unsigned long new_end = old_end - shift;
58527 struct mmu_gather tlb;
58528
58529 - BUG_ON(new_start > new_end);
58530 + if (new_start >= new_end || new_start < mmap_min_addr)
58531 + return -ENOMEM;
58532
58533 /*
58534 * ensure there are no vmas between where we want to go
58535 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58536 if (vma != find_vma(mm, new_start))
58537 return -EFAULT;
58538
58539 +#ifdef CONFIG_PAX_SEGMEXEC
58540 + BUG_ON(pax_find_mirror_vma(vma));
58541 +#endif
58542 +
58543 /*
58544 * cover the whole range: [new_start, old_end)
58545 */
58546 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58547 stack_top = arch_align_stack(stack_top);
58548 stack_top = PAGE_ALIGN(stack_top);
58549
58550 - if (unlikely(stack_top < mmap_min_addr) ||
58551 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58552 - return -ENOMEM;
58553 -
58554 stack_shift = vma->vm_end - stack_top;
58555
58556 bprm->p -= stack_shift;
58557 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58558 bprm->exec -= stack_shift;
58559
58560 down_write(&mm->mmap_sem);
58561 +
58562 + /* Move stack pages down in memory. */
58563 + if (stack_shift) {
58564 + ret = shift_arg_pages(vma, stack_shift);
58565 + if (ret)
58566 + goto out_unlock;
58567 + }
58568 +
58569 vm_flags = VM_STACK_FLAGS;
58570
58571 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58572 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58573 + vm_flags &= ~VM_EXEC;
58574 +
58575 +#ifdef CONFIG_PAX_MPROTECT
58576 + if (mm->pax_flags & MF_PAX_MPROTECT)
58577 + vm_flags &= ~VM_MAYEXEC;
58578 +#endif
58579 +
58580 + }
58581 +#endif
58582 +
58583 /*
58584 * Adjust stack execute permissions; explicitly enable for
58585 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58586 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58587 goto out_unlock;
58588 BUG_ON(prev != vma);
58589
58590 - /* Move stack pages down in memory. */
58591 - if (stack_shift) {
58592 - ret = shift_arg_pages(vma, stack_shift);
58593 - if (ret)
58594 - goto out_unlock;
58595 - }
58596 -
58597 /* mprotect_fixup is overkill to remove the temporary stack flags */
58598 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58599
58600 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58601 #endif
58602 current->mm->start_stack = bprm->p;
58603 ret = expand_stack(vma, stack_base);
58604 +
58605 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58606 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58607 + unsigned long size;
58608 + vm_flags_t vm_flags;
58609 +
58610 + size = STACK_TOP - vma->vm_end;
58611 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58612 +
58613 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58614 +
58615 +#ifdef CONFIG_X86
58616 + if (!ret) {
58617 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58618 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58619 + }
58620 +#endif
58621 +
58622 + }
58623 +#endif
58624 +
58625 if (ret)
58626 ret = -EFAULT;
58627
58628 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
58629
58630 fsnotify_open(file);
58631
58632 + trace_open_exec(name->name);
58633 +
58634 err = deny_write_access(file);
58635 if (err)
58636 goto exit;
58637 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
58638 old_fs = get_fs();
58639 set_fs(get_ds());
58640 /* The cast to a user pointer is valid due to the set_fs() */
58641 - result = vfs_read(file, (void __user *)addr, count, &pos);
58642 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58643 set_fs(old_fs);
58644 return result;
58645 }
58646 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
58647 tsk->mm = mm;
58648 tsk->active_mm = mm;
58649 activate_mm(active_mm, mm);
58650 + populate_stack();
58651 tsk->mm->vmacache_seqnum = 0;
58652 vmacache_flush(tsk);
58653 task_unlock(tsk);
58654 @@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58655 }
58656 rcu_read_unlock();
58657
58658 - if (p->fs->users > n_fs)
58659 + if (atomic_read(&p->fs->users) > n_fs)
58660 bprm->unsafe |= LSM_UNSAFE_SHARE;
58661 else
58662 p->fs->in_exec = 1;
58663 @@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58664 return ret;
58665 }
58666
58667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58668 +static DEFINE_PER_CPU(u64, exec_counter);
58669 +static int __init init_exec_counters(void)
58670 +{
58671 + unsigned int cpu;
58672 +
58673 + for_each_possible_cpu(cpu) {
58674 + per_cpu(exec_counter, cpu) = (u64)cpu;
58675 + }
58676 +
58677 + return 0;
58678 +}
58679 +early_initcall(init_exec_counters);
58680 +static inline void increment_exec_counter(void)
58681 +{
58682 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58683 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58684 +}
58685 +#else
58686 +static inline void increment_exec_counter(void) {}
58687 +#endif
58688 +
58689 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58690 + struct user_arg_ptr argv);
58691 +
58692 /*
58693 * sys_execve() executes a new program.
58694 */
58695 @@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
58696 struct user_arg_ptr argv,
58697 struct user_arg_ptr envp)
58698 {
58699 +#ifdef CONFIG_GRKERNSEC
58700 + struct file *old_exec_file;
58701 + struct acl_subject_label *old_acl;
58702 + struct rlimit old_rlim[RLIM_NLIMITS];
58703 +#endif
58704 struct linux_binprm *bprm;
58705 struct file *file;
58706 struct files_struct *displaced;
58707 @@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
58708 if (IS_ERR(filename))
58709 return PTR_ERR(filename);
58710
58711 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58712 +
58713 /*
58714 * We move the actual failure in case of RLIMIT_NPROC excess from
58715 * set*uid() to execve() because too many poorly written programs
58716 @@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
58717 if (IS_ERR(file))
58718 goto out_unmark;
58719
58720 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58721 + retval = -EPERM;
58722 + goto out_unmark;
58723 + }
58724 +
58725 sched_exec();
58726
58727 bprm->file = file;
58728 bprm->filename = bprm->interp = filename->name;
58729
58730 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58731 + retval = -EACCES;
58732 + goto out_unmark;
58733 + }
58734 +
58735 retval = bprm_mm_init(bprm);
58736 if (retval)
58737 goto out_unmark;
58738 @@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
58739 if (retval < 0)
58740 goto out;
58741
58742 +#ifdef CONFIG_GRKERNSEC
58743 + old_acl = current->acl;
58744 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58745 + old_exec_file = current->exec_file;
58746 + get_file(file);
58747 + current->exec_file = file;
58748 +#endif
58749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58750 + /* limit suid stack to 8MB
58751 + * we saved the old limits above and will restore them if this exec fails
58752 + */
58753 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58754 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58755 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58756 +#endif
58757 +
58758 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58759 + retval = -EPERM;
58760 + goto out_fail;
58761 + }
58762 +
58763 + if (!gr_tpe_allow(file)) {
58764 + retval = -EACCES;
58765 + goto out_fail;
58766 + }
58767 +
58768 + if (gr_check_crash_exec(file)) {
58769 + retval = -EACCES;
58770 + goto out_fail;
58771 + }
58772 +
58773 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58774 + bprm->unsafe);
58775 + if (retval < 0)
58776 + goto out_fail;
58777 +
58778 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58779 if (retval < 0)
58780 - goto out;
58781 + goto out_fail;
58782
58783 bprm->exec = bprm->p;
58784 retval = copy_strings(bprm->envc, envp, bprm);
58785 if (retval < 0)
58786 - goto out;
58787 + goto out_fail;
58788
58789 retval = copy_strings(bprm->argc, argv, bprm);
58790 if (retval < 0)
58791 - goto out;
58792 + goto out_fail;
58793 +
58794 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58795 +
58796 + gr_handle_exec_args(bprm, argv);
58797
58798 retval = exec_binprm(bprm);
58799 if (retval < 0)
58800 - goto out;
58801 + goto out_fail;
58802 +#ifdef CONFIG_GRKERNSEC
58803 + if (old_exec_file)
58804 + fput(old_exec_file);
58805 +#endif
58806
58807 /* execve succeeded */
58808 +
58809 + increment_exec_counter();
58810 current->fs->in_exec = 0;
58811 current->in_execve = 0;
58812 acct_update_integrals(current);
58813 @@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
58814 put_files_struct(displaced);
58815 return retval;
58816
58817 +out_fail:
58818 +#ifdef CONFIG_GRKERNSEC
58819 + current->acl = old_acl;
58820 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58821 + fput(current->exec_file);
58822 + current->exec_file = old_exec_file;
58823 +#endif
58824 +
58825 out:
58826 if (bprm->mm) {
58827 acct_arg_size(bprm, 0);
58828 @@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
58829 return compat_do_execve(getname(filename), argv, envp);
58830 }
58831 #endif
58832 +
58833 +int pax_check_flags(unsigned long *flags)
58834 +{
58835 + int retval = 0;
58836 +
58837 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58838 + if (*flags & MF_PAX_SEGMEXEC)
58839 + {
58840 + *flags &= ~MF_PAX_SEGMEXEC;
58841 + retval = -EINVAL;
58842 + }
58843 +#endif
58844 +
58845 + if ((*flags & MF_PAX_PAGEEXEC)
58846 +
58847 +#ifdef CONFIG_PAX_PAGEEXEC
58848 + && (*flags & MF_PAX_SEGMEXEC)
58849 +#endif
58850 +
58851 + )
58852 + {
58853 + *flags &= ~MF_PAX_PAGEEXEC;
58854 + retval = -EINVAL;
58855 + }
58856 +
58857 + if ((*flags & MF_PAX_MPROTECT)
58858 +
58859 +#ifdef CONFIG_PAX_MPROTECT
58860 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58861 +#endif
58862 +
58863 + )
58864 + {
58865 + *flags &= ~MF_PAX_MPROTECT;
58866 + retval = -EINVAL;
58867 + }
58868 +
58869 + if ((*flags & MF_PAX_EMUTRAMP)
58870 +
58871 +#ifdef CONFIG_PAX_EMUTRAMP
58872 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58873 +#endif
58874 +
58875 + )
58876 + {
58877 + *flags &= ~MF_PAX_EMUTRAMP;
58878 + retval = -EINVAL;
58879 + }
58880 +
58881 + return retval;
58882 +}
58883 +
58884 +EXPORT_SYMBOL(pax_check_flags);
58885 +
58886 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58887 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58888 +{
58889 + char *pathname = d_path(path, buf, buflen);
58890 +
58891 + if (IS_ERR(pathname))
58892 + goto toolong;
58893 +
58894 + pathname = mangle_path(buf, pathname, "\t\n\\");
58895 + if (!pathname)
58896 + goto toolong;
58897 +
58898 + *pathname = 0;
58899 + return buf;
58900 +
58901 +toolong:
58902 + return "<path too long>";
58903 +}
58904 +EXPORT_SYMBOL(pax_get_path);
58905 +
58906 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58907 +{
58908 + struct task_struct *tsk = current;
58909 + struct mm_struct *mm = current->mm;
58910 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58911 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58912 + char *path_exec = NULL;
58913 + char *path_fault = NULL;
58914 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58915 + siginfo_t info = { };
58916 +
58917 + if (buffer_exec && buffer_fault) {
58918 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58919 +
58920 + down_read(&mm->mmap_sem);
58921 + vma = mm->mmap;
58922 + while (vma && (!vma_exec || !vma_fault)) {
58923 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58924 + vma_exec = vma;
58925 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58926 + vma_fault = vma;
58927 + vma = vma->vm_next;
58928 + }
58929 + if (vma_exec)
58930 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58931 + if (vma_fault) {
58932 + start = vma_fault->vm_start;
58933 + end = vma_fault->vm_end;
58934 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58935 + if (vma_fault->vm_file)
58936 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58937 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58938 + path_fault = "<heap>";
58939 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58940 + path_fault = "<stack>";
58941 + else
58942 + path_fault = "<anonymous mapping>";
58943 + }
58944 + up_read(&mm->mmap_sem);
58945 + }
58946 + if (tsk->signal->curr_ip)
58947 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58948 + else
58949 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58950 + 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),
58951 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58952 + free_page((unsigned long)buffer_exec);
58953 + free_page((unsigned long)buffer_fault);
58954 + pax_report_insns(regs, pc, sp);
58955 + info.si_signo = SIGKILL;
58956 + info.si_errno = 0;
58957 + info.si_code = SI_KERNEL;
58958 + info.si_pid = 0;
58959 + info.si_uid = 0;
58960 + do_coredump(&info);
58961 +}
58962 +#endif
58963 +
58964 +#ifdef CONFIG_PAX_REFCOUNT
58965 +void pax_report_refcount_overflow(struct pt_regs *regs)
58966 +{
58967 + if (current->signal->curr_ip)
58968 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58969 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58970 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58971 + else
58972 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58973 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58974 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58975 + preempt_disable();
58976 + show_regs(regs);
58977 + preempt_enable();
58978 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58979 +}
58980 +#endif
58981 +
58982 +#ifdef CONFIG_PAX_USERCOPY
58983 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58984 +static noinline int check_stack_object(const void *obj, unsigned long len)
58985 +{
58986 + const void * const stack = task_stack_page(current);
58987 + const void * const stackend = stack + THREAD_SIZE;
58988 +
58989 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58990 + const void *frame = NULL;
58991 + const void *oldframe;
58992 +#endif
58993 +
58994 + if (obj + len < obj)
58995 + return -1;
58996 +
58997 + if (obj + len <= stack || stackend <= obj)
58998 + return 0;
58999 +
59000 + if (obj < stack || stackend < obj + len)
59001 + return -1;
59002 +
59003 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59004 + oldframe = __builtin_frame_address(1);
59005 + if (oldframe)
59006 + frame = __builtin_frame_address(2);
59007 + /*
59008 + low ----------------------------------------------> high
59009 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59010 + ^----------------^
59011 + allow copies only within here
59012 + */
59013 + while (stack <= frame && frame < stackend) {
59014 + /* if obj + len extends past the last frame, this
59015 + check won't pass and the next frame will be 0,
59016 + causing us to bail out and correctly report
59017 + the copy as invalid
59018 + */
59019 + if (obj + len <= frame)
59020 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59021 + oldframe = frame;
59022 + frame = *(const void * const *)frame;
59023 + }
59024 + return -1;
59025 +#else
59026 + return 1;
59027 +#endif
59028 +}
59029 +
59030 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59031 +{
59032 + if (current->signal->curr_ip)
59033 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59034 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59035 + else
59036 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59037 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59038 + dump_stack();
59039 + gr_handle_kernel_exploit();
59040 + do_group_exit(SIGKILL);
59041 +}
59042 +#endif
59043 +
59044 +#ifdef CONFIG_PAX_USERCOPY
59045 +
59046 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59047 +{
59048 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59049 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59050 +#ifdef CONFIG_MODULES
59051 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59052 +#else
59053 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59054 +#endif
59055 +
59056 +#else
59057 + unsigned long textlow = (unsigned long)_stext;
59058 + unsigned long texthigh = (unsigned long)_etext;
59059 +
59060 +#ifdef CONFIG_X86_64
59061 + /* check against linear mapping as well */
59062 + if (high > (unsigned long)__va(__pa(textlow)) &&
59063 + low < (unsigned long)__va(__pa(texthigh)))
59064 + return true;
59065 +#endif
59066 +
59067 +#endif
59068 +
59069 + if (high <= textlow || low >= texthigh)
59070 + return false;
59071 + else
59072 + return true;
59073 +}
59074 +#endif
59075 +
59076 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59077 +{
59078 +#ifdef CONFIG_PAX_USERCOPY
59079 + const char *type;
59080 +#endif
59081 +
59082 +#ifndef CONFIG_STACK_GROWSUP
59083 + unsigned long stackstart = (unsigned long)task_stack_page(current);
59084 + unsigned long currentsp = (unsigned long)&stackstart;
59085 + if (unlikely((currentsp < stackstart + 512 ||
59086 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59087 + BUG();
59088 +#endif
59089 +
59090 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
59091 + if (const_size)
59092 + return;
59093 +#endif
59094 +
59095 +#ifdef CONFIG_PAX_USERCOPY
59096 + if (!n)
59097 + return;
59098 +
59099 + type = check_heap_object(ptr, n);
59100 + if (!type) {
59101 + int ret = check_stack_object(ptr, n);
59102 + if (ret == 1 || ret == 2)
59103 + return;
59104 + if (ret == 0) {
59105 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59106 + type = "<kernel text>";
59107 + else
59108 + return;
59109 + } else
59110 + type = "<process stack>";
59111 + }
59112 +
59113 + pax_report_usercopy(ptr, n, to_user, type);
59114 +#endif
59115 +
59116 +}
59117 +EXPORT_SYMBOL(__check_object_size);
59118 +
59119 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59120 +void pax_track_stack(void)
59121 +{
59122 + unsigned long sp = (unsigned long)&sp;
59123 + if (sp < current_thread_info()->lowest_stack &&
59124 + sp > (unsigned long)task_stack_page(current))
59125 + current_thread_info()->lowest_stack = sp;
59126 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59127 + BUG();
59128 +}
59129 +EXPORT_SYMBOL(pax_track_stack);
59130 +#endif
59131 +
59132 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59133 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59134 +{
59135 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59136 + dump_stack();
59137 + do_group_exit(SIGKILL);
59138 +}
59139 +EXPORT_SYMBOL(report_size_overflow);
59140 +#endif
59141 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59142 index 9f9992b..8b59411 100644
59143 --- a/fs/ext2/balloc.c
59144 +++ b/fs/ext2/balloc.c
59145 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59146
59147 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59148 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59149 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59150 + if (free_blocks < root_blocks + 1 &&
59151 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59152 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59153 - !in_group_p (sbi->s_resgid))) {
59154 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59155 return 0;
59156 }
59157 return 1;
59158 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59159 index 9142614..97484fa 100644
59160 --- a/fs/ext2/xattr.c
59161 +++ b/fs/ext2/xattr.c
59162 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59163 struct buffer_head *bh = NULL;
59164 struct ext2_xattr_entry *entry;
59165 char *end;
59166 - size_t rest = buffer_size;
59167 + size_t rest = buffer_size, total_size = 0;
59168 int error;
59169
59170 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59171 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59172 buffer += size;
59173 }
59174 rest -= size;
59175 + total_size += size;
59176 }
59177 }
59178 - error = buffer_size - rest; /* total size */
59179 + error = total_size;
59180
59181 cleanup:
59182 brelse(bh);
59183 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59184 index 158b5d4..2432610 100644
59185 --- a/fs/ext3/balloc.c
59186 +++ b/fs/ext3/balloc.c
59187 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59188
59189 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59190 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59191 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59192 + if (free_blocks < root_blocks + 1 &&
59193 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59194 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59195 - !in_group_p (sbi->s_resgid))) {
59196 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59197 return 0;
59198 }
59199 return 1;
59200 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59201 index c6874be..f8a6ae8 100644
59202 --- a/fs/ext3/xattr.c
59203 +++ b/fs/ext3/xattr.c
59204 @@ -330,7 +330,7 @@ static int
59205 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59206 char *buffer, size_t buffer_size)
59207 {
59208 - size_t rest = buffer_size;
59209 + size_t rest = buffer_size, total_size = 0;
59210
59211 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59212 const struct xattr_handler *handler =
59213 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59214 buffer += size;
59215 }
59216 rest -= size;
59217 + total_size += size;
59218 }
59219 }
59220 - return buffer_size - rest;
59221 + return total_size;
59222 }
59223
59224 static int
59225 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59226 index 5c56785..77698a2 100644
59227 --- a/fs/ext4/balloc.c
59228 +++ b/fs/ext4/balloc.c
59229 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59230 /* Hm, nope. Are (enough) root reserved clusters available? */
59231 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59232 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59233 - capable(CAP_SYS_RESOURCE) ||
59234 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59235 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59236 + capable_nolog(CAP_SYS_RESOURCE)) {
59237
59238 if (free_clusters >= (nclusters + dirty_clusters +
59239 resv_clusters))
59240 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59241 index f542e48..c0275f5 100644
59242 --- a/fs/ext4/ext4.h
59243 +++ b/fs/ext4/ext4.h
59244 @@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59245 unsigned long s_mb_last_start;
59246
59247 /* stats for buddy allocator */
59248 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59249 - atomic_t s_bal_success; /* we found long enough chunks */
59250 - atomic_t s_bal_allocated; /* in blocks */
59251 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59252 - atomic_t s_bal_goals; /* goal hits */
59253 - atomic_t s_bal_breaks; /* too long searches */
59254 - atomic_t s_bal_2orders; /* 2^order hits */
59255 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59256 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59257 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59258 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59259 + atomic_unchecked_t s_bal_goals; /* goal hits */
59260 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59261 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59262 spinlock_t s_bal_lock;
59263 unsigned long s_mb_buddies_generated;
59264 unsigned long long s_mb_generation_time;
59265 - atomic_t s_mb_lost_chunks;
59266 - atomic_t s_mb_preallocated;
59267 - atomic_t s_mb_discarded;
59268 + atomic_unchecked_t s_mb_lost_chunks;
59269 + atomic_unchecked_t s_mb_preallocated;
59270 + atomic_unchecked_t s_mb_discarded;
59271 atomic_t s_lock_busy;
59272
59273 /* locality groups */
59274 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59275 index 594009f..c30cbe2 100644
59276 --- a/fs/ext4/indirect.c
59277 +++ b/fs/ext4/indirect.c
59278 @@ -389,7 +389,13 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
59279 return 0;
59280 failed:
59281 for (; i >= 0; i--) {
59282 - if (i != indirect_blks && branch[i].bh)
59283 + /*
59284 + * We want to ext4_forget() only freshly allocated indirect
59285 + * blocks. Buffer for new_blocks[i-1] is at branch[i].bh and
59286 + * buffer at branch[0].bh is indirect block / inode already
59287 + * existing before ext4_alloc_branch() was called.
59288 + */
59289 + if (i > 0 && i != indirect_blks && branch[i].bh)
59290 ext4_forget(handle, 1, inode, branch[i].bh,
59291 branch[i].bh->b_blocknr);
59292 ext4_free_blocks(handle, inode, NULL, new_blocks[i],
59293 @@ -1312,16 +1318,24 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59294 blk = *i_data;
59295 if (level > 0) {
59296 ext4_lblk_t first2;
59297 + ext4_lblk_t count2;
59298 +
59299 bh = sb_bread(inode->i_sb, le32_to_cpu(blk));
59300 if (!bh) {
59301 EXT4_ERROR_INODE_BLOCK(inode, le32_to_cpu(blk),
59302 "Read failure");
59303 return -EIO;
59304 }
59305 - first2 = (first > offset) ? first - offset : 0;
59306 + if (first > offset) {
59307 + first2 = first - offset;
59308 + count2 = count;
59309 + } else {
59310 + first2 = 0;
59311 + count2 = count - (offset - first);
59312 + }
59313 ret = free_hole_blocks(handle, inode, bh,
59314 (__le32 *)bh->b_data, level - 1,
59315 - first2, count - offset,
59316 + first2, count2,
59317 inode->i_sb->s_blocksize >> 2);
59318 if (ret) {
59319 brelse(bh);
59320 @@ -1331,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59321 if (level == 0 ||
59322 (bh && all_zeroes((__le32 *)bh->b_data,
59323 (__le32 *)bh->b_data + addr_per_block))) {
59324 - ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59325 - *i_data = 0;
59326 + ext4_free_data(handle, inode, parent_bh,
59327 + i_data, i_data + 1);
59328 }
59329 brelse(bh);
59330 bh = NULL;
59331 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59332 index fe4e668..f983538 100644
59333 --- a/fs/ext4/mballoc.c
59334 +++ b/fs/ext4/mballoc.c
59335 @@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59336 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59337
59338 if (EXT4_SB(sb)->s_mb_stats)
59339 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59340 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59341
59342 break;
59343 }
59344 @@ -2199,7 +2199,7 @@ repeat:
59345 ac->ac_status = AC_STATUS_CONTINUE;
59346 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59347 cr = 3;
59348 - atomic_inc(&sbi->s_mb_lost_chunks);
59349 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59350 goto repeat;
59351 }
59352 }
59353 @@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59354 if (sbi->s_mb_stats) {
59355 ext4_msg(sb, KERN_INFO,
59356 "mballoc: %u blocks %u reqs (%u success)",
59357 - atomic_read(&sbi->s_bal_allocated),
59358 - atomic_read(&sbi->s_bal_reqs),
59359 - atomic_read(&sbi->s_bal_success));
59360 + atomic_read_unchecked(&sbi->s_bal_allocated),
59361 + atomic_read_unchecked(&sbi->s_bal_reqs),
59362 + atomic_read_unchecked(&sbi->s_bal_success));
59363 ext4_msg(sb, KERN_INFO,
59364 "mballoc: %u extents scanned, %u goal hits, "
59365 "%u 2^N hits, %u breaks, %u lost",
59366 - atomic_read(&sbi->s_bal_ex_scanned),
59367 - atomic_read(&sbi->s_bal_goals),
59368 - atomic_read(&sbi->s_bal_2orders),
59369 - atomic_read(&sbi->s_bal_breaks),
59370 - atomic_read(&sbi->s_mb_lost_chunks));
59371 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59372 + atomic_read_unchecked(&sbi->s_bal_goals),
59373 + atomic_read_unchecked(&sbi->s_bal_2orders),
59374 + atomic_read_unchecked(&sbi->s_bal_breaks),
59375 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59376 ext4_msg(sb, KERN_INFO,
59377 "mballoc: %lu generated and it took %Lu",
59378 sbi->s_mb_buddies_generated,
59379 sbi->s_mb_generation_time);
59380 ext4_msg(sb, KERN_INFO,
59381 "mballoc: %u preallocated, %u discarded",
59382 - atomic_read(&sbi->s_mb_preallocated),
59383 - atomic_read(&sbi->s_mb_discarded));
59384 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59385 + atomic_read_unchecked(&sbi->s_mb_discarded));
59386 }
59387
59388 free_percpu(sbi->s_locality_groups);
59389 @@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59390 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59391
59392 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59393 - atomic_inc(&sbi->s_bal_reqs);
59394 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59395 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59396 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59397 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59398 - atomic_inc(&sbi->s_bal_success);
59399 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59400 + atomic_inc_unchecked(&sbi->s_bal_success);
59401 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59402 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59403 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59404 - atomic_inc(&sbi->s_bal_goals);
59405 + atomic_inc_unchecked(&sbi->s_bal_goals);
59406 if (ac->ac_found > sbi->s_mb_max_to_scan)
59407 - atomic_inc(&sbi->s_bal_breaks);
59408 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59409 }
59410
59411 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59412 @@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59413 trace_ext4_mb_new_inode_pa(ac, pa);
59414
59415 ext4_mb_use_inode_pa(ac, pa);
59416 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59417 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59418
59419 ei = EXT4_I(ac->ac_inode);
59420 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59421 @@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59422 trace_ext4_mb_new_group_pa(ac, pa);
59423
59424 ext4_mb_use_group_pa(ac, pa);
59425 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59426 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59427
59428 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59429 lg = ac->ac_lg;
59430 @@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59431 * from the bitmap and continue.
59432 */
59433 }
59434 - atomic_add(free, &sbi->s_mb_discarded);
59435 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59436
59437 return err;
59438 }
59439 @@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59440 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59441 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59442 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59443 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59444 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59445 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59446
59447 return 0;
59448 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59449 index 04434ad..6404663 100644
59450 --- a/fs/ext4/mmp.c
59451 +++ b/fs/ext4/mmp.c
59452 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59453 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59454 const char *function, unsigned int line, const char *msg)
59455 {
59456 - __ext4_warning(sb, function, line, msg);
59457 + __ext4_warning(sb, function, line, "%s", msg);
59458 __ext4_warning(sb, function, line,
59459 "MMP failure info: last update time: %llu, last update "
59460 "node: %s, last update device: %s\n",
59461 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59462 index 6f9e6fa..5431c02 100644
59463 --- a/fs/ext4/super.c
59464 +++ b/fs/ext4/super.c
59465 @@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59466 }
59467
59468 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59469 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59470 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59471 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59472
59473 #ifdef CONFIG_QUOTA
59474 @@ -2455,7 +2455,7 @@ struct ext4_attr {
59475 int offset;
59476 int deprecated_val;
59477 } u;
59478 -};
59479 +} __do_const;
59480
59481 static int parse_strtoull(const char *buf,
59482 unsigned long long max, unsigned long long *value)
59483 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59484 index 4eec399..1d9444c 100644
59485 --- a/fs/ext4/xattr.c
59486 +++ b/fs/ext4/xattr.c
59487 @@ -383,7 +383,7 @@ static int
59488 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59489 char *buffer, size_t buffer_size)
59490 {
59491 - size_t rest = buffer_size;
59492 + size_t rest = buffer_size, total_size = 0;
59493
59494 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59495 const struct xattr_handler *handler =
59496 @@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59497 buffer += size;
59498 }
59499 rest -= size;
59500 + total_size += size;
59501 }
59502 }
59503 - return buffer_size - rest;
59504 + return total_size;
59505 }
59506
59507 static int
59508 diff --git a/fs/fcntl.c b/fs/fcntl.c
59509 index 72c82f6..a18b263 100644
59510 --- a/fs/fcntl.c
59511 +++ b/fs/fcntl.c
59512 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59513 if (err)
59514 return err;
59515
59516 + if (gr_handle_chroot_fowner(pid, type))
59517 + return -ENOENT;
59518 + if (gr_check_protected_task_fowner(pid, type))
59519 + return -EACCES;
59520 +
59521 f_modown(filp, pid, type, force);
59522 return 0;
59523 }
59524 diff --git a/fs/fhandle.c b/fs/fhandle.c
59525 index 999ff5c..ac037c9 100644
59526 --- a/fs/fhandle.c
59527 +++ b/fs/fhandle.c
59528 @@ -8,6 +8,7 @@
59529 #include <linux/fs_struct.h>
59530 #include <linux/fsnotify.h>
59531 #include <linux/personality.h>
59532 +#include <linux/grsecurity.h>
59533 #include <asm/uaccess.h>
59534 #include "internal.h"
59535 #include "mount.h"
59536 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59537 } else
59538 retval = 0;
59539 /* copy the mount id */
59540 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59541 - sizeof(*mnt_id)) ||
59542 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59543 copy_to_user(ufh, handle,
59544 sizeof(struct file_handle) + handle_bytes))
59545 retval = -EFAULT;
59546 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59547 * the directory. Ideally we would like CAP_DAC_SEARCH.
59548 * But we don't have that
59549 */
59550 - if (!capable(CAP_DAC_READ_SEARCH)) {
59551 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59552 retval = -EPERM;
59553 goto out_err;
59554 }
59555 diff --git a/fs/file.c b/fs/file.c
59556 index 8f294cf..d0f3872 100644
59557 --- a/fs/file.c
59558 +++ b/fs/file.c
59559 @@ -16,6 +16,7 @@
59560 #include <linux/slab.h>
59561 #include <linux/vmalloc.h>
59562 #include <linux/file.h>
59563 +#include <linux/security.h>
59564 #include <linux/fdtable.h>
59565 #include <linux/bitops.h>
59566 #include <linux/interrupt.h>
59567 @@ -144,7 +145,7 @@ out:
59568 * Return <0 error code on error; 1 on successful completion.
59569 * The files->file_lock should be held on entry, and will be held on exit.
59570 */
59571 -static int expand_fdtable(struct files_struct *files, int nr)
59572 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59573 __releases(files->file_lock)
59574 __acquires(files->file_lock)
59575 {
59576 @@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59577 * expanded and execution may have blocked.
59578 * The files->file_lock should be held on entry, and will be held on exit.
59579 */
59580 -static int expand_files(struct files_struct *files, int nr)
59581 +static int expand_files(struct files_struct *files, unsigned int nr)
59582 {
59583 struct fdtable *fdt;
59584
59585 @@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59586 if (!file)
59587 return __close_fd(files, fd);
59588
59589 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59590 if (fd >= rlimit(RLIMIT_NOFILE))
59591 return -EBADF;
59592
59593 @@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59594 if (unlikely(oldfd == newfd))
59595 return -EINVAL;
59596
59597 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59598 if (newfd >= rlimit(RLIMIT_NOFILE))
59599 return -EBADF;
59600
59601 @@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59602 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59603 {
59604 int err;
59605 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59606 if (from >= rlimit(RLIMIT_NOFILE))
59607 return -EINVAL;
59608 err = alloc_fd(from, flags);
59609 diff --git a/fs/filesystems.c b/fs/filesystems.c
59610 index 5797d45..7d7d79a 100644
59611 --- a/fs/filesystems.c
59612 +++ b/fs/filesystems.c
59613 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59614 int len = dot ? dot - name : strlen(name);
59615
59616 fs = __get_fs_type(name, len);
59617 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59618 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59619 +#else
59620 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59621 +#endif
59622 fs = __get_fs_type(name, len);
59623
59624 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59625 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59626 index 7dca743..543d620 100644
59627 --- a/fs/fs_struct.c
59628 +++ b/fs/fs_struct.c
59629 @@ -4,6 +4,7 @@
59630 #include <linux/path.h>
59631 #include <linux/slab.h>
59632 #include <linux/fs_struct.h>
59633 +#include <linux/grsecurity.h>
59634 #include "internal.h"
59635
59636 /*
59637 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59638 write_seqcount_begin(&fs->seq);
59639 old_root = fs->root;
59640 fs->root = *path;
59641 + gr_set_chroot_entries(current, path);
59642 write_seqcount_end(&fs->seq);
59643 spin_unlock(&fs->lock);
59644 if (old_root.dentry)
59645 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59646 int hits = 0;
59647 spin_lock(&fs->lock);
59648 write_seqcount_begin(&fs->seq);
59649 + /* this root replacement is only done by pivot_root,
59650 + leave grsec's chroot tagging alone for this task
59651 + so that a pivoted root isn't treated as a chroot
59652 + */
59653 hits += replace_path(&fs->root, old_root, new_root);
59654 hits += replace_path(&fs->pwd, old_root, new_root);
59655 write_seqcount_end(&fs->seq);
59656 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59657 task_lock(tsk);
59658 spin_lock(&fs->lock);
59659 tsk->fs = NULL;
59660 - kill = !--fs->users;
59661 + gr_clear_chroot_entries(tsk);
59662 + kill = !atomic_dec_return(&fs->users);
59663 spin_unlock(&fs->lock);
59664 task_unlock(tsk);
59665 if (kill)
59666 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59667 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59668 /* We don't need to lock fs - think why ;-) */
59669 if (fs) {
59670 - fs->users = 1;
59671 + atomic_set(&fs->users, 1);
59672 fs->in_exec = 0;
59673 spin_lock_init(&fs->lock);
59674 seqcount_init(&fs->seq);
59675 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59676 spin_lock(&old->lock);
59677 fs->root = old->root;
59678 path_get(&fs->root);
59679 + /* instead of calling gr_set_chroot_entries here,
59680 + we call it from every caller of this function
59681 + */
59682 fs->pwd = old->pwd;
59683 path_get(&fs->pwd);
59684 spin_unlock(&old->lock);
59685 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59686
59687 task_lock(current);
59688 spin_lock(&fs->lock);
59689 - kill = !--fs->users;
59690 + kill = !atomic_dec_return(&fs->users);
59691 current->fs = new_fs;
59692 + gr_set_chroot_entries(current, &new_fs->root);
59693 spin_unlock(&fs->lock);
59694 task_unlock(current);
59695
59696 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59697
59698 int current_umask(void)
59699 {
59700 - return current->fs->umask;
59701 + return current->fs->umask | gr_acl_umask();
59702 }
59703 EXPORT_SYMBOL(current_umask);
59704
59705 /* to be mentioned only in INIT_TASK */
59706 struct fs_struct init_fs = {
59707 - .users = 1,
59708 + .users = ATOMIC_INIT(1),
59709 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59710 .seq = SEQCNT_ZERO(init_fs.seq),
59711 .umask = 0022,
59712 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59713 index 29d7feb..303644d 100644
59714 --- a/fs/fscache/cookie.c
59715 +++ b/fs/fscache/cookie.c
59716 @@ -19,7 +19,7 @@
59717
59718 struct kmem_cache *fscache_cookie_jar;
59719
59720 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59721 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59722
59723 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59724 static int fscache_alloc_object(struct fscache_cache *cache,
59725 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59726 parent ? (char *) parent->def->name : "<no-parent>",
59727 def->name, netfs_data, enable);
59728
59729 - fscache_stat(&fscache_n_acquires);
59730 + fscache_stat_unchecked(&fscache_n_acquires);
59731
59732 /* if there's no parent cookie, then we don't create one here either */
59733 if (!parent) {
59734 - fscache_stat(&fscache_n_acquires_null);
59735 + fscache_stat_unchecked(&fscache_n_acquires_null);
59736 _leave(" [no parent]");
59737 return NULL;
59738 }
59739 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59740 /* allocate and initialise a cookie */
59741 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59742 if (!cookie) {
59743 - fscache_stat(&fscache_n_acquires_oom);
59744 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59745 _leave(" [ENOMEM]");
59746 return NULL;
59747 }
59748 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59749
59750 switch (cookie->def->type) {
59751 case FSCACHE_COOKIE_TYPE_INDEX:
59752 - fscache_stat(&fscache_n_cookie_index);
59753 + fscache_stat_unchecked(&fscache_n_cookie_index);
59754 break;
59755 case FSCACHE_COOKIE_TYPE_DATAFILE:
59756 - fscache_stat(&fscache_n_cookie_data);
59757 + fscache_stat_unchecked(&fscache_n_cookie_data);
59758 break;
59759 default:
59760 - fscache_stat(&fscache_n_cookie_special);
59761 + fscache_stat_unchecked(&fscache_n_cookie_special);
59762 break;
59763 }
59764
59765 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59766 } else {
59767 atomic_dec(&parent->n_children);
59768 __fscache_cookie_put(cookie);
59769 - fscache_stat(&fscache_n_acquires_nobufs);
59770 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59771 _leave(" = NULL");
59772 return NULL;
59773 }
59774 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59775 }
59776 }
59777
59778 - fscache_stat(&fscache_n_acquires_ok);
59779 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59780 _leave(" = %p", cookie);
59781 return cookie;
59782 }
59783 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59784 cache = fscache_select_cache_for_object(cookie->parent);
59785 if (!cache) {
59786 up_read(&fscache_addremove_sem);
59787 - fscache_stat(&fscache_n_acquires_no_cache);
59788 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59789 _leave(" = -ENOMEDIUM [no cache]");
59790 return -ENOMEDIUM;
59791 }
59792 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59793 object = cache->ops->alloc_object(cache, cookie);
59794 fscache_stat_d(&fscache_n_cop_alloc_object);
59795 if (IS_ERR(object)) {
59796 - fscache_stat(&fscache_n_object_no_alloc);
59797 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59798 ret = PTR_ERR(object);
59799 goto error;
59800 }
59801
59802 - fscache_stat(&fscache_n_object_alloc);
59803 + fscache_stat_unchecked(&fscache_n_object_alloc);
59804
59805 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59806 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59807
59808 _debug("ALLOC OBJ%x: %s {%lx}",
59809 object->debug_id, cookie->def->name, object->events);
59810 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59811
59812 _enter("{%s}", cookie->def->name);
59813
59814 - fscache_stat(&fscache_n_invalidates);
59815 + fscache_stat_unchecked(&fscache_n_invalidates);
59816
59817 /* Only permit invalidation of data files. Invalidating an index will
59818 * require the caller to release all its attachments to the tree rooted
59819 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59820 {
59821 struct fscache_object *object;
59822
59823 - fscache_stat(&fscache_n_updates);
59824 + fscache_stat_unchecked(&fscache_n_updates);
59825
59826 if (!cookie) {
59827 - fscache_stat(&fscache_n_updates_null);
59828 + fscache_stat_unchecked(&fscache_n_updates_null);
59829 _leave(" [no cookie]");
59830 return;
59831 }
59832 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59833 */
59834 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59835 {
59836 - fscache_stat(&fscache_n_relinquishes);
59837 + fscache_stat_unchecked(&fscache_n_relinquishes);
59838 if (retire)
59839 - fscache_stat(&fscache_n_relinquishes_retire);
59840 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59841
59842 if (!cookie) {
59843 - fscache_stat(&fscache_n_relinquishes_null);
59844 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59845 _leave(" [no cookie]");
59846 return;
59847 }
59848 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59849 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59850 goto inconsistent;
59851
59852 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59853 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59854
59855 __fscache_use_cookie(cookie);
59856 if (fscache_submit_op(object, op) < 0)
59857 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59858 index 4226f66..0fb3f45 100644
59859 --- a/fs/fscache/internal.h
59860 +++ b/fs/fscache/internal.h
59861 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59862 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59863 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59864 struct fscache_operation *,
59865 - atomic_t *,
59866 - atomic_t *,
59867 + atomic_unchecked_t *,
59868 + atomic_unchecked_t *,
59869 void (*)(struct fscache_operation *));
59870 extern void fscache_invalidate_writes(struct fscache_cookie *);
59871
59872 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59873 * stats.c
59874 */
59875 #ifdef CONFIG_FSCACHE_STATS
59876 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59877 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59878 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59879 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59880
59881 -extern atomic_t fscache_n_op_pend;
59882 -extern atomic_t fscache_n_op_run;
59883 -extern atomic_t fscache_n_op_enqueue;
59884 -extern atomic_t fscache_n_op_deferred_release;
59885 -extern atomic_t fscache_n_op_release;
59886 -extern atomic_t fscache_n_op_gc;
59887 -extern atomic_t fscache_n_op_cancelled;
59888 -extern atomic_t fscache_n_op_rejected;
59889 +extern atomic_unchecked_t fscache_n_op_pend;
59890 +extern atomic_unchecked_t fscache_n_op_run;
59891 +extern atomic_unchecked_t fscache_n_op_enqueue;
59892 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59893 +extern atomic_unchecked_t fscache_n_op_release;
59894 +extern atomic_unchecked_t fscache_n_op_gc;
59895 +extern atomic_unchecked_t fscache_n_op_cancelled;
59896 +extern atomic_unchecked_t fscache_n_op_rejected;
59897
59898 -extern atomic_t fscache_n_attr_changed;
59899 -extern atomic_t fscache_n_attr_changed_ok;
59900 -extern atomic_t fscache_n_attr_changed_nobufs;
59901 -extern atomic_t fscache_n_attr_changed_nomem;
59902 -extern atomic_t fscache_n_attr_changed_calls;
59903 +extern atomic_unchecked_t fscache_n_attr_changed;
59904 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59905 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59906 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59907 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59908
59909 -extern atomic_t fscache_n_allocs;
59910 -extern atomic_t fscache_n_allocs_ok;
59911 -extern atomic_t fscache_n_allocs_wait;
59912 -extern atomic_t fscache_n_allocs_nobufs;
59913 -extern atomic_t fscache_n_allocs_intr;
59914 -extern atomic_t fscache_n_allocs_object_dead;
59915 -extern atomic_t fscache_n_alloc_ops;
59916 -extern atomic_t fscache_n_alloc_op_waits;
59917 +extern atomic_unchecked_t fscache_n_allocs;
59918 +extern atomic_unchecked_t fscache_n_allocs_ok;
59919 +extern atomic_unchecked_t fscache_n_allocs_wait;
59920 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59921 +extern atomic_unchecked_t fscache_n_allocs_intr;
59922 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59923 +extern atomic_unchecked_t fscache_n_alloc_ops;
59924 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59925
59926 -extern atomic_t fscache_n_retrievals;
59927 -extern atomic_t fscache_n_retrievals_ok;
59928 -extern atomic_t fscache_n_retrievals_wait;
59929 -extern atomic_t fscache_n_retrievals_nodata;
59930 -extern atomic_t fscache_n_retrievals_nobufs;
59931 -extern atomic_t fscache_n_retrievals_intr;
59932 -extern atomic_t fscache_n_retrievals_nomem;
59933 -extern atomic_t fscache_n_retrievals_object_dead;
59934 -extern atomic_t fscache_n_retrieval_ops;
59935 -extern atomic_t fscache_n_retrieval_op_waits;
59936 +extern atomic_unchecked_t fscache_n_retrievals;
59937 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59938 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59939 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59940 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59941 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59942 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59943 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59944 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59945 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59946
59947 -extern atomic_t fscache_n_stores;
59948 -extern atomic_t fscache_n_stores_ok;
59949 -extern atomic_t fscache_n_stores_again;
59950 -extern atomic_t fscache_n_stores_nobufs;
59951 -extern atomic_t fscache_n_stores_oom;
59952 -extern atomic_t fscache_n_store_ops;
59953 -extern atomic_t fscache_n_store_calls;
59954 -extern atomic_t fscache_n_store_pages;
59955 -extern atomic_t fscache_n_store_radix_deletes;
59956 -extern atomic_t fscache_n_store_pages_over_limit;
59957 +extern atomic_unchecked_t fscache_n_stores;
59958 +extern atomic_unchecked_t fscache_n_stores_ok;
59959 +extern atomic_unchecked_t fscache_n_stores_again;
59960 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59961 +extern atomic_unchecked_t fscache_n_stores_oom;
59962 +extern atomic_unchecked_t fscache_n_store_ops;
59963 +extern atomic_unchecked_t fscache_n_store_calls;
59964 +extern atomic_unchecked_t fscache_n_store_pages;
59965 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59966 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59967
59968 -extern atomic_t fscache_n_store_vmscan_not_storing;
59969 -extern atomic_t fscache_n_store_vmscan_gone;
59970 -extern atomic_t fscache_n_store_vmscan_busy;
59971 -extern atomic_t fscache_n_store_vmscan_cancelled;
59972 -extern atomic_t fscache_n_store_vmscan_wait;
59973 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59974 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59975 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59976 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59977 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59978
59979 -extern atomic_t fscache_n_marks;
59980 -extern atomic_t fscache_n_uncaches;
59981 +extern atomic_unchecked_t fscache_n_marks;
59982 +extern atomic_unchecked_t fscache_n_uncaches;
59983
59984 -extern atomic_t fscache_n_acquires;
59985 -extern atomic_t fscache_n_acquires_null;
59986 -extern atomic_t fscache_n_acquires_no_cache;
59987 -extern atomic_t fscache_n_acquires_ok;
59988 -extern atomic_t fscache_n_acquires_nobufs;
59989 -extern atomic_t fscache_n_acquires_oom;
59990 +extern atomic_unchecked_t fscache_n_acquires;
59991 +extern atomic_unchecked_t fscache_n_acquires_null;
59992 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59993 +extern atomic_unchecked_t fscache_n_acquires_ok;
59994 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59995 +extern atomic_unchecked_t fscache_n_acquires_oom;
59996
59997 -extern atomic_t fscache_n_invalidates;
59998 -extern atomic_t fscache_n_invalidates_run;
59999 +extern atomic_unchecked_t fscache_n_invalidates;
60000 +extern atomic_unchecked_t fscache_n_invalidates_run;
60001
60002 -extern atomic_t fscache_n_updates;
60003 -extern atomic_t fscache_n_updates_null;
60004 -extern atomic_t fscache_n_updates_run;
60005 +extern atomic_unchecked_t fscache_n_updates;
60006 +extern atomic_unchecked_t fscache_n_updates_null;
60007 +extern atomic_unchecked_t fscache_n_updates_run;
60008
60009 -extern atomic_t fscache_n_relinquishes;
60010 -extern atomic_t fscache_n_relinquishes_null;
60011 -extern atomic_t fscache_n_relinquishes_waitcrt;
60012 -extern atomic_t fscache_n_relinquishes_retire;
60013 +extern atomic_unchecked_t fscache_n_relinquishes;
60014 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60015 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60016 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60017
60018 -extern atomic_t fscache_n_cookie_index;
60019 -extern atomic_t fscache_n_cookie_data;
60020 -extern atomic_t fscache_n_cookie_special;
60021 +extern atomic_unchecked_t fscache_n_cookie_index;
60022 +extern atomic_unchecked_t fscache_n_cookie_data;
60023 +extern atomic_unchecked_t fscache_n_cookie_special;
60024
60025 -extern atomic_t fscache_n_object_alloc;
60026 -extern atomic_t fscache_n_object_no_alloc;
60027 -extern atomic_t fscache_n_object_lookups;
60028 -extern atomic_t fscache_n_object_lookups_negative;
60029 -extern atomic_t fscache_n_object_lookups_positive;
60030 -extern atomic_t fscache_n_object_lookups_timed_out;
60031 -extern atomic_t fscache_n_object_created;
60032 -extern atomic_t fscache_n_object_avail;
60033 -extern atomic_t fscache_n_object_dead;
60034 +extern atomic_unchecked_t fscache_n_object_alloc;
60035 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60036 +extern atomic_unchecked_t fscache_n_object_lookups;
60037 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60038 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60039 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60040 +extern atomic_unchecked_t fscache_n_object_created;
60041 +extern atomic_unchecked_t fscache_n_object_avail;
60042 +extern atomic_unchecked_t fscache_n_object_dead;
60043
60044 -extern atomic_t fscache_n_checkaux_none;
60045 -extern atomic_t fscache_n_checkaux_okay;
60046 -extern atomic_t fscache_n_checkaux_update;
60047 -extern atomic_t fscache_n_checkaux_obsolete;
60048 +extern atomic_unchecked_t fscache_n_checkaux_none;
60049 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60050 +extern atomic_unchecked_t fscache_n_checkaux_update;
60051 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60052
60053 extern atomic_t fscache_n_cop_alloc_object;
60054 extern atomic_t fscache_n_cop_lookup_object;
60055 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60056 atomic_inc(stat);
60057 }
60058
60059 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60060 +{
60061 + atomic_inc_unchecked(stat);
60062 +}
60063 +
60064 static inline void fscache_stat_d(atomic_t *stat)
60065 {
60066 atomic_dec(stat);
60067 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60068
60069 #define __fscache_stat(stat) (NULL)
60070 #define fscache_stat(stat) do {} while (0)
60071 +#define fscache_stat_unchecked(stat) do {} while (0)
60072 #define fscache_stat_d(stat) do {} while (0)
60073 #endif
60074
60075 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60076 index d3b4539..ed0c659 100644
60077 --- a/fs/fscache/object.c
60078 +++ b/fs/fscache/object.c
60079 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60080 _debug("LOOKUP \"%s\" in \"%s\"",
60081 cookie->def->name, object->cache->tag->name);
60082
60083 - fscache_stat(&fscache_n_object_lookups);
60084 + fscache_stat_unchecked(&fscache_n_object_lookups);
60085 fscache_stat(&fscache_n_cop_lookup_object);
60086 ret = object->cache->ops->lookup_object(object);
60087 fscache_stat_d(&fscache_n_cop_lookup_object);
60088 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60089 if (ret == -ETIMEDOUT) {
60090 /* probably stuck behind another object, so move this one to
60091 * the back of the queue */
60092 - fscache_stat(&fscache_n_object_lookups_timed_out);
60093 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60094 _leave(" [timeout]");
60095 return NO_TRANSIT;
60096 }
60097 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60098 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60099
60100 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60101 - fscache_stat(&fscache_n_object_lookups_negative);
60102 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60103
60104 /* Allow write requests to begin stacking up and read requests to begin
60105 * returning ENODATA.
60106 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60107 /* if we were still looking up, then we must have a positive lookup
60108 * result, in which case there may be data available */
60109 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60110 - fscache_stat(&fscache_n_object_lookups_positive);
60111 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60112
60113 /* We do (presumably) have data */
60114 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60115 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60116 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60117 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60118 } else {
60119 - fscache_stat(&fscache_n_object_created);
60120 + fscache_stat_unchecked(&fscache_n_object_created);
60121 }
60122
60123 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60124 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60125 fscache_stat_d(&fscache_n_cop_lookup_complete);
60126
60127 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60128 - fscache_stat(&fscache_n_object_avail);
60129 + fscache_stat_unchecked(&fscache_n_object_avail);
60130
60131 _leave("");
60132 return transit_to(JUMPSTART_DEPS);
60133 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60134
60135 /* this just shifts the object release to the work processor */
60136 fscache_put_object(object);
60137 - fscache_stat(&fscache_n_object_dead);
60138 + fscache_stat_unchecked(&fscache_n_object_dead);
60139
60140 _leave("");
60141 return transit_to(OBJECT_DEAD);
60142 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60143 enum fscache_checkaux result;
60144
60145 if (!object->cookie->def->check_aux) {
60146 - fscache_stat(&fscache_n_checkaux_none);
60147 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60148 return FSCACHE_CHECKAUX_OKAY;
60149 }
60150
60151 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60152 switch (result) {
60153 /* entry okay as is */
60154 case FSCACHE_CHECKAUX_OKAY:
60155 - fscache_stat(&fscache_n_checkaux_okay);
60156 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60157 break;
60158
60159 /* entry requires update */
60160 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60161 - fscache_stat(&fscache_n_checkaux_update);
60162 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60163 break;
60164
60165 /* entry requires deletion */
60166 case FSCACHE_CHECKAUX_OBSOLETE:
60167 - fscache_stat(&fscache_n_checkaux_obsolete);
60168 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60169 break;
60170
60171 default:
60172 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60173 {
60174 const struct fscache_state *s;
60175
60176 - fscache_stat(&fscache_n_invalidates_run);
60177 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60178 fscache_stat(&fscache_n_cop_invalidate_object);
60179 s = _fscache_invalidate_object(object, event);
60180 fscache_stat_d(&fscache_n_cop_invalidate_object);
60181 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60182 {
60183 _enter("{OBJ%x},%d", object->debug_id, event);
60184
60185 - fscache_stat(&fscache_n_updates_run);
60186 + fscache_stat_unchecked(&fscache_n_updates_run);
60187 fscache_stat(&fscache_n_cop_update_object);
60188 object->cache->ops->update_object(object);
60189 fscache_stat_d(&fscache_n_cop_update_object);
60190 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60191 index 318071a..379938b 100644
60192 --- a/fs/fscache/operation.c
60193 +++ b/fs/fscache/operation.c
60194 @@ -17,7 +17,7 @@
60195 #include <linux/slab.h>
60196 #include "internal.h"
60197
60198 -atomic_t fscache_op_debug_id;
60199 +atomic_unchecked_t fscache_op_debug_id;
60200 EXPORT_SYMBOL(fscache_op_debug_id);
60201
60202 /**
60203 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60204 ASSERTCMP(atomic_read(&op->usage), >, 0);
60205 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60206
60207 - fscache_stat(&fscache_n_op_enqueue);
60208 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60209 switch (op->flags & FSCACHE_OP_TYPE) {
60210 case FSCACHE_OP_ASYNC:
60211 _debug("queue async");
60212 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60213 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60214 if (op->processor)
60215 fscache_enqueue_operation(op);
60216 - fscache_stat(&fscache_n_op_run);
60217 + fscache_stat_unchecked(&fscache_n_op_run);
60218 }
60219
60220 /*
60221 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60222 if (object->n_in_progress > 0) {
60223 atomic_inc(&op->usage);
60224 list_add_tail(&op->pend_link, &object->pending_ops);
60225 - fscache_stat(&fscache_n_op_pend);
60226 + fscache_stat_unchecked(&fscache_n_op_pend);
60227 } else if (!list_empty(&object->pending_ops)) {
60228 atomic_inc(&op->usage);
60229 list_add_tail(&op->pend_link, &object->pending_ops);
60230 - fscache_stat(&fscache_n_op_pend);
60231 + fscache_stat_unchecked(&fscache_n_op_pend);
60232 fscache_start_operations(object);
60233 } else {
60234 ASSERTCMP(object->n_in_progress, ==, 0);
60235 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60236 object->n_exclusive++; /* reads and writes must wait */
60237 atomic_inc(&op->usage);
60238 list_add_tail(&op->pend_link, &object->pending_ops);
60239 - fscache_stat(&fscache_n_op_pend);
60240 + fscache_stat_unchecked(&fscache_n_op_pend);
60241 ret = 0;
60242 } else {
60243 /* If we're in any other state, there must have been an I/O
60244 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60245 if (object->n_exclusive > 0) {
60246 atomic_inc(&op->usage);
60247 list_add_tail(&op->pend_link, &object->pending_ops);
60248 - fscache_stat(&fscache_n_op_pend);
60249 + fscache_stat_unchecked(&fscache_n_op_pend);
60250 } else if (!list_empty(&object->pending_ops)) {
60251 atomic_inc(&op->usage);
60252 list_add_tail(&op->pend_link, &object->pending_ops);
60253 - fscache_stat(&fscache_n_op_pend);
60254 + fscache_stat_unchecked(&fscache_n_op_pend);
60255 fscache_start_operations(object);
60256 } else {
60257 ASSERTCMP(object->n_exclusive, ==, 0);
60258 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60259 object->n_ops++;
60260 atomic_inc(&op->usage);
60261 list_add_tail(&op->pend_link, &object->pending_ops);
60262 - fscache_stat(&fscache_n_op_pend);
60263 + fscache_stat_unchecked(&fscache_n_op_pend);
60264 ret = 0;
60265 } else if (fscache_object_is_dying(object)) {
60266 - fscache_stat(&fscache_n_op_rejected);
60267 + fscache_stat_unchecked(&fscache_n_op_rejected);
60268 op->state = FSCACHE_OP_ST_CANCELLED;
60269 ret = -ENOBUFS;
60270 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60271 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60272 ret = -EBUSY;
60273 if (op->state == FSCACHE_OP_ST_PENDING) {
60274 ASSERT(!list_empty(&op->pend_link));
60275 - fscache_stat(&fscache_n_op_cancelled);
60276 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60277 list_del_init(&op->pend_link);
60278 if (do_cancel)
60279 do_cancel(op);
60280 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60281 while (!list_empty(&object->pending_ops)) {
60282 op = list_entry(object->pending_ops.next,
60283 struct fscache_operation, pend_link);
60284 - fscache_stat(&fscache_n_op_cancelled);
60285 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60286 list_del_init(&op->pend_link);
60287
60288 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60289 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60290 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60291 op->state = FSCACHE_OP_ST_DEAD;
60292
60293 - fscache_stat(&fscache_n_op_release);
60294 + fscache_stat_unchecked(&fscache_n_op_release);
60295
60296 if (op->release) {
60297 op->release(op);
60298 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60299 * lock, and defer it otherwise */
60300 if (!spin_trylock(&object->lock)) {
60301 _debug("defer put");
60302 - fscache_stat(&fscache_n_op_deferred_release);
60303 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60304
60305 cache = object->cache;
60306 spin_lock(&cache->op_gc_list_lock);
60307 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60308
60309 _debug("GC DEFERRED REL OBJ%x OP%x",
60310 object->debug_id, op->debug_id);
60311 - fscache_stat(&fscache_n_op_gc);
60312 + fscache_stat_unchecked(&fscache_n_op_gc);
60313
60314 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60315 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60316 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60317 index 7f5c658..6c1e164 100644
60318 --- a/fs/fscache/page.c
60319 +++ b/fs/fscache/page.c
60320 @@ -61,7 +61,7 @@ try_again:
60321 val = radix_tree_lookup(&cookie->stores, page->index);
60322 if (!val) {
60323 rcu_read_unlock();
60324 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60325 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60326 __fscache_uncache_page(cookie, page);
60327 return true;
60328 }
60329 @@ -91,11 +91,11 @@ try_again:
60330 spin_unlock(&cookie->stores_lock);
60331
60332 if (xpage) {
60333 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60334 - fscache_stat(&fscache_n_store_radix_deletes);
60335 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60336 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60337 ASSERTCMP(xpage, ==, page);
60338 } else {
60339 - fscache_stat(&fscache_n_store_vmscan_gone);
60340 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60341 }
60342
60343 wake_up_bit(&cookie->flags, 0);
60344 @@ -110,11 +110,11 @@ page_busy:
60345 * sleeping on memory allocation, so we may need to impose a timeout
60346 * too. */
60347 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60348 - fscache_stat(&fscache_n_store_vmscan_busy);
60349 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60350 return false;
60351 }
60352
60353 - fscache_stat(&fscache_n_store_vmscan_wait);
60354 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60355 __fscache_wait_on_page_write(cookie, page);
60356 gfp &= ~__GFP_WAIT;
60357 goto try_again;
60358 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60359 FSCACHE_COOKIE_STORING_TAG);
60360 if (!radix_tree_tag_get(&cookie->stores, page->index,
60361 FSCACHE_COOKIE_PENDING_TAG)) {
60362 - fscache_stat(&fscache_n_store_radix_deletes);
60363 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60364 xpage = radix_tree_delete(&cookie->stores, page->index);
60365 }
60366 spin_unlock(&cookie->stores_lock);
60367 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60368
60369 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60370
60371 - fscache_stat(&fscache_n_attr_changed_calls);
60372 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60373
60374 if (fscache_object_is_active(object)) {
60375 fscache_stat(&fscache_n_cop_attr_changed);
60376 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60377
60378 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60379
60380 - fscache_stat(&fscache_n_attr_changed);
60381 + fscache_stat_unchecked(&fscache_n_attr_changed);
60382
60383 op = kzalloc(sizeof(*op), GFP_KERNEL);
60384 if (!op) {
60385 - fscache_stat(&fscache_n_attr_changed_nomem);
60386 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60387 _leave(" = -ENOMEM");
60388 return -ENOMEM;
60389 }
60390 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60391 if (fscache_submit_exclusive_op(object, op) < 0)
60392 goto nobufs;
60393 spin_unlock(&cookie->lock);
60394 - fscache_stat(&fscache_n_attr_changed_ok);
60395 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60396 fscache_put_operation(op);
60397 _leave(" = 0");
60398 return 0;
60399 @@ -225,7 +225,7 @@ nobufs:
60400 kfree(op);
60401 if (wake_cookie)
60402 __fscache_wake_unused_cookie(cookie);
60403 - fscache_stat(&fscache_n_attr_changed_nobufs);
60404 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60405 _leave(" = %d", -ENOBUFS);
60406 return -ENOBUFS;
60407 }
60408 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60409 /* allocate a retrieval operation and attempt to submit it */
60410 op = kzalloc(sizeof(*op), GFP_NOIO);
60411 if (!op) {
60412 - fscache_stat(&fscache_n_retrievals_nomem);
60413 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60414 return NULL;
60415 }
60416
60417 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60418 return 0;
60419 }
60420
60421 - fscache_stat(&fscache_n_retrievals_wait);
60422 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60423
60424 jif = jiffies;
60425 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60426 fscache_wait_bit_interruptible,
60427 TASK_INTERRUPTIBLE) != 0) {
60428 - fscache_stat(&fscache_n_retrievals_intr);
60429 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60430 _leave(" = -ERESTARTSYS");
60431 return -ERESTARTSYS;
60432 }
60433 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60434 */
60435 int fscache_wait_for_operation_activation(struct fscache_object *object,
60436 struct fscache_operation *op,
60437 - atomic_t *stat_op_waits,
60438 - atomic_t *stat_object_dead,
60439 + atomic_unchecked_t *stat_op_waits,
60440 + atomic_unchecked_t *stat_object_dead,
60441 void (*do_cancel)(struct fscache_operation *))
60442 {
60443 int ret;
60444 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60445
60446 _debug(">>> WT");
60447 if (stat_op_waits)
60448 - fscache_stat(stat_op_waits);
60449 + fscache_stat_unchecked(stat_op_waits);
60450 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60451 fscache_wait_bit_interruptible,
60452 TASK_INTERRUPTIBLE) != 0) {
60453 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60454 check_if_dead:
60455 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60456 if (stat_object_dead)
60457 - fscache_stat(stat_object_dead);
60458 + fscache_stat_unchecked(stat_object_dead);
60459 _leave(" = -ENOBUFS [cancelled]");
60460 return -ENOBUFS;
60461 }
60462 @@ -366,7 +366,7 @@ check_if_dead:
60463 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60464 fscache_cancel_op(op, do_cancel);
60465 if (stat_object_dead)
60466 - fscache_stat(stat_object_dead);
60467 + fscache_stat_unchecked(stat_object_dead);
60468 return -ENOBUFS;
60469 }
60470 return 0;
60471 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60472
60473 _enter("%p,%p,,,", cookie, page);
60474
60475 - fscache_stat(&fscache_n_retrievals);
60476 + fscache_stat_unchecked(&fscache_n_retrievals);
60477
60478 if (hlist_empty(&cookie->backing_objects))
60479 goto nobufs;
60480 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60481 goto nobufs_unlock_dec;
60482 spin_unlock(&cookie->lock);
60483
60484 - fscache_stat(&fscache_n_retrieval_ops);
60485 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60486
60487 /* pin the netfs read context in case we need to do the actual netfs
60488 * read because we've encountered a cache read failure */
60489 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60490
60491 error:
60492 if (ret == -ENOMEM)
60493 - fscache_stat(&fscache_n_retrievals_nomem);
60494 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60495 else if (ret == -ERESTARTSYS)
60496 - fscache_stat(&fscache_n_retrievals_intr);
60497 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60498 else if (ret == -ENODATA)
60499 - fscache_stat(&fscache_n_retrievals_nodata);
60500 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60501 else if (ret < 0)
60502 - fscache_stat(&fscache_n_retrievals_nobufs);
60503 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60504 else
60505 - fscache_stat(&fscache_n_retrievals_ok);
60506 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60507
60508 fscache_put_retrieval(op);
60509 _leave(" = %d", ret);
60510 @@ -490,7 +490,7 @@ nobufs_unlock:
60511 __fscache_wake_unused_cookie(cookie);
60512 kfree(op);
60513 nobufs:
60514 - fscache_stat(&fscache_n_retrievals_nobufs);
60515 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60516 _leave(" = -ENOBUFS");
60517 return -ENOBUFS;
60518 }
60519 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60520
60521 _enter("%p,,%d,,,", cookie, *nr_pages);
60522
60523 - fscache_stat(&fscache_n_retrievals);
60524 + fscache_stat_unchecked(&fscache_n_retrievals);
60525
60526 if (hlist_empty(&cookie->backing_objects))
60527 goto nobufs;
60528 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60529 goto nobufs_unlock_dec;
60530 spin_unlock(&cookie->lock);
60531
60532 - fscache_stat(&fscache_n_retrieval_ops);
60533 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60534
60535 /* pin the netfs read context in case we need to do the actual netfs
60536 * read because we've encountered a cache read failure */
60537 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60538
60539 error:
60540 if (ret == -ENOMEM)
60541 - fscache_stat(&fscache_n_retrievals_nomem);
60542 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60543 else if (ret == -ERESTARTSYS)
60544 - fscache_stat(&fscache_n_retrievals_intr);
60545 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60546 else if (ret == -ENODATA)
60547 - fscache_stat(&fscache_n_retrievals_nodata);
60548 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60549 else if (ret < 0)
60550 - fscache_stat(&fscache_n_retrievals_nobufs);
60551 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60552 else
60553 - fscache_stat(&fscache_n_retrievals_ok);
60554 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60555
60556 fscache_put_retrieval(op);
60557 _leave(" = %d", ret);
60558 @@ -621,7 +621,7 @@ nobufs_unlock:
60559 if (wake_cookie)
60560 __fscache_wake_unused_cookie(cookie);
60561 nobufs:
60562 - fscache_stat(&fscache_n_retrievals_nobufs);
60563 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60564 _leave(" = -ENOBUFS");
60565 return -ENOBUFS;
60566 }
60567 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60568
60569 _enter("%p,%p,,,", cookie, page);
60570
60571 - fscache_stat(&fscache_n_allocs);
60572 + fscache_stat_unchecked(&fscache_n_allocs);
60573
60574 if (hlist_empty(&cookie->backing_objects))
60575 goto nobufs;
60576 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60577 goto nobufs_unlock_dec;
60578 spin_unlock(&cookie->lock);
60579
60580 - fscache_stat(&fscache_n_alloc_ops);
60581 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60582
60583 ret = fscache_wait_for_operation_activation(
60584 object, &op->op,
60585 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60586
60587 error:
60588 if (ret == -ERESTARTSYS)
60589 - fscache_stat(&fscache_n_allocs_intr);
60590 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60591 else if (ret < 0)
60592 - fscache_stat(&fscache_n_allocs_nobufs);
60593 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60594 else
60595 - fscache_stat(&fscache_n_allocs_ok);
60596 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60597
60598 fscache_put_retrieval(op);
60599 _leave(" = %d", ret);
60600 @@ -715,7 +715,7 @@ nobufs_unlock:
60601 if (wake_cookie)
60602 __fscache_wake_unused_cookie(cookie);
60603 nobufs:
60604 - fscache_stat(&fscache_n_allocs_nobufs);
60605 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60606 _leave(" = -ENOBUFS");
60607 return -ENOBUFS;
60608 }
60609 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60610
60611 spin_lock(&cookie->stores_lock);
60612
60613 - fscache_stat(&fscache_n_store_calls);
60614 + fscache_stat_unchecked(&fscache_n_store_calls);
60615
60616 /* find a page to store */
60617 page = NULL;
60618 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60619 page = results[0];
60620 _debug("gang %d [%lx]", n, page->index);
60621 if (page->index > op->store_limit) {
60622 - fscache_stat(&fscache_n_store_pages_over_limit);
60623 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60624 goto superseded;
60625 }
60626
60627 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60628 spin_unlock(&cookie->stores_lock);
60629 spin_unlock(&object->lock);
60630
60631 - fscache_stat(&fscache_n_store_pages);
60632 + fscache_stat_unchecked(&fscache_n_store_pages);
60633 fscache_stat(&fscache_n_cop_write_page);
60634 ret = object->cache->ops->write_page(op, page);
60635 fscache_stat_d(&fscache_n_cop_write_page);
60636 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60637 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60638 ASSERT(PageFsCache(page));
60639
60640 - fscache_stat(&fscache_n_stores);
60641 + fscache_stat_unchecked(&fscache_n_stores);
60642
60643 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60644 _leave(" = -ENOBUFS [invalidating]");
60645 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60646 spin_unlock(&cookie->stores_lock);
60647 spin_unlock(&object->lock);
60648
60649 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60650 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60651 op->store_limit = object->store_limit;
60652
60653 __fscache_use_cookie(cookie);
60654 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60655
60656 spin_unlock(&cookie->lock);
60657 radix_tree_preload_end();
60658 - fscache_stat(&fscache_n_store_ops);
60659 - fscache_stat(&fscache_n_stores_ok);
60660 + fscache_stat_unchecked(&fscache_n_store_ops);
60661 + fscache_stat_unchecked(&fscache_n_stores_ok);
60662
60663 /* the work queue now carries its own ref on the object */
60664 fscache_put_operation(&op->op);
60665 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60666 return 0;
60667
60668 already_queued:
60669 - fscache_stat(&fscache_n_stores_again);
60670 + fscache_stat_unchecked(&fscache_n_stores_again);
60671 already_pending:
60672 spin_unlock(&cookie->stores_lock);
60673 spin_unlock(&object->lock);
60674 spin_unlock(&cookie->lock);
60675 radix_tree_preload_end();
60676 kfree(op);
60677 - fscache_stat(&fscache_n_stores_ok);
60678 + fscache_stat_unchecked(&fscache_n_stores_ok);
60679 _leave(" = 0");
60680 return 0;
60681
60682 @@ -1024,14 +1024,14 @@ nobufs:
60683 kfree(op);
60684 if (wake_cookie)
60685 __fscache_wake_unused_cookie(cookie);
60686 - fscache_stat(&fscache_n_stores_nobufs);
60687 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60688 _leave(" = -ENOBUFS");
60689 return -ENOBUFS;
60690
60691 nomem_free:
60692 kfree(op);
60693 nomem:
60694 - fscache_stat(&fscache_n_stores_oom);
60695 + fscache_stat_unchecked(&fscache_n_stores_oom);
60696 _leave(" = -ENOMEM");
60697 return -ENOMEM;
60698 }
60699 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60700 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60701 ASSERTCMP(page, !=, NULL);
60702
60703 - fscache_stat(&fscache_n_uncaches);
60704 + fscache_stat_unchecked(&fscache_n_uncaches);
60705
60706 /* cache withdrawal may beat us to it */
60707 if (!PageFsCache(page))
60708 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60709 struct fscache_cookie *cookie = op->op.object->cookie;
60710
60711 #ifdef CONFIG_FSCACHE_STATS
60712 - atomic_inc(&fscache_n_marks);
60713 + atomic_inc_unchecked(&fscache_n_marks);
60714 #endif
60715
60716 _debug("- mark %p{%lx}", page, page->index);
60717 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60718 index 40d13c7..ddf52b9 100644
60719 --- a/fs/fscache/stats.c
60720 +++ b/fs/fscache/stats.c
60721 @@ -18,99 +18,99 @@
60722 /*
60723 * operation counters
60724 */
60725 -atomic_t fscache_n_op_pend;
60726 -atomic_t fscache_n_op_run;
60727 -atomic_t fscache_n_op_enqueue;
60728 -atomic_t fscache_n_op_requeue;
60729 -atomic_t fscache_n_op_deferred_release;
60730 -atomic_t fscache_n_op_release;
60731 -atomic_t fscache_n_op_gc;
60732 -atomic_t fscache_n_op_cancelled;
60733 -atomic_t fscache_n_op_rejected;
60734 +atomic_unchecked_t fscache_n_op_pend;
60735 +atomic_unchecked_t fscache_n_op_run;
60736 +atomic_unchecked_t fscache_n_op_enqueue;
60737 +atomic_unchecked_t fscache_n_op_requeue;
60738 +atomic_unchecked_t fscache_n_op_deferred_release;
60739 +atomic_unchecked_t fscache_n_op_release;
60740 +atomic_unchecked_t fscache_n_op_gc;
60741 +atomic_unchecked_t fscache_n_op_cancelled;
60742 +atomic_unchecked_t fscache_n_op_rejected;
60743
60744 -atomic_t fscache_n_attr_changed;
60745 -atomic_t fscache_n_attr_changed_ok;
60746 -atomic_t fscache_n_attr_changed_nobufs;
60747 -atomic_t fscache_n_attr_changed_nomem;
60748 -atomic_t fscache_n_attr_changed_calls;
60749 +atomic_unchecked_t fscache_n_attr_changed;
60750 +atomic_unchecked_t fscache_n_attr_changed_ok;
60751 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60752 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60753 +atomic_unchecked_t fscache_n_attr_changed_calls;
60754
60755 -atomic_t fscache_n_allocs;
60756 -atomic_t fscache_n_allocs_ok;
60757 -atomic_t fscache_n_allocs_wait;
60758 -atomic_t fscache_n_allocs_nobufs;
60759 -atomic_t fscache_n_allocs_intr;
60760 -atomic_t fscache_n_allocs_object_dead;
60761 -atomic_t fscache_n_alloc_ops;
60762 -atomic_t fscache_n_alloc_op_waits;
60763 +atomic_unchecked_t fscache_n_allocs;
60764 +atomic_unchecked_t fscache_n_allocs_ok;
60765 +atomic_unchecked_t fscache_n_allocs_wait;
60766 +atomic_unchecked_t fscache_n_allocs_nobufs;
60767 +atomic_unchecked_t fscache_n_allocs_intr;
60768 +atomic_unchecked_t fscache_n_allocs_object_dead;
60769 +atomic_unchecked_t fscache_n_alloc_ops;
60770 +atomic_unchecked_t fscache_n_alloc_op_waits;
60771
60772 -atomic_t fscache_n_retrievals;
60773 -atomic_t fscache_n_retrievals_ok;
60774 -atomic_t fscache_n_retrievals_wait;
60775 -atomic_t fscache_n_retrievals_nodata;
60776 -atomic_t fscache_n_retrievals_nobufs;
60777 -atomic_t fscache_n_retrievals_intr;
60778 -atomic_t fscache_n_retrievals_nomem;
60779 -atomic_t fscache_n_retrievals_object_dead;
60780 -atomic_t fscache_n_retrieval_ops;
60781 -atomic_t fscache_n_retrieval_op_waits;
60782 +atomic_unchecked_t fscache_n_retrievals;
60783 +atomic_unchecked_t fscache_n_retrievals_ok;
60784 +atomic_unchecked_t fscache_n_retrievals_wait;
60785 +atomic_unchecked_t fscache_n_retrievals_nodata;
60786 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60787 +atomic_unchecked_t fscache_n_retrievals_intr;
60788 +atomic_unchecked_t fscache_n_retrievals_nomem;
60789 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60790 +atomic_unchecked_t fscache_n_retrieval_ops;
60791 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60792
60793 -atomic_t fscache_n_stores;
60794 -atomic_t fscache_n_stores_ok;
60795 -atomic_t fscache_n_stores_again;
60796 -atomic_t fscache_n_stores_nobufs;
60797 -atomic_t fscache_n_stores_oom;
60798 -atomic_t fscache_n_store_ops;
60799 -atomic_t fscache_n_store_calls;
60800 -atomic_t fscache_n_store_pages;
60801 -atomic_t fscache_n_store_radix_deletes;
60802 -atomic_t fscache_n_store_pages_over_limit;
60803 +atomic_unchecked_t fscache_n_stores;
60804 +atomic_unchecked_t fscache_n_stores_ok;
60805 +atomic_unchecked_t fscache_n_stores_again;
60806 +atomic_unchecked_t fscache_n_stores_nobufs;
60807 +atomic_unchecked_t fscache_n_stores_oom;
60808 +atomic_unchecked_t fscache_n_store_ops;
60809 +atomic_unchecked_t fscache_n_store_calls;
60810 +atomic_unchecked_t fscache_n_store_pages;
60811 +atomic_unchecked_t fscache_n_store_radix_deletes;
60812 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60813
60814 -atomic_t fscache_n_store_vmscan_not_storing;
60815 -atomic_t fscache_n_store_vmscan_gone;
60816 -atomic_t fscache_n_store_vmscan_busy;
60817 -atomic_t fscache_n_store_vmscan_cancelled;
60818 -atomic_t fscache_n_store_vmscan_wait;
60819 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60820 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60821 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60822 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60823 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60824
60825 -atomic_t fscache_n_marks;
60826 -atomic_t fscache_n_uncaches;
60827 +atomic_unchecked_t fscache_n_marks;
60828 +atomic_unchecked_t fscache_n_uncaches;
60829
60830 -atomic_t fscache_n_acquires;
60831 -atomic_t fscache_n_acquires_null;
60832 -atomic_t fscache_n_acquires_no_cache;
60833 -atomic_t fscache_n_acquires_ok;
60834 -atomic_t fscache_n_acquires_nobufs;
60835 -atomic_t fscache_n_acquires_oom;
60836 +atomic_unchecked_t fscache_n_acquires;
60837 +atomic_unchecked_t fscache_n_acquires_null;
60838 +atomic_unchecked_t fscache_n_acquires_no_cache;
60839 +atomic_unchecked_t fscache_n_acquires_ok;
60840 +atomic_unchecked_t fscache_n_acquires_nobufs;
60841 +atomic_unchecked_t fscache_n_acquires_oom;
60842
60843 -atomic_t fscache_n_invalidates;
60844 -atomic_t fscache_n_invalidates_run;
60845 +atomic_unchecked_t fscache_n_invalidates;
60846 +atomic_unchecked_t fscache_n_invalidates_run;
60847
60848 -atomic_t fscache_n_updates;
60849 -atomic_t fscache_n_updates_null;
60850 -atomic_t fscache_n_updates_run;
60851 +atomic_unchecked_t fscache_n_updates;
60852 +atomic_unchecked_t fscache_n_updates_null;
60853 +atomic_unchecked_t fscache_n_updates_run;
60854
60855 -atomic_t fscache_n_relinquishes;
60856 -atomic_t fscache_n_relinquishes_null;
60857 -atomic_t fscache_n_relinquishes_waitcrt;
60858 -atomic_t fscache_n_relinquishes_retire;
60859 +atomic_unchecked_t fscache_n_relinquishes;
60860 +atomic_unchecked_t fscache_n_relinquishes_null;
60861 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60862 +atomic_unchecked_t fscache_n_relinquishes_retire;
60863
60864 -atomic_t fscache_n_cookie_index;
60865 -atomic_t fscache_n_cookie_data;
60866 -atomic_t fscache_n_cookie_special;
60867 +atomic_unchecked_t fscache_n_cookie_index;
60868 +atomic_unchecked_t fscache_n_cookie_data;
60869 +atomic_unchecked_t fscache_n_cookie_special;
60870
60871 -atomic_t fscache_n_object_alloc;
60872 -atomic_t fscache_n_object_no_alloc;
60873 -atomic_t fscache_n_object_lookups;
60874 -atomic_t fscache_n_object_lookups_negative;
60875 -atomic_t fscache_n_object_lookups_positive;
60876 -atomic_t fscache_n_object_lookups_timed_out;
60877 -atomic_t fscache_n_object_created;
60878 -atomic_t fscache_n_object_avail;
60879 -atomic_t fscache_n_object_dead;
60880 +atomic_unchecked_t fscache_n_object_alloc;
60881 +atomic_unchecked_t fscache_n_object_no_alloc;
60882 +atomic_unchecked_t fscache_n_object_lookups;
60883 +atomic_unchecked_t fscache_n_object_lookups_negative;
60884 +atomic_unchecked_t fscache_n_object_lookups_positive;
60885 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60886 +atomic_unchecked_t fscache_n_object_created;
60887 +atomic_unchecked_t fscache_n_object_avail;
60888 +atomic_unchecked_t fscache_n_object_dead;
60889
60890 -atomic_t fscache_n_checkaux_none;
60891 -atomic_t fscache_n_checkaux_okay;
60892 -atomic_t fscache_n_checkaux_update;
60893 -atomic_t fscache_n_checkaux_obsolete;
60894 +atomic_unchecked_t fscache_n_checkaux_none;
60895 +atomic_unchecked_t fscache_n_checkaux_okay;
60896 +atomic_unchecked_t fscache_n_checkaux_update;
60897 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60898
60899 atomic_t fscache_n_cop_alloc_object;
60900 atomic_t fscache_n_cop_lookup_object;
60901 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60902 seq_puts(m, "FS-Cache statistics\n");
60903
60904 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60905 - atomic_read(&fscache_n_cookie_index),
60906 - atomic_read(&fscache_n_cookie_data),
60907 - atomic_read(&fscache_n_cookie_special));
60908 + atomic_read_unchecked(&fscache_n_cookie_index),
60909 + atomic_read_unchecked(&fscache_n_cookie_data),
60910 + atomic_read_unchecked(&fscache_n_cookie_special));
60911
60912 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60913 - atomic_read(&fscache_n_object_alloc),
60914 - atomic_read(&fscache_n_object_no_alloc),
60915 - atomic_read(&fscache_n_object_avail),
60916 - atomic_read(&fscache_n_object_dead));
60917 + atomic_read_unchecked(&fscache_n_object_alloc),
60918 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60919 + atomic_read_unchecked(&fscache_n_object_avail),
60920 + atomic_read_unchecked(&fscache_n_object_dead));
60921 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60922 - atomic_read(&fscache_n_checkaux_none),
60923 - atomic_read(&fscache_n_checkaux_okay),
60924 - atomic_read(&fscache_n_checkaux_update),
60925 - atomic_read(&fscache_n_checkaux_obsolete));
60926 + atomic_read_unchecked(&fscache_n_checkaux_none),
60927 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60928 + atomic_read_unchecked(&fscache_n_checkaux_update),
60929 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60930
60931 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60932 - atomic_read(&fscache_n_marks),
60933 - atomic_read(&fscache_n_uncaches));
60934 + atomic_read_unchecked(&fscache_n_marks),
60935 + atomic_read_unchecked(&fscache_n_uncaches));
60936
60937 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60938 " oom=%u\n",
60939 - atomic_read(&fscache_n_acquires),
60940 - atomic_read(&fscache_n_acquires_null),
60941 - atomic_read(&fscache_n_acquires_no_cache),
60942 - atomic_read(&fscache_n_acquires_ok),
60943 - atomic_read(&fscache_n_acquires_nobufs),
60944 - atomic_read(&fscache_n_acquires_oom));
60945 + atomic_read_unchecked(&fscache_n_acquires),
60946 + atomic_read_unchecked(&fscache_n_acquires_null),
60947 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60948 + atomic_read_unchecked(&fscache_n_acquires_ok),
60949 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60950 + atomic_read_unchecked(&fscache_n_acquires_oom));
60951
60952 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60953 - atomic_read(&fscache_n_object_lookups),
60954 - atomic_read(&fscache_n_object_lookups_negative),
60955 - atomic_read(&fscache_n_object_lookups_positive),
60956 - atomic_read(&fscache_n_object_created),
60957 - atomic_read(&fscache_n_object_lookups_timed_out));
60958 + atomic_read_unchecked(&fscache_n_object_lookups),
60959 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60960 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60961 + atomic_read_unchecked(&fscache_n_object_created),
60962 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60963
60964 seq_printf(m, "Invals : n=%u run=%u\n",
60965 - atomic_read(&fscache_n_invalidates),
60966 - atomic_read(&fscache_n_invalidates_run));
60967 + atomic_read_unchecked(&fscache_n_invalidates),
60968 + atomic_read_unchecked(&fscache_n_invalidates_run));
60969
60970 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60971 - atomic_read(&fscache_n_updates),
60972 - atomic_read(&fscache_n_updates_null),
60973 - atomic_read(&fscache_n_updates_run));
60974 + atomic_read_unchecked(&fscache_n_updates),
60975 + atomic_read_unchecked(&fscache_n_updates_null),
60976 + atomic_read_unchecked(&fscache_n_updates_run));
60977
60978 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60979 - atomic_read(&fscache_n_relinquishes),
60980 - atomic_read(&fscache_n_relinquishes_null),
60981 - atomic_read(&fscache_n_relinquishes_waitcrt),
60982 - atomic_read(&fscache_n_relinquishes_retire));
60983 + atomic_read_unchecked(&fscache_n_relinquishes),
60984 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60985 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60986 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60987
60988 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60989 - atomic_read(&fscache_n_attr_changed),
60990 - atomic_read(&fscache_n_attr_changed_ok),
60991 - atomic_read(&fscache_n_attr_changed_nobufs),
60992 - atomic_read(&fscache_n_attr_changed_nomem),
60993 - atomic_read(&fscache_n_attr_changed_calls));
60994 + atomic_read_unchecked(&fscache_n_attr_changed),
60995 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60996 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60997 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60998 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60999
61000 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61001 - atomic_read(&fscache_n_allocs),
61002 - atomic_read(&fscache_n_allocs_ok),
61003 - atomic_read(&fscache_n_allocs_wait),
61004 - atomic_read(&fscache_n_allocs_nobufs),
61005 - atomic_read(&fscache_n_allocs_intr));
61006 + atomic_read_unchecked(&fscache_n_allocs),
61007 + atomic_read_unchecked(&fscache_n_allocs_ok),
61008 + atomic_read_unchecked(&fscache_n_allocs_wait),
61009 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61010 + atomic_read_unchecked(&fscache_n_allocs_intr));
61011 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61012 - atomic_read(&fscache_n_alloc_ops),
61013 - atomic_read(&fscache_n_alloc_op_waits),
61014 - atomic_read(&fscache_n_allocs_object_dead));
61015 + atomic_read_unchecked(&fscache_n_alloc_ops),
61016 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61017 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61018
61019 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61020 " int=%u oom=%u\n",
61021 - atomic_read(&fscache_n_retrievals),
61022 - atomic_read(&fscache_n_retrievals_ok),
61023 - atomic_read(&fscache_n_retrievals_wait),
61024 - atomic_read(&fscache_n_retrievals_nodata),
61025 - atomic_read(&fscache_n_retrievals_nobufs),
61026 - atomic_read(&fscache_n_retrievals_intr),
61027 - atomic_read(&fscache_n_retrievals_nomem));
61028 + atomic_read_unchecked(&fscache_n_retrievals),
61029 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61030 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61031 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61032 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61033 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61034 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61035 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61036 - atomic_read(&fscache_n_retrieval_ops),
61037 - atomic_read(&fscache_n_retrieval_op_waits),
61038 - atomic_read(&fscache_n_retrievals_object_dead));
61039 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61040 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61041 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61042
61043 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61044 - atomic_read(&fscache_n_stores),
61045 - atomic_read(&fscache_n_stores_ok),
61046 - atomic_read(&fscache_n_stores_again),
61047 - atomic_read(&fscache_n_stores_nobufs),
61048 - atomic_read(&fscache_n_stores_oom));
61049 + atomic_read_unchecked(&fscache_n_stores),
61050 + atomic_read_unchecked(&fscache_n_stores_ok),
61051 + atomic_read_unchecked(&fscache_n_stores_again),
61052 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61053 + atomic_read_unchecked(&fscache_n_stores_oom));
61054 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61055 - atomic_read(&fscache_n_store_ops),
61056 - atomic_read(&fscache_n_store_calls),
61057 - atomic_read(&fscache_n_store_pages),
61058 - atomic_read(&fscache_n_store_radix_deletes),
61059 - atomic_read(&fscache_n_store_pages_over_limit));
61060 + atomic_read_unchecked(&fscache_n_store_ops),
61061 + atomic_read_unchecked(&fscache_n_store_calls),
61062 + atomic_read_unchecked(&fscache_n_store_pages),
61063 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61064 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61065
61066 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61067 - atomic_read(&fscache_n_store_vmscan_not_storing),
61068 - atomic_read(&fscache_n_store_vmscan_gone),
61069 - atomic_read(&fscache_n_store_vmscan_busy),
61070 - atomic_read(&fscache_n_store_vmscan_cancelled),
61071 - atomic_read(&fscache_n_store_vmscan_wait));
61072 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61073 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61074 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61075 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61076 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61077
61078 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61079 - atomic_read(&fscache_n_op_pend),
61080 - atomic_read(&fscache_n_op_run),
61081 - atomic_read(&fscache_n_op_enqueue),
61082 - atomic_read(&fscache_n_op_cancelled),
61083 - atomic_read(&fscache_n_op_rejected));
61084 + atomic_read_unchecked(&fscache_n_op_pend),
61085 + atomic_read_unchecked(&fscache_n_op_run),
61086 + atomic_read_unchecked(&fscache_n_op_enqueue),
61087 + atomic_read_unchecked(&fscache_n_op_cancelled),
61088 + atomic_read_unchecked(&fscache_n_op_rejected));
61089 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61090 - atomic_read(&fscache_n_op_deferred_release),
61091 - atomic_read(&fscache_n_op_release),
61092 - atomic_read(&fscache_n_op_gc));
61093 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61094 + atomic_read_unchecked(&fscache_n_op_release),
61095 + atomic_read_unchecked(&fscache_n_op_gc));
61096
61097 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61098 atomic_read(&fscache_n_cop_alloc_object),
61099 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61100 index 13b691a..1ffca5ae 100644
61101 --- a/fs/fuse/cuse.c
61102 +++ b/fs/fuse/cuse.c
61103 @@ -607,10 +607,12 @@ static int __init cuse_init(void)
61104 INIT_LIST_HEAD(&cuse_conntbl[i]);
61105
61106 /* inherit and extend fuse_dev_operations */
61107 - cuse_channel_fops = fuse_dev_operations;
61108 - cuse_channel_fops.owner = THIS_MODULE;
61109 - cuse_channel_fops.open = cuse_channel_open;
61110 - cuse_channel_fops.release = cuse_channel_release;
61111 + pax_open_kernel();
61112 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61113 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61114 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61115 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61116 + pax_close_kernel();
61117
61118 cuse_class = class_create(THIS_MODULE, "cuse");
61119 if (IS_ERR(cuse_class))
61120 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61121 index aac71ce..fcd6a1b 100644
61122 --- a/fs/fuse/dev.c
61123 +++ b/fs/fuse/dev.c
61124 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61125 ret = 0;
61126 pipe_lock(pipe);
61127
61128 - if (!pipe->readers) {
61129 + if (!atomic_read(&pipe->readers)) {
61130 send_sig(SIGPIPE, current, 0);
61131 if (!ret)
61132 ret = -EPIPE;
61133 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61134 page_nr++;
61135 ret += buf->len;
61136
61137 - if (pipe->files)
61138 + if (atomic_read(&pipe->files))
61139 do_wakeup = 1;
61140 }
61141
61142 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61143 index 4219835..3473b7e 100644
61144 --- a/fs/fuse/dir.c
61145 +++ b/fs/fuse/dir.c
61146 @@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61147 return link;
61148 }
61149
61150 -static void free_link(char *link)
61151 +static void free_link(const char *link)
61152 {
61153 if (!IS_ERR(link))
61154 free_page((unsigned long) link);
61155 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61156 index 9c470fd..aae410e 100644
61157 --- a/fs/hostfs/hostfs_kern.c
61158 +++ b/fs/hostfs/hostfs_kern.c
61159 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61160
61161 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61162 {
61163 - char *s = nd_get_link(nd);
61164 + const char *s = nd_get_link(nd);
61165 if (!IS_ERR(s))
61166 __putname(s);
61167 }
61168 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61169 index e19d4c0..8a357a9 100644
61170 --- a/fs/hugetlbfs/inode.c
61171 +++ b/fs/hugetlbfs/inode.c
61172 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61173 struct mm_struct *mm = current->mm;
61174 struct vm_area_struct *vma;
61175 struct hstate *h = hstate_file(file);
61176 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61177 struct vm_unmapped_area_info info;
61178
61179 if (len & ~huge_page_mask(h))
61180 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61181 return addr;
61182 }
61183
61184 +#ifdef CONFIG_PAX_RANDMMAP
61185 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61186 +#endif
61187 +
61188 if (addr) {
61189 addr = ALIGN(addr, huge_page_size(h));
61190 vma = find_vma(mm, addr);
61191 - if (TASK_SIZE - len >= addr &&
61192 - (!vma || addr + len <= vma->vm_start))
61193 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61194 return addr;
61195 }
61196
61197 info.flags = 0;
61198 info.length = len;
61199 info.low_limit = TASK_UNMAPPED_BASE;
61200 +
61201 +#ifdef CONFIG_PAX_RANDMMAP
61202 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61203 + info.low_limit += mm->delta_mmap;
61204 +#endif
61205 +
61206 info.high_limit = TASK_SIZE;
61207 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61208 info.align_offset = 0;
61209 @@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61210 };
61211 MODULE_ALIAS_FS("hugetlbfs");
61212
61213 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61214 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61215
61216 static int can_do_hugetlb_shm(void)
61217 {
61218 diff --git a/fs/inode.c b/fs/inode.c
61219 index d2fb2f2..a6444b0 100644
61220 --- a/fs/inode.c
61221 +++ b/fs/inode.c
61222 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61223 unsigned int *p = &get_cpu_var(last_ino);
61224 unsigned int res = *p;
61225
61226 +start:
61227 +
61228 #ifdef CONFIG_SMP
61229 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61230 - static atomic_t shared_last_ino;
61231 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61232 + static atomic_unchecked_t shared_last_ino;
61233 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61234
61235 res = next - LAST_INO_BATCH;
61236 }
61237 #endif
61238
61239 - *p = ++res;
61240 + if (unlikely(!++res))
61241 + goto start; /* never zero */
61242 + *p = res;
61243 put_cpu_var(last_ino);
61244 return res;
61245 }
61246 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61247 index 4a6cf28..d3a29d3 100644
61248 --- a/fs/jffs2/erase.c
61249 +++ b/fs/jffs2/erase.c
61250 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61251 struct jffs2_unknown_node marker = {
61252 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61253 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61254 - .totlen = cpu_to_je32(c->cleanmarker_size)
61255 + .totlen = cpu_to_je32(c->cleanmarker_size),
61256 + .hdr_crc = cpu_to_je32(0)
61257 };
61258
61259 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61260 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61261 index a6597d6..41b30ec 100644
61262 --- a/fs/jffs2/wbuf.c
61263 +++ b/fs/jffs2/wbuf.c
61264 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61265 {
61266 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61267 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61268 - .totlen = constant_cpu_to_je32(8)
61269 + .totlen = constant_cpu_to_je32(8),
61270 + .hdr_crc = constant_cpu_to_je32(0)
61271 };
61272
61273 /*
61274 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61275 index 97f7fda..09bd33d 100644
61276 --- a/fs/jfs/super.c
61277 +++ b/fs/jfs/super.c
61278 @@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61279
61280 jfs_inode_cachep =
61281 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61282 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61283 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61284 init_once);
61285 if (jfs_inode_cachep == NULL)
61286 return -ENOMEM;
61287 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61288 index ac127cd..d8079db 100644
61289 --- a/fs/kernfs/dir.c
61290 +++ b/fs/kernfs/dir.c
61291 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61292 *
61293 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61294 */
61295 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61296 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61297 {
61298 unsigned long hash = init_name_hash();
61299 unsigned int len = strlen(name);
61300 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61301 index 5e9a80c..3853a24 100644
61302 --- a/fs/kernfs/file.c
61303 +++ b/fs/kernfs/file.c
61304 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61305
61306 struct kernfs_open_node {
61307 atomic_t refcnt;
61308 - atomic_t event;
61309 + atomic_unchecked_t event;
61310 wait_queue_head_t poll;
61311 struct list_head files; /* goes through kernfs_open_file.list */
61312 };
61313 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61314 {
61315 struct kernfs_open_file *of = sf->private;
61316
61317 - of->event = atomic_read(&of->kn->attr.open->event);
61318 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61319
61320 return of->kn->attr.ops->seq_show(sf, v);
61321 }
61322 @@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61323 return ret;
61324 }
61325
61326 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61327 - void *buf, int len, int write)
61328 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61329 + void *buf, size_t len, int write)
61330 {
61331 struct file *file = vma->vm_file;
61332 struct kernfs_open_file *of = kernfs_of(file);
61333 - int ret;
61334 + ssize_t ret;
61335
61336 if (!of->vm_ops)
61337 return -EINVAL;
61338 @@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61339 return -ENOMEM;
61340
61341 atomic_set(&new_on->refcnt, 0);
61342 - atomic_set(&new_on->event, 1);
61343 + atomic_set_unchecked(&new_on->event, 1);
61344 init_waitqueue_head(&new_on->poll);
61345 INIT_LIST_HEAD(&new_on->files);
61346 goto retry;
61347 @@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61348
61349 kernfs_put_active(kn);
61350
61351 - if (of->event != atomic_read(&on->event))
61352 + if (of->event != atomic_read_unchecked(&on->event))
61353 goto trigger;
61354
61355 return DEFAULT_POLLMASK;
61356 @@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61357 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61358 on = kn->attr.open;
61359 if (on) {
61360 - atomic_inc(&on->event);
61361 + atomic_inc_unchecked(&on->event);
61362 wake_up_interruptible(&on->poll);
61363 }
61364 }
61365 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61366 index 8a19889..4c3069a 100644
61367 --- a/fs/kernfs/symlink.c
61368 +++ b/fs/kernfs/symlink.c
61369 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61370 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61371 void *cookie)
61372 {
61373 - char *page = nd_get_link(nd);
61374 + const char *page = nd_get_link(nd);
61375 if (!IS_ERR(page))
61376 free_page((unsigned long)page);
61377 }
61378 diff --git a/fs/libfs.c b/fs/libfs.c
61379 index a184424..944ddce 100644
61380 --- a/fs/libfs.c
61381 +++ b/fs/libfs.c
61382 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61383
61384 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61385 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61386 + char d_name[sizeof(next->d_iname)];
61387 + const unsigned char *name;
61388 +
61389 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61390 if (!simple_positive(next)) {
61391 spin_unlock(&next->d_lock);
61392 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61393
61394 spin_unlock(&next->d_lock);
61395 spin_unlock(&dentry->d_lock);
61396 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61397 + name = next->d_name.name;
61398 + if (name == next->d_iname) {
61399 + memcpy(d_name, name, next->d_name.len);
61400 + name = d_name;
61401 + }
61402 + if (!dir_emit(ctx, name, next->d_name.len,
61403 next->d_inode->i_ino, dt_type(next->d_inode)))
61404 return 0;
61405 spin_lock(&dentry->d_lock);
61406 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61407 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61408 void *cookie)
61409 {
61410 - char *s = nd_get_link(nd);
61411 + const char *s = nd_get_link(nd);
61412 if (!IS_ERR(s))
61413 kfree(s);
61414 }
61415 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61416 index acd3947..1f896e2 100644
61417 --- a/fs/lockd/clntproc.c
61418 +++ b/fs/lockd/clntproc.c
61419 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61420 /*
61421 * Cookie counter for NLM requests
61422 */
61423 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61424 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61425
61426 void nlmclnt_next_cookie(struct nlm_cookie *c)
61427 {
61428 - u32 cookie = atomic_inc_return(&nlm_cookie);
61429 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61430
61431 memcpy(c->data, &cookie, 4);
61432 c->len=4;
61433 diff --git a/fs/locks.c b/fs/locks.c
61434 index e390bd9..c79870e 100644
61435 --- a/fs/locks.c
61436 +++ b/fs/locks.c
61437 @@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61438 locks_remove_posix(filp, (fl_owner_t)filp);
61439
61440 if (filp->f_op->flock) {
61441 - struct file_lock fl = {
61442 + struct file_lock flock = {
61443 .fl_pid = current->tgid,
61444 .fl_file = filp,
61445 .fl_flags = FL_FLOCK,
61446 .fl_type = F_UNLCK,
61447 .fl_end = OFFSET_MAX,
61448 };
61449 - filp->f_op->flock(filp, F_SETLKW, &fl);
61450 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61451 - fl.fl_ops->fl_release_private(&fl);
61452 + filp->f_op->flock(filp, F_SETLKW, &flock);
61453 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61454 + flock.fl_ops->fl_release_private(&flock);
61455 }
61456
61457 spin_lock(&inode->i_lock);
61458 diff --git a/fs/mount.h b/fs/mount.h
61459 index d55297f..f5b28c5 100644
61460 --- a/fs/mount.h
61461 +++ b/fs/mount.h
61462 @@ -11,7 +11,7 @@ struct mnt_namespace {
61463 u64 seq; /* Sequence number to prevent loops */
61464 wait_queue_head_t poll;
61465 u64 event;
61466 -};
61467 +} __randomize_layout;
61468
61469 struct mnt_pcp {
61470 int mnt_count;
61471 @@ -57,7 +57,7 @@ struct mount {
61472 int mnt_expiry_mark; /* true if marked for expiry */
61473 int mnt_pinned;
61474 struct path mnt_ex_mountpoint;
61475 -};
61476 +} __randomize_layout;
61477
61478 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61479
61480 diff --git a/fs/namei.c b/fs/namei.c
61481 index 985c6f3..f67a0f8 100644
61482 --- a/fs/namei.c
61483 +++ b/fs/namei.c
61484 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61485 if (ret != -EACCES)
61486 return ret;
61487
61488 +#ifdef CONFIG_GRKERNSEC
61489 + /* we'll block if we have to log due to a denied capability use */
61490 + if (mask & MAY_NOT_BLOCK)
61491 + return -ECHILD;
61492 +#endif
61493 +
61494 if (S_ISDIR(inode->i_mode)) {
61495 /* DACs are overridable for directories */
61496 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61497 - return 0;
61498 if (!(mask & MAY_WRITE))
61499 - if (capable_wrt_inode_uidgid(inode,
61500 - CAP_DAC_READ_SEARCH))
61501 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61502 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61503 return 0;
61504 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61505 + return 0;
61506 return -EACCES;
61507 }
61508 /*
61509 + * Searching includes executable on directories, else just read.
61510 + */
61511 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61512 + if (mask == MAY_READ)
61513 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61514 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61515 + return 0;
61516 +
61517 + /*
61518 * Read/write DACs are always overridable.
61519 * Executable DACs are overridable when there is
61520 * at least one exec bit set.
61521 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61522 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61523 return 0;
61524
61525 - /*
61526 - * Searching includes executable on directories, else just read.
61527 - */
61528 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61529 - if (mask == MAY_READ)
61530 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61531 - return 0;
61532 -
61533 return -EACCES;
61534 }
61535 EXPORT_SYMBOL(generic_permission);
61536 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61537 {
61538 struct dentry *dentry = link->dentry;
61539 int error;
61540 - char *s;
61541 + const char *s;
61542
61543 BUG_ON(nd->flags & LOOKUP_RCU);
61544
61545 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61546 if (error)
61547 goto out_put_nd_path;
61548
61549 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61550 + dentry->d_inode, dentry, nd->path.mnt)) {
61551 + error = -EACCES;
61552 + goto out_put_nd_path;
61553 + }
61554 +
61555 nd->last_type = LAST_BIND;
61556 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61557 error = PTR_ERR(*p);
61558 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61559 if (res)
61560 break;
61561 res = walk_component(nd, path, LOOKUP_FOLLOW);
61562 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61563 + res = -EACCES;
61564 put_link(nd, &link, cookie);
61565 } while (res > 0);
61566
61567 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61568 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61569 {
61570 unsigned long a, b, adata, bdata, mask, hash, len;
61571 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61572 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61573
61574 hash = a = 0;
61575 len = -sizeof(unsigned long);
61576 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61577 if (err)
61578 break;
61579 err = lookup_last(nd, &path);
61580 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61581 + err = -EACCES;
61582 put_link(nd, &link, cookie);
61583 }
61584 }
61585 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61586 if (!err)
61587 err = complete_walk(nd);
61588
61589 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61590 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61591 + path_put(&nd->path);
61592 + err = -ENOENT;
61593 + }
61594 + }
61595 +
61596 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61597 if (!d_can_lookup(nd->path.dentry)) {
61598 path_put(&nd->path);
61599 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61600 retval = path_lookupat(dfd, name->name,
61601 flags | LOOKUP_REVAL, nd);
61602
61603 - if (likely(!retval))
61604 + if (likely(!retval)) {
61605 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61606 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61607 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61608 + path_put(&nd->path);
61609 + return -ENOENT;
61610 + }
61611 + }
61612 + }
61613 return retval;
61614 }
61615
61616 @@ -2569,6 +2600,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61617 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61618 return -EPERM;
61619
61620 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61621 + return -EPERM;
61622 + if (gr_handle_rawio(inode))
61623 + return -EPERM;
61624 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61625 + return -EACCES;
61626 +
61627 return 0;
61628 }
61629
61630 @@ -2800,7 +2838,7 @@ looked_up:
61631 * cleared otherwise prior to returning.
61632 */
61633 static int lookup_open(struct nameidata *nd, struct path *path,
61634 - struct file *file,
61635 + struct path *link, struct file *file,
61636 const struct open_flags *op,
61637 bool got_write, int *opened)
61638 {
61639 @@ -2835,6 +2873,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61640 /* Negative dentry, just create the file */
61641 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61642 umode_t mode = op->mode;
61643 +
61644 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61645 + error = -EACCES;
61646 + goto out_dput;
61647 + }
61648 +
61649 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61650 + error = -EACCES;
61651 + goto out_dput;
61652 + }
61653 +
61654 if (!IS_POSIXACL(dir->d_inode))
61655 mode &= ~current_umask();
61656 /*
61657 @@ -2856,6 +2905,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61658 nd->flags & LOOKUP_EXCL);
61659 if (error)
61660 goto out_dput;
61661 + else
61662 + gr_handle_create(dentry, nd->path.mnt);
61663 }
61664 out_no_open:
61665 path->dentry = dentry;
61666 @@ -2870,7 +2921,7 @@ out_dput:
61667 /*
61668 * Handle the last step of open()
61669 */
61670 -static int do_last(struct nameidata *nd, struct path *path,
61671 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61672 struct file *file, const struct open_flags *op,
61673 int *opened, struct filename *name)
61674 {
61675 @@ -2920,6 +2971,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61676 if (error)
61677 return error;
61678
61679 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61680 + error = -ENOENT;
61681 + goto out;
61682 + }
61683 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61684 + error = -EACCES;
61685 + goto out;
61686 + }
61687 +
61688 audit_inode(name, dir, LOOKUP_PARENT);
61689 error = -EISDIR;
61690 /* trailing slashes? */
61691 @@ -2939,7 +2999,7 @@ retry_lookup:
61692 */
61693 }
61694 mutex_lock(&dir->d_inode->i_mutex);
61695 - error = lookup_open(nd, path, file, op, got_write, opened);
61696 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61697 mutex_unlock(&dir->d_inode->i_mutex);
61698
61699 if (error <= 0) {
61700 @@ -2963,11 +3023,28 @@ retry_lookup:
61701 goto finish_open_created;
61702 }
61703
61704 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61705 + error = -ENOENT;
61706 + goto exit_dput;
61707 + }
61708 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61709 + error = -EACCES;
61710 + goto exit_dput;
61711 + }
61712 +
61713 /*
61714 * create/update audit record if it already exists.
61715 */
61716 - if (d_is_positive(path->dentry))
61717 + if (d_is_positive(path->dentry)) {
61718 + /* only check if O_CREAT is specified, all other checks need to go
61719 + into may_open */
61720 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61721 + error = -EACCES;
61722 + goto exit_dput;
61723 + }
61724 +
61725 audit_inode(name, path->dentry, 0);
61726 + }
61727
61728 /*
61729 * If atomic_open() acquired write access it is dropped now due to
61730 @@ -3008,6 +3085,11 @@ finish_lookup:
61731 }
61732 }
61733 BUG_ON(inode != path->dentry->d_inode);
61734 + /* if we're resolving a symlink to another symlink */
61735 + if (link && gr_handle_symlink_owner(link, inode)) {
61736 + error = -EACCES;
61737 + goto out;
61738 + }
61739 return 1;
61740 }
61741
61742 @@ -3017,7 +3099,6 @@ finish_lookup:
61743 save_parent.dentry = nd->path.dentry;
61744 save_parent.mnt = mntget(path->mnt);
61745 nd->path.dentry = path->dentry;
61746 -
61747 }
61748 nd->inode = inode;
61749 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61750 @@ -3027,7 +3108,18 @@ finish_open:
61751 path_put(&save_parent);
61752 return error;
61753 }
61754 +
61755 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61756 + error = -ENOENT;
61757 + goto out;
61758 + }
61759 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61760 + error = -EACCES;
61761 + goto out;
61762 + }
61763 +
61764 audit_inode(name, nd->path.dentry, 0);
61765 +
61766 error = -EISDIR;
61767 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
61768 goto out;
61769 @@ -3190,7 +3282,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61770 if (unlikely(error))
61771 goto out;
61772
61773 - error = do_last(nd, &path, file, op, &opened, pathname);
61774 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61775 while (unlikely(error > 0)) { /* trailing symlink */
61776 struct path link = path;
61777 void *cookie;
61778 @@ -3208,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61779 error = follow_link(&link, nd, &cookie);
61780 if (unlikely(error))
61781 break;
61782 - error = do_last(nd, &path, file, op, &opened, pathname);
61783 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61784 put_link(nd, &link, cookie);
61785 }
61786 out:
61787 @@ -3308,9 +3400,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61788 goto unlock;
61789
61790 error = -EEXIST;
61791 - if (d_is_positive(dentry))
61792 + if (d_is_positive(dentry)) {
61793 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61794 + error = -ENOENT;
61795 goto fail;
61796 -
61797 + }
61798 /*
61799 * Special case - lookup gave negative, but... we had foo/bar/
61800 * From the vfs_mknod() POV we just have a negative dentry -
61801 @@ -3362,6 +3456,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61802 }
61803 EXPORT_SYMBOL(user_path_create);
61804
61805 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61806 +{
61807 + struct filename *tmp = getname(pathname);
61808 + struct dentry *res;
61809 + if (IS_ERR(tmp))
61810 + return ERR_CAST(tmp);
61811 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61812 + if (IS_ERR(res))
61813 + putname(tmp);
61814 + else
61815 + *to = tmp;
61816 + return res;
61817 +}
61818 +
61819 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61820 {
61821 int error = may_create(dir, dentry);
61822 @@ -3425,6 +3533,17 @@ retry:
61823
61824 if (!IS_POSIXACL(path.dentry->d_inode))
61825 mode &= ~current_umask();
61826 +
61827 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61828 + error = -EPERM;
61829 + goto out;
61830 + }
61831 +
61832 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61833 + error = -EACCES;
61834 + goto out;
61835 + }
61836 +
61837 error = security_path_mknod(&path, dentry, mode, dev);
61838 if (error)
61839 goto out;
61840 @@ -3441,6 +3560,8 @@ retry:
61841 break;
61842 }
61843 out:
61844 + if (!error)
61845 + gr_handle_create(dentry, path.mnt);
61846 done_path_create(&path, dentry);
61847 if (retry_estale(error, lookup_flags)) {
61848 lookup_flags |= LOOKUP_REVAL;
61849 @@ -3494,9 +3615,16 @@ retry:
61850
61851 if (!IS_POSIXACL(path.dentry->d_inode))
61852 mode &= ~current_umask();
61853 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61854 + error = -EACCES;
61855 + goto out;
61856 + }
61857 error = security_path_mkdir(&path, dentry, mode);
61858 if (!error)
61859 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61860 + if (!error)
61861 + gr_handle_create(dentry, path.mnt);
61862 +out:
61863 done_path_create(&path, dentry);
61864 if (retry_estale(error, lookup_flags)) {
61865 lookup_flags |= LOOKUP_REVAL;
61866 @@ -3579,6 +3707,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61867 struct filename *name;
61868 struct dentry *dentry;
61869 struct nameidata nd;
61870 + ino_t saved_ino = 0;
61871 + dev_t saved_dev = 0;
61872 unsigned int lookup_flags = 0;
61873 retry:
61874 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61875 @@ -3611,10 +3741,21 @@ retry:
61876 error = -ENOENT;
61877 goto exit3;
61878 }
61879 +
61880 + saved_ino = dentry->d_inode->i_ino;
61881 + saved_dev = gr_get_dev_from_dentry(dentry);
61882 +
61883 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61884 + error = -EACCES;
61885 + goto exit3;
61886 + }
61887 +
61888 error = security_path_rmdir(&nd.path, dentry);
61889 if (error)
61890 goto exit3;
61891 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61892 + if (!error && (saved_dev || saved_ino))
61893 + gr_handle_delete(saved_ino, saved_dev);
61894 exit3:
61895 dput(dentry);
61896 exit2:
61897 @@ -3705,6 +3846,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61898 struct nameidata nd;
61899 struct inode *inode = NULL;
61900 struct inode *delegated_inode = NULL;
61901 + ino_t saved_ino = 0;
61902 + dev_t saved_dev = 0;
61903 unsigned int lookup_flags = 0;
61904 retry:
61905 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61906 @@ -3731,10 +3874,22 @@ retry_deleg:
61907 if (d_is_negative(dentry))
61908 goto slashes;
61909 ihold(inode);
61910 +
61911 + if (inode->i_nlink <= 1) {
61912 + saved_ino = inode->i_ino;
61913 + saved_dev = gr_get_dev_from_dentry(dentry);
61914 + }
61915 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61916 + error = -EACCES;
61917 + goto exit2;
61918 + }
61919 +
61920 error = security_path_unlink(&nd.path, dentry);
61921 if (error)
61922 goto exit2;
61923 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61924 + if (!error && (saved_ino || saved_dev))
61925 + gr_handle_delete(saved_ino, saved_dev);
61926 exit2:
61927 dput(dentry);
61928 }
61929 @@ -3823,9 +3978,17 @@ retry:
61930 if (IS_ERR(dentry))
61931 goto out_putname;
61932
61933 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61934 + error = -EACCES;
61935 + goto out;
61936 + }
61937 +
61938 error = security_path_symlink(&path, dentry, from->name);
61939 if (!error)
61940 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61941 + if (!error)
61942 + gr_handle_create(dentry, path.mnt);
61943 +out:
61944 done_path_create(&path, dentry);
61945 if (retry_estale(error, lookup_flags)) {
61946 lookup_flags |= LOOKUP_REVAL;
61947 @@ -3929,6 +4092,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61948 struct dentry *new_dentry;
61949 struct path old_path, new_path;
61950 struct inode *delegated_inode = NULL;
61951 + struct filename *to = NULL;
61952 int how = 0;
61953 int error;
61954
61955 @@ -3952,7 +4116,7 @@ retry:
61956 if (error)
61957 return error;
61958
61959 - new_dentry = user_path_create(newdfd, newname, &new_path,
61960 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61961 (how & LOOKUP_REVAL));
61962 error = PTR_ERR(new_dentry);
61963 if (IS_ERR(new_dentry))
61964 @@ -3964,11 +4128,28 @@ retry:
61965 error = may_linkat(&old_path);
61966 if (unlikely(error))
61967 goto out_dput;
61968 +
61969 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61970 + old_path.dentry->d_inode,
61971 + old_path.dentry->d_inode->i_mode, to)) {
61972 + error = -EACCES;
61973 + goto out_dput;
61974 + }
61975 +
61976 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61977 + old_path.dentry, old_path.mnt, to)) {
61978 + error = -EACCES;
61979 + goto out_dput;
61980 + }
61981 +
61982 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61983 if (error)
61984 goto out_dput;
61985 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61986 + if (!error)
61987 + gr_handle_create(new_dentry, new_path.mnt);
61988 out_dput:
61989 + putname(to);
61990 done_path_create(&new_path, new_dentry);
61991 if (delegated_inode) {
61992 error = break_deleg_wait(&delegated_inode);
61993 @@ -4278,6 +4459,12 @@ retry_deleg:
61994 if (new_dentry == trap)
61995 goto exit5;
61996
61997 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61998 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61999 + to, flags);
62000 + if (error)
62001 + goto exit5;
62002 +
62003 error = security_path_rename(&oldnd.path, old_dentry,
62004 &newnd.path, new_dentry, flags);
62005 if (error)
62006 @@ -4285,6 +4472,9 @@ retry_deleg:
62007 error = vfs_rename(old_dir->d_inode, old_dentry,
62008 new_dir->d_inode, new_dentry,
62009 &delegated_inode, flags);
62010 + if (!error)
62011 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62012 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62013 exit5:
62014 dput(new_dentry);
62015 exit4:
62016 @@ -4327,14 +4517,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62017
62018 int readlink_copy(char __user *buffer, int buflen, const char *link)
62019 {
62020 + char tmpbuf[64];
62021 + const char *newlink;
62022 int len = PTR_ERR(link);
62023 +
62024 if (IS_ERR(link))
62025 goto out;
62026
62027 len = strlen(link);
62028 if (len > (unsigned) buflen)
62029 len = buflen;
62030 - if (copy_to_user(buffer, link, len))
62031 +
62032 + if (len < sizeof(tmpbuf)) {
62033 + memcpy(tmpbuf, link, len);
62034 + newlink = tmpbuf;
62035 + } else
62036 + newlink = link;
62037 +
62038 + if (copy_to_user(buffer, newlink, len))
62039 len = -EFAULT;
62040 out:
62041 return len;
62042 diff --git a/fs/namespace.c b/fs/namespace.c
62043 index 182bc41..72e3cf1 100644
62044 --- a/fs/namespace.c
62045 +++ b/fs/namespace.c
62046 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62047 if (!(sb->s_flags & MS_RDONLY))
62048 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62049 up_write(&sb->s_umount);
62050 +
62051 + gr_log_remount(mnt->mnt_devname, retval);
62052 +
62053 return retval;
62054 }
62055
62056 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62057 }
62058 unlock_mount_hash();
62059 namespace_unlock();
62060 +
62061 + gr_log_unmount(mnt->mnt_devname, retval);
62062 +
62063 return retval;
62064 }
62065
62066 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62067 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62068 */
62069
62070 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62071 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62072 {
62073 struct path path;
62074 struct mount *mnt;
62075 @@ -1431,7 +1437,7 @@ out:
62076 /*
62077 * The 2.0 compatible umount. No flags.
62078 */
62079 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62080 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62081 {
62082 return sys_umount(name, 0);
62083 }
62084 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62085 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62086 MS_STRICTATIME);
62087
62088 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62089 + retval = -EPERM;
62090 + goto dput_out;
62091 + }
62092 +
62093 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62094 + retval = -EPERM;
62095 + goto dput_out;
62096 + }
62097 +
62098 if (flags & MS_REMOUNT)
62099 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62100 data_page);
62101 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62102 dev_name, data_page);
62103 dput_out:
62104 path_put(&path);
62105 +
62106 + gr_log_mount(dev_name, dir_name, retval);
62107 +
62108 return retval;
62109 }
62110
62111 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62112 * number incrementing at 10Ghz will take 12,427 years to wrap which
62113 * is effectively never, so we can ignore the possibility.
62114 */
62115 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62116 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62117
62118 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62119 {
62120 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62121 kfree(new_ns);
62122 return ERR_PTR(ret);
62123 }
62124 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62125 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62126 atomic_set(&new_ns->count, 1);
62127 new_ns->root = NULL;
62128 INIT_LIST_HEAD(&new_ns->list);
62129 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62130 return new_ns;
62131 }
62132
62133 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62134 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62135 struct user_namespace *user_ns, struct fs_struct *new_fs)
62136 {
62137 struct mnt_namespace *new_ns;
62138 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62139 }
62140 EXPORT_SYMBOL(mount_subtree);
62141
62142 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62143 - char __user *, type, unsigned long, flags, void __user *, data)
62144 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62145 + const char __user *, type, unsigned long, flags, void __user *, data)
62146 {
62147 int ret;
62148 char *kernel_type;
62149 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62150 if (error)
62151 goto out2;
62152
62153 + if (gr_handle_chroot_pivot()) {
62154 + error = -EPERM;
62155 + goto out2;
62156 + }
62157 +
62158 get_fs_root(current->fs, &root);
62159 old_mp = lock_mount(&old);
62160 error = PTR_ERR(old_mp);
62161 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62162 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62163 return -EPERM;
62164
62165 - if (fs->users != 1)
62166 + if (atomic_read(&fs->users) != 1)
62167 return -EINVAL;
62168
62169 get_mnt_ns(mnt_ns);
62170 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62171 index f4ccfe6..a5cf064 100644
62172 --- a/fs/nfs/callback_xdr.c
62173 +++ b/fs/nfs/callback_xdr.c
62174 @@ -51,7 +51,7 @@ struct callback_op {
62175 callback_decode_arg_t decode_args;
62176 callback_encode_res_t encode_res;
62177 long res_maxsize;
62178 -};
62179 +} __do_const;
62180
62181 static struct callback_op callback_ops[];
62182
62183 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62184 index 0c43897..0949f08 100644
62185 --- a/fs/nfs/inode.c
62186 +++ b/fs/nfs/inode.c
62187 @@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62188 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62189 }
62190
62191 -static atomic_long_t nfs_attr_generation_counter;
62192 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62193
62194 static unsigned long nfs_read_attr_generation_counter(void)
62195 {
62196 - return atomic_long_read(&nfs_attr_generation_counter);
62197 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62198 }
62199
62200 unsigned long nfs_inc_attr_generation_counter(void)
62201 {
62202 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62203 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62204 }
62205
62206 void nfs_fattr_init(struct nfs_fattr *fattr)
62207 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62208 index d543222..2cfa2a2 100644
62209 --- a/fs/nfsd/nfs4proc.c
62210 +++ b/fs/nfsd/nfs4proc.c
62211 @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62212 nfsd4op_rsize op_rsize_bop;
62213 stateid_getter op_get_currentstateid;
62214 stateid_setter op_set_currentstateid;
62215 -};
62216 +} __do_const;
62217
62218 static struct nfsd4_operation nfsd4_ops[];
62219
62220 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62221 index 18881f3..40e5bef 100644
62222 --- a/fs/nfsd/nfs4xdr.c
62223 +++ b/fs/nfsd/nfs4xdr.c
62224 @@ -1530,7 +1530,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62225
62226 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62227
62228 -static nfsd4_dec nfsd4_dec_ops[] = {
62229 +static const nfsd4_dec nfsd4_dec_ops[] = {
62230 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62231 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62232 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62233 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62234 index f8f060f..c4ba09a 100644
62235 --- a/fs/nfsd/nfscache.c
62236 +++ b/fs/nfsd/nfscache.c
62237 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62238 {
62239 struct svc_cacherep *rp = rqstp->rq_cacherep;
62240 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62241 - int len;
62242 + long len;
62243 size_t bufsize = 0;
62244
62245 if (!rp)
62246 return;
62247
62248 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62249 - len >>= 2;
62250 + if (statp) {
62251 + len = (char*)statp - (char*)resv->iov_base;
62252 + len = resv->iov_len - len;
62253 + len >>= 2;
62254 + }
62255
62256 /* Don't cache excessive amounts of data and XDR failures */
62257 if (!statp || len > (256 >> 2)) {
62258 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62259 index 16f0673..1c2c30ab 100644
62260 --- a/fs/nfsd/vfs.c
62261 +++ b/fs/nfsd/vfs.c
62262 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62263 } else {
62264 oldfs = get_fs();
62265 set_fs(KERNEL_DS);
62266 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62267 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62268 set_fs(oldfs);
62269 }
62270
62271 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62272
62273 /* Write the data. */
62274 oldfs = get_fs(); set_fs(KERNEL_DS);
62275 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62276 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62277 set_fs(oldfs);
62278 if (host_err < 0)
62279 goto out_nfserr;
62280 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62281 */
62282
62283 oldfs = get_fs(); set_fs(KERNEL_DS);
62284 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62285 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62286 set_fs(oldfs);
62287
62288 if (host_err < 0)
62289 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62290 index 52ccd34..43a53b1 100644
62291 --- a/fs/nls/nls_base.c
62292 +++ b/fs/nls/nls_base.c
62293 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62294
62295 int __register_nls(struct nls_table *nls, struct module *owner)
62296 {
62297 - struct nls_table ** tmp = &tables;
62298 + struct nls_table *tmp = tables;
62299
62300 if (nls->next)
62301 return -EBUSY;
62302
62303 - nls->owner = owner;
62304 + pax_open_kernel();
62305 + *(void **)&nls->owner = owner;
62306 + pax_close_kernel();
62307 spin_lock(&nls_lock);
62308 - while (*tmp) {
62309 - if (nls == *tmp) {
62310 + while (tmp) {
62311 + if (nls == tmp) {
62312 spin_unlock(&nls_lock);
62313 return -EBUSY;
62314 }
62315 - tmp = &(*tmp)->next;
62316 + tmp = tmp->next;
62317 }
62318 - nls->next = tables;
62319 + pax_open_kernel();
62320 + *(struct nls_table **)&nls->next = tables;
62321 + pax_close_kernel();
62322 tables = nls;
62323 spin_unlock(&nls_lock);
62324 return 0;
62325 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62326
62327 int unregister_nls(struct nls_table * nls)
62328 {
62329 - struct nls_table ** tmp = &tables;
62330 + struct nls_table * const * tmp = &tables;
62331
62332 spin_lock(&nls_lock);
62333 while (*tmp) {
62334 if (nls == *tmp) {
62335 - *tmp = nls->next;
62336 + pax_open_kernel();
62337 + *(struct nls_table **)tmp = nls->next;
62338 + pax_close_kernel();
62339 spin_unlock(&nls_lock);
62340 return 0;
62341 }
62342 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62343 index 162b3f1..6076a7c 100644
62344 --- a/fs/nls/nls_euc-jp.c
62345 +++ b/fs/nls/nls_euc-jp.c
62346 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62347 p_nls = load_nls("cp932");
62348
62349 if (p_nls) {
62350 - table.charset2upper = p_nls->charset2upper;
62351 - table.charset2lower = p_nls->charset2lower;
62352 + pax_open_kernel();
62353 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62354 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62355 + pax_close_kernel();
62356 return register_nls(&table);
62357 }
62358
62359 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62360 index a80a741..7b96e1b 100644
62361 --- a/fs/nls/nls_koi8-ru.c
62362 +++ b/fs/nls/nls_koi8-ru.c
62363 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62364 p_nls = load_nls("koi8-u");
62365
62366 if (p_nls) {
62367 - table.charset2upper = p_nls->charset2upper;
62368 - table.charset2lower = p_nls->charset2lower;
62369 + pax_open_kernel();
62370 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62371 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62372 + pax_close_kernel();
62373 return register_nls(&table);
62374 }
62375
62376 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62377 index 732648b..d3b017f 100644
62378 --- a/fs/notify/fanotify/fanotify_user.c
62379 +++ b/fs/notify/fanotify/fanotify_user.c
62380 @@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62381
62382 fd = fanotify_event_metadata.fd;
62383 ret = -EFAULT;
62384 - if (copy_to_user(buf, &fanotify_event_metadata,
62385 - fanotify_event_metadata.event_len))
62386 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62387 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62388 goto out_close_fd;
62389
62390 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62391 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62392 index 1e58402..bb2d6f4 100644
62393 --- a/fs/notify/notification.c
62394 +++ b/fs/notify/notification.c
62395 @@ -48,7 +48,7 @@
62396 #include <linux/fsnotify_backend.h>
62397 #include "fsnotify.h"
62398
62399 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62400 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62401
62402 /**
62403 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62404 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62405 */
62406 u32 fsnotify_get_cookie(void)
62407 {
62408 - return atomic_inc_return(&fsnotify_sync_cookie);
62409 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62410 }
62411 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62412
62413 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62414 index 9e38daf..5727cae 100644
62415 --- a/fs/ntfs/dir.c
62416 +++ b/fs/ntfs/dir.c
62417 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62418 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62419 ~(s64)(ndir->itype.index.block_size - 1)));
62420 /* Bounds checks. */
62421 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62422 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62423 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62424 "inode 0x%lx or driver bug.", vdir->i_ino);
62425 goto err_out;
62426 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62427 index db9bd8a..8338fb6 100644
62428 --- a/fs/ntfs/file.c
62429 +++ b/fs/ntfs/file.c
62430 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62431 char *addr;
62432 size_t total = 0;
62433 unsigned len;
62434 - int left;
62435 + unsigned left;
62436
62437 do {
62438 len = PAGE_CACHE_SIZE - ofs;
62439 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62440 index 9de2491..3306095 100644
62441 --- a/fs/ntfs/super.c
62442 +++ b/fs/ntfs/super.c
62443 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62444 if (!silent)
62445 ntfs_error(sb, "Primary boot sector is invalid.");
62446 } else if (!silent)
62447 - ntfs_error(sb, read_err_str, "primary");
62448 + ntfs_error(sb, read_err_str, "%s", "primary");
62449 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62450 if (bh_primary)
62451 brelse(bh_primary);
62452 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62453 goto hotfix_primary_boot_sector;
62454 brelse(bh_backup);
62455 } else if (!silent)
62456 - ntfs_error(sb, read_err_str, "backup");
62457 + ntfs_error(sb, read_err_str, "%s", "backup");
62458 /* Try to read NT3.51- backup boot sector. */
62459 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62460 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62461 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62462 "sector.");
62463 brelse(bh_backup);
62464 } else if (!silent)
62465 - ntfs_error(sb, read_err_str, "backup");
62466 + ntfs_error(sb, read_err_str, "%s", "backup");
62467 /* We failed. Cleanup and return. */
62468 if (bh_primary)
62469 brelse(bh_primary);
62470 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62471 index 0440134..d52c93a 100644
62472 --- a/fs/ocfs2/localalloc.c
62473 +++ b/fs/ocfs2/localalloc.c
62474 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62475 goto bail;
62476 }
62477
62478 - atomic_inc(&osb->alloc_stats.moves);
62479 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62480
62481 bail:
62482 if (handle)
62483 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62484 index 8d64a97..c37665d 100644
62485 --- a/fs/ocfs2/ocfs2.h
62486 +++ b/fs/ocfs2/ocfs2.h
62487 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
62488
62489 struct ocfs2_alloc_stats
62490 {
62491 - atomic_t moves;
62492 - atomic_t local_data;
62493 - atomic_t bitmap_data;
62494 - atomic_t bg_allocs;
62495 - atomic_t bg_extends;
62496 + atomic_unchecked_t moves;
62497 + atomic_unchecked_t local_data;
62498 + atomic_unchecked_t bitmap_data;
62499 + atomic_unchecked_t bg_allocs;
62500 + atomic_unchecked_t bg_extends;
62501 };
62502
62503 enum ocfs2_local_alloc_state
62504 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62505 index 0cb889a..6a26b24 100644
62506 --- a/fs/ocfs2/suballoc.c
62507 +++ b/fs/ocfs2/suballoc.c
62508 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62509 mlog_errno(status);
62510 goto bail;
62511 }
62512 - atomic_inc(&osb->alloc_stats.bg_extends);
62513 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62514
62515 /* You should never ask for this much metadata */
62516 BUG_ON(bits_wanted >
62517 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62518 mlog_errno(status);
62519 goto bail;
62520 }
62521 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62522 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62523
62524 *suballoc_loc = res.sr_bg_blkno;
62525 *suballoc_bit_start = res.sr_bit_offset;
62526 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62527 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62528 res->sr_bits);
62529
62530 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62531 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62532
62533 BUG_ON(res->sr_bits != 1);
62534
62535 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62536 mlog_errno(status);
62537 goto bail;
62538 }
62539 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62540 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62541
62542 BUG_ON(res.sr_bits != 1);
62543
62544 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62545 cluster_start,
62546 num_clusters);
62547 if (!status)
62548 - atomic_inc(&osb->alloc_stats.local_data);
62549 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62550 } else {
62551 if (min_clusters > (osb->bitmap_cpg - 1)) {
62552 /* The only paths asking for contiguousness
62553 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62554 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62555 res.sr_bg_blkno,
62556 res.sr_bit_offset);
62557 - atomic_inc(&osb->alloc_stats.bitmap_data);
62558 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62559 *num_clusters = res.sr_bits;
62560 }
62561 }
62562 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62563 index a7cdd56..c583144 100644
62564 --- a/fs/ocfs2/super.c
62565 +++ b/fs/ocfs2/super.c
62566 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62567 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62568 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62569 "Stats",
62570 - atomic_read(&osb->alloc_stats.bitmap_data),
62571 - atomic_read(&osb->alloc_stats.local_data),
62572 - atomic_read(&osb->alloc_stats.bg_allocs),
62573 - atomic_read(&osb->alloc_stats.moves),
62574 - atomic_read(&osb->alloc_stats.bg_extends));
62575 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62576 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62577 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62578 + atomic_read_unchecked(&osb->alloc_stats.moves),
62579 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62580
62581 out += snprintf(buf + out, len - out,
62582 "%10s => State: %u Descriptor: %llu Size: %u bits "
62583 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62584
62585 mutex_init(&osb->system_file_mutex);
62586
62587 - atomic_set(&osb->alloc_stats.moves, 0);
62588 - atomic_set(&osb->alloc_stats.local_data, 0);
62589 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62590 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62591 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62592 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62593 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62594 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62595 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62596 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62597
62598 /* Copy the blockcheck stats from the superblock probe */
62599 osb->osb_ecc_stats = *stats;
62600 diff --git a/fs/open.c b/fs/open.c
62601 index 9d64679..75f925c 100644
62602 --- a/fs/open.c
62603 +++ b/fs/open.c
62604 @@ -32,6 +32,8 @@
62605 #include <linux/dnotify.h>
62606 #include <linux/compat.h>
62607
62608 +#define CREATE_TRACE_POINTS
62609 +#include <trace/events/fs.h>
62610 #include "internal.h"
62611
62612 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62613 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62614 error = locks_verify_truncate(inode, NULL, length);
62615 if (!error)
62616 error = security_path_truncate(path);
62617 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62618 + error = -EACCES;
62619 if (!error)
62620 error = do_truncate(path->dentry, length, 0, NULL);
62621
62622 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62623 error = locks_verify_truncate(inode, f.file, length);
62624 if (!error)
62625 error = security_path_truncate(&f.file->f_path);
62626 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62627 + error = -EACCES;
62628 if (!error)
62629 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62630 sb_end_write(inode->i_sb);
62631 @@ -381,6 +387,9 @@ retry:
62632 if (__mnt_is_readonly(path.mnt))
62633 res = -EROFS;
62634
62635 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62636 + res = -EACCES;
62637 +
62638 out_path_release:
62639 path_put(&path);
62640 if (retry_estale(res, lookup_flags)) {
62641 @@ -412,6 +421,8 @@ retry:
62642 if (error)
62643 goto dput_and_out;
62644
62645 + gr_log_chdir(path.dentry, path.mnt);
62646 +
62647 set_fs_pwd(current->fs, &path);
62648
62649 dput_and_out:
62650 @@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62651 goto out_putf;
62652
62653 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62654 +
62655 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62656 + error = -EPERM;
62657 +
62658 + if (!error)
62659 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62660 +
62661 if (!error)
62662 set_fs_pwd(current->fs, &f.file->f_path);
62663 out_putf:
62664 @@ -470,7 +488,13 @@ retry:
62665 if (error)
62666 goto dput_and_out;
62667
62668 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62669 + goto dput_and_out;
62670 +
62671 set_fs_root(current->fs, &path);
62672 +
62673 + gr_handle_chroot_chdir(&path);
62674 +
62675 error = 0;
62676 dput_and_out:
62677 path_put(&path);
62678 @@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
62679 return error;
62680 retry_deleg:
62681 mutex_lock(&inode->i_mutex);
62682 +
62683 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62684 + error = -EACCES;
62685 + goto out_unlock;
62686 + }
62687 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62688 + error = -EACCES;
62689 + goto out_unlock;
62690 + }
62691 +
62692 error = security_path_chmod(path, mode);
62693 if (error)
62694 goto out_unlock;
62695 @@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62696 uid = make_kuid(current_user_ns(), user);
62697 gid = make_kgid(current_user_ns(), group);
62698
62699 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62700 + return -EACCES;
62701 +
62702 newattrs.ia_valid = ATTR_CTIME;
62703 if (user != (uid_t) -1) {
62704 if (!uid_valid(uid))
62705 @@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62706 } else {
62707 fsnotify_open(f);
62708 fd_install(fd, f);
62709 + trace_do_sys_open(tmp->name, flags, mode);
62710 }
62711 }
62712 putname(tmp);
62713 diff --git a/fs/pipe.c b/fs/pipe.c
62714 index 034bffa..6c6b522 100644
62715 --- a/fs/pipe.c
62716 +++ b/fs/pipe.c
62717 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62718
62719 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62720 {
62721 - if (pipe->files)
62722 + if (atomic_read(&pipe->files))
62723 mutex_lock_nested(&pipe->mutex, subclass);
62724 }
62725
62726 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62727
62728 void pipe_unlock(struct pipe_inode_info *pipe)
62729 {
62730 - if (pipe->files)
62731 + if (atomic_read(&pipe->files))
62732 mutex_unlock(&pipe->mutex);
62733 }
62734 EXPORT_SYMBOL(pipe_unlock);
62735 @@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
62736 }
62737 if (bufs) /* More to do? */
62738 continue;
62739 - if (!pipe->writers)
62740 + if (!atomic_read(&pipe->writers))
62741 break;
62742 - if (!pipe->waiting_writers) {
62743 + if (!atomic_read(&pipe->waiting_writers)) {
62744 /* syscall merging: Usually we must not sleep
62745 * if O_NONBLOCK is set, or if we got some data.
62746 * But if a writer sleeps in kernel space, then
62747 @@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62748 ret = 0;
62749 __pipe_lock(pipe);
62750
62751 - if (!pipe->readers) {
62752 + if (!atomic_read(&pipe->readers)) {
62753 send_sig(SIGPIPE, current, 0);
62754 ret = -EPIPE;
62755 goto out;
62756 @@ -461,7 +461,7 @@ redo1:
62757 for (;;) {
62758 int bufs;
62759
62760 - if (!pipe->readers) {
62761 + if (!atomic_read(&pipe->readers)) {
62762 send_sig(SIGPIPE, current, 0);
62763 if (!ret)
62764 ret = -EPIPE;
62765 @@ -552,9 +552,9 @@ redo2:
62766 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62767 do_wakeup = 0;
62768 }
62769 - pipe->waiting_writers++;
62770 + atomic_inc(&pipe->waiting_writers);
62771 pipe_wait(pipe);
62772 - pipe->waiting_writers--;
62773 + atomic_dec(&pipe->waiting_writers);
62774 }
62775 out:
62776 __pipe_unlock(pipe);
62777 @@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62778 mask = 0;
62779 if (filp->f_mode & FMODE_READ) {
62780 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62781 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62782 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62783 mask |= POLLHUP;
62784 }
62785
62786 @@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62787 * Most Unices do not set POLLERR for FIFOs but on Linux they
62788 * behave exactly like pipes for poll().
62789 */
62790 - if (!pipe->readers)
62791 + if (!atomic_read(&pipe->readers))
62792 mask |= POLLERR;
62793 }
62794
62795 @@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62796 int kill = 0;
62797
62798 spin_lock(&inode->i_lock);
62799 - if (!--pipe->files) {
62800 + if (atomic_dec_and_test(&pipe->files)) {
62801 inode->i_pipe = NULL;
62802 kill = 1;
62803 }
62804 @@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
62805
62806 __pipe_lock(pipe);
62807 if (file->f_mode & FMODE_READ)
62808 - pipe->readers--;
62809 + atomic_dec(&pipe->readers);
62810 if (file->f_mode & FMODE_WRITE)
62811 - pipe->writers--;
62812 + atomic_dec(&pipe->writers);
62813
62814 - if (pipe->readers || pipe->writers) {
62815 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62816 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62817 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62818 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62819 @@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62820 kfree(pipe);
62821 }
62822
62823 -static struct vfsmount *pipe_mnt __read_mostly;
62824 +struct vfsmount *pipe_mnt __read_mostly;
62825
62826 /*
62827 * pipefs_dname() is called from d_path().
62828 @@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
62829 goto fail_iput;
62830
62831 inode->i_pipe = pipe;
62832 - pipe->files = 2;
62833 - pipe->readers = pipe->writers = 1;
62834 + atomic_set(&pipe->files, 2);
62835 + atomic_set(&pipe->readers, 1);
62836 + atomic_set(&pipe->writers, 1);
62837 inode->i_fop = &pipefifo_fops;
62838
62839 /*
62840 @@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62841 spin_lock(&inode->i_lock);
62842 if (inode->i_pipe) {
62843 pipe = inode->i_pipe;
62844 - pipe->files++;
62845 + atomic_inc(&pipe->files);
62846 spin_unlock(&inode->i_lock);
62847 } else {
62848 spin_unlock(&inode->i_lock);
62849 pipe = alloc_pipe_info();
62850 if (!pipe)
62851 return -ENOMEM;
62852 - pipe->files = 1;
62853 + atomic_set(&pipe->files, 1);
62854 spin_lock(&inode->i_lock);
62855 if (unlikely(inode->i_pipe)) {
62856 - inode->i_pipe->files++;
62857 + atomic_inc(&inode->i_pipe->files);
62858 spin_unlock(&inode->i_lock);
62859 free_pipe_info(pipe);
62860 pipe = inode->i_pipe;
62861 @@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62862 * opened, even when there is no process writing the FIFO.
62863 */
62864 pipe->r_counter++;
62865 - if (pipe->readers++ == 0)
62866 + if (atomic_inc_return(&pipe->readers) == 1)
62867 wake_up_partner(pipe);
62868
62869 - if (!is_pipe && !pipe->writers) {
62870 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62871 if ((filp->f_flags & O_NONBLOCK)) {
62872 /* suppress POLLHUP until we have
62873 * seen a writer */
62874 @@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62875 * errno=ENXIO when there is no process reading the FIFO.
62876 */
62877 ret = -ENXIO;
62878 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62879 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62880 goto err;
62881
62882 pipe->w_counter++;
62883 - if (!pipe->writers++)
62884 + if (atomic_inc_return(&pipe->writers) == 1)
62885 wake_up_partner(pipe);
62886
62887 - if (!is_pipe && !pipe->readers) {
62888 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62889 if (wait_for_partner(pipe, &pipe->r_counter))
62890 goto err_wr;
62891 }
62892 @@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62893 * the process can at least talk to itself.
62894 */
62895
62896 - pipe->readers++;
62897 - pipe->writers++;
62898 + atomic_inc(&pipe->readers);
62899 + atomic_inc(&pipe->writers);
62900 pipe->r_counter++;
62901 pipe->w_counter++;
62902 - if (pipe->readers == 1 || pipe->writers == 1)
62903 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62904 wake_up_partner(pipe);
62905 break;
62906
62907 @@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62908 return 0;
62909
62910 err_rd:
62911 - if (!--pipe->readers)
62912 + if (atomic_dec_and_test(&pipe->readers))
62913 wake_up_interruptible(&pipe->wait);
62914 ret = -ERESTARTSYS;
62915 goto err;
62916
62917 err_wr:
62918 - if (!--pipe->writers)
62919 + if (atomic_dec_and_test(&pipe->writers))
62920 wake_up_interruptible(&pipe->wait);
62921 ret = -ERESTARTSYS;
62922 goto err;
62923 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62924 index 0855f77..6787d50 100644
62925 --- a/fs/posix_acl.c
62926 +++ b/fs/posix_acl.c
62927 @@ -20,6 +20,7 @@
62928 #include <linux/xattr.h>
62929 #include <linux/export.h>
62930 #include <linux/user_namespace.h>
62931 +#include <linux/grsecurity.h>
62932
62933 struct posix_acl **acl_by_type(struct inode *inode, int type)
62934 {
62935 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62936 }
62937 }
62938 if (mode_p)
62939 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62940 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62941 return not_equiv;
62942 }
62943 EXPORT_SYMBOL(posix_acl_equiv_mode);
62944 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62945 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62946 }
62947
62948 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62949 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62950 return not_equiv;
62951 }
62952
62953 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62954 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62955 int err = -ENOMEM;
62956 if (clone) {
62957 + *mode_p &= ~gr_acl_umask();
62958 +
62959 err = posix_acl_create_masq(clone, mode_p);
62960 if (err < 0) {
62961 posix_acl_release(clone);
62962 @@ -659,11 +662,12 @@ struct posix_acl *
62963 posix_acl_from_xattr(struct user_namespace *user_ns,
62964 const void *value, size_t size)
62965 {
62966 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62967 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62968 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62969 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62970 int count;
62971 struct posix_acl *acl;
62972 struct posix_acl_entry *acl_e;
62973 + umode_t umask = gr_acl_umask();
62974
62975 if (!value)
62976 return NULL;
62977 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62978
62979 switch(acl_e->e_tag) {
62980 case ACL_USER_OBJ:
62981 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62982 + break;
62983 case ACL_GROUP_OBJ:
62984 case ACL_MASK:
62985 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62986 + break;
62987 case ACL_OTHER:
62988 + acl_e->e_perm &= ~(umask & S_IRWXO);
62989 break;
62990
62991 case ACL_USER:
62992 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62993 acl_e->e_uid =
62994 make_kuid(user_ns,
62995 le32_to_cpu(entry->e_id));
62996 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62997 goto fail;
62998 break;
62999 case ACL_GROUP:
63000 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63001 acl_e->e_gid =
63002 make_kgid(user_ns,
63003 le32_to_cpu(entry->e_id));
63004 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63005 index 2183fcf..3c32a98 100644
63006 --- a/fs/proc/Kconfig
63007 +++ b/fs/proc/Kconfig
63008 @@ -30,7 +30,7 @@ config PROC_FS
63009
63010 config PROC_KCORE
63011 bool "/proc/kcore support" if !ARM
63012 - depends on PROC_FS && MMU
63013 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63014 help
63015 Provides a virtual ELF core file of the live kernel. This can
63016 be read with gdb and other ELF tools. No modifications can be
63017 @@ -38,8 +38,8 @@ config PROC_KCORE
63018
63019 config PROC_VMCORE
63020 bool "/proc/vmcore support"
63021 - depends on PROC_FS && CRASH_DUMP
63022 - default y
63023 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63024 + default n
63025 help
63026 Exports the dump image of crashed kernel in ELF format.
63027
63028 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63029 limited in memory.
63030
63031 config PROC_PAGE_MONITOR
63032 - default y
63033 - depends on PROC_FS && MMU
63034 + default n
63035 + depends on PROC_FS && MMU && !GRKERNSEC
63036 bool "Enable /proc page monitoring" if EXPERT
63037 help
63038 Various /proc files exist to monitor process memory utilization:
63039 diff --git a/fs/proc/array.c b/fs/proc/array.c
63040 index 64db2bc..a8185d6 100644
63041 --- a/fs/proc/array.c
63042 +++ b/fs/proc/array.c
63043 @@ -60,6 +60,7 @@
63044 #include <linux/tty.h>
63045 #include <linux/string.h>
63046 #include <linux/mman.h>
63047 +#include <linux/grsecurity.h>
63048 #include <linux/proc_fs.h>
63049 #include <linux/ioport.h>
63050 #include <linux/uaccess.h>
63051 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63052 seq_putc(m, '\n');
63053 }
63054
63055 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63056 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63057 +{
63058 + if (p->mm)
63059 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63060 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63061 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63062 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63063 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63064 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63065 + else
63066 + seq_printf(m, "PaX:\t-----\n");
63067 +}
63068 +#endif
63069 +
63070 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63071 struct pid *pid, struct task_struct *task)
63072 {
63073 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63074 task_cpus_allowed(m, task);
63075 cpuset_task_status_allowed(m, task);
63076 task_context_switch_counts(m, task);
63077 +
63078 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63079 + task_pax(m, task);
63080 +#endif
63081 +
63082 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63083 + task_grsec_rbac(m, task);
63084 +#endif
63085 +
63086 return 0;
63087 }
63088
63089 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63090 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63091 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63092 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63093 +#endif
63094 +
63095 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63096 struct pid *pid, struct task_struct *task, int whole)
63097 {
63098 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63099 char tcomm[sizeof(task->comm)];
63100 unsigned long flags;
63101
63102 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63103 + if (current->exec_id != m->exec_id) {
63104 + gr_log_badprocpid("stat");
63105 + return 0;
63106 + }
63107 +#endif
63108 +
63109 state = *get_task_state(task);
63110 vsize = eip = esp = 0;
63111 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63112 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63113 gtime = task_gtime(task);
63114 }
63115
63116 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63117 + if (PAX_RAND_FLAGS(mm)) {
63118 + eip = 0;
63119 + esp = 0;
63120 + wchan = 0;
63121 + }
63122 +#endif
63123 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63124 + wchan = 0;
63125 + eip =0;
63126 + esp =0;
63127 +#endif
63128 +
63129 /* scale priority and nice values from timeslices to -20..20 */
63130 /* to make it look like a "normal" Unix priority/nice value */
63131 priority = task_prio(task);
63132 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63133 seq_put_decimal_ull(m, ' ', vsize);
63134 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63135 seq_put_decimal_ull(m, ' ', rsslim);
63136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63137 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63138 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63139 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63140 +#else
63141 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63142 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63143 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63144 +#endif
63145 seq_put_decimal_ull(m, ' ', esp);
63146 seq_put_decimal_ull(m, ' ', eip);
63147 /* The signal information here is obsolete.
63148 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63149 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63150 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63151
63152 - if (mm && permitted) {
63153 + if (mm && permitted
63154 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63155 + && !PAX_RAND_FLAGS(mm)
63156 +#endif
63157 + ) {
63158 seq_put_decimal_ull(m, ' ', mm->start_data);
63159 seq_put_decimal_ull(m, ' ', mm->end_data);
63160 seq_put_decimal_ull(m, ' ', mm->start_brk);
63161 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63162 struct pid *pid, struct task_struct *task)
63163 {
63164 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63165 - struct mm_struct *mm = get_task_mm(task);
63166 + struct mm_struct *mm;
63167
63168 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63169 + if (current->exec_id != m->exec_id) {
63170 + gr_log_badprocpid("statm");
63171 + return 0;
63172 + }
63173 +#endif
63174 + mm = get_task_mm(task);
63175 if (mm) {
63176 size = task_statm(mm, &shared, &text, &data, &resident);
63177 mmput(mm);
63178 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63179 return 0;
63180 }
63181
63182 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63183 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63184 +{
63185 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63186 +}
63187 +#endif
63188 +
63189 #ifdef CONFIG_CHECKPOINT_RESTORE
63190 static struct pid *
63191 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63192 diff --git a/fs/proc/base.c b/fs/proc/base.c
63193 index 2d696b0..b9da447 100644
63194 --- a/fs/proc/base.c
63195 +++ b/fs/proc/base.c
63196 @@ -113,6 +113,14 @@ struct pid_entry {
63197 union proc_op op;
63198 };
63199
63200 +struct getdents_callback {
63201 + struct linux_dirent __user * current_dir;
63202 + struct linux_dirent __user * previous;
63203 + struct file * file;
63204 + int count;
63205 + int error;
63206 +};
63207 +
63208 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63209 .name = (NAME), \
63210 .len = sizeof(NAME) - 1, \
63211 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63212 return get_cmdline(task, buffer, PAGE_SIZE);
63213 }
63214
63215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63216 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63217 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63218 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63219 +#endif
63220 +
63221 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63222 {
63223 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63224 int res = PTR_ERR(mm);
63225 if (mm && !IS_ERR(mm)) {
63226 unsigned int nwords = 0;
63227 +
63228 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63229 + /* allow if we're currently ptracing this task */
63230 + if (PAX_RAND_FLAGS(mm) &&
63231 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63232 + mmput(mm);
63233 + return 0;
63234 + }
63235 +#endif
63236 +
63237 do {
63238 nwords += 2;
63239 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63240 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63241 }
63242
63243
63244 -#ifdef CONFIG_KALLSYMS
63245 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63246 /*
63247 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63248 * Returns the resolved symbol. If that fails, simply return the address.
63249 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63250 mutex_unlock(&task->signal->cred_guard_mutex);
63251 }
63252
63253 -#ifdef CONFIG_STACKTRACE
63254 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63255
63256 #define MAX_STACK_TRACE_DEPTH 64
63257
63258 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63259 return count;
63260 }
63261
63262 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63263 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63264 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63265 {
63266 long nr;
63267 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63268 /************************************************************************/
63269
63270 /* permission checks */
63271 -static int proc_fd_access_allowed(struct inode *inode)
63272 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63273 {
63274 struct task_struct *task;
63275 int allowed = 0;
63276 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63277 */
63278 task = get_proc_task(inode);
63279 if (task) {
63280 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63281 + if (log)
63282 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63283 + else
63284 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63285 put_task_struct(task);
63286 }
63287 return allowed;
63288 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63289 struct task_struct *task,
63290 int hide_pid_min)
63291 {
63292 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63293 + return false;
63294 +
63295 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63296 + rcu_read_lock();
63297 + {
63298 + const struct cred *tmpcred = current_cred();
63299 + const struct cred *cred = __task_cred(task);
63300 +
63301 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63302 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63303 + || in_group_p(grsec_proc_gid)
63304 +#endif
63305 + ) {
63306 + rcu_read_unlock();
63307 + return true;
63308 + }
63309 + }
63310 + rcu_read_unlock();
63311 +
63312 + if (!pid->hide_pid)
63313 + return false;
63314 +#endif
63315 +
63316 if (pid->hide_pid < hide_pid_min)
63317 return true;
63318 if (in_group_p(pid->pid_gid))
63319 return true;
63320 +
63321 return ptrace_may_access(task, PTRACE_MODE_READ);
63322 }
63323
63324 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63325 put_task_struct(task);
63326
63327 if (!has_perms) {
63328 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63329 + {
63330 +#else
63331 if (pid->hide_pid == 2) {
63332 +#endif
63333 /*
63334 * Let's make getdents(), stat(), and open()
63335 * consistent with each other. If a process
63336 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63337 if (!task)
63338 return -ESRCH;
63339
63340 + if (gr_acl_handle_procpidmem(task)) {
63341 + put_task_struct(task);
63342 + return -EPERM;
63343 + }
63344 +
63345 mm = mm_access(task, mode);
63346 put_task_struct(task);
63347
63348 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63349
63350 file->private_data = mm;
63351
63352 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63353 + file->f_version = current->exec_id;
63354 +#endif
63355 +
63356 return 0;
63357 }
63358
63359 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63360 ssize_t copied;
63361 char *page;
63362
63363 +#ifdef CONFIG_GRKERNSEC
63364 + if (write)
63365 + return -EPERM;
63366 +#endif
63367 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63368 + if (file->f_version != current->exec_id) {
63369 + gr_log_badprocpid("mem");
63370 + return 0;
63371 + }
63372 +#endif
63373 +
63374 if (!mm)
63375 return 0;
63376
63377 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63378 goto free;
63379
63380 while (count > 0) {
63381 - int this_len = min_t(int, count, PAGE_SIZE);
63382 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63383
63384 if (write && copy_from_user(page, buf, this_len)) {
63385 copied = -EFAULT;
63386 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63387 if (!mm)
63388 return 0;
63389
63390 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63391 + if (file->f_version != current->exec_id) {
63392 + gr_log_badprocpid("environ");
63393 + return 0;
63394 + }
63395 +#endif
63396 +
63397 page = (char *)__get_free_page(GFP_TEMPORARY);
63398 if (!page)
63399 return -ENOMEM;
63400 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63401 goto free;
63402 while (count > 0) {
63403 size_t this_len, max_len;
63404 - int retval;
63405 + ssize_t retval;
63406
63407 if (src >= (mm->env_end - mm->env_start))
63408 break;
63409 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63410 int error = -EACCES;
63411
63412 /* Are we allowed to snoop on the tasks file descriptors? */
63413 - if (!proc_fd_access_allowed(inode))
63414 + if (!proc_fd_access_allowed(inode, 0))
63415 goto out;
63416
63417 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63418 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63419 struct path path;
63420
63421 /* Are we allowed to snoop on the tasks file descriptors? */
63422 - if (!proc_fd_access_allowed(inode))
63423 - goto out;
63424 + /* logging this is needed for learning on chromium to work properly,
63425 + but we don't want to flood the logs from 'ps' which does a readlink
63426 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63427 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63428 + */
63429 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63430 + if (!proc_fd_access_allowed(inode,0))
63431 + goto out;
63432 + } else {
63433 + if (!proc_fd_access_allowed(inode,1))
63434 + goto out;
63435 + }
63436
63437 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63438 if (error)
63439 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63440 rcu_read_lock();
63441 cred = __task_cred(task);
63442 inode->i_uid = cred->euid;
63443 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63444 + inode->i_gid = grsec_proc_gid;
63445 +#else
63446 inode->i_gid = cred->egid;
63447 +#endif
63448 rcu_read_unlock();
63449 }
63450 security_task_to_inode(task, inode);
63451 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63452 return -ENOENT;
63453 }
63454 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63455 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63456 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63457 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63458 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63459 +#endif
63460 task_dumpable(task)) {
63461 cred = __task_cred(task);
63462 stat->uid = cred->euid;
63463 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63464 + stat->gid = grsec_proc_gid;
63465 +#else
63466 stat->gid = cred->egid;
63467 +#endif
63468 }
63469 }
63470 rcu_read_unlock();
63471 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63472
63473 if (task) {
63474 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63475 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63476 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63477 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63478 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63479 +#endif
63480 task_dumpable(task)) {
63481 rcu_read_lock();
63482 cred = __task_cred(task);
63483 inode->i_uid = cred->euid;
63484 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63485 + inode->i_gid = grsec_proc_gid;
63486 +#else
63487 inode->i_gid = cred->egid;
63488 +#endif
63489 rcu_read_unlock();
63490 } else {
63491 inode->i_uid = GLOBAL_ROOT_UID;
63492 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63493 if (!task)
63494 goto out_no_task;
63495
63496 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63497 + goto out;
63498 +
63499 /*
63500 * Yes, it does not scale. And it should not. Don't add
63501 * new entries into /proc/<tgid>/ without very good reasons.
63502 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63503 if (!task)
63504 return -ENOENT;
63505
63506 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63507 + goto out;
63508 +
63509 if (!dir_emit_dots(file, ctx))
63510 goto out;
63511
63512 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63513 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63514 #endif
63515 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63516 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63517 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63518 INF("syscall", S_IRUSR, proc_pid_syscall),
63519 #endif
63520 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63521 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63522 #ifdef CONFIG_SECURITY
63523 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63524 #endif
63525 -#ifdef CONFIG_KALLSYMS
63526 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63527 INF("wchan", S_IRUGO, proc_pid_wchan),
63528 #endif
63529 -#ifdef CONFIG_STACKTRACE
63530 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63531 ONE("stack", S_IRUSR, proc_pid_stack),
63532 #endif
63533 #ifdef CONFIG_SCHEDSTATS
63534 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63535 #ifdef CONFIG_HARDWALL
63536 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63537 #endif
63538 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63539 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63540 +#endif
63541 #ifdef CONFIG_USER_NS
63542 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63543 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63544 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63545 if (!inode)
63546 goto out;
63547
63548 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63549 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63550 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63551 + inode->i_gid = grsec_proc_gid;
63552 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63553 +#else
63554 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63555 +#endif
63556 inode->i_op = &proc_tgid_base_inode_operations;
63557 inode->i_fop = &proc_tgid_base_operations;
63558 inode->i_flags|=S_IMMUTABLE;
63559 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63560 if (!task)
63561 goto out;
63562
63563 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63564 + goto out_put_task;
63565 +
63566 result = proc_pid_instantiate(dir, dentry, task, NULL);
63567 +out_put_task:
63568 put_task_struct(task);
63569 out:
63570 return ERR_PTR(result);
63571 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63572 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63573 #endif
63574 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63575 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63576 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63577 INF("syscall", S_IRUSR, proc_pid_syscall),
63578 #endif
63579 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63580 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63581 #ifdef CONFIG_SECURITY
63582 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63583 #endif
63584 -#ifdef CONFIG_KALLSYMS
63585 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63586 INF("wchan", S_IRUGO, proc_pid_wchan),
63587 #endif
63588 -#ifdef CONFIG_STACKTRACE
63589 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63590 ONE("stack", S_IRUSR, proc_pid_stack),
63591 #endif
63592 #ifdef CONFIG_SCHEDSTATS
63593 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63594 index cbd82df..c0407d2 100644
63595 --- a/fs/proc/cmdline.c
63596 +++ b/fs/proc/cmdline.c
63597 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63598
63599 static int __init proc_cmdline_init(void)
63600 {
63601 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63602 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63603 +#else
63604 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63605 +#endif
63606 return 0;
63607 }
63608 fs_initcall(proc_cmdline_init);
63609 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63610 index 50493ed..248166b 100644
63611 --- a/fs/proc/devices.c
63612 +++ b/fs/proc/devices.c
63613 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63614
63615 static int __init proc_devices_init(void)
63616 {
63617 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63618 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63619 +#else
63620 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63621 +#endif
63622 return 0;
63623 }
63624 fs_initcall(proc_devices_init);
63625 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63626 index 0788d09..9cc1385 100644
63627 --- a/fs/proc/fd.c
63628 +++ b/fs/proc/fd.c
63629 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63630 if (!task)
63631 return -ENOENT;
63632
63633 - files = get_files_struct(task);
63634 + if (!gr_acl_handle_procpidmem(task))
63635 + files = get_files_struct(task);
63636 put_task_struct(task);
63637
63638 if (files) {
63639 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63640 */
63641 int proc_fd_permission(struct inode *inode, int mask)
63642 {
63643 + struct task_struct *task;
63644 int rv = generic_permission(inode, mask);
63645 - if (rv == 0)
63646 - return 0;
63647 +
63648 if (task_tgid(current) == proc_pid(inode))
63649 rv = 0;
63650 +
63651 + task = get_proc_task(inode);
63652 + if (task == NULL)
63653 + return rv;
63654 +
63655 + if (gr_acl_handle_procpidmem(task))
63656 + rv = -EACCES;
63657 +
63658 + put_task_struct(task);
63659 +
63660 return rv;
63661 }
63662
63663 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63664 index b7f268e..3bea6b7 100644
63665 --- a/fs/proc/generic.c
63666 +++ b/fs/proc/generic.c
63667 @@ -23,6 +23,7 @@
63668 #include <linux/bitops.h>
63669 #include <linux/spinlock.h>
63670 #include <linux/completion.h>
63671 +#include <linux/grsecurity.h>
63672 #include <asm/uaccess.h>
63673
63674 #include "internal.h"
63675 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63676 return proc_lookup_de(PDE(dir), dir, dentry);
63677 }
63678
63679 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63680 + unsigned int flags)
63681 +{
63682 + if (gr_proc_is_restricted())
63683 + return ERR_PTR(-EACCES);
63684 +
63685 + return proc_lookup_de(PDE(dir), dir, dentry);
63686 +}
63687 +
63688 /*
63689 * This returns non-zero if at EOF, so that the /proc
63690 * root directory can use this and check if it should
63691 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63692 return proc_readdir_de(PDE(inode), file, ctx);
63693 }
63694
63695 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63696 +{
63697 + struct inode *inode = file_inode(file);
63698 +
63699 + if (gr_proc_is_restricted())
63700 + return -EACCES;
63701 +
63702 + return proc_readdir_de(PDE(inode), file, ctx);
63703 +}
63704 +
63705 /*
63706 * These are the generic /proc directory operations. They
63707 * use the in-memory "struct proc_dir_entry" tree to parse
63708 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63709 .iterate = proc_readdir,
63710 };
63711
63712 +static const struct file_operations proc_dir_restricted_operations = {
63713 + .llseek = generic_file_llseek,
63714 + .read = generic_read_dir,
63715 + .iterate = proc_readdir_restrict,
63716 +};
63717 +
63718 /*
63719 * proc directories can do almost nothing..
63720 */
63721 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63722 .setattr = proc_notify_change,
63723 };
63724
63725 +static const struct inode_operations proc_dir_restricted_inode_operations = {
63726 + .lookup = proc_lookup_restrict,
63727 + .getattr = proc_getattr,
63728 + .setattr = proc_notify_change,
63729 +};
63730 +
63731 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63732 {
63733 struct proc_dir_entry *tmp;
63734 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63735 return ret;
63736
63737 if (S_ISDIR(dp->mode)) {
63738 - dp->proc_fops = &proc_dir_operations;
63739 - dp->proc_iops = &proc_dir_inode_operations;
63740 + if (dp->restricted) {
63741 + dp->proc_fops = &proc_dir_restricted_operations;
63742 + dp->proc_iops = &proc_dir_restricted_inode_operations;
63743 + } else {
63744 + dp->proc_fops = &proc_dir_operations;
63745 + dp->proc_iops = &proc_dir_inode_operations;
63746 + }
63747 dir->nlink++;
63748 } else if (S_ISLNK(dp->mode)) {
63749 dp->proc_iops = &proc_link_inode_operations;
63750 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63751 }
63752 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63753
63754 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63755 + struct proc_dir_entry *parent, void *data)
63756 +{
63757 + struct proc_dir_entry *ent;
63758 +
63759 + if (mode == 0)
63760 + mode = S_IRUGO | S_IXUGO;
63761 +
63762 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63763 + if (ent) {
63764 + ent->data = data;
63765 + ent->restricted = 1;
63766 + if (proc_register(parent, ent) < 0) {
63767 + kfree(ent);
63768 + ent = NULL;
63769 + }
63770 + }
63771 + return ent;
63772 +}
63773 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63774 +
63775 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63776 struct proc_dir_entry *parent)
63777 {
63778 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63779 }
63780 EXPORT_SYMBOL(proc_mkdir);
63781
63782 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63783 + struct proc_dir_entry *parent)
63784 +{
63785 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
63786 +}
63787 +EXPORT_SYMBOL(proc_mkdir_restrict);
63788 +
63789 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63790 struct proc_dir_entry *parent,
63791 const struct file_operations *proc_fops,
63792 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63793 index 0adbc02..bee4d0b 100644
63794 --- a/fs/proc/inode.c
63795 +++ b/fs/proc/inode.c
63796 @@ -23,11 +23,17 @@
63797 #include <linux/slab.h>
63798 #include <linux/mount.h>
63799 #include <linux/magic.h>
63800 +#include <linux/grsecurity.h>
63801
63802 #include <asm/uaccess.h>
63803
63804 #include "internal.h"
63805
63806 +#ifdef CONFIG_PROC_SYSCTL
63807 +extern const struct inode_operations proc_sys_inode_operations;
63808 +extern const struct inode_operations proc_sys_dir_operations;
63809 +#endif
63810 +
63811 static void proc_evict_inode(struct inode *inode)
63812 {
63813 struct proc_dir_entry *de;
63814 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63815 ns = PROC_I(inode)->ns.ns;
63816 if (ns_ops && ns)
63817 ns_ops->put(ns);
63818 +
63819 +#ifdef CONFIG_PROC_SYSCTL
63820 + if (inode->i_op == &proc_sys_inode_operations ||
63821 + inode->i_op == &proc_sys_dir_operations)
63822 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63823 +#endif
63824 +
63825 }
63826
63827 static struct kmem_cache * proc_inode_cachep;
63828 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63829 if (de->mode) {
63830 inode->i_mode = de->mode;
63831 inode->i_uid = de->uid;
63832 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63833 + inode->i_gid = grsec_proc_gid;
63834 +#else
63835 inode->i_gid = de->gid;
63836 +#endif
63837 }
63838 if (de->size)
63839 inode->i_size = de->size;
63840 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63841 index 3ab6d14..b26174e 100644
63842 --- a/fs/proc/internal.h
63843 +++ b/fs/proc/internal.h
63844 @@ -46,9 +46,10 @@ struct proc_dir_entry {
63845 struct completion *pde_unload_completion;
63846 struct list_head pde_openers; /* who did ->open, but not ->release */
63847 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63848 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63849 u8 namelen;
63850 char name[];
63851 -};
63852 +} __randomize_layout;
63853
63854 union proc_op {
63855 int (*proc_get_link)(struct dentry *, struct path *);
63856 @@ -67,7 +68,7 @@ struct proc_inode {
63857 struct ctl_table *sysctl_entry;
63858 struct proc_ns ns;
63859 struct inode vfs_inode;
63860 -};
63861 +} __randomize_layout;
63862
63863 /*
63864 * General functions
63865 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63866 struct pid *, struct task_struct *);
63867 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63868 struct pid *, struct task_struct *);
63869 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63870 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63871 +#endif
63872
63873 /*
63874 * base.c
63875 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63876 extern spinlock_t proc_subdir_lock;
63877
63878 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63879 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63880 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63881 struct dentry *);
63882 extern int proc_readdir(struct file *, struct dir_context *);
63883 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
63884 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63885
63886 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63887 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63888 index a352d57..cb94a5c 100644
63889 --- a/fs/proc/interrupts.c
63890 +++ b/fs/proc/interrupts.c
63891 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63892
63893 static int __init proc_interrupts_init(void)
63894 {
63895 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63896 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63897 +#else
63898 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63899 +#endif
63900 return 0;
63901 }
63902 fs_initcall(proc_interrupts_init);
63903 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63904 index 39e6ef3..2f9cb5e 100644
63905 --- a/fs/proc/kcore.c
63906 +++ b/fs/proc/kcore.c
63907 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63908 * the addresses in the elf_phdr on our list.
63909 */
63910 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63911 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63912 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63913 + if (tsz > buflen)
63914 tsz = buflen;
63915 -
63916 +
63917 while (buflen) {
63918 struct kcore_list *m;
63919
63920 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63921 kfree(elf_buf);
63922 } else {
63923 if (kern_addr_valid(start)) {
63924 - unsigned long n;
63925 + char *elf_buf;
63926 + mm_segment_t oldfs;
63927
63928 - n = copy_to_user(buffer, (char *)start, tsz);
63929 - /*
63930 - * We cannot distinguish between fault on source
63931 - * and fault on destination. When this happens
63932 - * we clear too and hope it will trigger the
63933 - * EFAULT again.
63934 - */
63935 - if (n) {
63936 - if (clear_user(buffer + tsz - n,
63937 - n))
63938 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63939 + if (!elf_buf)
63940 + return -ENOMEM;
63941 + oldfs = get_fs();
63942 + set_fs(KERNEL_DS);
63943 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63944 + set_fs(oldfs);
63945 + if (copy_to_user(buffer, elf_buf, tsz)) {
63946 + kfree(elf_buf);
63947 return -EFAULT;
63948 + }
63949 }
63950 + set_fs(oldfs);
63951 + kfree(elf_buf);
63952 } else {
63953 if (clear_user(buffer, tsz))
63954 return -EFAULT;
63955 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63956
63957 static int open_kcore(struct inode *inode, struct file *filp)
63958 {
63959 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63960 + return -EPERM;
63961 +#endif
63962 if (!capable(CAP_SYS_RAWIO))
63963 return -EPERM;
63964 if (kcore_need_update)
63965 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63966 index 7445af0..7c5113c 100644
63967 --- a/fs/proc/meminfo.c
63968 +++ b/fs/proc/meminfo.c
63969 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63970 vmi.used >> 10,
63971 vmi.largest_chunk >> 10
63972 #ifdef CONFIG_MEMORY_FAILURE
63973 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63974 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63975 #endif
63976 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63977 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63978 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63979 index d4a3574..b421ce9 100644
63980 --- a/fs/proc/nommu.c
63981 +++ b/fs/proc/nommu.c
63982 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63983
63984 if (file) {
63985 seq_pad(m, ' ');
63986 - seq_path(m, &file->f_path, "");
63987 + seq_path(m, &file->f_path, "\n\\");
63988 }
63989
63990 seq_putc(m, '\n');
63991 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63992 index 4677bb7..94067cd 100644
63993 --- a/fs/proc/proc_net.c
63994 +++ b/fs/proc/proc_net.c
63995 @@ -23,6 +23,7 @@
63996 #include <linux/nsproxy.h>
63997 #include <net/net_namespace.h>
63998 #include <linux/seq_file.h>
63999 +#include <linux/grsecurity.h>
64000
64001 #include "internal.h"
64002
64003 @@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64004 return maybe_get_net(PDE_NET(PDE(inode)));
64005 }
64006
64007 +extern const struct seq_operations dev_seq_ops;
64008 +
64009 int seq_open_net(struct inode *ino, struct file *f,
64010 const struct seq_operations *ops, int size)
64011 {
64012 @@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64013
64014 BUG_ON(size < sizeof(*p));
64015
64016 + /* only permit access to /proc/net/dev */
64017 + if (ops != &dev_seq_ops && gr_proc_is_restricted())
64018 + return -EACCES;
64019 +
64020 net = get_proc_net(ino);
64021 if (net == NULL)
64022 return -ENXIO;
64023 @@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64024 int err;
64025 struct net *net;
64026
64027 + if (gr_proc_is_restricted())
64028 + return -EACCES;
64029 +
64030 err = -ENXIO;
64031 net = get_proc_net(inode);
64032 if (net == NULL)
64033 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64034 index 7129046..6914844 100644
64035 --- a/fs/proc/proc_sysctl.c
64036 +++ b/fs/proc/proc_sysctl.c
64037 @@ -11,13 +11,21 @@
64038 #include <linux/namei.h>
64039 #include <linux/mm.h>
64040 #include <linux/module.h>
64041 +#include <linux/nsproxy.h>
64042 +#ifdef CONFIG_GRKERNSEC
64043 +#include <net/net_namespace.h>
64044 +#endif
64045 #include "internal.h"
64046
64047 +extern int gr_handle_chroot_sysctl(const int op);
64048 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64049 + const int op);
64050 +
64051 static const struct dentry_operations proc_sys_dentry_operations;
64052 static const struct file_operations proc_sys_file_operations;
64053 -static const struct inode_operations proc_sys_inode_operations;
64054 +const struct inode_operations proc_sys_inode_operations;
64055 static const struct file_operations proc_sys_dir_file_operations;
64056 -static const struct inode_operations proc_sys_dir_operations;
64057 +const struct inode_operations proc_sys_dir_operations;
64058
64059 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64060 {
64061 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64062
64063 err = NULL;
64064 d_set_d_op(dentry, &proc_sys_dentry_operations);
64065 +
64066 + gr_handle_proc_create(dentry, inode);
64067 +
64068 d_add(dentry, inode);
64069
64070 out:
64071 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64072 struct inode *inode = file_inode(filp);
64073 struct ctl_table_header *head = grab_header(inode);
64074 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64075 + int op = write ? MAY_WRITE : MAY_READ;
64076 ssize_t error;
64077 size_t res;
64078
64079 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64080 * and won't be until we finish.
64081 */
64082 error = -EPERM;
64083 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64084 + if (sysctl_perm(head, table, op))
64085 goto out;
64086
64087 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64088 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64089 if (!table->proc_handler)
64090 goto out;
64091
64092 +#ifdef CONFIG_GRKERNSEC
64093 + error = -EPERM;
64094 + if (gr_handle_chroot_sysctl(op))
64095 + goto out;
64096 + dget(filp->f_path.dentry);
64097 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64098 + dput(filp->f_path.dentry);
64099 + goto out;
64100 + }
64101 + dput(filp->f_path.dentry);
64102 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64103 + goto out;
64104 + if (write) {
64105 + if (current->nsproxy->net_ns != table->extra2) {
64106 + if (!capable(CAP_SYS_ADMIN))
64107 + goto out;
64108 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64109 + goto out;
64110 + }
64111 +#endif
64112 +
64113 /* careful: calling conventions are nasty here */
64114 res = count;
64115 error = table->proc_handler(table, write, buf, &res, ppos);
64116 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64117 return false;
64118 } else {
64119 d_set_d_op(child, &proc_sys_dentry_operations);
64120 +
64121 + gr_handle_proc_create(child, inode);
64122 +
64123 d_add(child, inode);
64124 }
64125 } else {
64126 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64127 if ((*pos)++ < ctx->pos)
64128 return true;
64129
64130 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64131 + return 0;
64132 +
64133 if (unlikely(S_ISLNK(table->mode)))
64134 res = proc_sys_link_fill_cache(file, ctx, head, table);
64135 else
64136 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64137 if (IS_ERR(head))
64138 return PTR_ERR(head);
64139
64140 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64141 + return -ENOENT;
64142 +
64143 generic_fillattr(inode, stat);
64144 if (table)
64145 stat->mode = (stat->mode & S_IFMT) | table->mode;
64146 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64147 .llseek = generic_file_llseek,
64148 };
64149
64150 -static const struct inode_operations proc_sys_inode_operations = {
64151 +const struct inode_operations proc_sys_inode_operations = {
64152 .permission = proc_sys_permission,
64153 .setattr = proc_sys_setattr,
64154 .getattr = proc_sys_getattr,
64155 };
64156
64157 -static const struct inode_operations proc_sys_dir_operations = {
64158 +const struct inode_operations proc_sys_dir_operations = {
64159 .lookup = proc_sys_lookup,
64160 .permission = proc_sys_permission,
64161 .setattr = proc_sys_setattr,
64162 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64163 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64164 const char *name, int namelen)
64165 {
64166 - struct ctl_table *table;
64167 + ctl_table_no_const *table;
64168 struct ctl_dir *new;
64169 struct ctl_node *node;
64170 char *new_name;
64171 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64172 return NULL;
64173
64174 node = (struct ctl_node *)(new + 1);
64175 - table = (struct ctl_table *)(node + 1);
64176 + table = (ctl_table_no_const *)(node + 1);
64177 new_name = (char *)(table + 2);
64178 memcpy(new_name, name, namelen);
64179 new_name[namelen] = '\0';
64180 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64181 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64182 struct ctl_table_root *link_root)
64183 {
64184 - struct ctl_table *link_table, *entry, *link;
64185 + ctl_table_no_const *link_table, *link;
64186 + struct ctl_table *entry;
64187 struct ctl_table_header *links;
64188 struct ctl_node *node;
64189 char *link_name;
64190 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64191 return NULL;
64192
64193 node = (struct ctl_node *)(links + 1);
64194 - link_table = (struct ctl_table *)(node + nr_entries);
64195 + link_table = (ctl_table_no_const *)(node + nr_entries);
64196 link_name = (char *)&link_table[nr_entries + 1];
64197
64198 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64199 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64200 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64201 struct ctl_table *table)
64202 {
64203 - struct ctl_table *ctl_table_arg = NULL;
64204 - struct ctl_table *entry, *files;
64205 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64206 + struct ctl_table *entry;
64207 int nr_files = 0;
64208 int nr_dirs = 0;
64209 int err = -ENOMEM;
64210 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64211 nr_files++;
64212 }
64213
64214 - files = table;
64215 /* If there are mixed files and directories we need a new table */
64216 if (nr_dirs && nr_files) {
64217 - struct ctl_table *new;
64218 + ctl_table_no_const *new;
64219 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64220 GFP_KERNEL);
64221 if (!files)
64222 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64223 /* Register everything except a directory full of subdirectories */
64224 if (nr_files || !nr_dirs) {
64225 struct ctl_table_header *header;
64226 - header = __register_sysctl_table(set, path, files);
64227 + header = __register_sysctl_table(set, path, files ? files : table);
64228 if (!header) {
64229 kfree(ctl_table_arg);
64230 goto out;
64231 diff --git a/fs/proc/root.c b/fs/proc/root.c
64232 index 5dbadec..473af2f 100644
64233 --- a/fs/proc/root.c
64234 +++ b/fs/proc/root.c
64235 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
64236 proc_mkdir("openprom", NULL);
64237 #endif
64238 proc_tty_init();
64239 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64240 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64241 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64242 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64243 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64244 +#endif
64245 +#else
64246 proc_mkdir("bus", NULL);
64247 +#endif
64248 proc_sys_init();
64249 }
64250
64251 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64252 index 9d231e9..2e1b51a 100644
64253 --- a/fs/proc/stat.c
64254 +++ b/fs/proc/stat.c
64255 @@ -11,6 +11,7 @@
64256 #include <linux/irqnr.h>
64257 #include <linux/cputime.h>
64258 #include <linux/tick.h>
64259 +#include <linux/grsecurity.h>
64260
64261 #ifndef arch_irq_stat_cpu
64262 #define arch_irq_stat_cpu(cpu) 0
64263 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64264 u64 sum_softirq = 0;
64265 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64266 struct timespec boottime;
64267 + int unrestricted = 1;
64268 +
64269 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64270 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64271 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64272 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64273 + && !in_group_p(grsec_proc_gid)
64274 +#endif
64275 + )
64276 + unrestricted = 0;
64277 +#endif
64278 +#endif
64279
64280 user = nice = system = idle = iowait =
64281 irq = softirq = steal = 0;
64282 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64283 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64284 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64285 idle += get_idle_time(i);
64286 - iowait += get_iowait_time(i);
64287 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64288 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64289 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64290 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64291 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64292 - sum += kstat_cpu_irqs_sum(i);
64293 - sum += arch_irq_stat_cpu(i);
64294 + if (unrestricted) {
64295 + iowait += get_iowait_time(i);
64296 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64297 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64298 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64299 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64300 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64301 + sum += kstat_cpu_irqs_sum(i);
64302 + sum += arch_irq_stat_cpu(i);
64303 + for (j = 0; j < NR_SOFTIRQS; j++) {
64304 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64305
64306 - for (j = 0; j < NR_SOFTIRQS; j++) {
64307 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64308 -
64309 - per_softirq_sums[j] += softirq_stat;
64310 - sum_softirq += softirq_stat;
64311 + per_softirq_sums[j] += softirq_stat;
64312 + sum_softirq += softirq_stat;
64313 + }
64314 }
64315 }
64316 - sum += arch_irq_stat();
64317 + if (unrestricted)
64318 + sum += arch_irq_stat();
64319
64320 seq_puts(p, "cpu ");
64321 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64322 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64323 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64324 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64325 idle = get_idle_time(i);
64326 - iowait = get_iowait_time(i);
64327 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64328 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64329 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64330 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64331 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64332 + if (unrestricted) {
64333 + iowait = get_iowait_time(i);
64334 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64335 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64336 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64337 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64338 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64339 + }
64340 seq_printf(p, "cpu%d", i);
64341 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64342 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64343 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64344
64345 /* sum again ? it could be updated? */
64346 for_each_irq_nr(j)
64347 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64348 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64349
64350 seq_printf(p,
64351 "\nctxt %llu\n"
64352 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64353 "processes %lu\n"
64354 "procs_running %lu\n"
64355 "procs_blocked %lu\n",
64356 - nr_context_switches(),
64357 + unrestricted ? nr_context_switches() : 0ULL,
64358 (unsigned long)jif,
64359 - total_forks,
64360 - nr_running(),
64361 - nr_iowait());
64362 + unrestricted ? total_forks : 0UL,
64363 + unrestricted ? nr_running() : 0UL,
64364 + unrestricted ? nr_iowait() : 0UL);
64365
64366 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64367
64368 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64369 index c4b2646..84f0d7b 100644
64370 --- a/fs/proc/task_mmu.c
64371 +++ b/fs/proc/task_mmu.c
64372 @@ -13,12 +13,19 @@
64373 #include <linux/swap.h>
64374 #include <linux/swapops.h>
64375 #include <linux/mmu_notifier.h>
64376 +#include <linux/grsecurity.h>
64377
64378 #include <asm/elf.h>
64379 #include <asm/uaccess.h>
64380 #include <asm/tlbflush.h>
64381 #include "internal.h"
64382
64383 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64384 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64385 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64386 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64387 +#endif
64388 +
64389 void task_mem(struct seq_file *m, struct mm_struct *mm)
64390 {
64391 unsigned long data, text, lib, swap;
64392 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64393 "VmExe:\t%8lu kB\n"
64394 "VmLib:\t%8lu kB\n"
64395 "VmPTE:\t%8lu kB\n"
64396 - "VmSwap:\t%8lu kB\n",
64397 - hiwater_vm << (PAGE_SHIFT-10),
64398 + "VmSwap:\t%8lu kB\n"
64399 +
64400 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64401 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64402 +#endif
64403 +
64404 + ,hiwater_vm << (PAGE_SHIFT-10),
64405 total_vm << (PAGE_SHIFT-10),
64406 mm->locked_vm << (PAGE_SHIFT-10),
64407 mm->pinned_vm << (PAGE_SHIFT-10),
64408 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64409 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64410 (PTRS_PER_PTE * sizeof(pte_t) *
64411 atomic_long_read(&mm->nr_ptes)) >> 10,
64412 - swap << (PAGE_SHIFT-10));
64413 + swap << (PAGE_SHIFT-10)
64414 +
64415 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64416 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64417 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64418 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64419 +#else
64420 + , mm->context.user_cs_base
64421 + , mm->context.user_cs_limit
64422 +#endif
64423 +#endif
64424 +
64425 + );
64426 }
64427
64428 unsigned long task_vsize(struct mm_struct *mm)
64429 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64430 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64431 }
64432
64433 - /* We don't show the stack guard page in /proc/maps */
64434 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64435 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64436 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64437 +#else
64438 start = vma->vm_start;
64439 - if (stack_guard_page_start(vma, start))
64440 - start += PAGE_SIZE;
64441 end = vma->vm_end;
64442 - if (stack_guard_page_end(vma, end))
64443 - end -= PAGE_SIZE;
64444 +#endif
64445
64446 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64447 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64448 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64449 flags & VM_WRITE ? 'w' : '-',
64450 flags & VM_EXEC ? 'x' : '-',
64451 flags & VM_MAYSHARE ? 's' : 'p',
64452 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64453 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64454 +#else
64455 pgoff,
64456 +#endif
64457 MAJOR(dev), MINOR(dev), ino);
64458
64459 /*
64460 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64461 */
64462 if (file) {
64463 seq_pad(m, ' ');
64464 - seq_path(m, &file->f_path, "\n");
64465 + seq_path(m, &file->f_path, "\n\\");
64466 goto done;
64467 }
64468
64469 @@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64470 * Thread stack in /proc/PID/task/TID/maps or
64471 * the main process stack.
64472 */
64473 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64474 - vma->vm_end >= mm->start_stack)) {
64475 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64476 + (vma->vm_start <= mm->start_stack &&
64477 + vma->vm_end >= mm->start_stack)) {
64478 name = "[stack]";
64479 } else {
64480 /* Thread stack in /proc/PID/maps */
64481 @@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64482 struct proc_maps_private *priv = m->private;
64483 struct task_struct *task = priv->task;
64484
64485 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64486 + if (current->exec_id != m->exec_id) {
64487 + gr_log_badprocpid("maps");
64488 + return 0;
64489 + }
64490 +#endif
64491 +
64492 show_map_vma(m, vma, is_pid);
64493
64494 if (m->count < m->size) /* vma is copied successfully */
64495 @@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64496 .private = &mss,
64497 };
64498
64499 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64500 + if (current->exec_id != m->exec_id) {
64501 + gr_log_badprocpid("smaps");
64502 + return 0;
64503 + }
64504 +#endif
64505 memset(&mss, 0, sizeof mss);
64506 - mss.vma = vma;
64507 - /* mmap_sem is held in m_start */
64508 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64509 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64510 -
64511 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64512 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64513 +#endif
64514 + mss.vma = vma;
64515 + /* mmap_sem is held in m_start */
64516 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64517 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64518 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64519 + }
64520 +#endif
64521 show_map_vma(m, vma, is_pid);
64522
64523 seq_printf(m,
64524 @@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64525 "KernelPageSize: %8lu kB\n"
64526 "MMUPageSize: %8lu kB\n"
64527 "Locked: %8lu kB\n",
64528 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64529 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64530 +#else
64531 (vma->vm_end - vma->vm_start) >> 10,
64532 +#endif
64533 mss.resident >> 10,
64534 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64535 mss.shared_clean >> 10,
64536 @@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64537 char buffer[64];
64538 int nid;
64539
64540 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64541 + if (current->exec_id != m->exec_id) {
64542 + gr_log_badprocpid("numa_maps");
64543 + return 0;
64544 + }
64545 +#endif
64546 +
64547 if (!mm)
64548 return 0;
64549
64550 @@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64551 mpol_to_str(buffer, sizeof(buffer), pol);
64552 mpol_cond_put(pol);
64553
64554 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64555 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64556 +#else
64557 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64558 +#endif
64559
64560 if (file) {
64561 seq_printf(m, " file=");
64562 - seq_path(m, &file->f_path, "\n\t= ");
64563 + seq_path(m, &file->f_path, "\n\t\\= ");
64564 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64565 seq_printf(m, " heap");
64566 } else {
64567 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64568 index 678455d..ebd3245 100644
64569 --- a/fs/proc/task_nommu.c
64570 +++ b/fs/proc/task_nommu.c
64571 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64572 else
64573 bytes += kobjsize(mm);
64574
64575 - if (current->fs && current->fs->users > 1)
64576 + if (current->fs && atomic_read(&current->fs->users) > 1)
64577 sbytes += kobjsize(current->fs);
64578 else
64579 bytes += kobjsize(current->fs);
64580 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64581
64582 if (file) {
64583 seq_pad(m, ' ');
64584 - seq_path(m, &file->f_path, "");
64585 + seq_path(m, &file->f_path, "\n\\");
64586 } else if (mm) {
64587 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64588
64589 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64590 index 6a8e785..41f2a6c 100644
64591 --- a/fs/proc/vmcore.c
64592 +++ b/fs/proc/vmcore.c
64593 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64594 nr_bytes = count;
64595
64596 /* If pfn is not ram, return zeros for sparse dump files */
64597 - if (pfn_is_ram(pfn) == 0)
64598 - memset(buf, 0, nr_bytes);
64599 - else {
64600 + if (pfn_is_ram(pfn) == 0) {
64601 + if (userbuf) {
64602 + if (clear_user((char __force_user *)buf, nr_bytes))
64603 + return -EFAULT;
64604 + } else
64605 + memset(buf, 0, nr_bytes);
64606 + } else {
64607 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64608 offset, userbuf);
64609 if (tmp < 0)
64610 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64611 static int copy_to(void *target, void *src, size_t size, int userbuf)
64612 {
64613 if (userbuf) {
64614 - if (copy_to_user((char __user *) target, src, size))
64615 + if (copy_to_user((char __force_user *) target, src, size))
64616 return -EFAULT;
64617 } else {
64618 memcpy(target, src, size);
64619 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64620 if (*fpos < m->offset + m->size) {
64621 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64622 start = m->paddr + *fpos - m->offset;
64623 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64624 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64625 if (tmp < 0)
64626 return tmp;
64627 buflen -= tsz;
64628 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64629 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64630 size_t buflen, loff_t *fpos)
64631 {
64632 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64633 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64634 }
64635
64636 /*
64637 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64638 index b00fcc9..e0c6381 100644
64639 --- a/fs/qnx6/qnx6.h
64640 +++ b/fs/qnx6/qnx6.h
64641 @@ -74,7 +74,7 @@ enum {
64642 BYTESEX_BE,
64643 };
64644
64645 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64646 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64647 {
64648 if (sbi->s_bytesex == BYTESEX_LE)
64649 return le64_to_cpu((__force __le64)n);
64650 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64651 return (__force __fs64)cpu_to_be64(n);
64652 }
64653
64654 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64655 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64656 {
64657 if (sbi->s_bytesex == BYTESEX_LE)
64658 return le32_to_cpu((__force __le32)n);
64659 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64660 index 72d2917..c917c12 100644
64661 --- a/fs/quota/netlink.c
64662 +++ b/fs/quota/netlink.c
64663 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64664 void quota_send_warning(struct kqid qid, dev_t dev,
64665 const char warntype)
64666 {
64667 - static atomic_t seq;
64668 + static atomic_unchecked_t seq;
64669 struct sk_buff *skb;
64670 void *msg_head;
64671 int ret;
64672 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64673 "VFS: Not enough memory to send quota warning.\n");
64674 return;
64675 }
64676 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64677 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64678 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64679 if (!msg_head) {
64680 printk(KERN_ERR
64681 diff --git a/fs/read_write.c b/fs/read_write.c
64682 index 31c6efa..a068805 100644
64683 --- a/fs/read_write.c
64684 +++ b/fs/read_write.c
64685 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64686
64687 old_fs = get_fs();
64688 set_fs(get_ds());
64689 - p = (__force const char __user *)buf;
64690 + p = (const char __force_user *)buf;
64691 if (count > MAX_RW_COUNT)
64692 count = MAX_RW_COUNT;
64693 if (file->f_op->write)
64694 diff --git a/fs/readdir.c b/fs/readdir.c
64695 index 5b53d99..a6c3049 100644
64696 --- a/fs/readdir.c
64697 +++ b/fs/readdir.c
64698 @@ -17,6 +17,7 @@
64699 #include <linux/security.h>
64700 #include <linux/syscalls.h>
64701 #include <linux/unistd.h>
64702 +#include <linux/namei.h>
64703
64704 #include <asm/uaccess.h>
64705
64706 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64707 struct readdir_callback {
64708 struct dir_context ctx;
64709 struct old_linux_dirent __user * dirent;
64710 + struct file * file;
64711 int result;
64712 };
64713
64714 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64715 buf->result = -EOVERFLOW;
64716 return -EOVERFLOW;
64717 }
64718 +
64719 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64720 + return 0;
64721 +
64722 buf->result++;
64723 dirent = buf->dirent;
64724 if (!access_ok(VERIFY_WRITE, dirent,
64725 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64726 if (!f.file)
64727 return -EBADF;
64728
64729 + buf.file = f.file;
64730 error = iterate_dir(f.file, &buf.ctx);
64731 if (buf.result)
64732 error = buf.result;
64733 @@ -142,6 +149,7 @@ struct getdents_callback {
64734 struct dir_context ctx;
64735 struct linux_dirent __user * current_dir;
64736 struct linux_dirent __user * previous;
64737 + struct file * file;
64738 int count;
64739 int error;
64740 };
64741 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64742 buf->error = -EOVERFLOW;
64743 return -EOVERFLOW;
64744 }
64745 +
64746 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64747 + return 0;
64748 +
64749 dirent = buf->previous;
64750 if (dirent) {
64751 if (__put_user(offset, &dirent->d_off))
64752 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64753 if (!f.file)
64754 return -EBADF;
64755
64756 + buf.file = f.file;
64757 error = iterate_dir(f.file, &buf.ctx);
64758 if (error >= 0)
64759 error = buf.error;
64760 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64761 struct dir_context ctx;
64762 struct linux_dirent64 __user * current_dir;
64763 struct linux_dirent64 __user * previous;
64764 + struct file *file;
64765 int count;
64766 int error;
64767 };
64768 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64769 buf->error = -EINVAL; /* only used if we fail.. */
64770 if (reclen > buf->count)
64771 return -EINVAL;
64772 +
64773 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64774 + return 0;
64775 +
64776 dirent = buf->previous;
64777 if (dirent) {
64778 if (__put_user(offset, &dirent->d_off))
64779 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64780 if (!f.file)
64781 return -EBADF;
64782
64783 + buf.file = f.file;
64784 error = iterate_dir(f.file, &buf.ctx);
64785 if (error >= 0)
64786 error = buf.error;
64787 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64788 index 9a3c68c..767933e 100644
64789 --- a/fs/reiserfs/do_balan.c
64790 +++ b/fs/reiserfs/do_balan.c
64791 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64792 return;
64793 }
64794
64795 - atomic_inc(&(fs_generation(tb->tb_sb)));
64796 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64797 do_balance_starts(tb);
64798
64799 /* balance leaf returns 0 except if combining L R and S into
64800 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64801 index ee382ef..f4eb6eb5 100644
64802 --- a/fs/reiserfs/item_ops.c
64803 +++ b/fs/reiserfs/item_ops.c
64804 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64805 }
64806
64807 static struct item_operations errcatch_ops = {
64808 - errcatch_bytes_number,
64809 - errcatch_decrement_key,
64810 - errcatch_is_left_mergeable,
64811 - errcatch_print_item,
64812 - errcatch_check_item,
64813 + .bytes_number = errcatch_bytes_number,
64814 + .decrement_key = errcatch_decrement_key,
64815 + .is_left_mergeable = errcatch_is_left_mergeable,
64816 + .print_item = errcatch_print_item,
64817 + .check_item = errcatch_check_item,
64818
64819 - errcatch_create_vi,
64820 - errcatch_check_left,
64821 - errcatch_check_right,
64822 - errcatch_part_size,
64823 - errcatch_unit_num,
64824 - errcatch_print_vi
64825 + .create_vi = errcatch_create_vi,
64826 + .check_left = errcatch_check_left,
64827 + .check_right = errcatch_check_right,
64828 + .part_size = errcatch_part_size,
64829 + .unit_num = errcatch_unit_num,
64830 + .print_vi = errcatch_print_vi
64831 };
64832
64833 //////////////////////////////////////////////////////////////////////////////
64834 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64835 index 02b0b7d..c85018b 100644
64836 --- a/fs/reiserfs/procfs.c
64837 +++ b/fs/reiserfs/procfs.c
64838 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64839 "SMALL_TAILS " : "NO_TAILS ",
64840 replay_only(sb) ? "REPLAY_ONLY " : "",
64841 convert_reiserfs(sb) ? "CONV " : "",
64842 - atomic_read(&r->s_generation_counter),
64843 + atomic_read_unchecked(&r->s_generation_counter),
64844 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64845 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64846 SF(s_good_search_by_key_reada), SF(s_bmaps),
64847 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64848 index 83d4eac..04e39a7 100644
64849 --- a/fs/reiserfs/reiserfs.h
64850 +++ b/fs/reiserfs/reiserfs.h
64851 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64852 /* Comment? -Hans */
64853 wait_queue_head_t s_wait;
64854 /* To be obsoleted soon by per buffer seals.. -Hans */
64855 - atomic_t s_generation_counter; // increased by one every time the
64856 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64857 // tree gets re-balanced
64858 unsigned long s_properties; /* File system properties. Currently holds
64859 on-disk FS format */
64860 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64861 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64862
64863 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64864 -#define get_generation(s) atomic_read (&fs_generation(s))
64865 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64866 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64867 #define __fs_changed(gen,s) (gen != get_generation (s))
64868 #define fs_changed(gen,s) \
64869 diff --git a/fs/select.c b/fs/select.c
64870 index 467bb1c..cf9d65a 100644
64871 --- a/fs/select.c
64872 +++ b/fs/select.c
64873 @@ -20,6 +20,7 @@
64874 #include <linux/export.h>
64875 #include <linux/slab.h>
64876 #include <linux/poll.h>
64877 +#include <linux/security.h>
64878 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64879 #include <linux/file.h>
64880 #include <linux/fdtable.h>
64881 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64882 struct poll_list *walk = head;
64883 unsigned long todo = nfds;
64884
64885 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64886 if (nfds > rlimit(RLIMIT_NOFILE))
64887 return -EINVAL;
64888
64889 diff --git a/fs/seq_file.c b/fs/seq_file.c
64890 index 1d641bb..c2f4743 100644
64891 --- a/fs/seq_file.c
64892 +++ b/fs/seq_file.c
64893 @@ -10,6 +10,8 @@
64894 #include <linux/seq_file.h>
64895 #include <linux/slab.h>
64896 #include <linux/cred.h>
64897 +#include <linux/sched.h>
64898 +#include <linux/grsecurity.h>
64899
64900 #include <asm/uaccess.h>
64901 #include <asm/page.h>
64902 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64903 #ifdef CONFIG_USER_NS
64904 p->user_ns = file->f_cred->user_ns;
64905 #endif
64906 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64907 + p->exec_id = current->exec_id;
64908 +#endif
64909
64910 /*
64911 * Wrappers around seq_open(e.g. swaps_open) need to be
64912 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64913 }
64914 EXPORT_SYMBOL(seq_open);
64915
64916 +
64917 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
64918 +{
64919 + if (gr_proc_is_restricted())
64920 + return -EACCES;
64921 +
64922 + return seq_open(file, op);
64923 +}
64924 +EXPORT_SYMBOL(seq_open_restrict);
64925 +
64926 static int traverse(struct seq_file *m, loff_t offset)
64927 {
64928 loff_t pos = 0, index;
64929 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64930 return 0;
64931 }
64932 if (!m->buf) {
64933 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64934 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64935 if (!m->buf)
64936 return -ENOMEM;
64937 }
64938 @@ -137,7 +152,7 @@ Eoverflow:
64939 m->op->stop(m, p);
64940 kfree(m->buf);
64941 m->count = 0;
64942 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64943 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64944 return !m->buf ? -ENOMEM : -EAGAIN;
64945 }
64946
64947 @@ -153,7 +168,7 @@ Eoverflow:
64948 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64949 {
64950 struct seq_file *m = file->private_data;
64951 - size_t copied = 0;
64952 + ssize_t copied = 0;
64953 loff_t pos;
64954 size_t n;
64955 void *p;
64956 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64957
64958 /* grab buffer if we didn't have one */
64959 if (!m->buf) {
64960 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64961 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64962 if (!m->buf)
64963 goto Enomem;
64964 }
64965 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64966 m->op->stop(m, p);
64967 kfree(m->buf);
64968 m->count = 0;
64969 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64970 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64971 if (!m->buf)
64972 goto Enomem;
64973 m->version = 0;
64974 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
64975 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64976 void *data)
64977 {
64978 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64979 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64980 int res = -ENOMEM;
64981
64982 if (op) {
64983 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
64984 }
64985 EXPORT_SYMBOL(single_open_size);
64986
64987 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
64988 + void *data)
64989 +{
64990 + if (gr_proc_is_restricted())
64991 + return -EACCES;
64992 +
64993 + return single_open(file, show, data);
64994 +}
64995 +EXPORT_SYMBOL(single_open_restrict);
64996 +
64997 +
64998 int single_release(struct inode *inode, struct file *file)
64999 {
65000 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65001 diff --git a/fs/splice.c b/fs/splice.c
65002 index e246954..bd4f5b5 100644
65003 --- a/fs/splice.c
65004 +++ b/fs/splice.c
65005 @@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65006 pipe_lock(pipe);
65007
65008 for (;;) {
65009 - if (!pipe->readers) {
65010 + if (!atomic_read(&pipe->readers)) {
65011 send_sig(SIGPIPE, current, 0);
65012 if (!ret)
65013 ret = -EPIPE;
65014 @@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65015 page_nr++;
65016 ret += buf->len;
65017
65018 - if (pipe->files)
65019 + if (atomic_read(&pipe->files))
65020 do_wakeup = 1;
65021
65022 if (!--spd->nr_pages)
65023 @@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65024 do_wakeup = 0;
65025 }
65026
65027 - pipe->waiting_writers++;
65028 + atomic_inc(&pipe->waiting_writers);
65029 pipe_wait(pipe);
65030 - pipe->waiting_writers--;
65031 + atomic_dec(&pipe->waiting_writers);
65032 }
65033
65034 pipe_unlock(pipe);
65035 @@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65036 old_fs = get_fs();
65037 set_fs(get_ds());
65038 /* The cast to a user pointer is valid due to the set_fs() */
65039 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65040 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65041 set_fs(old_fs);
65042
65043 return res;
65044 @@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65045 old_fs = get_fs();
65046 set_fs(get_ds());
65047 /* The cast to a user pointer is valid due to the set_fs() */
65048 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65049 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65050 set_fs(old_fs);
65051
65052 return res;
65053 @@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65054 goto err;
65055
65056 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65057 - vec[i].iov_base = (void __user *) page_address(page);
65058 + vec[i].iov_base = (void __force_user *) page_address(page);
65059 vec[i].iov_len = this_len;
65060 spd.pages[i] = page;
65061 spd.nr_pages++;
65062 @@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65063 ops->release(pipe, buf);
65064 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65065 pipe->nrbufs--;
65066 - if (pipe->files)
65067 + if (atomic_read(&pipe->files))
65068 sd->need_wakeup = true;
65069 }
65070
65071 @@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65072 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65073 {
65074 while (!pipe->nrbufs) {
65075 - if (!pipe->writers)
65076 + if (!atomic_read(&pipe->writers))
65077 return 0;
65078
65079 - if (!pipe->waiting_writers && sd->num_spliced)
65080 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65081 return 0;
65082
65083 if (sd->flags & SPLICE_F_NONBLOCK)
65084 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65085 * out of the pipe right after the splice_to_pipe(). So set
65086 * PIPE_READERS appropriately.
65087 */
65088 - pipe->readers = 1;
65089 + atomic_set(&pipe->readers, 1);
65090
65091 current->splice_pipe = pipe;
65092 }
65093 @@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65094
65095 partial[buffers].offset = off;
65096 partial[buffers].len = plen;
65097 + partial[buffers].private = 0;
65098
65099 off = 0;
65100 len -= plen;
65101 @@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65102 ret = -ERESTARTSYS;
65103 break;
65104 }
65105 - if (!pipe->writers)
65106 + if (!atomic_read(&pipe->writers))
65107 break;
65108 - if (!pipe->waiting_writers) {
65109 + if (!atomic_read(&pipe->waiting_writers)) {
65110 if (flags & SPLICE_F_NONBLOCK) {
65111 ret = -EAGAIN;
65112 break;
65113 @@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65114 pipe_lock(pipe);
65115
65116 while (pipe->nrbufs >= pipe->buffers) {
65117 - if (!pipe->readers) {
65118 + if (!atomic_read(&pipe->readers)) {
65119 send_sig(SIGPIPE, current, 0);
65120 ret = -EPIPE;
65121 break;
65122 @@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65123 ret = -ERESTARTSYS;
65124 break;
65125 }
65126 - pipe->waiting_writers++;
65127 + atomic_inc(&pipe->waiting_writers);
65128 pipe_wait(pipe);
65129 - pipe->waiting_writers--;
65130 + atomic_dec(&pipe->waiting_writers);
65131 }
65132
65133 pipe_unlock(pipe);
65134 @@ -1806,14 +1807,14 @@ retry:
65135 pipe_double_lock(ipipe, opipe);
65136
65137 do {
65138 - if (!opipe->readers) {
65139 + if (!atomic_read(&opipe->readers)) {
65140 send_sig(SIGPIPE, current, 0);
65141 if (!ret)
65142 ret = -EPIPE;
65143 break;
65144 }
65145
65146 - if (!ipipe->nrbufs && !ipipe->writers)
65147 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65148 break;
65149
65150 /*
65151 @@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65152 pipe_double_lock(ipipe, opipe);
65153
65154 do {
65155 - if (!opipe->readers) {
65156 + if (!atomic_read(&opipe->readers)) {
65157 send_sig(SIGPIPE, current, 0);
65158 if (!ret)
65159 ret = -EPIPE;
65160 @@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65161 * return EAGAIN if we have the potential of some data in the
65162 * future, otherwise just return 0
65163 */
65164 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65165 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65166 ret = -EAGAIN;
65167
65168 pipe_unlock(ipipe);
65169 diff --git a/fs/stat.c b/fs/stat.c
65170 index ae0c3ce..9ee641c 100644
65171 --- a/fs/stat.c
65172 +++ b/fs/stat.c
65173 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65174 stat->gid = inode->i_gid;
65175 stat->rdev = inode->i_rdev;
65176 stat->size = i_size_read(inode);
65177 - stat->atime = inode->i_atime;
65178 - stat->mtime = inode->i_mtime;
65179 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65180 + stat->atime = inode->i_ctime;
65181 + stat->mtime = inode->i_ctime;
65182 + } else {
65183 + stat->atime = inode->i_atime;
65184 + stat->mtime = inode->i_mtime;
65185 + }
65186 stat->ctime = inode->i_ctime;
65187 stat->blksize = (1 << inode->i_blkbits);
65188 stat->blocks = inode->i_blocks;
65189 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65190 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65191 {
65192 struct inode *inode = path->dentry->d_inode;
65193 + int retval;
65194
65195 - if (inode->i_op->getattr)
65196 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65197 + if (inode->i_op->getattr) {
65198 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65199 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65200 + stat->atime = stat->ctime;
65201 + stat->mtime = stat->ctime;
65202 + }
65203 + return retval;
65204 + }
65205
65206 generic_fillattr(inode, stat);
65207 return 0;
65208 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65209 index 0b45ff4..847de5b 100644
65210 --- a/fs/sysfs/dir.c
65211 +++ b/fs/sysfs/dir.c
65212 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65213 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65214 {
65215 struct kernfs_node *parent, *kn;
65216 + const char *name;
65217 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65218 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65219 + const char *parent_name;
65220 +#endif
65221
65222 BUG_ON(!kobj);
65223
65224 + name = kobject_name(kobj);
65225 +
65226 if (kobj->parent)
65227 parent = kobj->parent->sd;
65228 else
65229 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65230 if (!parent)
65231 return -ENOENT;
65232
65233 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65234 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65235 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65236 + parent_name = parent->name;
65237 + mode = S_IRWXU;
65238 +
65239 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65240 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65241 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65242 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65243 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65244 +#endif
65245 +
65246 + kn = kernfs_create_dir_ns(parent, name,
65247 + mode, kobj, ns);
65248 if (IS_ERR(kn)) {
65249 if (PTR_ERR(kn) == -EEXIST)
65250 - sysfs_warn_dup(parent, kobject_name(kobj));
65251 + sysfs_warn_dup(parent, name);
65252 return PTR_ERR(kn);
65253 }
65254
65255 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65256 index 69d4889..a810bd4 100644
65257 --- a/fs/sysv/sysv.h
65258 +++ b/fs/sysv/sysv.h
65259 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65260 #endif
65261 }
65262
65263 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65264 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65265 {
65266 if (sbi->s_bytesex == BYTESEX_PDP)
65267 return PDP_swab((__force __u32)n);
65268 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65269 index e18b988..f1d4ad0f 100644
65270 --- a/fs/ubifs/io.c
65271 +++ b/fs/ubifs/io.c
65272 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65273 return err;
65274 }
65275
65276 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65277 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65278 {
65279 int err;
65280
65281 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65282 index c175b4d..8f36a16 100644
65283 --- a/fs/udf/misc.c
65284 +++ b/fs/udf/misc.c
65285 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65286
65287 u8 udf_tag_checksum(const struct tag *t)
65288 {
65289 - u8 *data = (u8 *)t;
65290 + const u8 *data = (const u8 *)t;
65291 u8 checksum = 0;
65292 int i;
65293 for (i = 0; i < sizeof(struct tag); ++i)
65294 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65295 index 8d974c4..b82f6ec 100644
65296 --- a/fs/ufs/swab.h
65297 +++ b/fs/ufs/swab.h
65298 @@ -22,7 +22,7 @@ enum {
65299 BYTESEX_BE
65300 };
65301
65302 -static inline u64
65303 +static inline u64 __intentional_overflow(-1)
65304 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65305 {
65306 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65307 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65308 return (__force __fs64)cpu_to_be64(n);
65309 }
65310
65311 -static inline u32
65312 +static inline u32 __intentional_overflow(-1)
65313 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65314 {
65315 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65316 diff --git a/fs/utimes.c b/fs/utimes.c
65317 index aa138d6..5f3a811 100644
65318 --- a/fs/utimes.c
65319 +++ b/fs/utimes.c
65320 @@ -1,6 +1,7 @@
65321 #include <linux/compiler.h>
65322 #include <linux/file.h>
65323 #include <linux/fs.h>
65324 +#include <linux/security.h>
65325 #include <linux/linkage.h>
65326 #include <linux/mount.h>
65327 #include <linux/namei.h>
65328 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65329 }
65330 }
65331 retry_deleg:
65332 +
65333 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65334 + error = -EACCES;
65335 + goto mnt_drop_write_and_out;
65336 + }
65337 +
65338 mutex_lock(&inode->i_mutex);
65339 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65340 mutex_unlock(&inode->i_mutex);
65341 diff --git a/fs/xattr.c b/fs/xattr.c
65342 index 3377dff..f394815 100644
65343 --- a/fs/xattr.c
65344 +++ b/fs/xattr.c
65345 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65346 return rc;
65347 }
65348
65349 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65350 +ssize_t
65351 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65352 +{
65353 + struct inode *inode = dentry->d_inode;
65354 + ssize_t error;
65355 +
65356 + error = inode_permission(inode, MAY_EXEC);
65357 + if (error)
65358 + return error;
65359 +
65360 + if (inode->i_op->getxattr)
65361 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65362 + else
65363 + error = -EOPNOTSUPP;
65364 +
65365 + return error;
65366 +}
65367 +EXPORT_SYMBOL(pax_getxattr);
65368 +#endif
65369 +
65370 ssize_t
65371 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65372 {
65373 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65374 * Extended attribute SET operations
65375 */
65376 static long
65377 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65378 +setxattr(struct path *path, const char __user *name, const void __user *value,
65379 size_t size, int flags)
65380 {
65381 int error;
65382 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65383 posix_acl_fix_xattr_from_user(kvalue, size);
65384 }
65385
65386 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65387 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65388 + error = -EACCES;
65389 + goto out;
65390 + }
65391 +
65392 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65393 out:
65394 if (vvalue)
65395 vfree(vvalue);
65396 @@ -377,7 +403,7 @@ retry:
65397 return error;
65398 error = mnt_want_write(path.mnt);
65399 if (!error) {
65400 - error = setxattr(path.dentry, name, value, size, flags);
65401 + error = setxattr(&path, name, value, size, flags);
65402 mnt_drop_write(path.mnt);
65403 }
65404 path_put(&path);
65405 @@ -401,7 +427,7 @@ retry:
65406 return error;
65407 error = mnt_want_write(path.mnt);
65408 if (!error) {
65409 - error = setxattr(path.dentry, name, value, size, flags);
65410 + error = setxattr(&path, name, value, size, flags);
65411 mnt_drop_write(path.mnt);
65412 }
65413 path_put(&path);
65414 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65415 const void __user *,value, size_t, size, int, flags)
65416 {
65417 struct fd f = fdget(fd);
65418 - struct dentry *dentry;
65419 int error = -EBADF;
65420
65421 if (!f.file)
65422 return error;
65423 - dentry = f.file->f_path.dentry;
65424 - audit_inode(NULL, dentry, 0);
65425 + audit_inode(NULL, f.file->f_path.dentry, 0);
65426 error = mnt_want_write_file(f.file);
65427 if (!error) {
65428 - error = setxattr(dentry, name, value, size, flags);
65429 + error = setxattr(&f.file->f_path, name, value, size, flags);
65430 mnt_drop_write_file(f.file);
65431 }
65432 fdput(f);
65433 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65434 * Extended attribute REMOVE operations
65435 */
65436 static long
65437 -removexattr(struct dentry *d, const char __user *name)
65438 +removexattr(struct path *path, const char __user *name)
65439 {
65440 int error;
65441 char kname[XATTR_NAME_MAX + 1];
65442 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65443 if (error < 0)
65444 return error;
65445
65446 - return vfs_removexattr(d, kname);
65447 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65448 + return -EACCES;
65449 +
65450 + return vfs_removexattr(path->dentry, kname);
65451 }
65452
65453 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65454 @@ -652,7 +679,7 @@ retry:
65455 return error;
65456 error = mnt_want_write(path.mnt);
65457 if (!error) {
65458 - error = removexattr(path.dentry, name);
65459 + error = removexattr(&path, name);
65460 mnt_drop_write(path.mnt);
65461 }
65462 path_put(&path);
65463 @@ -675,7 +702,7 @@ retry:
65464 return error;
65465 error = mnt_want_write(path.mnt);
65466 if (!error) {
65467 - error = removexattr(path.dentry, name);
65468 + error = removexattr(&path, name);
65469 mnt_drop_write(path.mnt);
65470 }
65471 path_put(&path);
65472 @@ -689,16 +716,16 @@ retry:
65473 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65474 {
65475 struct fd f = fdget(fd);
65476 - struct dentry *dentry;
65477 + struct path *path;
65478 int error = -EBADF;
65479
65480 if (!f.file)
65481 return error;
65482 - dentry = f.file->f_path.dentry;
65483 - audit_inode(NULL, dentry, 0);
65484 + path = &f.file->f_path;
65485 + audit_inode(NULL, path->dentry, 0);
65486 error = mnt_want_write_file(f.file);
65487 if (!error) {
65488 - error = removexattr(dentry, name);
65489 + error = removexattr(path, name);
65490 mnt_drop_write_file(f.file);
65491 }
65492 fdput(f);
65493 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65494 index f0efc7e..ba72910 100644
65495 --- a/fs/xfs/xfs_bmap.c
65496 +++ b/fs/xfs/xfs_bmap.c
65497 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65498
65499 #else
65500 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65501 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65502 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65503 #endif /* DEBUG */
65504
65505 /*
65506 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65507 index aead369..0dfecfd 100644
65508 --- a/fs/xfs/xfs_dir2_readdir.c
65509 +++ b/fs/xfs/xfs_dir2_readdir.c
65510 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65511 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65512 filetype = dp->d_ops->sf_get_ftype(sfep);
65513 ctx->pos = off & 0x7fffffff;
65514 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65515 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65516 + char name[sfep->namelen];
65517 + memcpy(name, sfep->name, sfep->namelen);
65518 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65519 + return 0;
65520 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65521 xfs_dir3_get_dtype(mp, filetype)))
65522 return 0;
65523 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65524 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65525 index 6152cbe..f0f9eaa 100644
65526 --- a/fs/xfs/xfs_ioctl.c
65527 +++ b/fs/xfs/xfs_ioctl.c
65528 @@ -122,7 +122,7 @@ xfs_find_handle(
65529 }
65530
65531 error = -EFAULT;
65532 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65533 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65534 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65535 goto out_put;
65536
65537 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65538 new file mode 100644
65539 index 0000000..bfd482c
65540 --- /dev/null
65541 +++ b/grsecurity/Kconfig
65542 @@ -0,0 +1,1176 @@
65543 +#
65544 +# grecurity configuration
65545 +#
65546 +menu "Memory Protections"
65547 +depends on GRKERNSEC
65548 +
65549 +config GRKERNSEC_KMEM
65550 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65551 + default y if GRKERNSEC_CONFIG_AUTO
65552 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65553 + help
65554 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65555 + be written to or read from to modify or leak the contents of the running
65556 + kernel. /dev/port will also not be allowed to be opened, writing to
65557 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65558 + If you have module support disabled, enabling this will close up several
65559 + ways that are currently used to insert malicious code into the running
65560 + kernel.
65561 +
65562 + Even with this feature enabled, we still highly recommend that
65563 + you use the RBAC system, as it is still possible for an attacker to
65564 + modify the running kernel through other more obscure methods.
65565 +
65566 + It is highly recommended that you say Y here if you meet all the
65567 + conditions above.
65568 +
65569 +config GRKERNSEC_VM86
65570 + bool "Restrict VM86 mode"
65571 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65572 + depends on X86_32
65573 +
65574 + help
65575 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65576 + make use of a special execution mode on 32bit x86 processors called
65577 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65578 + video cards and will still work with this option enabled. The purpose
65579 + of the option is to prevent exploitation of emulation errors in
65580 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65581 + Nearly all users should be able to enable this option.
65582 +
65583 +config GRKERNSEC_IO
65584 + bool "Disable privileged I/O"
65585 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65586 + depends on X86
65587 + select RTC_CLASS
65588 + select RTC_INTF_DEV
65589 + select RTC_DRV_CMOS
65590 +
65591 + help
65592 + If you say Y here, all ioperm and iopl calls will return an error.
65593 + Ioperm and iopl can be used to modify the running kernel.
65594 + Unfortunately, some programs need this access to operate properly,
65595 + the most notable of which are XFree86 and hwclock. hwclock can be
65596 + remedied by having RTC support in the kernel, so real-time
65597 + clock support is enabled if this option is enabled, to ensure
65598 + that hwclock operates correctly. If hwclock still does not work,
65599 + either update udev or symlink /dev/rtc to /dev/rtc0.
65600 +
65601 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65602 + you may not be able to boot into a graphical environment with this
65603 + option enabled. In this case, you should use the RBAC system instead.
65604 +
65605 +config GRKERNSEC_JIT_HARDEN
65606 + bool "Harden BPF JIT against spray attacks"
65607 + default y if GRKERNSEC_CONFIG_AUTO
65608 + depends on BPF_JIT && X86
65609 + help
65610 + If you say Y here, the native code generated by the kernel's Berkeley
65611 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65612 + attacks that attempt to fit attacker-beneficial instructions in
65613 + 32bit immediate fields of JIT-generated native instructions. The
65614 + attacker will generally aim to cause an unintended instruction sequence
65615 + of JIT-generated native code to execute by jumping into the middle of
65616 + a generated instruction. This feature effectively randomizes the 32bit
65617 + immediate constants present in the generated code to thwart such attacks.
65618 +
65619 + If you're using KERNEXEC, it's recommended that you enable this option
65620 + to supplement the hardening of the kernel.
65621 +
65622 +config GRKERNSEC_PERF_HARDEN
65623 + bool "Disable unprivileged PERF_EVENTS usage by default"
65624 + default y if GRKERNSEC_CONFIG_AUTO
65625 + depends on PERF_EVENTS
65626 + help
65627 + If you say Y here, the range of acceptable values for the
65628 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65629 + default to a new value: 3. When the sysctl is set to this value, no
65630 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65631 +
65632 + Though PERF_EVENTS can be used legitimately for performance monitoring
65633 + and low-level application profiling, it is forced on regardless of
65634 + configuration, has been at fault for several vulnerabilities, and
65635 + creates new opportunities for side channels and other information leaks.
65636 +
65637 + This feature puts PERF_EVENTS into a secure default state and permits
65638 + the administrator to change out of it temporarily if unprivileged
65639 + application profiling is needed.
65640 +
65641 +config GRKERNSEC_RAND_THREADSTACK
65642 + bool "Insert random gaps between thread stacks"
65643 + default y if GRKERNSEC_CONFIG_AUTO
65644 + depends on PAX_RANDMMAP && !PPC
65645 + help
65646 + If you say Y here, a random-sized gap will be enforced between allocated
65647 + thread stacks. Glibc's NPTL and other threading libraries that
65648 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65649 + The implementation currently provides 8 bits of entropy for the gap.
65650 +
65651 + Many distributions do not compile threaded remote services with the
65652 + -fstack-check argument to GCC, causing the variable-sized stack-based
65653 + allocator, alloca(), to not probe the stack on allocation. This
65654 + permits an unbounded alloca() to skip over any guard page and potentially
65655 + modify another thread's stack reliably. An enforced random gap
65656 + reduces the reliability of such an attack and increases the chance
65657 + that such a read/write to another thread's stack instead lands in
65658 + an unmapped area, causing a crash and triggering grsecurity's
65659 + anti-bruteforcing logic.
65660 +
65661 +config GRKERNSEC_PROC_MEMMAP
65662 + bool "Harden ASLR against information leaks and entropy reduction"
65663 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65664 + depends on PAX_NOEXEC || PAX_ASLR
65665 + help
65666 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65667 + give no information about the addresses of its mappings if
65668 + PaX features that rely on random addresses are enabled on the task.
65669 + In addition to sanitizing this information and disabling other
65670 + dangerous sources of information, this option causes reads of sensitive
65671 + /proc/<pid> entries where the file descriptor was opened in a different
65672 + task than the one performing the read. Such attempts are logged.
65673 + This option also limits argv/env strings for suid/sgid binaries
65674 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65675 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65676 + binaries to prevent alternative mmap layouts from being abused.
65677 +
65678 + If you use PaX it is essential that you say Y here as it closes up
65679 + several holes that make full ASLR useless locally.
65680 +
65681 +
65682 +config GRKERNSEC_KSTACKOVERFLOW
65683 + bool "Prevent kernel stack overflows"
65684 + default y if GRKERNSEC_CONFIG_AUTO
65685 + depends on !IA64 && 64BIT
65686 + help
65687 + If you say Y here, the kernel's process stacks will be allocated
65688 + with vmalloc instead of the kernel's default allocator. This
65689 + introduces guard pages that in combination with the alloca checking
65690 + of the STACKLEAK feature prevents all forms of kernel process stack
65691 + overflow abuse. Note that this is different from kernel stack
65692 + buffer overflows.
65693 +
65694 +config GRKERNSEC_BRUTE
65695 + bool "Deter exploit bruteforcing"
65696 + default y if GRKERNSEC_CONFIG_AUTO
65697 + help
65698 + If you say Y here, attempts to bruteforce exploits against forking
65699 + daemons such as apache or sshd, as well as against suid/sgid binaries
65700 + will be deterred. When a child of a forking daemon is killed by PaX
65701 + or crashes due to an illegal instruction or other suspicious signal,
65702 + the parent process will be delayed 30 seconds upon every subsequent
65703 + fork until the administrator is able to assess the situation and
65704 + restart the daemon.
65705 + In the suid/sgid case, the attempt is logged, the user has all their
65706 + existing instances of the suid/sgid binary terminated and will
65707 + be unable to execute any suid/sgid binaries for 15 minutes.
65708 +
65709 + It is recommended that you also enable signal logging in the auditing
65710 + section so that logs are generated when a process triggers a suspicious
65711 + signal.
65712 + If the sysctl option is enabled, a sysctl option with name
65713 + "deter_bruteforce" is created.
65714 +
65715 +config GRKERNSEC_MODHARDEN
65716 + bool "Harden module auto-loading"
65717 + default y if GRKERNSEC_CONFIG_AUTO
65718 + depends on MODULES
65719 + help
65720 + If you say Y here, module auto-loading in response to use of some
65721 + feature implemented by an unloaded module will be restricted to
65722 + root users. Enabling this option helps defend against attacks
65723 + by unprivileged users who abuse the auto-loading behavior to
65724 + cause a vulnerable module to load that is then exploited.
65725 +
65726 + If this option prevents a legitimate use of auto-loading for a
65727 + non-root user, the administrator can execute modprobe manually
65728 + with the exact name of the module mentioned in the alert log.
65729 + Alternatively, the administrator can add the module to the list
65730 + of modules loaded at boot by modifying init scripts.
65731 +
65732 + Modification of init scripts will most likely be needed on
65733 + Ubuntu servers with encrypted home directory support enabled,
65734 + as the first non-root user logging in will cause the ecb(aes),
65735 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65736 +
65737 +config GRKERNSEC_HIDESYM
65738 + bool "Hide kernel symbols"
65739 + default y if GRKERNSEC_CONFIG_AUTO
65740 + select PAX_USERCOPY_SLABS
65741 + help
65742 + If you say Y here, getting information on loaded modules, and
65743 + displaying all kernel symbols through a syscall will be restricted
65744 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65745 + /proc/kallsyms will be restricted to the root user. The RBAC
65746 + system can hide that entry even from root.
65747 +
65748 + This option also prevents leaking of kernel addresses through
65749 + several /proc entries.
65750 +
65751 + Note that this option is only effective provided the following
65752 + conditions are met:
65753 + 1) The kernel using grsecurity is not precompiled by some distribution
65754 + 2) You have also enabled GRKERNSEC_DMESG
65755 + 3) You are using the RBAC system and hiding other files such as your
65756 + kernel image and System.map. Alternatively, enabling this option
65757 + causes the permissions on /boot, /lib/modules, and the kernel
65758 + source directory to change at compile time to prevent
65759 + reading by non-root users.
65760 + If the above conditions are met, this option will aid in providing a
65761 + useful protection against local kernel exploitation of overflows
65762 + and arbitrary read/write vulnerabilities.
65763 +
65764 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65765 + in addition to this feature.
65766 +
65767 +config GRKERNSEC_RANDSTRUCT
65768 + bool "Randomize layout of sensitive kernel structures"
65769 + default y if GRKERNSEC_CONFIG_AUTO
65770 + select GRKERNSEC_HIDESYM
65771 + select MODVERSIONS if MODULES
65772 + help
65773 + If you say Y here, the layouts of a number of sensitive kernel
65774 + structures (task, fs, cred, etc) and all structures composed entirely
65775 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65776 + This can introduce the requirement of an additional infoleak
65777 + vulnerability for exploits targeting these structure types.
65778 +
65779 + Enabling this feature will introduce some performance impact, slightly
65780 + increase memory usage, and prevent the use of forensic tools like
65781 + Volatility against the system (unless the kernel source tree isn't
65782 + cleaned after kernel installation).
65783 +
65784 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65785 + It remains after a make clean to allow for external modules to be compiled
65786 + with the existing seed and will be removed by a make mrproper or
65787 + make distclean.
65788 +
65789 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65790 + to install the supporting headers explicitly in addition to the normal
65791 + gcc package.
65792 +
65793 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65794 + bool "Use cacheline-aware structure randomization"
65795 + depends on GRKERNSEC_RANDSTRUCT
65796 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65797 + help
65798 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65799 + at restricting randomization to cacheline-sized groups of elements. It
65800 + will further not randomize bitfields in structures. This reduces the
65801 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65802 +
65803 +config GRKERNSEC_KERN_LOCKOUT
65804 + bool "Active kernel exploit response"
65805 + default y if GRKERNSEC_CONFIG_AUTO
65806 + depends on X86 || ARM || PPC || SPARC
65807 + help
65808 + If you say Y here, when a PaX alert is triggered due to suspicious
65809 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65810 + or an OOPS occurs due to bad memory accesses, instead of just
65811 + terminating the offending process (and potentially allowing
65812 + a subsequent exploit from the same user), we will take one of two
65813 + actions:
65814 + If the user was root, we will panic the system
65815 + If the user was non-root, we will log the attempt, terminate
65816 + all processes owned by the user, then prevent them from creating
65817 + any new processes until the system is restarted
65818 + This deters repeated kernel exploitation/bruteforcing attempts
65819 + and is useful for later forensics.
65820 +
65821 +config GRKERNSEC_OLD_ARM_USERLAND
65822 + bool "Old ARM userland compatibility"
65823 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65824 + help
65825 + If you say Y here, stubs of executable code to perform such operations
65826 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65827 + table. This is unfortunately needed for old ARM userland meant to run
65828 + across a wide range of processors. Without this option enabled,
65829 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65830 + which is enough for Linaro userlands or other userlands designed for v6
65831 + and newer ARM CPUs. It's recommended that you try without this option enabled
65832 + first, and only enable it if your userland does not boot (it will likely fail
65833 + at init time).
65834 +
65835 +endmenu
65836 +menu "Role Based Access Control Options"
65837 +depends on GRKERNSEC
65838 +
65839 +config GRKERNSEC_RBAC_DEBUG
65840 + bool
65841 +
65842 +config GRKERNSEC_NO_RBAC
65843 + bool "Disable RBAC system"
65844 + help
65845 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65846 + preventing the RBAC system from being enabled. You should only say Y
65847 + here if you have no intention of using the RBAC system, so as to prevent
65848 + an attacker with root access from misusing the RBAC system to hide files
65849 + and processes when loadable module support and /dev/[k]mem have been
65850 + locked down.
65851 +
65852 +config GRKERNSEC_ACL_HIDEKERN
65853 + bool "Hide kernel processes"
65854 + help
65855 + If you say Y here, all kernel threads will be hidden to all
65856 + processes but those whose subject has the "view hidden processes"
65857 + flag.
65858 +
65859 +config GRKERNSEC_ACL_MAXTRIES
65860 + int "Maximum tries before password lockout"
65861 + default 3
65862 + help
65863 + This option enforces the maximum number of times a user can attempt
65864 + to authorize themselves with the grsecurity RBAC system before being
65865 + denied the ability to attempt authorization again for a specified time.
65866 + The lower the number, the harder it will be to brute-force a password.
65867 +
65868 +config GRKERNSEC_ACL_TIMEOUT
65869 + int "Time to wait after max password tries, in seconds"
65870 + default 30
65871 + help
65872 + This option specifies the time the user must wait after attempting to
65873 + authorize to the RBAC system with the maximum number of invalid
65874 + passwords. The higher the number, the harder it will be to brute-force
65875 + a password.
65876 +
65877 +endmenu
65878 +menu "Filesystem Protections"
65879 +depends on GRKERNSEC
65880 +
65881 +config GRKERNSEC_PROC
65882 + bool "Proc restrictions"
65883 + default y if GRKERNSEC_CONFIG_AUTO
65884 + help
65885 + If you say Y here, the permissions of the /proc filesystem
65886 + will be altered to enhance system security and privacy. You MUST
65887 + choose either a user only restriction or a user and group restriction.
65888 + Depending upon the option you choose, you can either restrict users to
65889 + see only the processes they themselves run, or choose a group that can
65890 + view all processes and files normally restricted to root if you choose
65891 + the "restrict to user only" option. NOTE: If you're running identd or
65892 + ntpd as a non-root user, you will have to run it as the group you
65893 + specify here.
65894 +
65895 +config GRKERNSEC_PROC_USER
65896 + bool "Restrict /proc to user only"
65897 + depends on GRKERNSEC_PROC
65898 + help
65899 + If you say Y here, non-root users will only be able to view their own
65900 + processes, and restricts them from viewing network-related information,
65901 + and viewing kernel symbol and module information.
65902 +
65903 +config GRKERNSEC_PROC_USERGROUP
65904 + bool "Allow special group"
65905 + default y if GRKERNSEC_CONFIG_AUTO
65906 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65907 + help
65908 + If you say Y here, you will be able to select a group that will be
65909 + able to view all processes and network-related information. If you've
65910 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65911 + remain hidden. This option is useful if you want to run identd as
65912 + a non-root user. The group you select may also be chosen at boot time
65913 + via "grsec_proc_gid=" on the kernel commandline.
65914 +
65915 +config GRKERNSEC_PROC_GID
65916 + int "GID for special group"
65917 + depends on GRKERNSEC_PROC_USERGROUP
65918 + default 1001
65919 +
65920 +config GRKERNSEC_PROC_ADD
65921 + bool "Additional restrictions"
65922 + default y if GRKERNSEC_CONFIG_AUTO
65923 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65924 + help
65925 + If you say Y here, additional restrictions will be placed on
65926 + /proc that keep normal users from viewing device information and
65927 + slabinfo information that could be useful for exploits.
65928 +
65929 +config GRKERNSEC_LINK
65930 + bool "Linking restrictions"
65931 + default y if GRKERNSEC_CONFIG_AUTO
65932 + help
65933 + If you say Y here, /tmp race exploits will be prevented, since users
65934 + will no longer be able to follow symlinks owned by other users in
65935 + world-writable +t directories (e.g. /tmp), unless the owner of the
65936 + symlink is the owner of the directory. users will also not be
65937 + able to hardlink to files they do not own. If the sysctl option is
65938 + enabled, a sysctl option with name "linking_restrictions" is created.
65939 +
65940 +config GRKERNSEC_SYMLINKOWN
65941 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65942 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65943 + help
65944 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65945 + that prevents it from being used as a security feature. As Apache
65946 + verifies the symlink by performing a stat() against the target of
65947 + the symlink before it is followed, an attacker can setup a symlink
65948 + to point to a same-owned file, then replace the symlink with one
65949 + that targets another user's file just after Apache "validates" the
65950 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65951 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65952 + will be in place for the group you specify. If the sysctl option
65953 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65954 + created.
65955 +
65956 +config GRKERNSEC_SYMLINKOWN_GID
65957 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65958 + depends on GRKERNSEC_SYMLINKOWN
65959 + default 1006
65960 + help
65961 + Setting this GID determines what group kernel-enforced
65962 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65963 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65964 +
65965 +config GRKERNSEC_FIFO
65966 + bool "FIFO restrictions"
65967 + default y if GRKERNSEC_CONFIG_AUTO
65968 + help
65969 + If you say Y here, users will not be able to write to FIFOs they don't
65970 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65971 + the FIFO is the same owner of the directory it's held in. If the sysctl
65972 + option is enabled, a sysctl option with name "fifo_restrictions" is
65973 + created.
65974 +
65975 +config GRKERNSEC_SYSFS_RESTRICT
65976 + bool "Sysfs/debugfs restriction"
65977 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65978 + depends on SYSFS
65979 + help
65980 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65981 + any filesystem normally mounted under it (e.g. debugfs) will be
65982 + mostly accessible only by root. These filesystems generally provide access
65983 + to hardware and debug information that isn't appropriate for unprivileged
65984 + users of the system. Sysfs and debugfs have also become a large source
65985 + of new vulnerabilities, ranging from infoleaks to local compromise.
65986 + There has been very little oversight with an eye toward security involved
65987 + in adding new exporters of information to these filesystems, so their
65988 + use is discouraged.
65989 + For reasons of compatibility, a few directories have been whitelisted
65990 + for access by non-root users:
65991 + /sys/fs/selinux
65992 + /sys/fs/fuse
65993 + /sys/devices/system/cpu
65994 +
65995 +config GRKERNSEC_ROFS
65996 + bool "Runtime read-only mount protection"
65997 + depends on SYSCTL
65998 + help
65999 + If you say Y here, a sysctl option with name "romount_protect" will
66000 + be created. By setting this option to 1 at runtime, filesystems
66001 + will be protected in the following ways:
66002 + * No new writable mounts will be allowed
66003 + * Existing read-only mounts won't be able to be remounted read/write
66004 + * Write operations will be denied on all block devices
66005 + This option acts independently of grsec_lock: once it is set to 1,
66006 + it cannot be turned off. Therefore, please be mindful of the resulting
66007 + behavior if this option is enabled in an init script on a read-only
66008 + filesystem.
66009 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66010 + and GRKERNSEC_IO should be enabled and module loading disabled via
66011 + config or at runtime.
66012 + This feature is mainly intended for secure embedded systems.
66013 +
66014 +
66015 +config GRKERNSEC_DEVICE_SIDECHANNEL
66016 + bool "Eliminate stat/notify-based device sidechannels"
66017 + default y if GRKERNSEC_CONFIG_AUTO
66018 + help
66019 + If you say Y here, timing analyses on block or character
66020 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66021 + will be thwarted for unprivileged users. If a process without
66022 + CAP_MKNOD stats such a device, the last access and last modify times
66023 + will match the device's create time. No access or modify events
66024 + will be triggered through inotify/dnotify/fanotify for such devices.
66025 + This feature will prevent attacks that may at a minimum
66026 + allow an attacker to determine the administrator's password length.
66027 +
66028 +config GRKERNSEC_CHROOT
66029 + bool "Chroot jail restrictions"
66030 + default y if GRKERNSEC_CONFIG_AUTO
66031 + help
66032 + If you say Y here, you will be able to choose several options that will
66033 + make breaking out of a chrooted jail much more difficult. If you
66034 + encounter no software incompatibilities with the following options, it
66035 + is recommended that you enable each one.
66036 +
66037 + Note that the chroot restrictions are not intended to apply to "chroots"
66038 + to directories that are simple bind mounts of the global root filesystem.
66039 + For several other reasons, a user shouldn't expect any significant
66040 + security by performing such a chroot.
66041 +
66042 +config GRKERNSEC_CHROOT_MOUNT
66043 + bool "Deny mounts"
66044 + default y if GRKERNSEC_CONFIG_AUTO
66045 + depends on GRKERNSEC_CHROOT
66046 + help
66047 + If you say Y here, processes inside a chroot will not be able to
66048 + mount or remount filesystems. If the sysctl option is enabled, a
66049 + sysctl option with name "chroot_deny_mount" is created.
66050 +
66051 +config GRKERNSEC_CHROOT_DOUBLE
66052 + bool "Deny double-chroots"
66053 + default y if GRKERNSEC_CONFIG_AUTO
66054 + depends on GRKERNSEC_CHROOT
66055 + help
66056 + If you say Y here, processes inside a chroot will not be able to chroot
66057 + again outside the chroot. This is a widely used method of breaking
66058 + out of a chroot jail and should not be allowed. If the sysctl
66059 + option is enabled, a sysctl option with name
66060 + "chroot_deny_chroot" is created.
66061 +
66062 +config GRKERNSEC_CHROOT_PIVOT
66063 + bool "Deny pivot_root in chroot"
66064 + default y if GRKERNSEC_CONFIG_AUTO
66065 + depends on GRKERNSEC_CHROOT
66066 + help
66067 + If you say Y here, processes inside a chroot will not be able to use
66068 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66069 + works similar to chroot in that it changes the root filesystem. This
66070 + function could be misused in a chrooted process to attempt to break out
66071 + of the chroot, and therefore should not be allowed. If the sysctl
66072 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66073 + created.
66074 +
66075 +config GRKERNSEC_CHROOT_CHDIR
66076 + bool "Enforce chdir(\"/\") on all chroots"
66077 + default y if GRKERNSEC_CONFIG_AUTO
66078 + depends on GRKERNSEC_CHROOT
66079 + help
66080 + If you say Y here, the current working directory of all newly-chrooted
66081 + applications will be set to the the root directory of the chroot.
66082 + The man page on chroot(2) states:
66083 + Note that this call does not change the current working
66084 + directory, so that `.' can be outside the tree rooted at
66085 + `/'. In particular, the super-user can escape from a
66086 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66087 +
66088 + It is recommended that you say Y here, since it's not known to break
66089 + any software. If the sysctl option is enabled, a sysctl option with
66090 + name "chroot_enforce_chdir" is created.
66091 +
66092 +config GRKERNSEC_CHROOT_CHMOD
66093 + bool "Deny (f)chmod +s"
66094 + default y if GRKERNSEC_CONFIG_AUTO
66095 + depends on GRKERNSEC_CHROOT
66096 + help
66097 + If you say Y here, processes inside a chroot will not be able to chmod
66098 + or fchmod files to make them have suid or sgid bits. This protects
66099 + against another published method of breaking a chroot. If the sysctl
66100 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66101 + created.
66102 +
66103 +config GRKERNSEC_CHROOT_FCHDIR
66104 + bool "Deny fchdir and fhandle out of chroot"
66105 + default y if GRKERNSEC_CONFIG_AUTO
66106 + depends on GRKERNSEC_CHROOT
66107 + help
66108 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66109 + to a file descriptor of the chrooting process that points to a directory
66110 + outside the filesystem will be stopped. Additionally, this option prevents
66111 + use of the recently-created syscall for opening files by a guessable "file
66112 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66113 + with name "chroot_deny_fchdir" is created.
66114 +
66115 +config GRKERNSEC_CHROOT_MKNOD
66116 + bool "Deny mknod"
66117 + default y if GRKERNSEC_CONFIG_AUTO
66118 + depends on GRKERNSEC_CHROOT
66119 + help
66120 + If you say Y here, processes inside a chroot will not be allowed to
66121 + mknod. The problem with using mknod inside a chroot is that it
66122 + would allow an attacker to create a device entry that is the same
66123 + as one on the physical root of your system, which could range from
66124 + anything from the console device to a device for your harddrive (which
66125 + they could then use to wipe the drive or steal data). It is recommended
66126 + that you say Y here, unless you run into software incompatibilities.
66127 + If the sysctl option is enabled, a sysctl option with name
66128 + "chroot_deny_mknod" is created.
66129 +
66130 +config GRKERNSEC_CHROOT_SHMAT
66131 + bool "Deny shmat() out of chroot"
66132 + default y if GRKERNSEC_CONFIG_AUTO
66133 + depends on GRKERNSEC_CHROOT
66134 + help
66135 + If you say Y here, processes inside a chroot will not be able to attach
66136 + to shared memory segments that were created outside of the chroot jail.
66137 + It is recommended that you say Y here. If the sysctl option is enabled,
66138 + a sysctl option with name "chroot_deny_shmat" is created.
66139 +
66140 +config GRKERNSEC_CHROOT_UNIX
66141 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66142 + default y if GRKERNSEC_CONFIG_AUTO
66143 + depends on GRKERNSEC_CHROOT
66144 + help
66145 + If you say Y here, processes inside a chroot will not be able to
66146 + connect to abstract (meaning not belonging to a filesystem) Unix
66147 + domain sockets that were bound outside of a chroot. It is recommended
66148 + that you say Y here. If the sysctl option is enabled, a sysctl option
66149 + with name "chroot_deny_unix" is created.
66150 +
66151 +config GRKERNSEC_CHROOT_FINDTASK
66152 + bool "Protect outside processes"
66153 + default y if GRKERNSEC_CONFIG_AUTO
66154 + depends on GRKERNSEC_CHROOT
66155 + help
66156 + If you say Y here, processes inside a chroot will not be able to
66157 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66158 + getsid, or view any process outside of the chroot. If the sysctl
66159 + option is enabled, a sysctl option with name "chroot_findtask" is
66160 + created.
66161 +
66162 +config GRKERNSEC_CHROOT_NICE
66163 + bool "Restrict priority changes"
66164 + default y if GRKERNSEC_CONFIG_AUTO
66165 + depends on GRKERNSEC_CHROOT
66166 + help
66167 + If you say Y here, processes inside a chroot will not be able to raise
66168 + the priority of processes in the chroot, or alter the priority of
66169 + processes outside the chroot. This provides more security than simply
66170 + removing CAP_SYS_NICE from the process' capability set. If the
66171 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66172 + is created.
66173 +
66174 +config GRKERNSEC_CHROOT_SYSCTL
66175 + bool "Deny sysctl writes"
66176 + default y if GRKERNSEC_CONFIG_AUTO
66177 + depends on GRKERNSEC_CHROOT
66178 + help
66179 + If you say Y here, an attacker in a chroot will not be able to
66180 + write to sysctl entries, either by sysctl(2) or through a /proc
66181 + interface. It is strongly recommended that you say Y here. If the
66182 + sysctl option is enabled, a sysctl option with name
66183 + "chroot_deny_sysctl" is created.
66184 +
66185 +config GRKERNSEC_CHROOT_CAPS
66186 + bool "Capability restrictions"
66187 + default y if GRKERNSEC_CONFIG_AUTO
66188 + depends on GRKERNSEC_CHROOT
66189 + help
66190 + If you say Y here, the capabilities on all processes within a
66191 + chroot jail will be lowered to stop module insertion, raw i/o,
66192 + system and net admin tasks, rebooting the system, modifying immutable
66193 + files, modifying IPC owned by another, and changing the system time.
66194 + This is left an option because it can break some apps. Disable this
66195 + if your chrooted apps are having problems performing those kinds of
66196 + tasks. If the sysctl option is enabled, a sysctl option with
66197 + name "chroot_caps" is created.
66198 +
66199 +config GRKERNSEC_CHROOT_INITRD
66200 + bool "Exempt initrd tasks from restrictions"
66201 + default y if GRKERNSEC_CONFIG_AUTO
66202 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66203 + help
66204 + If you say Y here, tasks started prior to init will be exempted from
66205 + grsecurity's chroot restrictions. This option is mainly meant to
66206 + resolve Plymouth's performing privileged operations unnecessarily
66207 + in a chroot.
66208 +
66209 +endmenu
66210 +menu "Kernel Auditing"
66211 +depends on GRKERNSEC
66212 +
66213 +config GRKERNSEC_AUDIT_GROUP
66214 + bool "Single group for auditing"
66215 + help
66216 + If you say Y here, the exec and chdir logging features will only operate
66217 + on a group you specify. This option is recommended if you only want to
66218 + watch certain users instead of having a large amount of logs from the
66219 + entire system. If the sysctl option is enabled, a sysctl option with
66220 + name "audit_group" is created.
66221 +
66222 +config GRKERNSEC_AUDIT_GID
66223 + int "GID for auditing"
66224 + depends on GRKERNSEC_AUDIT_GROUP
66225 + default 1007
66226 +
66227 +config GRKERNSEC_EXECLOG
66228 + bool "Exec logging"
66229 + help
66230 + If you say Y here, all execve() calls will be logged (since the
66231 + other exec*() calls are frontends to execve(), all execution
66232 + will be logged). Useful for shell-servers that like to keep track
66233 + of their users. If the sysctl option is enabled, a sysctl option with
66234 + name "exec_logging" is created.
66235 + WARNING: This option when enabled will produce a LOT of logs, especially
66236 + on an active system.
66237 +
66238 +config GRKERNSEC_RESLOG
66239 + bool "Resource logging"
66240 + default y if GRKERNSEC_CONFIG_AUTO
66241 + help
66242 + If you say Y here, all attempts to overstep resource limits will
66243 + be logged with the resource name, the requested size, and the current
66244 + limit. It is highly recommended that you say Y here. If the sysctl
66245 + option is enabled, a sysctl option with name "resource_logging" is
66246 + created. If the RBAC system is enabled, the sysctl value is ignored.
66247 +
66248 +config GRKERNSEC_CHROOT_EXECLOG
66249 + bool "Log execs within chroot"
66250 + help
66251 + If you say Y here, all executions inside a chroot jail will be logged
66252 + to syslog. This can cause a large amount of logs if certain
66253 + applications (eg. djb's daemontools) are installed on the system, and
66254 + is therefore left as an option. If the sysctl option is enabled, a
66255 + sysctl option with name "chroot_execlog" is created.
66256 +
66257 +config GRKERNSEC_AUDIT_PTRACE
66258 + bool "Ptrace logging"
66259 + help
66260 + If you say Y here, all attempts to attach to a process via ptrace
66261 + will be logged. If the sysctl option is enabled, a sysctl option
66262 + with name "audit_ptrace" is created.
66263 +
66264 +config GRKERNSEC_AUDIT_CHDIR
66265 + bool "Chdir logging"
66266 + help
66267 + If you say Y here, all chdir() calls will be logged. If the sysctl
66268 + option is enabled, a sysctl option with name "audit_chdir" is created.
66269 +
66270 +config GRKERNSEC_AUDIT_MOUNT
66271 + bool "(Un)Mount logging"
66272 + help
66273 + If you say Y here, all mounts and unmounts will be logged. If the
66274 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66275 + created.
66276 +
66277 +config GRKERNSEC_SIGNAL
66278 + bool "Signal logging"
66279 + default y if GRKERNSEC_CONFIG_AUTO
66280 + help
66281 + If you say Y here, certain important signals will be logged, such as
66282 + SIGSEGV, which will as a result inform you of when a error in a program
66283 + occurred, which in some cases could mean a possible exploit attempt.
66284 + If the sysctl option is enabled, a sysctl option with name
66285 + "signal_logging" is created.
66286 +
66287 +config GRKERNSEC_FORKFAIL
66288 + bool "Fork failure logging"
66289 + help
66290 + If you say Y here, all failed fork() attempts will be logged.
66291 + This could suggest a fork bomb, or someone attempting to overstep
66292 + their process limit. If the sysctl option is enabled, a sysctl option
66293 + with name "forkfail_logging" is created.
66294 +
66295 +config GRKERNSEC_TIME
66296 + bool "Time change logging"
66297 + default y if GRKERNSEC_CONFIG_AUTO
66298 + help
66299 + If you say Y here, any changes of the system clock will be logged.
66300 + If the sysctl option is enabled, a sysctl option with name
66301 + "timechange_logging" is created.
66302 +
66303 +config GRKERNSEC_PROC_IPADDR
66304 + bool "/proc/<pid>/ipaddr support"
66305 + default y if GRKERNSEC_CONFIG_AUTO
66306 + help
66307 + If you say Y here, a new entry will be added to each /proc/<pid>
66308 + directory that contains the IP address of the person using the task.
66309 + The IP is carried across local TCP and AF_UNIX stream sockets.
66310 + This information can be useful for IDS/IPSes to perform remote response
66311 + to a local attack. The entry is readable by only the owner of the
66312 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66313 + the RBAC system), and thus does not create privacy concerns.
66314 +
66315 +config GRKERNSEC_RWXMAP_LOG
66316 + bool 'Denied RWX mmap/mprotect logging'
66317 + default y if GRKERNSEC_CONFIG_AUTO
66318 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66319 + help
66320 + If you say Y here, calls to mmap() and mprotect() with explicit
66321 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66322 + denied by the PAX_MPROTECT feature. This feature will also
66323 + log other problematic scenarios that can occur when PAX_MPROTECT
66324 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66325 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66326 + is created.
66327 +
66328 +endmenu
66329 +
66330 +menu "Executable Protections"
66331 +depends on GRKERNSEC
66332 +
66333 +config GRKERNSEC_DMESG
66334 + bool "Dmesg(8) restriction"
66335 + default y if GRKERNSEC_CONFIG_AUTO
66336 + help
66337 + If you say Y here, non-root users will not be able to use dmesg(8)
66338 + to view the contents of the kernel's circular log buffer.
66339 + The kernel's log buffer often contains kernel addresses and other
66340 + identifying information useful to an attacker in fingerprinting a
66341 + system for a targeted exploit.
66342 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66343 + created.
66344 +
66345 +config GRKERNSEC_HARDEN_PTRACE
66346 + bool "Deter ptrace-based process snooping"
66347 + default y if GRKERNSEC_CONFIG_AUTO
66348 + help
66349 + If you say Y here, TTY sniffers and other malicious monitoring
66350 + programs implemented through ptrace will be defeated. If you
66351 + have been using the RBAC system, this option has already been
66352 + enabled for several years for all users, with the ability to make
66353 + fine-grained exceptions.
66354 +
66355 + This option only affects the ability of non-root users to ptrace
66356 + processes that are not a descendent of the ptracing process.
66357 + This means that strace ./binary and gdb ./binary will still work,
66358 + but attaching to arbitrary processes will not. If the sysctl
66359 + option is enabled, a sysctl option with name "harden_ptrace" is
66360 + created.
66361 +
66362 +config GRKERNSEC_PTRACE_READEXEC
66363 + bool "Require read access to ptrace sensitive binaries"
66364 + default y if GRKERNSEC_CONFIG_AUTO
66365 + help
66366 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66367 + binaries. This option is useful in environments that
66368 + remove the read bits (e.g. file mode 4711) from suid binaries to
66369 + prevent infoleaking of their contents. This option adds
66370 + consistency to the use of that file mode, as the binary could normally
66371 + be read out when run without privileges while ptracing.
66372 +
66373 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66374 + is created.
66375 +
66376 +config GRKERNSEC_SETXID
66377 + bool "Enforce consistent multithreaded privileges"
66378 + default y if GRKERNSEC_CONFIG_AUTO
66379 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66380 + help
66381 + If you say Y here, a change from a root uid to a non-root uid
66382 + in a multithreaded application will cause the resulting uids,
66383 + gids, supplementary groups, and capabilities in that thread
66384 + to be propagated to the other threads of the process. In most
66385 + cases this is unnecessary, as glibc will emulate this behavior
66386 + on behalf of the application. Other libcs do not act in the
66387 + same way, allowing the other threads of the process to continue
66388 + running with root privileges. If the sysctl option is enabled,
66389 + a sysctl option with name "consistent_setxid" is created.
66390 +
66391 +config GRKERNSEC_HARDEN_IPC
66392 + bool "Disallow access to overly-permissive IPC objects"
66393 + default y if GRKERNSEC_CONFIG_AUTO
66394 + depends on SYSVIPC
66395 + help
66396 + If you say Y here, access to overly-permissive IPC objects (shared
66397 + memory, message queues, and semaphores) will be denied for processes
66398 + given the following criteria beyond normal permission checks:
66399 + 1) If the IPC object is world-accessible and the euid doesn't match
66400 + that of the creator or current uid for the IPC object
66401 + 2) If the IPC object is group-accessible and the egid doesn't
66402 + match that of the creator or current gid for the IPC object
66403 + It's a common error to grant too much permission to these objects,
66404 + with impact ranging from denial of service and information leaking to
66405 + privilege escalation. This feature was developed in response to
66406 + research by Tim Brown:
66407 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66408 + who found hundreds of such insecure usages. Processes with
66409 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66410 + If the sysctl option is enabled, a sysctl option with name
66411 + "harden_ipc" is created.
66412 +
66413 +config GRKERNSEC_TPE
66414 + bool "Trusted Path Execution (TPE)"
66415 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66416 + help
66417 + If you say Y here, you will be able to choose a gid to add to the
66418 + supplementary groups of users you want to mark as "untrusted."
66419 + These users will not be able to execute any files that are not in
66420 + root-owned directories writable only by root. If the sysctl option
66421 + is enabled, a sysctl option with name "tpe" is created.
66422 +
66423 +config GRKERNSEC_TPE_ALL
66424 + bool "Partially restrict all non-root users"
66425 + depends on GRKERNSEC_TPE
66426 + help
66427 + If you say Y here, all non-root users will be covered under
66428 + a weaker TPE restriction. This is separate from, and in addition to,
66429 + the main TPE options that you have selected elsewhere. Thus, if a
66430 + "trusted" GID is chosen, this restriction applies to even that GID.
66431 + Under this restriction, all non-root users will only be allowed to
66432 + execute files in directories they own that are not group or
66433 + world-writable, or in directories owned by root and writable only by
66434 + root. If the sysctl option is enabled, a sysctl option with name
66435 + "tpe_restrict_all" is created.
66436 +
66437 +config GRKERNSEC_TPE_INVERT
66438 + bool "Invert GID option"
66439 + depends on GRKERNSEC_TPE
66440 + help
66441 + If you say Y here, the group you specify in the TPE configuration will
66442 + decide what group TPE restrictions will be *disabled* for. This
66443 + option is useful if you want TPE restrictions to be applied to most
66444 + users on the system. If the sysctl option is enabled, a sysctl option
66445 + with name "tpe_invert" is created. Unlike other sysctl options, this
66446 + entry will default to on for backward-compatibility.
66447 +
66448 +config GRKERNSEC_TPE_GID
66449 + int
66450 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66451 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66452 +
66453 +config GRKERNSEC_TPE_UNTRUSTED_GID
66454 + int "GID for TPE-untrusted users"
66455 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66456 + default 1005
66457 + help
66458 + Setting this GID determines what group TPE restrictions will be
66459 + *enabled* for. If the sysctl option is enabled, a sysctl option
66460 + with name "tpe_gid" is created.
66461 +
66462 +config GRKERNSEC_TPE_TRUSTED_GID
66463 + int "GID for TPE-trusted users"
66464 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66465 + default 1005
66466 + help
66467 + Setting this GID determines what group TPE restrictions will be
66468 + *disabled* for. If the sysctl option is enabled, a sysctl option
66469 + with name "tpe_gid" is created.
66470 +
66471 +endmenu
66472 +menu "Network Protections"
66473 +depends on GRKERNSEC
66474 +
66475 +config GRKERNSEC_RANDNET
66476 + bool "Larger entropy pools"
66477 + default y if GRKERNSEC_CONFIG_AUTO
66478 + help
66479 + If you say Y here, the entropy pools used for many features of Linux
66480 + and grsecurity will be doubled in size. Since several grsecurity
66481 + features use additional randomness, it is recommended that you say Y
66482 + here. Saying Y here has a similar effect as modifying
66483 + /proc/sys/kernel/random/poolsize.
66484 +
66485 +config GRKERNSEC_BLACKHOLE
66486 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66487 + default y if GRKERNSEC_CONFIG_AUTO
66488 + depends on NET
66489 + help
66490 + If you say Y here, neither TCP resets nor ICMP
66491 + destination-unreachable packets will be sent in response to packets
66492 + sent to ports for which no associated listening process exists.
66493 + This feature supports both IPV4 and IPV6 and exempts the
66494 + loopback interface from blackholing. Enabling this feature
66495 + makes a host more resilient to DoS attacks and reduces network
66496 + visibility against scanners.
66497 +
66498 + The blackhole feature as-implemented is equivalent to the FreeBSD
66499 + blackhole feature, as it prevents RST responses to all packets, not
66500 + just SYNs. Under most application behavior this causes no
66501 + problems, but applications (like haproxy) may not close certain
66502 + connections in a way that cleanly terminates them on the remote
66503 + end, leaving the remote host in LAST_ACK state. Because of this
66504 + side-effect and to prevent intentional LAST_ACK DoSes, this
66505 + feature also adds automatic mitigation against such attacks.
66506 + The mitigation drastically reduces the amount of time a socket
66507 + can spend in LAST_ACK state. If you're using haproxy and not
66508 + all servers it connects to have this option enabled, consider
66509 + disabling this feature on the haproxy host.
66510 +
66511 + If the sysctl option is enabled, two sysctl options with names
66512 + "ip_blackhole" and "lastack_retries" will be created.
66513 + While "ip_blackhole" takes the standard zero/non-zero on/off
66514 + toggle, "lastack_retries" uses the same kinds of values as
66515 + "tcp_retries1" and "tcp_retries2". The default value of 4
66516 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66517 + state.
66518 +
66519 +config GRKERNSEC_NO_SIMULT_CONNECT
66520 + bool "Disable TCP Simultaneous Connect"
66521 + default y if GRKERNSEC_CONFIG_AUTO
66522 + depends on NET
66523 + help
66524 + If you say Y here, a feature by Willy Tarreau will be enabled that
66525 + removes a weakness in Linux's strict implementation of TCP that
66526 + allows two clients to connect to each other without either entering
66527 + a listening state. The weakness allows an attacker to easily prevent
66528 + a client from connecting to a known server provided the source port
66529 + for the connection is guessed correctly.
66530 +
66531 + As the weakness could be used to prevent an antivirus or IPS from
66532 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66533 + it should be eliminated by enabling this option. Though Linux is
66534 + one of few operating systems supporting simultaneous connect, it
66535 + has no legitimate use in practice and is rarely supported by firewalls.
66536 +
66537 +config GRKERNSEC_SOCKET
66538 + bool "Socket restrictions"
66539 + depends on NET
66540 + help
66541 + If you say Y here, you will be able to choose from several options.
66542 + If you assign a GID on your system and add it to the supplementary
66543 + groups of users you want to restrict socket access to, this patch
66544 + will perform up to three things, based on the option(s) you choose.
66545 +
66546 +config GRKERNSEC_SOCKET_ALL
66547 + bool "Deny any sockets to group"
66548 + depends on GRKERNSEC_SOCKET
66549 + help
66550 + If you say Y here, you will be able to choose a GID of whose users will
66551 + be unable to connect to other hosts from your machine or run server
66552 + applications from your machine. If the sysctl option is enabled, a
66553 + sysctl option with name "socket_all" is created.
66554 +
66555 +config GRKERNSEC_SOCKET_ALL_GID
66556 + int "GID to deny all sockets for"
66557 + depends on GRKERNSEC_SOCKET_ALL
66558 + default 1004
66559 + help
66560 + Here you can choose the GID to disable socket access for. Remember to
66561 + add the users you want socket access disabled for to the GID
66562 + specified here. If the sysctl option is enabled, a sysctl option
66563 + with name "socket_all_gid" is created.
66564 +
66565 +config GRKERNSEC_SOCKET_CLIENT
66566 + bool "Deny client sockets to group"
66567 + depends on GRKERNSEC_SOCKET
66568 + help
66569 + If you say Y here, you will be able to choose a GID of whose users will
66570 + be unable to connect to other hosts from your machine, but will be
66571 + able to run servers. If this option is enabled, all users in the group
66572 + you specify will have to use passive mode when initiating ftp transfers
66573 + from the shell on your machine. If the sysctl option is enabled, a
66574 + sysctl option with name "socket_client" is created.
66575 +
66576 +config GRKERNSEC_SOCKET_CLIENT_GID
66577 + int "GID to deny client sockets for"
66578 + depends on GRKERNSEC_SOCKET_CLIENT
66579 + default 1003
66580 + help
66581 + Here you can choose the GID to disable client socket access for.
66582 + Remember to add the users you want client socket access disabled for to
66583 + the GID specified here. If the sysctl option is enabled, a sysctl
66584 + option with name "socket_client_gid" is created.
66585 +
66586 +config GRKERNSEC_SOCKET_SERVER
66587 + bool "Deny server sockets to group"
66588 + depends on GRKERNSEC_SOCKET
66589 + help
66590 + If you say Y here, you will be able to choose a GID of whose users will
66591 + be unable to run server applications from your machine. If the sysctl
66592 + option is enabled, a sysctl option with name "socket_server" is created.
66593 +
66594 +config GRKERNSEC_SOCKET_SERVER_GID
66595 + int "GID to deny server sockets for"
66596 + depends on GRKERNSEC_SOCKET_SERVER
66597 + default 1002
66598 + help
66599 + Here you can choose the GID to disable server socket access for.
66600 + Remember to add the users you want server socket access disabled for to
66601 + the GID specified here. If the sysctl option is enabled, a sysctl
66602 + option with name "socket_server_gid" is created.
66603 +
66604 +endmenu
66605 +
66606 +menu "Physical Protections"
66607 +depends on GRKERNSEC
66608 +
66609 +config GRKERNSEC_DENYUSB
66610 + bool "Deny new USB connections after toggle"
66611 + default y if GRKERNSEC_CONFIG_AUTO
66612 + depends on SYSCTL && USB_SUPPORT
66613 + help
66614 + If you say Y here, a new sysctl option with name "deny_new_usb"
66615 + will be created. Setting its value to 1 will prevent any new
66616 + USB devices from being recognized by the OS. Any attempted USB
66617 + device insertion will be logged. This option is intended to be
66618 + used against custom USB devices designed to exploit vulnerabilities
66619 + in various USB device drivers.
66620 +
66621 + For greatest effectiveness, this sysctl should be set after any
66622 + relevant init scripts. This option is safe to enable in distros
66623 + as each user can choose whether or not to toggle the sysctl.
66624 +
66625 +config GRKERNSEC_DENYUSB_FORCE
66626 + bool "Reject all USB devices not connected at boot"
66627 + select USB
66628 + depends on GRKERNSEC_DENYUSB
66629 + help
66630 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66631 + that doesn't involve a sysctl entry. This option should only be
66632 + enabled if you're sure you want to deny all new USB connections
66633 + at runtime and don't want to modify init scripts. This should not
66634 + be enabled by distros. It forces the core USB code to be built
66635 + into the kernel image so that all devices connected at boot time
66636 + can be recognized and new USB device connections can be prevented
66637 + prior to init running.
66638 +
66639 +endmenu
66640 +
66641 +menu "Sysctl Support"
66642 +depends on GRKERNSEC && SYSCTL
66643 +
66644 +config GRKERNSEC_SYSCTL
66645 + bool "Sysctl support"
66646 + default y if GRKERNSEC_CONFIG_AUTO
66647 + help
66648 + If you say Y here, you will be able to change the options that
66649 + grsecurity runs with at bootup, without having to recompile your
66650 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66651 + to enable (1) or disable (0) various features. All the sysctl entries
66652 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66653 + All features enabled in the kernel configuration are disabled at boot
66654 + if you do not say Y to the "Turn on features by default" option.
66655 + All options should be set at startup, and the grsec_lock entry should
66656 + be set to a non-zero value after all the options are set.
66657 + *THIS IS EXTREMELY IMPORTANT*
66658 +
66659 +config GRKERNSEC_SYSCTL_DISTRO
66660 + bool "Extra sysctl support for distro makers (READ HELP)"
66661 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66662 + help
66663 + If you say Y here, additional sysctl options will be created
66664 + for features that affect processes running as root. Therefore,
66665 + it is critical when using this option that the grsec_lock entry be
66666 + enabled after boot. Only distros with prebuilt kernel packages
66667 + with this option enabled that can ensure grsec_lock is enabled
66668 + after boot should use this option.
66669 + *Failure to set grsec_lock after boot makes all grsec features
66670 + this option covers useless*
66671 +
66672 + Currently this option creates the following sysctl entries:
66673 + "Disable Privileged I/O": "disable_priv_io"
66674 +
66675 +config GRKERNSEC_SYSCTL_ON
66676 + bool "Turn on features by default"
66677 + default y if GRKERNSEC_CONFIG_AUTO
66678 + depends on GRKERNSEC_SYSCTL
66679 + help
66680 + If you say Y here, instead of having all features enabled in the
66681 + kernel configuration disabled at boot time, the features will be
66682 + enabled at boot time. It is recommended you say Y here unless
66683 + there is some reason you would want all sysctl-tunable features to
66684 + be disabled by default. As mentioned elsewhere, it is important
66685 + to enable the grsec_lock entry once you have finished modifying
66686 + the sysctl entries.
66687 +
66688 +endmenu
66689 +menu "Logging Options"
66690 +depends on GRKERNSEC
66691 +
66692 +config GRKERNSEC_FLOODTIME
66693 + int "Seconds in between log messages (minimum)"
66694 + default 10
66695 + help
66696 + This option allows you to enforce the number of seconds between
66697 + grsecurity log messages. The default should be suitable for most
66698 + people, however, if you choose to change it, choose a value small enough
66699 + to allow informative logs to be produced, but large enough to
66700 + prevent flooding.
66701 +
66702 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66703 + any rate limiting on grsecurity log messages.
66704 +
66705 +config GRKERNSEC_FLOODBURST
66706 + int "Number of messages in a burst (maximum)"
66707 + default 6
66708 + help
66709 + This option allows you to choose the maximum number of messages allowed
66710 + within the flood time interval you chose in a separate option. The
66711 + default should be suitable for most people, however if you find that
66712 + many of your logs are being interpreted as flooding, you may want to
66713 + raise this value.
66714 +
66715 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66716 + any rate limiting on grsecurity log messages.
66717 +
66718 +endmenu
66719 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66720 new file mode 100644
66721 index 0000000..30ababb
66722 --- /dev/null
66723 +++ b/grsecurity/Makefile
66724 @@ -0,0 +1,54 @@
66725 +# grsecurity – access control and security hardening for Linux
66726 +# All code in this directory and various hooks located throughout the Linux kernel are
66727 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66728 +# http://www.grsecurity.net spender@grsecurity.net
66729 +#
66730 +# This program is free software; you can redistribute it and/or
66731 +# modify it under the terms of the GNU General Public License version 2
66732 +# as published by the Free Software Foundation.
66733 +#
66734 +# This program is distributed in the hope that it will be useful,
66735 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66736 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66737 +# GNU General Public License for more details.
66738 +#
66739 +# You should have received a copy of the GNU General Public License
66740 +# along with this program; if not, write to the Free Software
66741 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66742 +
66743 +KBUILD_CFLAGS += -Werror
66744 +
66745 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66746 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66747 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66748 + grsec_usb.o grsec_ipc.o grsec_proc.o
66749 +
66750 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66751 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66752 + gracl_learn.o grsec_log.o gracl_policy.o
66753 +ifdef CONFIG_COMPAT
66754 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66755 +endif
66756 +
66757 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66758 +
66759 +ifdef CONFIG_NET
66760 +obj-y += grsec_sock.o
66761 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66762 +endif
66763 +
66764 +ifndef CONFIG_GRKERNSEC
66765 +obj-y += grsec_disabled.o
66766 +endif
66767 +
66768 +ifdef CONFIG_GRKERNSEC_HIDESYM
66769 +extra-y := grsec_hidesym.o
66770 +$(obj)/grsec_hidesym.o:
66771 + @-chmod -f 500 /boot
66772 + @-chmod -f 500 /lib/modules
66773 + @-chmod -f 500 /lib64/modules
66774 + @-chmod -f 500 /lib32/modules
66775 + @-chmod -f 700 .
66776 + @-chmod -f 700 $(objtree)
66777 + @echo ' grsec: protected kernel image paths'
66778 +endif
66779 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66780 new file mode 100644
66781 index 0000000..58223f6
66782 --- /dev/null
66783 +++ b/grsecurity/gracl.c
66784 @@ -0,0 +1,2702 @@
66785 +#include <linux/kernel.h>
66786 +#include <linux/module.h>
66787 +#include <linux/sched.h>
66788 +#include <linux/mm.h>
66789 +#include <linux/file.h>
66790 +#include <linux/fs.h>
66791 +#include <linux/namei.h>
66792 +#include <linux/mount.h>
66793 +#include <linux/tty.h>
66794 +#include <linux/proc_fs.h>
66795 +#include <linux/lglock.h>
66796 +#include <linux/slab.h>
66797 +#include <linux/vmalloc.h>
66798 +#include <linux/types.h>
66799 +#include <linux/sysctl.h>
66800 +#include <linux/netdevice.h>
66801 +#include <linux/ptrace.h>
66802 +#include <linux/gracl.h>
66803 +#include <linux/gralloc.h>
66804 +#include <linux/security.h>
66805 +#include <linux/grinternal.h>
66806 +#include <linux/pid_namespace.h>
66807 +#include <linux/stop_machine.h>
66808 +#include <linux/fdtable.h>
66809 +#include <linux/percpu.h>
66810 +#include <linux/lglock.h>
66811 +#include <linux/hugetlb.h>
66812 +#include <linux/posix-timers.h>
66813 +#include <linux/prefetch.h>
66814 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66815 +#include <linux/magic.h>
66816 +#include <linux/pagemap.h>
66817 +#include "../fs/btrfs/async-thread.h"
66818 +#include "../fs/btrfs/ctree.h"
66819 +#include "../fs/btrfs/btrfs_inode.h"
66820 +#endif
66821 +#include "../fs/mount.h"
66822 +
66823 +#include <asm/uaccess.h>
66824 +#include <asm/errno.h>
66825 +#include <asm/mman.h>
66826 +
66827 +#define FOR_EACH_ROLE_START(role) \
66828 + role = running_polstate.role_list; \
66829 + while (role) {
66830 +
66831 +#define FOR_EACH_ROLE_END(role) \
66832 + role = role->prev; \
66833 + }
66834 +
66835 +extern struct path gr_real_root;
66836 +
66837 +static struct gr_policy_state running_polstate;
66838 +struct gr_policy_state *polstate = &running_polstate;
66839 +extern struct gr_alloc_state *current_alloc_state;
66840 +
66841 +extern char *gr_shared_page[4];
66842 +DEFINE_RWLOCK(gr_inode_lock);
66843 +
66844 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66845 +
66846 +#ifdef CONFIG_NET
66847 +extern struct vfsmount *sock_mnt;
66848 +#endif
66849 +
66850 +extern struct vfsmount *pipe_mnt;
66851 +extern struct vfsmount *shm_mnt;
66852 +
66853 +#ifdef CONFIG_HUGETLBFS
66854 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66855 +#endif
66856 +
66857 +extern u16 acl_sp_role_value;
66858 +extern struct acl_object_label *fakefs_obj_rw;
66859 +extern struct acl_object_label *fakefs_obj_rwx;
66860 +
66861 +int gr_acl_is_enabled(void)
66862 +{
66863 + return (gr_status & GR_READY);
66864 +}
66865 +
66866 +void gr_enable_rbac_system(void)
66867 +{
66868 + pax_open_kernel();
66869 + gr_status |= GR_READY;
66870 + pax_close_kernel();
66871 +}
66872 +
66873 +int gr_rbac_disable(void *unused)
66874 +{
66875 + pax_open_kernel();
66876 + gr_status &= ~GR_READY;
66877 + pax_close_kernel();
66878 +
66879 + return 0;
66880 +}
66881 +
66882 +static inline dev_t __get_dev(const struct dentry *dentry)
66883 +{
66884 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66885 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66886 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66887 + else
66888 +#endif
66889 + return dentry->d_sb->s_dev;
66890 +}
66891 +
66892 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66893 +{
66894 + return __get_dev(dentry);
66895 +}
66896 +
66897 +static char gr_task_roletype_to_char(struct task_struct *task)
66898 +{
66899 + switch (task->role->roletype &
66900 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66901 + GR_ROLE_SPECIAL)) {
66902 + case GR_ROLE_DEFAULT:
66903 + return 'D';
66904 + case GR_ROLE_USER:
66905 + return 'U';
66906 + case GR_ROLE_GROUP:
66907 + return 'G';
66908 + case GR_ROLE_SPECIAL:
66909 + return 'S';
66910 + }
66911 +
66912 + return 'X';
66913 +}
66914 +
66915 +char gr_roletype_to_char(void)
66916 +{
66917 + return gr_task_roletype_to_char(current);
66918 +}
66919 +
66920 +__inline__ int
66921 +gr_acl_tpe_check(void)
66922 +{
66923 + if (unlikely(!(gr_status & GR_READY)))
66924 + return 0;
66925 + if (current->role->roletype & GR_ROLE_TPE)
66926 + return 1;
66927 + else
66928 + return 0;
66929 +}
66930 +
66931 +int
66932 +gr_handle_rawio(const struct inode *inode)
66933 +{
66934 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66935 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66936 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66937 + !capable(CAP_SYS_RAWIO))
66938 + return 1;
66939 +#endif
66940 + return 0;
66941 +}
66942 +
66943 +int
66944 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66945 +{
66946 + if (likely(lena != lenb))
66947 + return 0;
66948 +
66949 + return !memcmp(a, b, lena);
66950 +}
66951 +
66952 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66953 +{
66954 + *buflen -= namelen;
66955 + if (*buflen < 0)
66956 + return -ENAMETOOLONG;
66957 + *buffer -= namelen;
66958 + memcpy(*buffer, str, namelen);
66959 + return 0;
66960 +}
66961 +
66962 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66963 +{
66964 + return prepend(buffer, buflen, name->name, name->len);
66965 +}
66966 +
66967 +static int prepend_path(const struct path *path, struct path *root,
66968 + char **buffer, int *buflen)
66969 +{
66970 + struct dentry *dentry = path->dentry;
66971 + struct vfsmount *vfsmnt = path->mnt;
66972 + struct mount *mnt = real_mount(vfsmnt);
66973 + bool slash = false;
66974 + int error = 0;
66975 +
66976 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66977 + struct dentry * parent;
66978 +
66979 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66980 + /* Global root? */
66981 + if (!mnt_has_parent(mnt)) {
66982 + goto out;
66983 + }
66984 + dentry = mnt->mnt_mountpoint;
66985 + mnt = mnt->mnt_parent;
66986 + vfsmnt = &mnt->mnt;
66987 + continue;
66988 + }
66989 + parent = dentry->d_parent;
66990 + prefetch(parent);
66991 + spin_lock(&dentry->d_lock);
66992 + error = prepend_name(buffer, buflen, &dentry->d_name);
66993 + spin_unlock(&dentry->d_lock);
66994 + if (!error)
66995 + error = prepend(buffer, buflen, "/", 1);
66996 + if (error)
66997 + break;
66998 +
66999 + slash = true;
67000 + dentry = parent;
67001 + }
67002 +
67003 +out:
67004 + if (!error && !slash)
67005 + error = prepend(buffer, buflen, "/", 1);
67006 +
67007 + return error;
67008 +}
67009 +
67010 +/* this must be called with mount_lock and rename_lock held */
67011 +
67012 +static char *__our_d_path(const struct path *path, struct path *root,
67013 + char *buf, int buflen)
67014 +{
67015 + char *res = buf + buflen;
67016 + int error;
67017 +
67018 + prepend(&res, &buflen, "\0", 1);
67019 + error = prepend_path(path, root, &res, &buflen);
67020 + if (error)
67021 + return ERR_PTR(error);
67022 +
67023 + return res;
67024 +}
67025 +
67026 +static char *
67027 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67028 +{
67029 + char *retval;
67030 +
67031 + retval = __our_d_path(path, root, buf, buflen);
67032 + if (unlikely(IS_ERR(retval)))
67033 + retval = strcpy(buf, "<path too long>");
67034 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67035 + retval[1] = '\0';
67036 +
67037 + return retval;
67038 +}
67039 +
67040 +static char *
67041 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67042 + char *buf, int buflen)
67043 +{
67044 + struct path path;
67045 + char *res;
67046 +
67047 + path.dentry = (struct dentry *)dentry;
67048 + path.mnt = (struct vfsmount *)vfsmnt;
67049 +
67050 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67051 + by the RBAC system */
67052 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67053 +
67054 + return res;
67055 +}
67056 +
67057 +static char *
67058 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67059 + char *buf, int buflen)
67060 +{
67061 + char *res;
67062 + struct path path;
67063 + struct path root;
67064 + struct task_struct *reaper = init_pid_ns.child_reaper;
67065 +
67066 + path.dentry = (struct dentry *)dentry;
67067 + path.mnt = (struct vfsmount *)vfsmnt;
67068 +
67069 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67070 + get_fs_root(reaper->fs, &root);
67071 +
67072 + read_seqlock_excl(&mount_lock);
67073 + write_seqlock(&rename_lock);
67074 + res = gen_full_path(&path, &root, buf, buflen);
67075 + write_sequnlock(&rename_lock);
67076 + read_sequnlock_excl(&mount_lock);
67077 +
67078 + path_put(&root);
67079 + return res;
67080 +}
67081 +
67082 +char *
67083 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67084 +{
67085 + char *ret;
67086 + read_seqlock_excl(&mount_lock);
67087 + write_seqlock(&rename_lock);
67088 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67089 + PAGE_SIZE);
67090 + write_sequnlock(&rename_lock);
67091 + read_sequnlock_excl(&mount_lock);
67092 + return ret;
67093 +}
67094 +
67095 +static char *
67096 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67097 +{
67098 + char *ret;
67099 + char *buf;
67100 + int buflen;
67101 +
67102 + read_seqlock_excl(&mount_lock);
67103 + write_seqlock(&rename_lock);
67104 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67105 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67106 + buflen = (int)(ret - buf);
67107 + if (buflen >= 5)
67108 + prepend(&ret, &buflen, "/proc", 5);
67109 + else
67110 + ret = strcpy(buf, "<path too long>");
67111 + write_sequnlock(&rename_lock);
67112 + read_sequnlock_excl(&mount_lock);
67113 + return ret;
67114 +}
67115 +
67116 +char *
67117 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67118 +{
67119 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67120 + PAGE_SIZE);
67121 +}
67122 +
67123 +char *
67124 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67125 +{
67126 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67127 + PAGE_SIZE);
67128 +}
67129 +
67130 +char *
67131 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67132 +{
67133 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67134 + PAGE_SIZE);
67135 +}
67136 +
67137 +char *
67138 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67139 +{
67140 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67141 + PAGE_SIZE);
67142 +}
67143 +
67144 +char *
67145 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67146 +{
67147 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67148 + PAGE_SIZE);
67149 +}
67150 +
67151 +__inline__ __u32
67152 +to_gr_audit(const __u32 reqmode)
67153 +{
67154 + /* masks off auditable permission flags, then shifts them to create
67155 + auditing flags, and adds the special case of append auditing if
67156 + we're requesting write */
67157 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67158 +}
67159 +
67160 +struct acl_role_label *
67161 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67162 + const gid_t gid)
67163 +{
67164 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67165 + struct acl_role_label *match;
67166 + struct role_allowed_ip *ipp;
67167 + unsigned int x;
67168 + u32 curr_ip = task->signal->saved_ip;
67169 +
67170 + match = state->acl_role_set.r_hash[index];
67171 +
67172 + while (match) {
67173 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67174 + for (x = 0; x < match->domain_child_num; x++) {
67175 + if (match->domain_children[x] == uid)
67176 + goto found;
67177 + }
67178 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67179 + break;
67180 + match = match->next;
67181 + }
67182 +found:
67183 + if (match == NULL) {
67184 + try_group:
67185 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67186 + match = state->acl_role_set.r_hash[index];
67187 +
67188 + while (match) {
67189 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67190 + for (x = 0; x < match->domain_child_num; x++) {
67191 + if (match->domain_children[x] == gid)
67192 + goto found2;
67193 + }
67194 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67195 + break;
67196 + match = match->next;
67197 + }
67198 +found2:
67199 + if (match == NULL)
67200 + match = state->default_role;
67201 + if (match->allowed_ips == NULL)
67202 + return match;
67203 + else {
67204 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67205 + if (likely
67206 + ((ntohl(curr_ip) & ipp->netmask) ==
67207 + (ntohl(ipp->addr) & ipp->netmask)))
67208 + return match;
67209 + }
67210 + match = state->default_role;
67211 + }
67212 + } else if (match->allowed_ips == NULL) {
67213 + return match;
67214 + } else {
67215 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67216 + if (likely
67217 + ((ntohl(curr_ip) & ipp->netmask) ==
67218 + (ntohl(ipp->addr) & ipp->netmask)))
67219 + return match;
67220 + }
67221 + goto try_group;
67222 + }
67223 +
67224 + return match;
67225 +}
67226 +
67227 +static struct acl_role_label *
67228 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67229 + const gid_t gid)
67230 +{
67231 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67232 +}
67233 +
67234 +struct acl_subject_label *
67235 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67236 + const struct acl_role_label *role)
67237 +{
67238 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67239 + struct acl_subject_label *match;
67240 +
67241 + match = role->subj_hash[index];
67242 +
67243 + while (match && (match->inode != ino || match->device != dev ||
67244 + (match->mode & GR_DELETED))) {
67245 + match = match->next;
67246 + }
67247 +
67248 + if (match && !(match->mode & GR_DELETED))
67249 + return match;
67250 + else
67251 + return NULL;
67252 +}
67253 +
67254 +struct acl_subject_label *
67255 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67256 + const struct acl_role_label *role)
67257 +{
67258 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67259 + struct acl_subject_label *match;
67260 +
67261 + match = role->subj_hash[index];
67262 +
67263 + while (match && (match->inode != ino || match->device != dev ||
67264 + !(match->mode & GR_DELETED))) {
67265 + match = match->next;
67266 + }
67267 +
67268 + if (match && (match->mode & GR_DELETED))
67269 + return match;
67270 + else
67271 + return NULL;
67272 +}
67273 +
67274 +static struct acl_object_label *
67275 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67276 + const struct acl_subject_label *subj)
67277 +{
67278 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67279 + struct acl_object_label *match;
67280 +
67281 + match = subj->obj_hash[index];
67282 +
67283 + while (match && (match->inode != ino || match->device != dev ||
67284 + (match->mode & GR_DELETED))) {
67285 + match = match->next;
67286 + }
67287 +
67288 + if (match && !(match->mode & GR_DELETED))
67289 + return match;
67290 + else
67291 + return NULL;
67292 +}
67293 +
67294 +static struct acl_object_label *
67295 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67296 + const struct acl_subject_label *subj)
67297 +{
67298 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67299 + struct acl_object_label *match;
67300 +
67301 + match = subj->obj_hash[index];
67302 +
67303 + while (match && (match->inode != ino || match->device != dev ||
67304 + !(match->mode & GR_DELETED))) {
67305 + match = match->next;
67306 + }
67307 +
67308 + if (match && (match->mode & GR_DELETED))
67309 + return match;
67310 +
67311 + match = subj->obj_hash[index];
67312 +
67313 + while (match && (match->inode != ino || match->device != dev ||
67314 + (match->mode & GR_DELETED))) {
67315 + match = match->next;
67316 + }
67317 +
67318 + if (match && !(match->mode & GR_DELETED))
67319 + return match;
67320 + else
67321 + return NULL;
67322 +}
67323 +
67324 +struct name_entry *
67325 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67326 +{
67327 + unsigned int len = strlen(name);
67328 + unsigned int key = full_name_hash(name, len);
67329 + unsigned int index = key % state->name_set.n_size;
67330 + struct name_entry *match;
67331 +
67332 + match = state->name_set.n_hash[index];
67333 +
67334 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67335 + match = match->next;
67336 +
67337 + return match;
67338 +}
67339 +
67340 +static struct name_entry *
67341 +lookup_name_entry(const char *name)
67342 +{
67343 + return __lookup_name_entry(&running_polstate, name);
67344 +}
67345 +
67346 +static struct name_entry *
67347 +lookup_name_entry_create(const char *name)
67348 +{
67349 + unsigned int len = strlen(name);
67350 + unsigned int key = full_name_hash(name, len);
67351 + unsigned int index = key % running_polstate.name_set.n_size;
67352 + struct name_entry *match;
67353 +
67354 + match = running_polstate.name_set.n_hash[index];
67355 +
67356 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67357 + !match->deleted))
67358 + match = match->next;
67359 +
67360 + if (match && match->deleted)
67361 + return match;
67362 +
67363 + match = running_polstate.name_set.n_hash[index];
67364 +
67365 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67366 + match->deleted))
67367 + match = match->next;
67368 +
67369 + if (match && !match->deleted)
67370 + return match;
67371 + else
67372 + return NULL;
67373 +}
67374 +
67375 +static struct inodev_entry *
67376 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67377 +{
67378 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67379 + struct inodev_entry *match;
67380 +
67381 + match = running_polstate.inodev_set.i_hash[index];
67382 +
67383 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67384 + match = match->next;
67385 +
67386 + return match;
67387 +}
67388 +
67389 +void
67390 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67391 +{
67392 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67393 + state->inodev_set.i_size);
67394 + struct inodev_entry **curr;
67395 +
67396 + entry->prev = NULL;
67397 +
67398 + curr = &state->inodev_set.i_hash[index];
67399 + if (*curr != NULL)
67400 + (*curr)->prev = entry;
67401 +
67402 + entry->next = *curr;
67403 + *curr = entry;
67404 +
67405 + return;
67406 +}
67407 +
67408 +static void
67409 +insert_inodev_entry(struct inodev_entry *entry)
67410 +{
67411 + __insert_inodev_entry(&running_polstate, entry);
67412 +}
67413 +
67414 +void
67415 +insert_acl_obj_label(struct acl_object_label *obj,
67416 + struct acl_subject_label *subj)
67417 +{
67418 + unsigned int index =
67419 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67420 + struct acl_object_label **curr;
67421 +
67422 + obj->prev = NULL;
67423 +
67424 + curr = &subj->obj_hash[index];
67425 + if (*curr != NULL)
67426 + (*curr)->prev = obj;
67427 +
67428 + obj->next = *curr;
67429 + *curr = obj;
67430 +
67431 + return;
67432 +}
67433 +
67434 +void
67435 +insert_acl_subj_label(struct acl_subject_label *obj,
67436 + struct acl_role_label *role)
67437 +{
67438 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67439 + struct acl_subject_label **curr;
67440 +
67441 + obj->prev = NULL;
67442 +
67443 + curr = &role->subj_hash[index];
67444 + if (*curr != NULL)
67445 + (*curr)->prev = obj;
67446 +
67447 + obj->next = *curr;
67448 + *curr = obj;
67449 +
67450 + return;
67451 +}
67452 +
67453 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67454 +
67455 +static int
67456 +glob_match(const char *p, const char *n)
67457 +{
67458 + char c;
67459 +
67460 + while ((c = *p++) != '\0') {
67461 + switch (c) {
67462 + case '?':
67463 + if (*n == '\0')
67464 + return 1;
67465 + else if (*n == '/')
67466 + return 1;
67467 + break;
67468 + case '\\':
67469 + if (*n != c)
67470 + return 1;
67471 + break;
67472 + case '*':
67473 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67474 + if (*n == '/')
67475 + return 1;
67476 + else if (c == '?') {
67477 + if (*n == '\0')
67478 + return 1;
67479 + else
67480 + ++n;
67481 + }
67482 + }
67483 + if (c == '\0') {
67484 + return 0;
67485 + } else {
67486 + const char *endp;
67487 +
67488 + if ((endp = strchr(n, '/')) == NULL)
67489 + endp = n + strlen(n);
67490 +
67491 + if (c == '[') {
67492 + for (--p; n < endp; ++n)
67493 + if (!glob_match(p, n))
67494 + return 0;
67495 + } else if (c == '/') {
67496 + while (*n != '\0' && *n != '/')
67497 + ++n;
67498 + if (*n == '/' && !glob_match(p, n + 1))
67499 + return 0;
67500 + } else {
67501 + for (--p; n < endp; ++n)
67502 + if (*n == c && !glob_match(p, n))
67503 + return 0;
67504 + }
67505 +
67506 + return 1;
67507 + }
67508 + case '[':
67509 + {
67510 + int not;
67511 + char cold;
67512 +
67513 + if (*n == '\0' || *n == '/')
67514 + return 1;
67515 +
67516 + not = (*p == '!' || *p == '^');
67517 + if (not)
67518 + ++p;
67519 +
67520 + c = *p++;
67521 + for (;;) {
67522 + unsigned char fn = (unsigned char)*n;
67523 +
67524 + if (c == '\0')
67525 + return 1;
67526 + else {
67527 + if (c == fn)
67528 + goto matched;
67529 + cold = c;
67530 + c = *p++;
67531 +
67532 + if (c == '-' && *p != ']') {
67533 + unsigned char cend = *p++;
67534 +
67535 + if (cend == '\0')
67536 + return 1;
67537 +
67538 + if (cold <= fn && fn <= cend)
67539 + goto matched;
67540 +
67541 + c = *p++;
67542 + }
67543 + }
67544 +
67545 + if (c == ']')
67546 + break;
67547 + }
67548 + if (!not)
67549 + return 1;
67550 + break;
67551 + matched:
67552 + while (c != ']') {
67553 + if (c == '\0')
67554 + return 1;
67555 +
67556 + c = *p++;
67557 + }
67558 + if (not)
67559 + return 1;
67560 + }
67561 + break;
67562 + default:
67563 + if (c != *n)
67564 + return 1;
67565 + }
67566 +
67567 + ++n;
67568 + }
67569 +
67570 + if (*n == '\0')
67571 + return 0;
67572 +
67573 + if (*n == '/')
67574 + return 0;
67575 +
67576 + return 1;
67577 +}
67578 +
67579 +static struct acl_object_label *
67580 +chk_glob_label(struct acl_object_label *globbed,
67581 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67582 +{
67583 + struct acl_object_label *tmp;
67584 +
67585 + if (*path == NULL)
67586 + *path = gr_to_filename_nolock(dentry, mnt);
67587 +
67588 + tmp = globbed;
67589 +
67590 + while (tmp) {
67591 + if (!glob_match(tmp->filename, *path))
67592 + return tmp;
67593 + tmp = tmp->next;
67594 + }
67595 +
67596 + return NULL;
67597 +}
67598 +
67599 +static struct acl_object_label *
67600 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67601 + const ino_t curr_ino, const dev_t curr_dev,
67602 + const struct acl_subject_label *subj, char **path, const int checkglob)
67603 +{
67604 + struct acl_subject_label *tmpsubj;
67605 + struct acl_object_label *retval;
67606 + struct acl_object_label *retval2;
67607 +
67608 + tmpsubj = (struct acl_subject_label *) subj;
67609 + read_lock(&gr_inode_lock);
67610 + do {
67611 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67612 + if (retval) {
67613 + if (checkglob && retval->globbed) {
67614 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67615 + if (retval2)
67616 + retval = retval2;
67617 + }
67618 + break;
67619 + }
67620 + } while ((tmpsubj = tmpsubj->parent_subject));
67621 + read_unlock(&gr_inode_lock);
67622 +
67623 + return retval;
67624 +}
67625 +
67626 +static __inline__ struct acl_object_label *
67627 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67628 + struct dentry *curr_dentry,
67629 + const struct acl_subject_label *subj, char **path, const int checkglob)
67630 +{
67631 + int newglob = checkglob;
67632 + ino_t inode;
67633 + dev_t device;
67634 +
67635 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67636 + as we don't want a / * rule to match instead of the / object
67637 + don't do this for create lookups that call this function though, since they're looking up
67638 + on the parent and thus need globbing checks on all paths
67639 + */
67640 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67641 + newglob = GR_NO_GLOB;
67642 +
67643 + spin_lock(&curr_dentry->d_lock);
67644 + inode = curr_dentry->d_inode->i_ino;
67645 + device = __get_dev(curr_dentry);
67646 + spin_unlock(&curr_dentry->d_lock);
67647 +
67648 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67649 +}
67650 +
67651 +#ifdef CONFIG_HUGETLBFS
67652 +static inline bool
67653 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67654 +{
67655 + int i;
67656 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67657 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67658 + return true;
67659 + }
67660 +
67661 + return false;
67662 +}
67663 +#endif
67664 +
67665 +static struct acl_object_label *
67666 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67667 + const struct acl_subject_label *subj, char *path, const int checkglob)
67668 +{
67669 + struct dentry *dentry = (struct dentry *) l_dentry;
67670 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67671 + struct mount *real_mnt = real_mount(mnt);
67672 + struct acl_object_label *retval;
67673 + struct dentry *parent;
67674 +
67675 + read_seqlock_excl(&mount_lock);
67676 + write_seqlock(&rename_lock);
67677 +
67678 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67679 +#ifdef CONFIG_NET
67680 + mnt == sock_mnt ||
67681 +#endif
67682 +#ifdef CONFIG_HUGETLBFS
67683 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67684 +#endif
67685 + /* ignore Eric Biederman */
67686 + IS_PRIVATE(l_dentry->d_inode))) {
67687 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67688 + goto out;
67689 + }
67690 +
67691 + for (;;) {
67692 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67693 + break;
67694 +
67695 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67696 + if (!mnt_has_parent(real_mnt))
67697 + break;
67698 +
67699 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67700 + if (retval != NULL)
67701 + goto out;
67702 +
67703 + dentry = real_mnt->mnt_mountpoint;
67704 + real_mnt = real_mnt->mnt_parent;
67705 + mnt = &real_mnt->mnt;
67706 + continue;
67707 + }
67708 +
67709 + parent = dentry->d_parent;
67710 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67711 + if (retval != NULL)
67712 + goto out;
67713 +
67714 + dentry = parent;
67715 + }
67716 +
67717 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67718 +
67719 + /* gr_real_root is pinned so we don't have to hold a reference */
67720 + if (retval == NULL)
67721 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67722 +out:
67723 + write_sequnlock(&rename_lock);
67724 + read_sequnlock_excl(&mount_lock);
67725 +
67726 + BUG_ON(retval == NULL);
67727 +
67728 + return retval;
67729 +}
67730 +
67731 +static __inline__ struct acl_object_label *
67732 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67733 + const struct acl_subject_label *subj)
67734 +{
67735 + char *path = NULL;
67736 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67737 +}
67738 +
67739 +static __inline__ struct acl_object_label *
67740 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67741 + const struct acl_subject_label *subj)
67742 +{
67743 + char *path = NULL;
67744 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67745 +}
67746 +
67747 +static __inline__ struct acl_object_label *
67748 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67749 + const struct acl_subject_label *subj, char *path)
67750 +{
67751 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67752 +}
67753 +
67754 +struct acl_subject_label *
67755 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67756 + const struct acl_role_label *role)
67757 +{
67758 + struct dentry *dentry = (struct dentry *) l_dentry;
67759 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67760 + struct mount *real_mnt = real_mount(mnt);
67761 + struct acl_subject_label *retval;
67762 + struct dentry *parent;
67763 +
67764 + read_seqlock_excl(&mount_lock);
67765 + write_seqlock(&rename_lock);
67766 +
67767 + for (;;) {
67768 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67769 + break;
67770 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67771 + if (!mnt_has_parent(real_mnt))
67772 + break;
67773 +
67774 + spin_lock(&dentry->d_lock);
67775 + read_lock(&gr_inode_lock);
67776 + retval =
67777 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67778 + __get_dev(dentry), role);
67779 + read_unlock(&gr_inode_lock);
67780 + spin_unlock(&dentry->d_lock);
67781 + if (retval != NULL)
67782 + goto out;
67783 +
67784 + dentry = real_mnt->mnt_mountpoint;
67785 + real_mnt = real_mnt->mnt_parent;
67786 + mnt = &real_mnt->mnt;
67787 + continue;
67788 + }
67789 +
67790 + spin_lock(&dentry->d_lock);
67791 + read_lock(&gr_inode_lock);
67792 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67793 + __get_dev(dentry), role);
67794 + read_unlock(&gr_inode_lock);
67795 + parent = dentry->d_parent;
67796 + spin_unlock(&dentry->d_lock);
67797 +
67798 + if (retval != NULL)
67799 + goto out;
67800 +
67801 + dentry = parent;
67802 + }
67803 +
67804 + spin_lock(&dentry->d_lock);
67805 + read_lock(&gr_inode_lock);
67806 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67807 + __get_dev(dentry), role);
67808 + read_unlock(&gr_inode_lock);
67809 + spin_unlock(&dentry->d_lock);
67810 +
67811 + if (unlikely(retval == NULL)) {
67812 + /* gr_real_root is pinned, we don't need to hold a reference */
67813 + read_lock(&gr_inode_lock);
67814 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67815 + __get_dev(gr_real_root.dentry), role);
67816 + read_unlock(&gr_inode_lock);
67817 + }
67818 +out:
67819 + write_sequnlock(&rename_lock);
67820 + read_sequnlock_excl(&mount_lock);
67821 +
67822 + BUG_ON(retval == NULL);
67823 +
67824 + return retval;
67825 +}
67826 +
67827 +void
67828 +assign_special_role(const char *rolename)
67829 +{
67830 + struct acl_object_label *obj;
67831 + struct acl_role_label *r;
67832 + struct acl_role_label *assigned = NULL;
67833 + struct task_struct *tsk;
67834 + struct file *filp;
67835 +
67836 + FOR_EACH_ROLE_START(r)
67837 + if (!strcmp(rolename, r->rolename) &&
67838 + (r->roletype & GR_ROLE_SPECIAL)) {
67839 + assigned = r;
67840 + break;
67841 + }
67842 + FOR_EACH_ROLE_END(r)
67843 +
67844 + if (!assigned)
67845 + return;
67846 +
67847 + read_lock(&tasklist_lock);
67848 + read_lock(&grsec_exec_file_lock);
67849 +
67850 + tsk = current->real_parent;
67851 + if (tsk == NULL)
67852 + goto out_unlock;
67853 +
67854 + filp = tsk->exec_file;
67855 + if (filp == NULL)
67856 + goto out_unlock;
67857 +
67858 + tsk->is_writable = 0;
67859 + tsk->inherited = 0;
67860 +
67861 + tsk->acl_sp_role = 1;
67862 + tsk->acl_role_id = ++acl_sp_role_value;
67863 + tsk->role = assigned;
67864 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67865 +
67866 + /* ignore additional mmap checks for processes that are writable
67867 + by the default ACL */
67868 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67869 + if (unlikely(obj->mode & GR_WRITE))
67870 + tsk->is_writable = 1;
67871 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67872 + if (unlikely(obj->mode & GR_WRITE))
67873 + tsk->is_writable = 1;
67874 +
67875 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67876 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67877 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67878 +#endif
67879 +
67880 +out_unlock:
67881 + read_unlock(&grsec_exec_file_lock);
67882 + read_unlock(&tasklist_lock);
67883 + return;
67884 +}
67885 +
67886 +
67887 +static void
67888 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67889 +{
67890 + struct task_struct *task = current;
67891 + const struct cred *cred = current_cred();
67892 +
67893 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67894 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67895 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67896 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67897 +
67898 + return;
67899 +}
67900 +
67901 +static void
67902 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67903 +{
67904 + struct task_struct *task = current;
67905 + const struct cred *cred = current_cred();
67906 +
67907 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67908 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67909 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67910 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67911 +
67912 + return;
67913 +}
67914 +
67915 +static void
67916 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67917 +{
67918 + struct task_struct *task = current;
67919 + const struct cred *cred = current_cred();
67920 +
67921 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67922 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67923 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67924 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67925 +
67926 + return;
67927 +}
67928 +
67929 +static void
67930 +gr_set_proc_res(struct task_struct *task)
67931 +{
67932 + struct acl_subject_label *proc;
67933 + unsigned short i;
67934 +
67935 + proc = task->acl;
67936 +
67937 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67938 + return;
67939 +
67940 + for (i = 0; i < RLIM_NLIMITS; i++) {
67941 + if (!(proc->resmask & (1U << i)))
67942 + continue;
67943 +
67944 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67945 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67946 +
67947 + if (i == RLIMIT_CPU)
67948 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67949 + }
67950 +
67951 + return;
67952 +}
67953 +
67954 +/* both of the below must be called with
67955 + rcu_read_lock();
67956 + read_lock(&tasklist_lock);
67957 + read_lock(&grsec_exec_file_lock);
67958 +*/
67959 +
67960 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67961 +{
67962 + char *tmpname;
67963 + struct acl_subject_label *tmpsubj;
67964 + struct file *filp;
67965 + struct name_entry *nmatch;
67966 +
67967 + filp = task->exec_file;
67968 + if (filp == NULL)
67969 + return NULL;
67970 +
67971 + /* the following is to apply the correct subject
67972 + on binaries running when the RBAC system
67973 + is enabled, when the binaries have been
67974 + replaced or deleted since their execution
67975 + -----
67976 + when the RBAC system starts, the inode/dev
67977 + from exec_file will be one the RBAC system
67978 + is unaware of. It only knows the inode/dev
67979 + of the present file on disk, or the absence
67980 + of it.
67981 + */
67982 +
67983 + if (filename)
67984 + nmatch = __lookup_name_entry(state, filename);
67985 + else {
67986 + preempt_disable();
67987 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67988 +
67989 + nmatch = __lookup_name_entry(state, tmpname);
67990 + preempt_enable();
67991 + }
67992 + tmpsubj = NULL;
67993 + if (nmatch) {
67994 + if (nmatch->deleted)
67995 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67996 + else
67997 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67998 + }
67999 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68000 + then we fall back to a normal lookup based on the binary's ino/dev
68001 + */
68002 + if (tmpsubj == NULL)
68003 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68004 +
68005 + return tmpsubj;
68006 +}
68007 +
68008 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68009 +{
68010 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68011 +}
68012 +
68013 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68014 +{
68015 + struct acl_object_label *obj;
68016 + struct file *filp;
68017 +
68018 + filp = task->exec_file;
68019 +
68020 + task->acl = subj;
68021 + task->is_writable = 0;
68022 + /* ignore additional mmap checks for processes that are writable
68023 + by the default ACL */
68024 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68025 + if (unlikely(obj->mode & GR_WRITE))
68026 + task->is_writable = 1;
68027 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68028 + if (unlikely(obj->mode & GR_WRITE))
68029 + task->is_writable = 1;
68030 +
68031 + gr_set_proc_res(task);
68032 +
68033 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68034 + 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);
68035 +#endif
68036 +}
68037 +
68038 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68039 +{
68040 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68041 +}
68042 +
68043 +__u32
68044 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68045 + const struct vfsmount * mnt)
68046 +{
68047 + __u32 retval = mode;
68048 + struct acl_subject_label *curracl;
68049 + struct acl_object_label *currobj;
68050 +
68051 + if (unlikely(!(gr_status & GR_READY)))
68052 + return (mode & ~GR_AUDITS);
68053 +
68054 + curracl = current->acl;
68055 +
68056 + currobj = chk_obj_label(dentry, mnt, curracl);
68057 + retval = currobj->mode & mode;
68058 +
68059 + /* if we're opening a specified transfer file for writing
68060 + (e.g. /dev/initctl), then transfer our role to init
68061 + */
68062 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68063 + current->role->roletype & GR_ROLE_PERSIST)) {
68064 + struct task_struct *task = init_pid_ns.child_reaper;
68065 +
68066 + if (task->role != current->role) {
68067 + struct acl_subject_label *subj;
68068 +
68069 + task->acl_sp_role = 0;
68070 + task->acl_role_id = current->acl_role_id;
68071 + task->role = current->role;
68072 + rcu_read_lock();
68073 + read_lock(&grsec_exec_file_lock);
68074 + subj = gr_get_subject_for_task(task, NULL);
68075 + gr_apply_subject_to_task(task, subj);
68076 + read_unlock(&grsec_exec_file_lock);
68077 + rcu_read_unlock();
68078 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68079 + }
68080 + }
68081 +
68082 + if (unlikely
68083 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68084 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68085 + __u32 new_mode = mode;
68086 +
68087 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68088 +
68089 + retval = new_mode;
68090 +
68091 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68092 + new_mode |= GR_INHERIT;
68093 +
68094 + if (!(mode & GR_NOLEARN))
68095 + gr_log_learn(dentry, mnt, new_mode);
68096 + }
68097 +
68098 + return retval;
68099 +}
68100 +
68101 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68102 + const struct dentry *parent,
68103 + const struct vfsmount *mnt)
68104 +{
68105 + struct name_entry *match;
68106 + struct acl_object_label *matchpo;
68107 + struct acl_subject_label *curracl;
68108 + char *path;
68109 +
68110 + if (unlikely(!(gr_status & GR_READY)))
68111 + return NULL;
68112 +
68113 + preempt_disable();
68114 + path = gr_to_filename_rbac(new_dentry, mnt);
68115 + match = lookup_name_entry_create(path);
68116 +
68117 + curracl = current->acl;
68118 +
68119 + if (match) {
68120 + read_lock(&gr_inode_lock);
68121 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68122 + read_unlock(&gr_inode_lock);
68123 +
68124 + if (matchpo) {
68125 + preempt_enable();
68126 + return matchpo;
68127 + }
68128 + }
68129 +
68130 + // lookup parent
68131 +
68132 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68133 +
68134 + preempt_enable();
68135 + return matchpo;
68136 +}
68137 +
68138 +__u32
68139 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68140 + const struct vfsmount * mnt, const __u32 mode)
68141 +{
68142 + struct acl_object_label *matchpo;
68143 + __u32 retval;
68144 +
68145 + if (unlikely(!(gr_status & GR_READY)))
68146 + return (mode & ~GR_AUDITS);
68147 +
68148 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68149 +
68150 + retval = matchpo->mode & mode;
68151 +
68152 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68153 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68154 + __u32 new_mode = mode;
68155 +
68156 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68157 +
68158 + gr_log_learn(new_dentry, mnt, new_mode);
68159 + return new_mode;
68160 + }
68161 +
68162 + return retval;
68163 +}
68164 +
68165 +__u32
68166 +gr_check_link(const struct dentry * new_dentry,
68167 + const struct dentry * parent_dentry,
68168 + const struct vfsmount * parent_mnt,
68169 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68170 +{
68171 + struct acl_object_label *obj;
68172 + __u32 oldmode, newmode;
68173 + __u32 needmode;
68174 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68175 + GR_DELETE | GR_INHERIT;
68176 +
68177 + if (unlikely(!(gr_status & GR_READY)))
68178 + return (GR_CREATE | GR_LINK);
68179 +
68180 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68181 + oldmode = obj->mode;
68182 +
68183 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68184 + newmode = obj->mode;
68185 +
68186 + needmode = newmode & checkmodes;
68187 +
68188 + // old name for hardlink must have at least the permissions of the new name
68189 + if ((oldmode & needmode) != needmode)
68190 + goto bad;
68191 +
68192 + // if old name had restrictions/auditing, make sure the new name does as well
68193 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68194 +
68195 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68196 + if (is_privileged_binary(old_dentry))
68197 + needmode |= GR_SETID;
68198 +
68199 + if ((newmode & needmode) != needmode)
68200 + goto bad;
68201 +
68202 + // enforce minimum permissions
68203 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68204 + return newmode;
68205 +bad:
68206 + needmode = oldmode;
68207 + if (is_privileged_binary(old_dentry))
68208 + needmode |= GR_SETID;
68209 +
68210 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68211 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68212 + return (GR_CREATE | GR_LINK);
68213 + } else if (newmode & GR_SUPPRESS)
68214 + return GR_SUPPRESS;
68215 + else
68216 + return 0;
68217 +}
68218 +
68219 +int
68220 +gr_check_hidden_task(const struct task_struct *task)
68221 +{
68222 + if (unlikely(!(gr_status & GR_READY)))
68223 + return 0;
68224 +
68225 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68226 + return 1;
68227 +
68228 + return 0;
68229 +}
68230 +
68231 +int
68232 +gr_check_protected_task(const struct task_struct *task)
68233 +{
68234 + if (unlikely(!(gr_status & GR_READY) || !task))
68235 + return 0;
68236 +
68237 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68238 + task->acl != current->acl)
68239 + return 1;
68240 +
68241 + return 0;
68242 +}
68243 +
68244 +int
68245 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68246 +{
68247 + struct task_struct *p;
68248 + int ret = 0;
68249 +
68250 + if (unlikely(!(gr_status & GR_READY) || !pid))
68251 + return ret;
68252 +
68253 + read_lock(&tasklist_lock);
68254 + do_each_pid_task(pid, type, p) {
68255 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68256 + p->acl != current->acl) {
68257 + ret = 1;
68258 + goto out;
68259 + }
68260 + } while_each_pid_task(pid, type, p);
68261 +out:
68262 + read_unlock(&tasklist_lock);
68263 +
68264 + return ret;
68265 +}
68266 +
68267 +void
68268 +gr_copy_label(struct task_struct *tsk)
68269 +{
68270 + struct task_struct *p = current;
68271 +
68272 + tsk->inherited = p->inherited;
68273 + tsk->acl_sp_role = 0;
68274 + tsk->acl_role_id = p->acl_role_id;
68275 + tsk->acl = p->acl;
68276 + tsk->role = p->role;
68277 + tsk->signal->used_accept = 0;
68278 + tsk->signal->curr_ip = p->signal->curr_ip;
68279 + tsk->signal->saved_ip = p->signal->saved_ip;
68280 + if (p->exec_file)
68281 + get_file(p->exec_file);
68282 + tsk->exec_file = p->exec_file;
68283 + tsk->is_writable = p->is_writable;
68284 + if (unlikely(p->signal->used_accept)) {
68285 + p->signal->curr_ip = 0;
68286 + p->signal->saved_ip = 0;
68287 + }
68288 +
68289 + return;
68290 +}
68291 +
68292 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68293 +
68294 +int
68295 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68296 +{
68297 + unsigned int i;
68298 + __u16 num;
68299 + uid_t *uidlist;
68300 + uid_t curuid;
68301 + int realok = 0;
68302 + int effectiveok = 0;
68303 + int fsok = 0;
68304 + uid_t globalreal, globaleffective, globalfs;
68305 +
68306 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68307 + struct user_struct *user;
68308 +
68309 + if (!uid_valid(real))
68310 + goto skipit;
68311 +
68312 + /* find user based on global namespace */
68313 +
68314 + globalreal = GR_GLOBAL_UID(real);
68315 +
68316 + user = find_user(make_kuid(&init_user_ns, globalreal));
68317 + if (user == NULL)
68318 + goto skipit;
68319 +
68320 + if (gr_process_kernel_setuid_ban(user)) {
68321 + /* for find_user */
68322 + free_uid(user);
68323 + return 1;
68324 + }
68325 +
68326 + /* for find_user */
68327 + free_uid(user);
68328 +
68329 +skipit:
68330 +#endif
68331 +
68332 + if (unlikely(!(gr_status & GR_READY)))
68333 + return 0;
68334 +
68335 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68336 + gr_log_learn_uid_change(real, effective, fs);
68337 +
68338 + num = current->acl->user_trans_num;
68339 + uidlist = current->acl->user_transitions;
68340 +
68341 + if (uidlist == NULL)
68342 + return 0;
68343 +
68344 + if (!uid_valid(real)) {
68345 + realok = 1;
68346 + globalreal = (uid_t)-1;
68347 + } else {
68348 + globalreal = GR_GLOBAL_UID(real);
68349 + }
68350 + if (!uid_valid(effective)) {
68351 + effectiveok = 1;
68352 + globaleffective = (uid_t)-1;
68353 + } else {
68354 + globaleffective = GR_GLOBAL_UID(effective);
68355 + }
68356 + if (!uid_valid(fs)) {
68357 + fsok = 1;
68358 + globalfs = (uid_t)-1;
68359 + } else {
68360 + globalfs = GR_GLOBAL_UID(fs);
68361 + }
68362 +
68363 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68364 + for (i = 0; i < num; i++) {
68365 + curuid = uidlist[i];
68366 + if (globalreal == curuid)
68367 + realok = 1;
68368 + if (globaleffective == curuid)
68369 + effectiveok = 1;
68370 + if (globalfs == curuid)
68371 + fsok = 1;
68372 + }
68373 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68374 + for (i = 0; i < num; i++) {
68375 + curuid = uidlist[i];
68376 + if (globalreal == curuid)
68377 + break;
68378 + if (globaleffective == curuid)
68379 + break;
68380 + if (globalfs == curuid)
68381 + break;
68382 + }
68383 + /* not in deny list */
68384 + if (i == num) {
68385 + realok = 1;
68386 + effectiveok = 1;
68387 + fsok = 1;
68388 + }
68389 + }
68390 +
68391 + if (realok && effectiveok && fsok)
68392 + return 0;
68393 + else {
68394 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68395 + return 1;
68396 + }
68397 +}
68398 +
68399 +int
68400 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68401 +{
68402 + unsigned int i;
68403 + __u16 num;
68404 + gid_t *gidlist;
68405 + gid_t curgid;
68406 + int realok = 0;
68407 + int effectiveok = 0;
68408 + int fsok = 0;
68409 + gid_t globalreal, globaleffective, globalfs;
68410 +
68411 + if (unlikely(!(gr_status & GR_READY)))
68412 + return 0;
68413 +
68414 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68415 + gr_log_learn_gid_change(real, effective, fs);
68416 +
68417 + num = current->acl->group_trans_num;
68418 + gidlist = current->acl->group_transitions;
68419 +
68420 + if (gidlist == NULL)
68421 + return 0;
68422 +
68423 + if (!gid_valid(real)) {
68424 + realok = 1;
68425 + globalreal = (gid_t)-1;
68426 + } else {
68427 + globalreal = GR_GLOBAL_GID(real);
68428 + }
68429 + if (!gid_valid(effective)) {
68430 + effectiveok = 1;
68431 + globaleffective = (gid_t)-1;
68432 + } else {
68433 + globaleffective = GR_GLOBAL_GID(effective);
68434 + }
68435 + if (!gid_valid(fs)) {
68436 + fsok = 1;
68437 + globalfs = (gid_t)-1;
68438 + } else {
68439 + globalfs = GR_GLOBAL_GID(fs);
68440 + }
68441 +
68442 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68443 + for (i = 0; i < num; i++) {
68444 + curgid = gidlist[i];
68445 + if (globalreal == curgid)
68446 + realok = 1;
68447 + if (globaleffective == curgid)
68448 + effectiveok = 1;
68449 + if (globalfs == curgid)
68450 + fsok = 1;
68451 + }
68452 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68453 + for (i = 0; i < num; i++) {
68454 + curgid = gidlist[i];
68455 + if (globalreal == curgid)
68456 + break;
68457 + if (globaleffective == curgid)
68458 + break;
68459 + if (globalfs == curgid)
68460 + break;
68461 + }
68462 + /* not in deny list */
68463 + if (i == num) {
68464 + realok = 1;
68465 + effectiveok = 1;
68466 + fsok = 1;
68467 + }
68468 + }
68469 +
68470 + if (realok && effectiveok && fsok)
68471 + return 0;
68472 + else {
68473 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68474 + return 1;
68475 + }
68476 +}
68477 +
68478 +extern int gr_acl_is_capable(const int cap);
68479 +
68480 +void
68481 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68482 +{
68483 + struct acl_role_label *role = task->role;
68484 + struct acl_subject_label *subj = NULL;
68485 + struct acl_object_label *obj;
68486 + struct file *filp;
68487 + uid_t uid;
68488 + gid_t gid;
68489 +
68490 + if (unlikely(!(gr_status & GR_READY)))
68491 + return;
68492 +
68493 + uid = GR_GLOBAL_UID(kuid);
68494 + gid = GR_GLOBAL_GID(kgid);
68495 +
68496 + filp = task->exec_file;
68497 +
68498 + /* kernel process, we'll give them the kernel role */
68499 + if (unlikely(!filp)) {
68500 + task->role = running_polstate.kernel_role;
68501 + task->acl = running_polstate.kernel_role->root_label;
68502 + return;
68503 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68504 + /* save the current ip at time of role lookup so that the proper
68505 + IP will be learned for role_allowed_ip */
68506 + task->signal->saved_ip = task->signal->curr_ip;
68507 + role = lookup_acl_role_label(task, uid, gid);
68508 + }
68509 +
68510 + /* don't change the role if we're not a privileged process */
68511 + if (role && task->role != role &&
68512 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68513 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68514 + return;
68515 +
68516 + /* perform subject lookup in possibly new role
68517 + we can use this result below in the case where role == task->role
68518 + */
68519 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68520 +
68521 + /* if we changed uid/gid, but result in the same role
68522 + and are using inheritance, don't lose the inherited subject
68523 + if current subject is other than what normal lookup
68524 + would result in, we arrived via inheritance, don't
68525 + lose subject
68526 + */
68527 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68528 + (subj == task->acl)))
68529 + task->acl = subj;
68530 +
68531 + /* leave task->inherited unaffected */
68532 +
68533 + task->role = role;
68534 +
68535 + task->is_writable = 0;
68536 +
68537 + /* ignore additional mmap checks for processes that are writable
68538 + by the default ACL */
68539 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68540 + if (unlikely(obj->mode & GR_WRITE))
68541 + task->is_writable = 1;
68542 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68543 + if (unlikely(obj->mode & GR_WRITE))
68544 + task->is_writable = 1;
68545 +
68546 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68547 + 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);
68548 +#endif
68549 +
68550 + gr_set_proc_res(task);
68551 +
68552 + return;
68553 +}
68554 +
68555 +int
68556 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68557 + const int unsafe_flags)
68558 +{
68559 + struct task_struct *task = current;
68560 + struct acl_subject_label *newacl;
68561 + struct acl_object_label *obj;
68562 + __u32 retmode;
68563 +
68564 + if (unlikely(!(gr_status & GR_READY)))
68565 + return 0;
68566 +
68567 + newacl = chk_subj_label(dentry, mnt, task->role);
68568 +
68569 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68570 + did an exec
68571 + */
68572 + rcu_read_lock();
68573 + read_lock(&tasklist_lock);
68574 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68575 + (task->parent->acl->mode & GR_POVERRIDE))) {
68576 + read_unlock(&tasklist_lock);
68577 + rcu_read_unlock();
68578 + goto skip_check;
68579 + }
68580 + read_unlock(&tasklist_lock);
68581 + rcu_read_unlock();
68582 +
68583 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68584 + !(task->role->roletype & GR_ROLE_GOD) &&
68585 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68586 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68587 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68588 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68589 + else
68590 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68591 + return -EACCES;
68592 + }
68593 +
68594 +skip_check:
68595 +
68596 + obj = chk_obj_label(dentry, mnt, task->acl);
68597 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68598 +
68599 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68600 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68601 + if (obj->nested)
68602 + task->acl = obj->nested;
68603 + else
68604 + task->acl = newacl;
68605 + task->inherited = 0;
68606 + } else {
68607 + task->inherited = 1;
68608 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68609 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68610 + }
68611 +
68612 + task->is_writable = 0;
68613 +
68614 + /* ignore additional mmap checks for processes that are writable
68615 + by the default ACL */
68616 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68617 + if (unlikely(obj->mode & GR_WRITE))
68618 + task->is_writable = 1;
68619 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68620 + if (unlikely(obj->mode & GR_WRITE))
68621 + task->is_writable = 1;
68622 +
68623 + gr_set_proc_res(task);
68624 +
68625 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68626 + 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);
68627 +#endif
68628 + return 0;
68629 +}
68630 +
68631 +/* always called with valid inodev ptr */
68632 +static void
68633 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68634 +{
68635 + struct acl_object_label *matchpo;
68636 + struct acl_subject_label *matchps;
68637 + struct acl_subject_label *subj;
68638 + struct acl_role_label *role;
68639 + unsigned int x;
68640 +
68641 + FOR_EACH_ROLE_START(role)
68642 + FOR_EACH_SUBJECT_START(role, subj, x)
68643 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68644 + matchpo->mode |= GR_DELETED;
68645 + FOR_EACH_SUBJECT_END(subj,x)
68646 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68647 + /* nested subjects aren't in the role's subj_hash table */
68648 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68649 + matchpo->mode |= GR_DELETED;
68650 + FOR_EACH_NESTED_SUBJECT_END(subj)
68651 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68652 + matchps->mode |= GR_DELETED;
68653 + FOR_EACH_ROLE_END(role)
68654 +
68655 + inodev->nentry->deleted = 1;
68656 +
68657 + return;
68658 +}
68659 +
68660 +void
68661 +gr_handle_delete(const ino_t ino, const dev_t dev)
68662 +{
68663 + struct inodev_entry *inodev;
68664 +
68665 + if (unlikely(!(gr_status & GR_READY)))
68666 + return;
68667 +
68668 + write_lock(&gr_inode_lock);
68669 + inodev = lookup_inodev_entry(ino, dev);
68670 + if (inodev != NULL)
68671 + do_handle_delete(inodev, ino, dev);
68672 + write_unlock(&gr_inode_lock);
68673 +
68674 + return;
68675 +}
68676 +
68677 +static void
68678 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68679 + const ino_t newinode, const dev_t newdevice,
68680 + struct acl_subject_label *subj)
68681 +{
68682 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68683 + struct acl_object_label *match;
68684 +
68685 + match = subj->obj_hash[index];
68686 +
68687 + while (match && (match->inode != oldinode ||
68688 + match->device != olddevice ||
68689 + !(match->mode & GR_DELETED)))
68690 + match = match->next;
68691 +
68692 + if (match && (match->inode == oldinode)
68693 + && (match->device == olddevice)
68694 + && (match->mode & GR_DELETED)) {
68695 + if (match->prev == NULL) {
68696 + subj->obj_hash[index] = match->next;
68697 + if (match->next != NULL)
68698 + match->next->prev = NULL;
68699 + } else {
68700 + match->prev->next = match->next;
68701 + if (match->next != NULL)
68702 + match->next->prev = match->prev;
68703 + }
68704 + match->prev = NULL;
68705 + match->next = NULL;
68706 + match->inode = newinode;
68707 + match->device = newdevice;
68708 + match->mode &= ~GR_DELETED;
68709 +
68710 + insert_acl_obj_label(match, subj);
68711 + }
68712 +
68713 + return;
68714 +}
68715 +
68716 +static void
68717 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68718 + const ino_t newinode, const dev_t newdevice,
68719 + struct acl_role_label *role)
68720 +{
68721 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68722 + struct acl_subject_label *match;
68723 +
68724 + match = role->subj_hash[index];
68725 +
68726 + while (match && (match->inode != oldinode ||
68727 + match->device != olddevice ||
68728 + !(match->mode & GR_DELETED)))
68729 + match = match->next;
68730 +
68731 + if (match && (match->inode == oldinode)
68732 + && (match->device == olddevice)
68733 + && (match->mode & GR_DELETED)) {
68734 + if (match->prev == NULL) {
68735 + role->subj_hash[index] = match->next;
68736 + if (match->next != NULL)
68737 + match->next->prev = NULL;
68738 + } else {
68739 + match->prev->next = match->next;
68740 + if (match->next != NULL)
68741 + match->next->prev = match->prev;
68742 + }
68743 + match->prev = NULL;
68744 + match->next = NULL;
68745 + match->inode = newinode;
68746 + match->device = newdevice;
68747 + match->mode &= ~GR_DELETED;
68748 +
68749 + insert_acl_subj_label(match, role);
68750 + }
68751 +
68752 + return;
68753 +}
68754 +
68755 +static void
68756 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68757 + const ino_t newinode, const dev_t newdevice)
68758 +{
68759 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68760 + struct inodev_entry *match;
68761 +
68762 + match = running_polstate.inodev_set.i_hash[index];
68763 +
68764 + while (match && (match->nentry->inode != oldinode ||
68765 + match->nentry->device != olddevice || !match->nentry->deleted))
68766 + match = match->next;
68767 +
68768 + if (match && (match->nentry->inode == oldinode)
68769 + && (match->nentry->device == olddevice) &&
68770 + match->nentry->deleted) {
68771 + if (match->prev == NULL) {
68772 + running_polstate.inodev_set.i_hash[index] = match->next;
68773 + if (match->next != NULL)
68774 + match->next->prev = NULL;
68775 + } else {
68776 + match->prev->next = match->next;
68777 + if (match->next != NULL)
68778 + match->next->prev = match->prev;
68779 + }
68780 + match->prev = NULL;
68781 + match->next = NULL;
68782 + match->nentry->inode = newinode;
68783 + match->nentry->device = newdevice;
68784 + match->nentry->deleted = 0;
68785 +
68786 + insert_inodev_entry(match);
68787 + }
68788 +
68789 + return;
68790 +}
68791 +
68792 +static void
68793 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68794 +{
68795 + struct acl_subject_label *subj;
68796 + struct acl_role_label *role;
68797 + unsigned int x;
68798 +
68799 + FOR_EACH_ROLE_START(role)
68800 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68801 +
68802 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68803 + if ((subj->inode == ino) && (subj->device == dev)) {
68804 + subj->inode = ino;
68805 + subj->device = dev;
68806 + }
68807 + /* nested subjects aren't in the role's subj_hash table */
68808 + update_acl_obj_label(matchn->inode, matchn->device,
68809 + ino, dev, subj);
68810 + FOR_EACH_NESTED_SUBJECT_END(subj)
68811 + FOR_EACH_SUBJECT_START(role, subj, x)
68812 + update_acl_obj_label(matchn->inode, matchn->device,
68813 + ino, dev, subj);
68814 + FOR_EACH_SUBJECT_END(subj,x)
68815 + FOR_EACH_ROLE_END(role)
68816 +
68817 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68818 +
68819 + return;
68820 +}
68821 +
68822 +static void
68823 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68824 + const struct vfsmount *mnt)
68825 +{
68826 + ino_t ino = dentry->d_inode->i_ino;
68827 + dev_t dev = __get_dev(dentry);
68828 +
68829 + __do_handle_create(matchn, ino, dev);
68830 +
68831 + return;
68832 +}
68833 +
68834 +void
68835 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68836 +{
68837 + struct name_entry *matchn;
68838 +
68839 + if (unlikely(!(gr_status & GR_READY)))
68840 + return;
68841 +
68842 + preempt_disable();
68843 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68844 +
68845 + if (unlikely((unsigned long)matchn)) {
68846 + write_lock(&gr_inode_lock);
68847 + do_handle_create(matchn, dentry, mnt);
68848 + write_unlock(&gr_inode_lock);
68849 + }
68850 + preempt_enable();
68851 +
68852 + return;
68853 +}
68854 +
68855 +void
68856 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68857 +{
68858 + struct name_entry *matchn;
68859 +
68860 + if (unlikely(!(gr_status & GR_READY)))
68861 + return;
68862 +
68863 + preempt_disable();
68864 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68865 +
68866 + if (unlikely((unsigned long)matchn)) {
68867 + write_lock(&gr_inode_lock);
68868 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68869 + write_unlock(&gr_inode_lock);
68870 + }
68871 + preempt_enable();
68872 +
68873 + return;
68874 +}
68875 +
68876 +void
68877 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68878 + struct dentry *old_dentry,
68879 + struct dentry *new_dentry,
68880 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
68881 +{
68882 + struct name_entry *matchn;
68883 + struct name_entry *matchn2 = NULL;
68884 + struct inodev_entry *inodev;
68885 + struct inode *inode = new_dentry->d_inode;
68886 + ino_t old_ino = old_dentry->d_inode->i_ino;
68887 + dev_t old_dev = __get_dev(old_dentry);
68888 + unsigned int exchange = flags & RENAME_EXCHANGE;
68889 +
68890 + /* vfs_rename swaps the name and parent link for old_dentry and
68891 + new_dentry
68892 + at this point, old_dentry has the new name, parent link, and inode
68893 + for the renamed file
68894 + if a file is being replaced by a rename, new_dentry has the inode
68895 + and name for the replaced file
68896 + */
68897 +
68898 + if (unlikely(!(gr_status & GR_READY)))
68899 + return;
68900 +
68901 + preempt_disable();
68902 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68903 +
68904 + /* exchange cases:
68905 + a filename exists for the source, but not dest
68906 + do a recreate on source
68907 + a filename exists for the dest, but not source
68908 + do a recreate on dest
68909 + a filename exists for both source and dest
68910 + delete source and dest, then create source and dest
68911 + a filename exists for neither source nor dest
68912 + no updates needed
68913 +
68914 + the name entry lookups get us the old inode/dev associated with
68915 + each name, so do the deletes first (if possible) so that when
68916 + we do the create, we pick up on the right entries
68917 + */
68918 +
68919 + if (exchange)
68920 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
68921 +
68922 + /* we wouldn't have to check d_inode if it weren't for
68923 + NFS silly-renaming
68924 + */
68925 +
68926 + write_lock(&gr_inode_lock);
68927 + if (unlikely((replace || exchange) && inode)) {
68928 + ino_t new_ino = inode->i_ino;
68929 + dev_t new_dev = __get_dev(new_dentry);
68930 +
68931 + inodev = lookup_inodev_entry(new_ino, new_dev);
68932 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68933 + do_handle_delete(inodev, new_ino, new_dev);
68934 + }
68935 +
68936 + inodev = lookup_inodev_entry(old_ino, old_dev);
68937 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68938 + do_handle_delete(inodev, old_ino, old_dev);
68939 +
68940 + if (unlikely(matchn != NULL))
68941 + do_handle_create(matchn, old_dentry, mnt);
68942 +
68943 + if (unlikely(matchn2 != NULL))
68944 + do_handle_create(matchn2, new_dentry, mnt);
68945 +
68946 + write_unlock(&gr_inode_lock);
68947 + preempt_enable();
68948 +
68949 + return;
68950 +}
68951 +
68952 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68953 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68954 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68955 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68956 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68957 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68958 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68959 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68960 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68961 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68962 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68963 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68964 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68965 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68966 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68967 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68968 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68969 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68970 +};
68971 +
68972 +void
68973 +gr_learn_resource(const struct task_struct *task,
68974 + const int res, const unsigned long wanted, const int gt)
68975 +{
68976 + struct acl_subject_label *acl;
68977 + const struct cred *cred;
68978 +
68979 + if (unlikely((gr_status & GR_READY) &&
68980 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68981 + goto skip_reslog;
68982 +
68983 + gr_log_resource(task, res, wanted, gt);
68984 +skip_reslog:
68985 +
68986 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68987 + return;
68988 +
68989 + acl = task->acl;
68990 +
68991 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68992 + !(acl->resmask & (1U << (unsigned short) res))))
68993 + return;
68994 +
68995 + if (wanted >= acl->res[res].rlim_cur) {
68996 + unsigned long res_add;
68997 +
68998 + res_add = wanted + res_learn_bumps[res];
68999 +
69000 + acl->res[res].rlim_cur = res_add;
69001 +
69002 + if (wanted > acl->res[res].rlim_max)
69003 + acl->res[res].rlim_max = res_add;
69004 +
69005 + /* only log the subject filename, since resource logging is supported for
69006 + single-subject learning only */
69007 + rcu_read_lock();
69008 + cred = __task_cred(task);
69009 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69010 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69011 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69012 + "", (unsigned long) res, &task->signal->saved_ip);
69013 + rcu_read_unlock();
69014 + }
69015 +
69016 + return;
69017 +}
69018 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69019 +#endif
69020 +
69021 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69022 +void
69023 +pax_set_initial_flags(struct linux_binprm *bprm)
69024 +{
69025 + struct task_struct *task = current;
69026 + struct acl_subject_label *proc;
69027 + unsigned long flags;
69028 +
69029 + if (unlikely(!(gr_status & GR_READY)))
69030 + return;
69031 +
69032 + flags = pax_get_flags(task);
69033 +
69034 + proc = task->acl;
69035 +
69036 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69037 + flags &= ~MF_PAX_PAGEEXEC;
69038 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69039 + flags &= ~MF_PAX_SEGMEXEC;
69040 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69041 + flags &= ~MF_PAX_RANDMMAP;
69042 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69043 + flags &= ~MF_PAX_EMUTRAMP;
69044 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69045 + flags &= ~MF_PAX_MPROTECT;
69046 +
69047 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69048 + flags |= MF_PAX_PAGEEXEC;
69049 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69050 + flags |= MF_PAX_SEGMEXEC;
69051 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69052 + flags |= MF_PAX_RANDMMAP;
69053 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69054 + flags |= MF_PAX_EMUTRAMP;
69055 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69056 + flags |= MF_PAX_MPROTECT;
69057 +
69058 + pax_set_flags(task, flags);
69059 +
69060 + return;
69061 +}
69062 +#endif
69063 +
69064 +int
69065 +gr_handle_proc_ptrace(struct task_struct *task)
69066 +{
69067 + struct file *filp;
69068 + struct task_struct *tmp = task;
69069 + struct task_struct *curtemp = current;
69070 + __u32 retmode;
69071 +
69072 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69073 + if (unlikely(!(gr_status & GR_READY)))
69074 + return 0;
69075 +#endif
69076 +
69077 + read_lock(&tasklist_lock);
69078 + read_lock(&grsec_exec_file_lock);
69079 + filp = task->exec_file;
69080 +
69081 + while (task_pid_nr(tmp) > 0) {
69082 + if (tmp == curtemp)
69083 + break;
69084 + tmp = tmp->real_parent;
69085 + }
69086 +
69087 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69088 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69089 + read_unlock(&grsec_exec_file_lock);
69090 + read_unlock(&tasklist_lock);
69091 + return 1;
69092 + }
69093 +
69094 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69095 + if (!(gr_status & GR_READY)) {
69096 + read_unlock(&grsec_exec_file_lock);
69097 + read_unlock(&tasklist_lock);
69098 + return 0;
69099 + }
69100 +#endif
69101 +
69102 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69103 + read_unlock(&grsec_exec_file_lock);
69104 + read_unlock(&tasklist_lock);
69105 +
69106 + if (retmode & GR_NOPTRACE)
69107 + return 1;
69108 +
69109 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69110 + && (current->acl != task->acl || (current->acl != current->role->root_label
69111 + && task_pid_nr(current) != task_pid_nr(task))))
69112 + return 1;
69113 +
69114 + return 0;
69115 +}
69116 +
69117 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69118 +{
69119 + if (unlikely(!(gr_status & GR_READY)))
69120 + return;
69121 +
69122 + if (!(current->role->roletype & GR_ROLE_GOD))
69123 + return;
69124 +
69125 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69126 + p->role->rolename, gr_task_roletype_to_char(p),
69127 + p->acl->filename);
69128 +}
69129 +
69130 +int
69131 +gr_handle_ptrace(struct task_struct *task, const long request)
69132 +{
69133 + struct task_struct *tmp = task;
69134 + struct task_struct *curtemp = current;
69135 + __u32 retmode;
69136 +
69137 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69138 + if (unlikely(!(gr_status & GR_READY)))
69139 + return 0;
69140 +#endif
69141 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69142 + read_lock(&tasklist_lock);
69143 + while (task_pid_nr(tmp) > 0) {
69144 + if (tmp == curtemp)
69145 + break;
69146 + tmp = tmp->real_parent;
69147 + }
69148 +
69149 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69150 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69151 + read_unlock(&tasklist_lock);
69152 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69153 + return 1;
69154 + }
69155 + read_unlock(&tasklist_lock);
69156 + }
69157 +
69158 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69159 + if (!(gr_status & GR_READY))
69160 + return 0;
69161 +#endif
69162 +
69163 + read_lock(&grsec_exec_file_lock);
69164 + if (unlikely(!task->exec_file)) {
69165 + read_unlock(&grsec_exec_file_lock);
69166 + return 0;
69167 + }
69168 +
69169 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69170 + read_unlock(&grsec_exec_file_lock);
69171 +
69172 + if (retmode & GR_NOPTRACE) {
69173 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69174 + return 1;
69175 + }
69176 +
69177 + if (retmode & GR_PTRACERD) {
69178 + switch (request) {
69179 + case PTRACE_SEIZE:
69180 + case PTRACE_POKETEXT:
69181 + case PTRACE_POKEDATA:
69182 + case PTRACE_POKEUSR:
69183 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69184 + case PTRACE_SETREGS:
69185 + case PTRACE_SETFPREGS:
69186 +#endif
69187 +#ifdef CONFIG_X86
69188 + case PTRACE_SETFPXREGS:
69189 +#endif
69190 +#ifdef CONFIG_ALTIVEC
69191 + case PTRACE_SETVRREGS:
69192 +#endif
69193 + return 1;
69194 + default:
69195 + return 0;
69196 + }
69197 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69198 + !(current->role->roletype & GR_ROLE_GOD) &&
69199 + (current->acl != task->acl)) {
69200 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69201 + return 1;
69202 + }
69203 +
69204 + return 0;
69205 +}
69206 +
69207 +static int is_writable_mmap(const struct file *filp)
69208 +{
69209 + struct task_struct *task = current;
69210 + struct acl_object_label *obj, *obj2;
69211 +
69212 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69213 + !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))) {
69214 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69215 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69216 + task->role->root_label);
69217 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69218 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69219 + return 1;
69220 + }
69221 + }
69222 + return 0;
69223 +}
69224 +
69225 +int
69226 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69227 +{
69228 + __u32 mode;
69229 +
69230 + if (unlikely(!file || !(prot & PROT_EXEC)))
69231 + return 1;
69232 +
69233 + if (is_writable_mmap(file))
69234 + return 0;
69235 +
69236 + mode =
69237 + gr_search_file(file->f_path.dentry,
69238 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69239 + file->f_path.mnt);
69240 +
69241 + if (!gr_tpe_allow(file))
69242 + return 0;
69243 +
69244 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69245 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69246 + return 0;
69247 + } else if (unlikely(!(mode & GR_EXEC))) {
69248 + return 0;
69249 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69250 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69251 + return 1;
69252 + }
69253 +
69254 + return 1;
69255 +}
69256 +
69257 +int
69258 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69259 +{
69260 + __u32 mode;
69261 +
69262 + if (unlikely(!file || !(prot & PROT_EXEC)))
69263 + return 1;
69264 +
69265 + if (is_writable_mmap(file))
69266 + return 0;
69267 +
69268 + mode =
69269 + gr_search_file(file->f_path.dentry,
69270 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69271 + file->f_path.mnt);
69272 +
69273 + if (!gr_tpe_allow(file))
69274 + return 0;
69275 +
69276 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69277 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69278 + return 0;
69279 + } else if (unlikely(!(mode & GR_EXEC))) {
69280 + return 0;
69281 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69282 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69283 + return 1;
69284 + }
69285 +
69286 + return 1;
69287 +}
69288 +
69289 +void
69290 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69291 +{
69292 + unsigned long runtime, cputime;
69293 + cputime_t utime, stime;
69294 + unsigned int wday, cday;
69295 + __u8 whr, chr;
69296 + __u8 wmin, cmin;
69297 + __u8 wsec, csec;
69298 + struct timespec timeval;
69299 +
69300 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69301 + !(task->acl->mode & GR_PROCACCT)))
69302 + return;
69303 +
69304 + do_posix_clock_monotonic_gettime(&timeval);
69305 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69306 + wday = runtime / (60 * 60 * 24);
69307 + runtime -= wday * (60 * 60 * 24);
69308 + whr = runtime / (60 * 60);
69309 + runtime -= whr * (60 * 60);
69310 + wmin = runtime / 60;
69311 + runtime -= wmin * 60;
69312 + wsec = runtime;
69313 +
69314 + task_cputime(task, &utime, &stime);
69315 + cputime = cputime_to_secs(utime + stime);
69316 + cday = cputime / (60 * 60 * 24);
69317 + cputime -= cday * (60 * 60 * 24);
69318 + chr = cputime / (60 * 60);
69319 + cputime -= chr * (60 * 60);
69320 + cmin = cputime / 60;
69321 + cputime -= cmin * 60;
69322 + csec = cputime;
69323 +
69324 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69325 +
69326 + return;
69327 +}
69328 +
69329 +#ifdef CONFIG_TASKSTATS
69330 +int gr_is_taskstats_denied(int pid)
69331 +{
69332 + struct task_struct *task;
69333 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69334 + const struct cred *cred;
69335 +#endif
69336 + int ret = 0;
69337 +
69338 + /* restrict taskstats viewing to un-chrooted root users
69339 + who have the 'view' subject flag if the RBAC system is enabled
69340 + */
69341 +
69342 + rcu_read_lock();
69343 + read_lock(&tasklist_lock);
69344 + task = find_task_by_vpid(pid);
69345 + if (task) {
69346 +#ifdef CONFIG_GRKERNSEC_CHROOT
69347 + if (proc_is_chrooted(task))
69348 + ret = -EACCES;
69349 +#endif
69350 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69351 + cred = __task_cred(task);
69352 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69353 + if (gr_is_global_nonroot(cred->uid))
69354 + ret = -EACCES;
69355 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69356 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69357 + ret = -EACCES;
69358 +#endif
69359 +#endif
69360 + if (gr_status & GR_READY) {
69361 + if (!(task->acl->mode & GR_VIEW))
69362 + ret = -EACCES;
69363 + }
69364 + } else
69365 + ret = -ENOENT;
69366 +
69367 + read_unlock(&tasklist_lock);
69368 + rcu_read_unlock();
69369 +
69370 + return ret;
69371 +}
69372 +#endif
69373 +
69374 +/* AUXV entries are filled via a descendant of search_binary_handler
69375 + after we've already applied the subject for the target
69376 +*/
69377 +int gr_acl_enable_at_secure(void)
69378 +{
69379 + if (unlikely(!(gr_status & GR_READY)))
69380 + return 0;
69381 +
69382 + if (current->acl->mode & GR_ATSECURE)
69383 + return 1;
69384 +
69385 + return 0;
69386 +}
69387 +
69388 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69389 +{
69390 + struct task_struct *task = current;
69391 + struct dentry *dentry = file->f_path.dentry;
69392 + struct vfsmount *mnt = file->f_path.mnt;
69393 + struct acl_object_label *obj, *tmp;
69394 + struct acl_subject_label *subj;
69395 + unsigned int bufsize;
69396 + int is_not_root;
69397 + char *path;
69398 + dev_t dev = __get_dev(dentry);
69399 +
69400 + if (unlikely(!(gr_status & GR_READY)))
69401 + return 1;
69402 +
69403 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69404 + return 1;
69405 +
69406 + /* ignore Eric Biederman */
69407 + if (IS_PRIVATE(dentry->d_inode))
69408 + return 1;
69409 +
69410 + subj = task->acl;
69411 + read_lock(&gr_inode_lock);
69412 + do {
69413 + obj = lookup_acl_obj_label(ino, dev, subj);
69414 + if (obj != NULL) {
69415 + read_unlock(&gr_inode_lock);
69416 + return (obj->mode & GR_FIND) ? 1 : 0;
69417 + }
69418 + } while ((subj = subj->parent_subject));
69419 + read_unlock(&gr_inode_lock);
69420 +
69421 + /* this is purely an optimization since we're looking for an object
69422 + for the directory we're doing a readdir on
69423 + if it's possible for any globbed object to match the entry we're
69424 + filling into the directory, then the object we find here will be
69425 + an anchor point with attached globbed objects
69426 + */
69427 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69428 + if (obj->globbed == NULL)
69429 + return (obj->mode & GR_FIND) ? 1 : 0;
69430 +
69431 + is_not_root = ((obj->filename[0] == '/') &&
69432 + (obj->filename[1] == '\0')) ? 0 : 1;
69433 + bufsize = PAGE_SIZE - namelen - is_not_root;
69434 +
69435 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69436 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69437 + return 1;
69438 +
69439 + preempt_disable();
69440 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69441 + bufsize);
69442 +
69443 + bufsize = strlen(path);
69444 +
69445 + /* if base is "/", don't append an additional slash */
69446 + if (is_not_root)
69447 + *(path + bufsize) = '/';
69448 + memcpy(path + bufsize + is_not_root, name, namelen);
69449 + *(path + bufsize + namelen + is_not_root) = '\0';
69450 +
69451 + tmp = obj->globbed;
69452 + while (tmp) {
69453 + if (!glob_match(tmp->filename, path)) {
69454 + preempt_enable();
69455 + return (tmp->mode & GR_FIND) ? 1 : 0;
69456 + }
69457 + tmp = tmp->next;
69458 + }
69459 + preempt_enable();
69460 + return (obj->mode & GR_FIND) ? 1 : 0;
69461 +}
69462 +
69463 +void gr_put_exec_file(struct task_struct *task)
69464 +{
69465 + struct file *filp;
69466 +
69467 + write_lock(&grsec_exec_file_lock);
69468 + filp = task->exec_file;
69469 + task->exec_file = NULL;
69470 + write_unlock(&grsec_exec_file_lock);
69471 +
69472 + if (filp)
69473 + fput(filp);
69474 +
69475 + return;
69476 +}
69477 +
69478 +
69479 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69480 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69481 +#endif
69482 +#ifdef CONFIG_SECURITY
69483 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69484 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69485 +#endif
69486 +
69487 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69488 new file mode 100644
69489 index 0000000..18ffbbd
69490 --- /dev/null
69491 +++ b/grsecurity/gracl_alloc.c
69492 @@ -0,0 +1,105 @@
69493 +#include <linux/kernel.h>
69494 +#include <linux/mm.h>
69495 +#include <linux/slab.h>
69496 +#include <linux/vmalloc.h>
69497 +#include <linux/gracl.h>
69498 +#include <linux/grsecurity.h>
69499 +
69500 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69501 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69502 +
69503 +static __inline__ int
69504 +alloc_pop(void)
69505 +{
69506 + if (current_alloc_state->alloc_stack_next == 1)
69507 + return 0;
69508 +
69509 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69510 +
69511 + current_alloc_state->alloc_stack_next--;
69512 +
69513 + return 1;
69514 +}
69515 +
69516 +static __inline__ int
69517 +alloc_push(void *buf)
69518 +{
69519 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69520 + return 1;
69521 +
69522 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69523 +
69524 + current_alloc_state->alloc_stack_next++;
69525 +
69526 + return 0;
69527 +}
69528 +
69529 +void *
69530 +acl_alloc(unsigned long len)
69531 +{
69532 + void *ret = NULL;
69533 +
69534 + if (!len || len > PAGE_SIZE)
69535 + goto out;
69536 +
69537 + ret = kmalloc(len, GFP_KERNEL);
69538 +
69539 + if (ret) {
69540 + if (alloc_push(ret)) {
69541 + kfree(ret);
69542 + ret = NULL;
69543 + }
69544 + }
69545 +
69546 +out:
69547 + return ret;
69548 +}
69549 +
69550 +void *
69551 +acl_alloc_num(unsigned long num, unsigned long len)
69552 +{
69553 + if (!len || (num > (PAGE_SIZE / len)))
69554 + return NULL;
69555 +
69556 + return acl_alloc(num * len);
69557 +}
69558 +
69559 +void
69560 +acl_free_all(void)
69561 +{
69562 + if (!current_alloc_state->alloc_stack)
69563 + return;
69564 +
69565 + while (alloc_pop()) ;
69566 +
69567 + if (current_alloc_state->alloc_stack) {
69568 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69569 + kfree(current_alloc_state->alloc_stack);
69570 + else
69571 + vfree(current_alloc_state->alloc_stack);
69572 + }
69573 +
69574 + current_alloc_state->alloc_stack = NULL;
69575 + current_alloc_state->alloc_stack_size = 1;
69576 + current_alloc_state->alloc_stack_next = 1;
69577 +
69578 + return;
69579 +}
69580 +
69581 +int
69582 +acl_alloc_stack_init(unsigned long size)
69583 +{
69584 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69585 + current_alloc_state->alloc_stack =
69586 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69587 + else
69588 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69589 +
69590 + current_alloc_state->alloc_stack_size = size;
69591 + current_alloc_state->alloc_stack_next = 1;
69592 +
69593 + if (!current_alloc_state->alloc_stack)
69594 + return 0;
69595 + else
69596 + return 1;
69597 +}
69598 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69599 new file mode 100644
69600 index 0000000..bdd51ea
69601 --- /dev/null
69602 +++ b/grsecurity/gracl_cap.c
69603 @@ -0,0 +1,110 @@
69604 +#include <linux/kernel.h>
69605 +#include <linux/module.h>
69606 +#include <linux/sched.h>
69607 +#include <linux/gracl.h>
69608 +#include <linux/grsecurity.h>
69609 +#include <linux/grinternal.h>
69610 +
69611 +extern const char *captab_log[];
69612 +extern int captab_log_entries;
69613 +
69614 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69615 +{
69616 + struct acl_subject_label *curracl;
69617 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69618 + kernel_cap_t cap_audit = __cap_empty_set;
69619 +
69620 + if (!gr_acl_is_enabled())
69621 + return 1;
69622 +
69623 + curracl = task->acl;
69624 +
69625 + cap_drop = curracl->cap_lower;
69626 + cap_mask = curracl->cap_mask;
69627 + cap_audit = curracl->cap_invert_audit;
69628 +
69629 + while ((curracl = curracl->parent_subject)) {
69630 + /* if the cap isn't specified in the current computed mask but is specified in the
69631 + current level subject, and is lowered in the current level subject, then add
69632 + it to the set of dropped capabilities
69633 + otherwise, add the current level subject's mask to the current computed mask
69634 + */
69635 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69636 + cap_raise(cap_mask, cap);
69637 + if (cap_raised(curracl->cap_lower, cap))
69638 + cap_raise(cap_drop, cap);
69639 + if (cap_raised(curracl->cap_invert_audit, cap))
69640 + cap_raise(cap_audit, cap);
69641 + }
69642 + }
69643 +
69644 + if (!cap_raised(cap_drop, cap)) {
69645 + if (cap_raised(cap_audit, cap))
69646 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69647 + return 1;
69648 + }
69649 +
69650 + curracl = task->acl;
69651 +
69652 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69653 + && cap_raised(cred->cap_effective, cap)) {
69654 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69655 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69656 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69657 + gr_to_filename(task->exec_file->f_path.dentry,
69658 + task->exec_file->f_path.mnt) : curracl->filename,
69659 + curracl->filename, 0UL,
69660 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69661 + return 1;
69662 + }
69663 +
69664 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69665 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69666 +
69667 + return 0;
69668 +}
69669 +
69670 +int
69671 +gr_acl_is_capable(const int cap)
69672 +{
69673 + return gr_task_acl_is_capable(current, current_cred(), cap);
69674 +}
69675 +
69676 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69677 +{
69678 + struct acl_subject_label *curracl;
69679 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69680 +
69681 + if (!gr_acl_is_enabled())
69682 + return 1;
69683 +
69684 + curracl = task->acl;
69685 +
69686 + cap_drop = curracl->cap_lower;
69687 + cap_mask = curracl->cap_mask;
69688 +
69689 + while ((curracl = curracl->parent_subject)) {
69690 + /* if the cap isn't specified in the current computed mask but is specified in the
69691 + current level subject, and is lowered in the current level subject, then add
69692 + it to the set of dropped capabilities
69693 + otherwise, add the current level subject's mask to the current computed mask
69694 + */
69695 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69696 + cap_raise(cap_mask, cap);
69697 + if (cap_raised(curracl->cap_lower, cap))
69698 + cap_raise(cap_drop, cap);
69699 + }
69700 + }
69701 +
69702 + if (!cap_raised(cap_drop, cap))
69703 + return 1;
69704 +
69705 + return 0;
69706 +}
69707 +
69708 +int
69709 +gr_acl_is_capable_nolog(const int cap)
69710 +{
69711 + return gr_task_acl_is_capable_nolog(current, cap);
69712 +}
69713 +
69714 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69715 new file mode 100644
69716 index 0000000..ca25605
69717 --- /dev/null
69718 +++ b/grsecurity/gracl_compat.c
69719 @@ -0,0 +1,270 @@
69720 +#include <linux/kernel.h>
69721 +#include <linux/gracl.h>
69722 +#include <linux/compat.h>
69723 +#include <linux/gracl_compat.h>
69724 +
69725 +#include <asm/uaccess.h>
69726 +
69727 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69728 +{
69729 + struct gr_arg_wrapper_compat uwrapcompat;
69730 +
69731 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69732 + return -EFAULT;
69733 +
69734 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69735 + (uwrapcompat.version != 0x2901)) ||
69736 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69737 + return -EINVAL;
69738 +
69739 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69740 + uwrap->version = uwrapcompat.version;
69741 + uwrap->size = sizeof(struct gr_arg);
69742 +
69743 + return 0;
69744 +}
69745 +
69746 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69747 +{
69748 + struct gr_arg_compat argcompat;
69749 +
69750 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69751 + return -EFAULT;
69752 +
69753 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69754 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69755 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69756 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69757 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69758 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69759 +
69760 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69761 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69762 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69763 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69764 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69765 + arg->segv_device = argcompat.segv_device;
69766 + arg->segv_inode = argcompat.segv_inode;
69767 + arg->segv_uid = argcompat.segv_uid;
69768 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69769 + arg->mode = argcompat.mode;
69770 +
69771 + return 0;
69772 +}
69773 +
69774 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69775 +{
69776 + struct acl_object_label_compat objcompat;
69777 +
69778 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69779 + return -EFAULT;
69780 +
69781 + obj->filename = compat_ptr(objcompat.filename);
69782 + obj->inode = objcompat.inode;
69783 + obj->device = objcompat.device;
69784 + obj->mode = objcompat.mode;
69785 +
69786 + obj->nested = compat_ptr(objcompat.nested);
69787 + obj->globbed = compat_ptr(objcompat.globbed);
69788 +
69789 + obj->prev = compat_ptr(objcompat.prev);
69790 + obj->next = compat_ptr(objcompat.next);
69791 +
69792 + return 0;
69793 +}
69794 +
69795 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69796 +{
69797 + unsigned int i;
69798 + struct acl_subject_label_compat subjcompat;
69799 +
69800 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69801 + return -EFAULT;
69802 +
69803 + subj->filename = compat_ptr(subjcompat.filename);
69804 + subj->inode = subjcompat.inode;
69805 + subj->device = subjcompat.device;
69806 + subj->mode = subjcompat.mode;
69807 + subj->cap_mask = subjcompat.cap_mask;
69808 + subj->cap_lower = subjcompat.cap_lower;
69809 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69810 +
69811 + for (i = 0; i < GR_NLIMITS; i++) {
69812 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69813 + subj->res[i].rlim_cur = RLIM_INFINITY;
69814 + else
69815 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69816 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69817 + subj->res[i].rlim_max = RLIM_INFINITY;
69818 + else
69819 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69820 + }
69821 + subj->resmask = subjcompat.resmask;
69822 +
69823 + subj->user_trans_type = subjcompat.user_trans_type;
69824 + subj->group_trans_type = subjcompat.group_trans_type;
69825 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69826 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69827 + subj->user_trans_num = subjcompat.user_trans_num;
69828 + subj->group_trans_num = subjcompat.group_trans_num;
69829 +
69830 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69831 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69832 + subj->ip_type = subjcompat.ip_type;
69833 + subj->ips = compat_ptr(subjcompat.ips);
69834 + subj->ip_num = subjcompat.ip_num;
69835 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69836 +
69837 + subj->crashes = subjcompat.crashes;
69838 + subj->expires = subjcompat.expires;
69839 +
69840 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69841 + subj->hash = compat_ptr(subjcompat.hash);
69842 + subj->prev = compat_ptr(subjcompat.prev);
69843 + subj->next = compat_ptr(subjcompat.next);
69844 +
69845 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69846 + subj->obj_hash_size = subjcompat.obj_hash_size;
69847 + subj->pax_flags = subjcompat.pax_flags;
69848 +
69849 + return 0;
69850 +}
69851 +
69852 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69853 +{
69854 + struct acl_role_label_compat rolecompat;
69855 +
69856 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69857 + return -EFAULT;
69858 +
69859 + role->rolename = compat_ptr(rolecompat.rolename);
69860 + role->uidgid = rolecompat.uidgid;
69861 + role->roletype = rolecompat.roletype;
69862 +
69863 + role->auth_attempts = rolecompat.auth_attempts;
69864 + role->expires = rolecompat.expires;
69865 +
69866 + role->root_label = compat_ptr(rolecompat.root_label);
69867 + role->hash = compat_ptr(rolecompat.hash);
69868 +
69869 + role->prev = compat_ptr(rolecompat.prev);
69870 + role->next = compat_ptr(rolecompat.next);
69871 +
69872 + role->transitions = compat_ptr(rolecompat.transitions);
69873 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69874 + role->domain_children = compat_ptr(rolecompat.domain_children);
69875 + role->domain_child_num = rolecompat.domain_child_num;
69876 +
69877 + role->umask = rolecompat.umask;
69878 +
69879 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69880 + role->subj_hash_size = rolecompat.subj_hash_size;
69881 +
69882 + return 0;
69883 +}
69884 +
69885 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69886 +{
69887 + struct role_allowed_ip_compat roleip_compat;
69888 +
69889 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69890 + return -EFAULT;
69891 +
69892 + roleip->addr = roleip_compat.addr;
69893 + roleip->netmask = roleip_compat.netmask;
69894 +
69895 + roleip->prev = compat_ptr(roleip_compat.prev);
69896 + roleip->next = compat_ptr(roleip_compat.next);
69897 +
69898 + return 0;
69899 +}
69900 +
69901 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69902 +{
69903 + struct role_transition_compat trans_compat;
69904 +
69905 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69906 + return -EFAULT;
69907 +
69908 + trans->rolename = compat_ptr(trans_compat.rolename);
69909 +
69910 + trans->prev = compat_ptr(trans_compat.prev);
69911 + trans->next = compat_ptr(trans_compat.next);
69912 +
69913 + return 0;
69914 +
69915 +}
69916 +
69917 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69918 +{
69919 + struct gr_hash_struct_compat hash_compat;
69920 +
69921 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69922 + return -EFAULT;
69923 +
69924 + hash->table = compat_ptr(hash_compat.table);
69925 + hash->nametable = compat_ptr(hash_compat.nametable);
69926 + hash->first = compat_ptr(hash_compat.first);
69927 +
69928 + hash->table_size = hash_compat.table_size;
69929 + hash->used_size = hash_compat.used_size;
69930 +
69931 + hash->type = hash_compat.type;
69932 +
69933 + return 0;
69934 +}
69935 +
69936 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69937 +{
69938 + compat_uptr_t ptrcompat;
69939 +
69940 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69941 + return -EFAULT;
69942 +
69943 + *(void **)ptr = compat_ptr(ptrcompat);
69944 +
69945 + return 0;
69946 +}
69947 +
69948 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69949 +{
69950 + struct acl_ip_label_compat ip_compat;
69951 +
69952 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69953 + return -EFAULT;
69954 +
69955 + ip->iface = compat_ptr(ip_compat.iface);
69956 + ip->addr = ip_compat.addr;
69957 + ip->netmask = ip_compat.netmask;
69958 + ip->low = ip_compat.low;
69959 + ip->high = ip_compat.high;
69960 + ip->mode = ip_compat.mode;
69961 + ip->type = ip_compat.type;
69962 +
69963 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69964 +
69965 + ip->prev = compat_ptr(ip_compat.prev);
69966 + ip->next = compat_ptr(ip_compat.next);
69967 +
69968 + return 0;
69969 +}
69970 +
69971 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69972 +{
69973 + struct sprole_pw_compat pw_compat;
69974 +
69975 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69976 + return -EFAULT;
69977 +
69978 + pw->rolename = compat_ptr(pw_compat.rolename);
69979 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69980 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69981 +
69982 + return 0;
69983 +}
69984 +
69985 +size_t get_gr_arg_wrapper_size_compat(void)
69986 +{
69987 + return sizeof(struct gr_arg_wrapper_compat);
69988 +}
69989 +
69990 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69991 new file mode 100644
69992 index 0000000..4008fdc
69993 --- /dev/null
69994 +++ b/grsecurity/gracl_fs.c
69995 @@ -0,0 +1,445 @@
69996 +#include <linux/kernel.h>
69997 +#include <linux/sched.h>
69998 +#include <linux/types.h>
69999 +#include <linux/fs.h>
70000 +#include <linux/file.h>
70001 +#include <linux/stat.h>
70002 +#include <linux/grsecurity.h>
70003 +#include <linux/grinternal.h>
70004 +#include <linux/gracl.h>
70005 +
70006 +umode_t
70007 +gr_acl_umask(void)
70008 +{
70009 + if (unlikely(!gr_acl_is_enabled()))
70010 + return 0;
70011 +
70012 + return current->role->umask;
70013 +}
70014 +
70015 +__u32
70016 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70017 + const struct vfsmount * mnt)
70018 +{
70019 + __u32 mode;
70020 +
70021 + if (unlikely(d_is_negative(dentry)))
70022 + return GR_FIND;
70023 +
70024 + mode =
70025 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70026 +
70027 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70028 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70029 + return mode;
70030 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70031 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70032 + return 0;
70033 + } else if (unlikely(!(mode & GR_FIND)))
70034 + return 0;
70035 +
70036 + return GR_FIND;
70037 +}
70038 +
70039 +__u32
70040 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70041 + int acc_mode)
70042 +{
70043 + __u32 reqmode = GR_FIND;
70044 + __u32 mode;
70045 +
70046 + if (unlikely(d_is_negative(dentry)))
70047 + return reqmode;
70048 +
70049 + if (acc_mode & MAY_APPEND)
70050 + reqmode |= GR_APPEND;
70051 + else if (acc_mode & MAY_WRITE)
70052 + reqmode |= GR_WRITE;
70053 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70054 + reqmode |= GR_READ;
70055 +
70056 + mode =
70057 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70058 + mnt);
70059 +
70060 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70061 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70062 + reqmode & GR_READ ? " reading" : "",
70063 + reqmode & GR_WRITE ? " writing" : reqmode &
70064 + GR_APPEND ? " appending" : "");
70065 + return reqmode;
70066 + } else
70067 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70068 + {
70069 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70070 + reqmode & GR_READ ? " reading" : "",
70071 + reqmode & GR_WRITE ? " writing" : reqmode &
70072 + GR_APPEND ? " appending" : "");
70073 + return 0;
70074 + } else if (unlikely((mode & reqmode) != reqmode))
70075 + return 0;
70076 +
70077 + return reqmode;
70078 +}
70079 +
70080 +__u32
70081 +gr_acl_handle_creat(const struct dentry * dentry,
70082 + const struct dentry * p_dentry,
70083 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70084 + const int imode)
70085 +{
70086 + __u32 reqmode = GR_WRITE | GR_CREATE;
70087 + __u32 mode;
70088 +
70089 + if (acc_mode & MAY_APPEND)
70090 + reqmode |= GR_APPEND;
70091 + // if a directory was required or the directory already exists, then
70092 + // don't count this open as a read
70093 + if ((acc_mode & MAY_READ) &&
70094 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70095 + reqmode |= GR_READ;
70096 + if ((open_flags & O_CREAT) &&
70097 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70098 + reqmode |= GR_SETID;
70099 +
70100 + mode =
70101 + gr_check_create(dentry, p_dentry, p_mnt,
70102 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70103 +
70104 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70105 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70106 + reqmode & GR_READ ? " reading" : "",
70107 + reqmode & GR_WRITE ? " writing" : reqmode &
70108 + GR_APPEND ? " appending" : "");
70109 + return reqmode;
70110 + } else
70111 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70112 + {
70113 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70114 + reqmode & GR_READ ? " reading" : "",
70115 + reqmode & GR_WRITE ? " writing" : reqmode &
70116 + GR_APPEND ? " appending" : "");
70117 + return 0;
70118 + } else if (unlikely((mode & reqmode) != reqmode))
70119 + return 0;
70120 +
70121 + return reqmode;
70122 +}
70123 +
70124 +__u32
70125 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70126 + const int fmode)
70127 +{
70128 + __u32 mode, reqmode = GR_FIND;
70129 +
70130 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70131 + reqmode |= GR_EXEC;
70132 + if (fmode & S_IWOTH)
70133 + reqmode |= GR_WRITE;
70134 + if (fmode & S_IROTH)
70135 + reqmode |= GR_READ;
70136 +
70137 + mode =
70138 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70139 + mnt);
70140 +
70141 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70142 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70143 + reqmode & GR_READ ? " reading" : "",
70144 + reqmode & GR_WRITE ? " writing" : "",
70145 + reqmode & GR_EXEC ? " executing" : "");
70146 + return reqmode;
70147 + } else
70148 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70149 + {
70150 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70151 + reqmode & GR_READ ? " reading" : "",
70152 + reqmode & GR_WRITE ? " writing" : "",
70153 + reqmode & GR_EXEC ? " executing" : "");
70154 + return 0;
70155 + } else if (unlikely((mode & reqmode) != reqmode))
70156 + return 0;
70157 +
70158 + return reqmode;
70159 +}
70160 +
70161 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70162 +{
70163 + __u32 mode;
70164 +
70165 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70166 +
70167 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70168 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70169 + return mode;
70170 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70171 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70172 + return 0;
70173 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70174 + return 0;
70175 +
70176 + return (reqmode);
70177 +}
70178 +
70179 +__u32
70180 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70181 +{
70182 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70183 +}
70184 +
70185 +__u32
70186 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70187 +{
70188 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70189 +}
70190 +
70191 +__u32
70192 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70193 +{
70194 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70195 +}
70196 +
70197 +__u32
70198 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70199 +{
70200 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70201 +}
70202 +
70203 +__u32
70204 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70205 + umode_t *modeptr)
70206 +{
70207 + umode_t mode;
70208 +
70209 + *modeptr &= ~gr_acl_umask();
70210 + mode = *modeptr;
70211 +
70212 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70213 + return 1;
70214 +
70215 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70216 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70217 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70218 + GR_CHMOD_ACL_MSG);
70219 + } else {
70220 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70221 + }
70222 +}
70223 +
70224 +__u32
70225 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70226 +{
70227 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70228 +}
70229 +
70230 +__u32
70231 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70232 +{
70233 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70234 +}
70235 +
70236 +__u32
70237 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70238 +{
70239 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70240 +}
70241 +
70242 +__u32
70243 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70244 +{
70245 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70246 +}
70247 +
70248 +__u32
70249 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70250 +{
70251 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70252 + GR_UNIXCONNECT_ACL_MSG);
70253 +}
70254 +
70255 +/* hardlinks require at minimum create and link permission,
70256 + any additional privilege required is based on the
70257 + privilege of the file being linked to
70258 +*/
70259 +__u32
70260 +gr_acl_handle_link(const struct dentry * new_dentry,
70261 + const struct dentry * parent_dentry,
70262 + const struct vfsmount * parent_mnt,
70263 + const struct dentry * old_dentry,
70264 + const struct vfsmount * old_mnt, const struct filename *to)
70265 +{
70266 + __u32 mode;
70267 + __u32 needmode = GR_CREATE | GR_LINK;
70268 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70269 +
70270 + mode =
70271 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70272 + old_mnt);
70273 +
70274 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70275 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70276 + return mode;
70277 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70278 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70279 + return 0;
70280 + } else if (unlikely((mode & needmode) != needmode))
70281 + return 0;
70282 +
70283 + return 1;
70284 +}
70285 +
70286 +__u32
70287 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70288 + const struct dentry * parent_dentry,
70289 + const struct vfsmount * parent_mnt, const struct filename *from)
70290 +{
70291 + __u32 needmode = GR_WRITE | GR_CREATE;
70292 + __u32 mode;
70293 +
70294 + mode =
70295 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
70296 + GR_CREATE | GR_AUDIT_CREATE |
70297 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70298 +
70299 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70300 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70301 + return mode;
70302 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70303 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70304 + return 0;
70305 + } else if (unlikely((mode & needmode) != needmode))
70306 + return 0;
70307 +
70308 + return (GR_WRITE | GR_CREATE);
70309 +}
70310 +
70311 +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)
70312 +{
70313 + __u32 mode;
70314 +
70315 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70316 +
70317 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70318 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70319 + return mode;
70320 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70321 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70322 + return 0;
70323 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70324 + return 0;
70325 +
70326 + return (reqmode);
70327 +}
70328 +
70329 +__u32
70330 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70331 + const struct dentry * parent_dentry,
70332 + const struct vfsmount * parent_mnt,
70333 + const int mode)
70334 +{
70335 + __u32 reqmode = GR_WRITE | GR_CREATE;
70336 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70337 + reqmode |= GR_SETID;
70338 +
70339 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70340 + reqmode, GR_MKNOD_ACL_MSG);
70341 +}
70342 +
70343 +__u32
70344 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70345 + const struct dentry *parent_dentry,
70346 + const struct vfsmount *parent_mnt)
70347 +{
70348 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70349 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70350 +}
70351 +
70352 +#define RENAME_CHECK_SUCCESS(old, new) \
70353 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70354 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70355 +
70356 +int
70357 +gr_acl_handle_rename(struct dentry *new_dentry,
70358 + struct dentry *parent_dentry,
70359 + const struct vfsmount *parent_mnt,
70360 + struct dentry *old_dentry,
70361 + struct inode *old_parent_inode,
70362 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70363 +{
70364 + __u32 comp1, comp2;
70365 + int error = 0;
70366 +
70367 + if (unlikely(!gr_acl_is_enabled()))
70368 + return 0;
70369 +
70370 + if (flags & RENAME_EXCHANGE) {
70371 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70372 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70373 + GR_SUPPRESS, parent_mnt);
70374 + comp2 =
70375 + gr_search_file(old_dentry,
70376 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70377 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70378 + } else if (d_is_negative(new_dentry)) {
70379 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70380 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70381 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70382 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70383 + GR_DELETE | GR_AUDIT_DELETE |
70384 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70385 + GR_SUPPRESS, old_mnt);
70386 + } else {
70387 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70388 + GR_CREATE | GR_DELETE |
70389 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70390 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70391 + GR_SUPPRESS, parent_mnt);
70392 + comp2 =
70393 + gr_search_file(old_dentry,
70394 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70395 + GR_DELETE | GR_AUDIT_DELETE |
70396 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70397 + }
70398 +
70399 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70400 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70401 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70402 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70403 + && !(comp2 & GR_SUPPRESS)) {
70404 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70405 + error = -EACCES;
70406 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70407 + error = -EACCES;
70408 +
70409 + return error;
70410 +}
70411 +
70412 +void
70413 +gr_acl_handle_exit(void)
70414 +{
70415 + u16 id;
70416 + char *rolename;
70417 +
70418 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70419 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70420 + id = current->acl_role_id;
70421 + rolename = current->role->rolename;
70422 + gr_set_acls(1);
70423 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70424 + }
70425 +
70426 + gr_put_exec_file(current);
70427 + return;
70428 +}
70429 +
70430 +int
70431 +gr_acl_handle_procpidmem(const struct task_struct *task)
70432 +{
70433 + if (unlikely(!gr_acl_is_enabled()))
70434 + return 0;
70435 +
70436 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70437 + return -EACCES;
70438 +
70439 + return 0;
70440 +}
70441 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70442 new file mode 100644
70443 index 0000000..f056b81
70444 --- /dev/null
70445 +++ b/grsecurity/gracl_ip.c
70446 @@ -0,0 +1,386 @@
70447 +#include <linux/kernel.h>
70448 +#include <asm/uaccess.h>
70449 +#include <asm/errno.h>
70450 +#include <net/sock.h>
70451 +#include <linux/file.h>
70452 +#include <linux/fs.h>
70453 +#include <linux/net.h>
70454 +#include <linux/in.h>
70455 +#include <linux/skbuff.h>
70456 +#include <linux/ip.h>
70457 +#include <linux/udp.h>
70458 +#include <linux/types.h>
70459 +#include <linux/sched.h>
70460 +#include <linux/netdevice.h>
70461 +#include <linux/inetdevice.h>
70462 +#include <linux/gracl.h>
70463 +#include <linux/grsecurity.h>
70464 +#include <linux/grinternal.h>
70465 +
70466 +#define GR_BIND 0x01
70467 +#define GR_CONNECT 0x02
70468 +#define GR_INVERT 0x04
70469 +#define GR_BINDOVERRIDE 0x08
70470 +#define GR_CONNECTOVERRIDE 0x10
70471 +#define GR_SOCK_FAMILY 0x20
70472 +
70473 +static const char * gr_protocols[IPPROTO_MAX] = {
70474 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70475 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70476 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70477 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70478 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70479 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70480 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70481 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70482 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70483 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70484 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70485 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70486 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70487 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70488 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70489 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70490 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70491 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70492 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70493 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70494 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70495 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70496 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70497 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70498 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70499 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70500 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70501 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70502 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70503 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70504 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70505 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70506 + };
70507 +
70508 +static const char * gr_socktypes[SOCK_MAX] = {
70509 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70510 + "unknown:7", "unknown:8", "unknown:9", "packet"
70511 + };
70512 +
70513 +static const char * gr_sockfamilies[AF_MAX+1] = {
70514 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70515 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70516 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70517 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70518 + };
70519 +
70520 +const char *
70521 +gr_proto_to_name(unsigned char proto)
70522 +{
70523 + return gr_protocols[proto];
70524 +}
70525 +
70526 +const char *
70527 +gr_socktype_to_name(unsigned char type)
70528 +{
70529 + return gr_socktypes[type];
70530 +}
70531 +
70532 +const char *
70533 +gr_sockfamily_to_name(unsigned char family)
70534 +{
70535 + return gr_sockfamilies[family];
70536 +}
70537 +
70538 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70539 +
70540 +int
70541 +gr_search_socket(const int domain, const int type, const int protocol)
70542 +{
70543 + struct acl_subject_label *curr;
70544 + const struct cred *cred = current_cred();
70545 +
70546 + if (unlikely(!gr_acl_is_enabled()))
70547 + goto exit;
70548 +
70549 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70550 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70551 + goto exit; // let the kernel handle it
70552 +
70553 + curr = current->acl;
70554 +
70555 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70556 + /* the family is allowed, if this is PF_INET allow it only if
70557 + the extra sock type/protocol checks pass */
70558 + if (domain == PF_INET)
70559 + goto inet_check;
70560 + goto exit;
70561 + } else {
70562 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70563 + __u32 fakeip = 0;
70564 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70565 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70566 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70567 + gr_to_filename(current->exec_file->f_path.dentry,
70568 + current->exec_file->f_path.mnt) :
70569 + curr->filename, curr->filename,
70570 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70571 + &current->signal->saved_ip);
70572 + goto exit;
70573 + }
70574 + goto exit_fail;
70575 + }
70576 +
70577 +inet_check:
70578 + /* the rest of this checking is for IPv4 only */
70579 + if (!curr->ips)
70580 + goto exit;
70581 +
70582 + if ((curr->ip_type & (1U << type)) &&
70583 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70584 + goto exit;
70585 +
70586 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70587 + /* we don't place acls on raw sockets , and sometimes
70588 + dgram/ip sockets are opened for ioctl and not
70589 + bind/connect, so we'll fake a bind learn log */
70590 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70591 + __u32 fakeip = 0;
70592 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70593 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70594 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70595 + gr_to_filename(current->exec_file->f_path.dentry,
70596 + current->exec_file->f_path.mnt) :
70597 + curr->filename, curr->filename,
70598 + &fakeip, 0, type,
70599 + protocol, GR_CONNECT, &current->signal->saved_ip);
70600 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70601 + __u32 fakeip = 0;
70602 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70603 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70604 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70605 + gr_to_filename(current->exec_file->f_path.dentry,
70606 + current->exec_file->f_path.mnt) :
70607 + curr->filename, curr->filename,
70608 + &fakeip, 0, type,
70609 + protocol, GR_BIND, &current->signal->saved_ip);
70610 + }
70611 + /* we'll log when they use connect or bind */
70612 + goto exit;
70613 + }
70614 +
70615 +exit_fail:
70616 + if (domain == PF_INET)
70617 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70618 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70619 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70620 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70621 + gr_socktype_to_name(type), protocol);
70622 +
70623 + return 0;
70624 +exit:
70625 + return 1;
70626 +}
70627 +
70628 +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)
70629 +{
70630 + if ((ip->mode & mode) &&
70631 + (ip_port >= ip->low) &&
70632 + (ip_port <= ip->high) &&
70633 + ((ntohl(ip_addr) & our_netmask) ==
70634 + (ntohl(our_addr) & our_netmask))
70635 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70636 + && (ip->type & (1U << type))) {
70637 + if (ip->mode & GR_INVERT)
70638 + return 2; // specifically denied
70639 + else
70640 + return 1; // allowed
70641 + }
70642 +
70643 + return 0; // not specifically allowed, may continue parsing
70644 +}
70645 +
70646 +static int
70647 +gr_search_connectbind(const int full_mode, struct sock *sk,
70648 + struct sockaddr_in *addr, const int type)
70649 +{
70650 + char iface[IFNAMSIZ] = {0};
70651 + struct acl_subject_label *curr;
70652 + struct acl_ip_label *ip;
70653 + struct inet_sock *isk;
70654 + struct net_device *dev;
70655 + struct in_device *idev;
70656 + unsigned long i;
70657 + int ret;
70658 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70659 + __u32 ip_addr = 0;
70660 + __u32 our_addr;
70661 + __u32 our_netmask;
70662 + char *p;
70663 + __u16 ip_port = 0;
70664 + const struct cred *cred = current_cred();
70665 +
70666 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70667 + return 0;
70668 +
70669 + curr = current->acl;
70670 + isk = inet_sk(sk);
70671 +
70672 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70673 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70674 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70675 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70676 + struct sockaddr_in saddr;
70677 + int err;
70678 +
70679 + saddr.sin_family = AF_INET;
70680 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70681 + saddr.sin_port = isk->inet_sport;
70682 +
70683 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70684 + if (err)
70685 + return err;
70686 +
70687 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70688 + if (err)
70689 + return err;
70690 + }
70691 +
70692 + if (!curr->ips)
70693 + return 0;
70694 +
70695 + ip_addr = addr->sin_addr.s_addr;
70696 + ip_port = ntohs(addr->sin_port);
70697 +
70698 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70699 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70700 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70701 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70702 + gr_to_filename(current->exec_file->f_path.dentry,
70703 + current->exec_file->f_path.mnt) :
70704 + curr->filename, curr->filename,
70705 + &ip_addr, ip_port, type,
70706 + sk->sk_protocol, mode, &current->signal->saved_ip);
70707 + return 0;
70708 + }
70709 +
70710 + for (i = 0; i < curr->ip_num; i++) {
70711 + ip = *(curr->ips + i);
70712 + if (ip->iface != NULL) {
70713 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70714 + p = strchr(iface, ':');
70715 + if (p != NULL)
70716 + *p = '\0';
70717 + dev = dev_get_by_name(sock_net(sk), iface);
70718 + if (dev == NULL)
70719 + continue;
70720 + idev = in_dev_get(dev);
70721 + if (idev == NULL) {
70722 + dev_put(dev);
70723 + continue;
70724 + }
70725 + rcu_read_lock();
70726 + for_ifa(idev) {
70727 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70728 + our_addr = ifa->ifa_address;
70729 + our_netmask = 0xffffffff;
70730 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70731 + if (ret == 1) {
70732 + rcu_read_unlock();
70733 + in_dev_put(idev);
70734 + dev_put(dev);
70735 + return 0;
70736 + } else if (ret == 2) {
70737 + rcu_read_unlock();
70738 + in_dev_put(idev);
70739 + dev_put(dev);
70740 + goto denied;
70741 + }
70742 + }
70743 + } endfor_ifa(idev);
70744 + rcu_read_unlock();
70745 + in_dev_put(idev);
70746 + dev_put(dev);
70747 + } else {
70748 + our_addr = ip->addr;
70749 + our_netmask = ip->netmask;
70750 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70751 + if (ret == 1)
70752 + return 0;
70753 + else if (ret == 2)
70754 + goto denied;
70755 + }
70756 + }
70757 +
70758 +denied:
70759 + if (mode == GR_BIND)
70760 + 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));
70761 + else if (mode == GR_CONNECT)
70762 + 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));
70763 +
70764 + return -EACCES;
70765 +}
70766 +
70767 +int
70768 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70769 +{
70770 + /* always allow disconnection of dgram sockets with connect */
70771 + if (addr->sin_family == AF_UNSPEC)
70772 + return 0;
70773 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70774 +}
70775 +
70776 +int
70777 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70778 +{
70779 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70780 +}
70781 +
70782 +int gr_search_listen(struct socket *sock)
70783 +{
70784 + struct sock *sk = sock->sk;
70785 + struct sockaddr_in addr;
70786 +
70787 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70788 + addr.sin_port = inet_sk(sk)->inet_sport;
70789 +
70790 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70791 +}
70792 +
70793 +int gr_search_accept(struct socket *sock)
70794 +{
70795 + struct sock *sk = sock->sk;
70796 + struct sockaddr_in addr;
70797 +
70798 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70799 + addr.sin_port = inet_sk(sk)->inet_sport;
70800 +
70801 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70802 +}
70803 +
70804 +int
70805 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70806 +{
70807 + if (addr)
70808 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70809 + else {
70810 + struct sockaddr_in sin;
70811 + const struct inet_sock *inet = inet_sk(sk);
70812 +
70813 + sin.sin_addr.s_addr = inet->inet_daddr;
70814 + sin.sin_port = inet->inet_dport;
70815 +
70816 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70817 + }
70818 +}
70819 +
70820 +int
70821 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70822 +{
70823 + struct sockaddr_in sin;
70824 +
70825 + if (unlikely(skb->len < sizeof (struct udphdr)))
70826 + return 0; // skip this packet
70827 +
70828 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70829 + sin.sin_port = udp_hdr(skb)->source;
70830 +
70831 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70832 +}
70833 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70834 new file mode 100644
70835 index 0000000..25f54ef
70836 --- /dev/null
70837 +++ b/grsecurity/gracl_learn.c
70838 @@ -0,0 +1,207 @@
70839 +#include <linux/kernel.h>
70840 +#include <linux/mm.h>
70841 +#include <linux/sched.h>
70842 +#include <linux/poll.h>
70843 +#include <linux/string.h>
70844 +#include <linux/file.h>
70845 +#include <linux/types.h>
70846 +#include <linux/vmalloc.h>
70847 +#include <linux/grinternal.h>
70848 +
70849 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70850 + size_t count, loff_t *ppos);
70851 +extern int gr_acl_is_enabled(void);
70852 +
70853 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70854 +static int gr_learn_attached;
70855 +
70856 +/* use a 512k buffer */
70857 +#define LEARN_BUFFER_SIZE (512 * 1024)
70858 +
70859 +static DEFINE_SPINLOCK(gr_learn_lock);
70860 +static DEFINE_MUTEX(gr_learn_user_mutex);
70861 +
70862 +/* we need to maintain two buffers, so that the kernel context of grlearn
70863 + uses a semaphore around the userspace copying, and the other kernel contexts
70864 + use a spinlock when copying into the buffer, since they cannot sleep
70865 +*/
70866 +static char *learn_buffer;
70867 +static char *learn_buffer_user;
70868 +static int learn_buffer_len;
70869 +static int learn_buffer_user_len;
70870 +
70871 +static ssize_t
70872 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70873 +{
70874 + DECLARE_WAITQUEUE(wait, current);
70875 + ssize_t retval = 0;
70876 +
70877 + add_wait_queue(&learn_wait, &wait);
70878 + set_current_state(TASK_INTERRUPTIBLE);
70879 + do {
70880 + mutex_lock(&gr_learn_user_mutex);
70881 + spin_lock(&gr_learn_lock);
70882 + if (learn_buffer_len)
70883 + break;
70884 + spin_unlock(&gr_learn_lock);
70885 + mutex_unlock(&gr_learn_user_mutex);
70886 + if (file->f_flags & O_NONBLOCK) {
70887 + retval = -EAGAIN;
70888 + goto out;
70889 + }
70890 + if (signal_pending(current)) {
70891 + retval = -ERESTARTSYS;
70892 + goto out;
70893 + }
70894 +
70895 + schedule();
70896 + } while (1);
70897 +
70898 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70899 + learn_buffer_user_len = learn_buffer_len;
70900 + retval = learn_buffer_len;
70901 + learn_buffer_len = 0;
70902 +
70903 + spin_unlock(&gr_learn_lock);
70904 +
70905 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70906 + retval = -EFAULT;
70907 +
70908 + mutex_unlock(&gr_learn_user_mutex);
70909 +out:
70910 + set_current_state(TASK_RUNNING);
70911 + remove_wait_queue(&learn_wait, &wait);
70912 + return retval;
70913 +}
70914 +
70915 +static unsigned int
70916 +poll_learn(struct file * file, poll_table * wait)
70917 +{
70918 + poll_wait(file, &learn_wait, wait);
70919 +
70920 + if (learn_buffer_len)
70921 + return (POLLIN | POLLRDNORM);
70922 +
70923 + return 0;
70924 +}
70925 +
70926 +void
70927 +gr_clear_learn_entries(void)
70928 +{
70929 + char *tmp;
70930 +
70931 + mutex_lock(&gr_learn_user_mutex);
70932 + spin_lock(&gr_learn_lock);
70933 + tmp = learn_buffer;
70934 + learn_buffer = NULL;
70935 + spin_unlock(&gr_learn_lock);
70936 + if (tmp)
70937 + vfree(tmp);
70938 + if (learn_buffer_user != NULL) {
70939 + vfree(learn_buffer_user);
70940 + learn_buffer_user = NULL;
70941 + }
70942 + learn_buffer_len = 0;
70943 + mutex_unlock(&gr_learn_user_mutex);
70944 +
70945 + return;
70946 +}
70947 +
70948 +void
70949 +gr_add_learn_entry(const char *fmt, ...)
70950 +{
70951 + va_list args;
70952 + unsigned int len;
70953 +
70954 + if (!gr_learn_attached)
70955 + return;
70956 +
70957 + spin_lock(&gr_learn_lock);
70958 +
70959 + /* leave a gap at the end so we know when it's "full" but don't have to
70960 + compute the exact length of the string we're trying to append
70961 + */
70962 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70963 + spin_unlock(&gr_learn_lock);
70964 + wake_up_interruptible(&learn_wait);
70965 + return;
70966 + }
70967 + if (learn_buffer == NULL) {
70968 + spin_unlock(&gr_learn_lock);
70969 + return;
70970 + }
70971 +
70972 + va_start(args, fmt);
70973 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70974 + va_end(args);
70975 +
70976 + learn_buffer_len += len + 1;
70977 +
70978 + spin_unlock(&gr_learn_lock);
70979 + wake_up_interruptible(&learn_wait);
70980 +
70981 + return;
70982 +}
70983 +
70984 +static int
70985 +open_learn(struct inode *inode, struct file *file)
70986 +{
70987 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70988 + return -EBUSY;
70989 + if (file->f_mode & FMODE_READ) {
70990 + int retval = 0;
70991 + mutex_lock(&gr_learn_user_mutex);
70992 + if (learn_buffer == NULL)
70993 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70994 + if (learn_buffer_user == NULL)
70995 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70996 + if (learn_buffer == NULL) {
70997 + retval = -ENOMEM;
70998 + goto out_error;
70999 + }
71000 + if (learn_buffer_user == NULL) {
71001 + retval = -ENOMEM;
71002 + goto out_error;
71003 + }
71004 + learn_buffer_len = 0;
71005 + learn_buffer_user_len = 0;
71006 + gr_learn_attached = 1;
71007 +out_error:
71008 + mutex_unlock(&gr_learn_user_mutex);
71009 + return retval;
71010 + }
71011 + return 0;
71012 +}
71013 +
71014 +static int
71015 +close_learn(struct inode *inode, struct file *file)
71016 +{
71017 + if (file->f_mode & FMODE_READ) {
71018 + char *tmp = NULL;
71019 + mutex_lock(&gr_learn_user_mutex);
71020 + spin_lock(&gr_learn_lock);
71021 + tmp = learn_buffer;
71022 + learn_buffer = NULL;
71023 + spin_unlock(&gr_learn_lock);
71024 + if (tmp)
71025 + vfree(tmp);
71026 + if (learn_buffer_user != NULL) {
71027 + vfree(learn_buffer_user);
71028 + learn_buffer_user = NULL;
71029 + }
71030 + learn_buffer_len = 0;
71031 + learn_buffer_user_len = 0;
71032 + gr_learn_attached = 0;
71033 + mutex_unlock(&gr_learn_user_mutex);
71034 + }
71035 +
71036 + return 0;
71037 +}
71038 +
71039 +const struct file_operations grsec_fops = {
71040 + .read = read_learn,
71041 + .write = write_grsec_handler,
71042 + .open = open_learn,
71043 + .release = close_learn,
71044 + .poll = poll_learn,
71045 +};
71046 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71047 new file mode 100644
71048 index 0000000..361a099
71049 --- /dev/null
71050 +++ b/grsecurity/gracl_policy.c
71051 @@ -0,0 +1,1782 @@
71052 +#include <linux/kernel.h>
71053 +#include <linux/module.h>
71054 +#include <linux/sched.h>
71055 +#include <linux/mm.h>
71056 +#include <linux/file.h>
71057 +#include <linux/fs.h>
71058 +#include <linux/namei.h>
71059 +#include <linux/mount.h>
71060 +#include <linux/tty.h>
71061 +#include <linux/proc_fs.h>
71062 +#include <linux/lglock.h>
71063 +#include <linux/slab.h>
71064 +#include <linux/vmalloc.h>
71065 +#include <linux/types.h>
71066 +#include <linux/sysctl.h>
71067 +#include <linux/netdevice.h>
71068 +#include <linux/ptrace.h>
71069 +#include <linux/gracl.h>
71070 +#include <linux/gralloc.h>
71071 +#include <linux/security.h>
71072 +#include <linux/grinternal.h>
71073 +#include <linux/pid_namespace.h>
71074 +#include <linux/stop_machine.h>
71075 +#include <linux/fdtable.h>
71076 +#include <linux/percpu.h>
71077 +#include <linux/lglock.h>
71078 +#include <linux/hugetlb.h>
71079 +#include <linux/posix-timers.h>
71080 +#include "../fs/mount.h"
71081 +
71082 +#include <asm/uaccess.h>
71083 +#include <asm/errno.h>
71084 +#include <asm/mman.h>
71085 +
71086 +extern struct gr_policy_state *polstate;
71087 +
71088 +#define FOR_EACH_ROLE_START(role) \
71089 + role = polstate->role_list; \
71090 + while (role) {
71091 +
71092 +#define FOR_EACH_ROLE_END(role) \
71093 + role = role->prev; \
71094 + }
71095 +
71096 +struct path gr_real_root;
71097 +
71098 +extern struct gr_alloc_state *current_alloc_state;
71099 +
71100 +u16 acl_sp_role_value;
71101 +
71102 +static DEFINE_MUTEX(gr_dev_mutex);
71103 +
71104 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71105 +extern void gr_clear_learn_entries(void);
71106 +
71107 +static struct gr_arg gr_usermode;
71108 +static unsigned char gr_system_salt[GR_SALT_LEN];
71109 +static unsigned char gr_system_sum[GR_SHA_LEN];
71110 +
71111 +static unsigned int gr_auth_attempts = 0;
71112 +static unsigned long gr_auth_expires = 0UL;
71113 +
71114 +struct acl_object_label *fakefs_obj_rw;
71115 +struct acl_object_label *fakefs_obj_rwx;
71116 +
71117 +extern int gr_init_uidset(void);
71118 +extern void gr_free_uidset(void);
71119 +extern void gr_remove_uid(uid_t uid);
71120 +extern int gr_find_uid(uid_t uid);
71121 +
71122 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71123 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71124 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71125 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71126 +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);
71127 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71128 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71129 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71130 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71131 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71132 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71133 +extern void assign_special_role(const char *rolename);
71134 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71135 +extern int gr_rbac_disable(void *unused);
71136 +extern void gr_enable_rbac_system(void);
71137 +
71138 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71139 +{
71140 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71141 + return -EFAULT;
71142 +
71143 + return 0;
71144 +}
71145 +
71146 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71147 +{
71148 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71149 + return -EFAULT;
71150 +
71151 + return 0;
71152 +}
71153 +
71154 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71155 +{
71156 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71157 + return -EFAULT;
71158 +
71159 + return 0;
71160 +}
71161 +
71162 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71163 +{
71164 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71165 + return -EFAULT;
71166 +
71167 + return 0;
71168 +}
71169 +
71170 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71171 +{
71172 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71173 + return -EFAULT;
71174 +
71175 + return 0;
71176 +}
71177 +
71178 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71179 +{
71180 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71181 + return -EFAULT;
71182 +
71183 + return 0;
71184 +}
71185 +
71186 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71187 +{
71188 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71189 + return -EFAULT;
71190 +
71191 + return 0;
71192 +}
71193 +
71194 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71195 +{
71196 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71197 + return -EFAULT;
71198 +
71199 + return 0;
71200 +}
71201 +
71202 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71203 +{
71204 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71205 + return -EFAULT;
71206 +
71207 + return 0;
71208 +}
71209 +
71210 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71211 +{
71212 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71213 + return -EFAULT;
71214 +
71215 + if (((uwrap->version != GRSECURITY_VERSION) &&
71216 + (uwrap->version != 0x2901)) ||
71217 + (uwrap->size != sizeof(struct gr_arg)))
71218 + return -EINVAL;
71219 +
71220 + return 0;
71221 +}
71222 +
71223 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71224 +{
71225 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71226 + return -EFAULT;
71227 +
71228 + return 0;
71229 +}
71230 +
71231 +static size_t get_gr_arg_wrapper_size_normal(void)
71232 +{
71233 + return sizeof(struct gr_arg_wrapper);
71234 +}
71235 +
71236 +#ifdef CONFIG_COMPAT
71237 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71238 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71239 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71240 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71241 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71242 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71243 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71244 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71245 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71246 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71247 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71248 +extern size_t get_gr_arg_wrapper_size_compat(void);
71249 +
71250 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71251 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71252 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71253 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71254 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71255 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71256 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71257 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71258 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71259 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71260 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71261 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71262 +
71263 +#else
71264 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71265 +#define copy_gr_arg copy_gr_arg_normal
71266 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71267 +#define copy_acl_object_label copy_acl_object_label_normal
71268 +#define copy_acl_subject_label copy_acl_subject_label_normal
71269 +#define copy_acl_role_label copy_acl_role_label_normal
71270 +#define copy_acl_ip_label copy_acl_ip_label_normal
71271 +#define copy_pointer_from_array copy_pointer_from_array_normal
71272 +#define copy_sprole_pw copy_sprole_pw_normal
71273 +#define copy_role_transition copy_role_transition_normal
71274 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71275 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71276 +#endif
71277 +
71278 +static struct acl_subject_label *
71279 +lookup_subject_map(const struct acl_subject_label *userp)
71280 +{
71281 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71282 + struct subject_map *match;
71283 +
71284 + match = polstate->subj_map_set.s_hash[index];
71285 +
71286 + while (match && match->user != userp)
71287 + match = match->next;
71288 +
71289 + if (match != NULL)
71290 + return match->kernel;
71291 + else
71292 + return NULL;
71293 +}
71294 +
71295 +static void
71296 +insert_subj_map_entry(struct subject_map *subjmap)
71297 +{
71298 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71299 + struct subject_map **curr;
71300 +
71301 + subjmap->prev = NULL;
71302 +
71303 + curr = &polstate->subj_map_set.s_hash[index];
71304 + if (*curr != NULL)
71305 + (*curr)->prev = subjmap;
71306 +
71307 + subjmap->next = *curr;
71308 + *curr = subjmap;
71309 +
71310 + return;
71311 +}
71312 +
71313 +static void
71314 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71315 +{
71316 + unsigned int index =
71317 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71318 + struct acl_role_label **curr;
71319 + struct acl_role_label *tmp, *tmp2;
71320 +
71321 + curr = &polstate->acl_role_set.r_hash[index];
71322 +
71323 + /* simple case, slot is empty, just set it to our role */
71324 + if (*curr == NULL) {
71325 + *curr = role;
71326 + } else {
71327 + /* example:
71328 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71329 + 2 -> 3
71330 + */
71331 + /* first check to see if we can already be reached via this slot */
71332 + tmp = *curr;
71333 + while (tmp && tmp != role)
71334 + tmp = tmp->next;
71335 + if (tmp == role) {
71336 + /* we don't need to add ourselves to this slot's chain */
71337 + return;
71338 + }
71339 + /* we need to add ourselves to this chain, two cases */
71340 + if (role->next == NULL) {
71341 + /* simple case, append the current chain to our role */
71342 + role->next = *curr;
71343 + *curr = role;
71344 + } else {
71345 + /* 1 -> 2 -> 3 -> 4
71346 + 2 -> 3 -> 4
71347 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71348 + */
71349 + /* trickier case: walk our role's chain until we find
71350 + the role for the start of the current slot's chain */
71351 + tmp = role;
71352 + tmp2 = *curr;
71353 + while (tmp->next && tmp->next != tmp2)
71354 + tmp = tmp->next;
71355 + if (tmp->next == tmp2) {
71356 + /* from example above, we found 3, so just
71357 + replace this slot's chain with ours */
71358 + *curr = role;
71359 + } else {
71360 + /* we didn't find a subset of our role's chain
71361 + in the current slot's chain, so append their
71362 + chain to ours, and set us as the first role in
71363 + the slot's chain
71364 +
71365 + we could fold this case with the case above,
71366 + but making it explicit for clarity
71367 + */
71368 + tmp->next = tmp2;
71369 + *curr = role;
71370 + }
71371 + }
71372 + }
71373 +
71374 + return;
71375 +}
71376 +
71377 +static void
71378 +insert_acl_role_label(struct acl_role_label *role)
71379 +{
71380 + int i;
71381 +
71382 + if (polstate->role_list == NULL) {
71383 + polstate->role_list = role;
71384 + role->prev = NULL;
71385 + } else {
71386 + role->prev = polstate->role_list;
71387 + polstate->role_list = role;
71388 + }
71389 +
71390 + /* used for hash chains */
71391 + role->next = NULL;
71392 +
71393 + if (role->roletype & GR_ROLE_DOMAIN) {
71394 + for (i = 0; i < role->domain_child_num; i++)
71395 + __insert_acl_role_label(role, role->domain_children[i]);
71396 + } else
71397 + __insert_acl_role_label(role, role->uidgid);
71398 +}
71399 +
71400 +static int
71401 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71402 +{
71403 + struct name_entry **curr, *nentry;
71404 + struct inodev_entry *ientry;
71405 + unsigned int len = strlen(name);
71406 + unsigned int key = full_name_hash(name, len);
71407 + unsigned int index = key % polstate->name_set.n_size;
71408 +
71409 + curr = &polstate->name_set.n_hash[index];
71410 +
71411 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71412 + curr = &((*curr)->next);
71413 +
71414 + if (*curr != NULL)
71415 + return 1;
71416 +
71417 + nentry = acl_alloc(sizeof (struct name_entry));
71418 + if (nentry == NULL)
71419 + return 0;
71420 + ientry = acl_alloc(sizeof (struct inodev_entry));
71421 + if (ientry == NULL)
71422 + return 0;
71423 + ientry->nentry = nentry;
71424 +
71425 + nentry->key = key;
71426 + nentry->name = name;
71427 + nentry->inode = inode;
71428 + nentry->device = device;
71429 + nentry->len = len;
71430 + nentry->deleted = deleted;
71431 +
71432 + nentry->prev = NULL;
71433 + curr = &polstate->name_set.n_hash[index];
71434 + if (*curr != NULL)
71435 + (*curr)->prev = nentry;
71436 + nentry->next = *curr;
71437 + *curr = nentry;
71438 +
71439 + /* insert us into the table searchable by inode/dev */
71440 + __insert_inodev_entry(polstate, ientry);
71441 +
71442 + return 1;
71443 +}
71444 +
71445 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71446 +
71447 +static void *
71448 +create_table(__u32 * len, int elementsize)
71449 +{
71450 + unsigned int table_sizes[] = {
71451 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71452 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71453 + 4194301, 8388593, 16777213, 33554393, 67108859
71454 + };
71455 + void *newtable = NULL;
71456 + unsigned int pwr = 0;
71457 +
71458 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71459 + table_sizes[pwr] <= *len)
71460 + pwr++;
71461 +
71462 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71463 + return newtable;
71464 +
71465 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71466 + newtable =
71467 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71468 + else
71469 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71470 +
71471 + *len = table_sizes[pwr];
71472 +
71473 + return newtable;
71474 +}
71475 +
71476 +static int
71477 +init_variables(const struct gr_arg *arg, bool reload)
71478 +{
71479 + struct task_struct *reaper = init_pid_ns.child_reaper;
71480 + unsigned int stacksize;
71481 +
71482 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71483 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71484 + polstate->name_set.n_size = arg->role_db.num_objects;
71485 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71486 +
71487 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71488 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71489 + return 1;
71490 +
71491 + if (!reload) {
71492 + if (!gr_init_uidset())
71493 + return 1;
71494 + }
71495 +
71496 + /* set up the stack that holds allocation info */
71497 +
71498 + stacksize = arg->role_db.num_pointers + 5;
71499 +
71500 + if (!acl_alloc_stack_init(stacksize))
71501 + return 1;
71502 +
71503 + if (!reload) {
71504 + /* grab reference for the real root dentry and vfsmount */
71505 + get_fs_root(reaper->fs, &gr_real_root);
71506 +
71507 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71508 + 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);
71509 +#endif
71510 +
71511 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71512 + if (fakefs_obj_rw == NULL)
71513 + return 1;
71514 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71515 +
71516 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71517 + if (fakefs_obj_rwx == NULL)
71518 + return 1;
71519 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71520 + }
71521 +
71522 + polstate->subj_map_set.s_hash =
71523 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71524 + polstate->acl_role_set.r_hash =
71525 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71526 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71527 + polstate->inodev_set.i_hash =
71528 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71529 +
71530 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71531 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71532 + return 1;
71533 +
71534 + memset(polstate->subj_map_set.s_hash, 0,
71535 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71536 + memset(polstate->acl_role_set.r_hash, 0,
71537 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71538 + memset(polstate->name_set.n_hash, 0,
71539 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71540 + memset(polstate->inodev_set.i_hash, 0,
71541 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71542 +
71543 + return 0;
71544 +}
71545 +
71546 +/* free information not needed after startup
71547 + currently contains user->kernel pointer mappings for subjects
71548 +*/
71549 +
71550 +static void
71551 +free_init_variables(void)
71552 +{
71553 + __u32 i;
71554 +
71555 + if (polstate->subj_map_set.s_hash) {
71556 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71557 + if (polstate->subj_map_set.s_hash[i]) {
71558 + kfree(polstate->subj_map_set.s_hash[i]);
71559 + polstate->subj_map_set.s_hash[i] = NULL;
71560 + }
71561 + }
71562 +
71563 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71564 + PAGE_SIZE)
71565 + kfree(polstate->subj_map_set.s_hash);
71566 + else
71567 + vfree(polstate->subj_map_set.s_hash);
71568 + }
71569 +
71570 + return;
71571 +}
71572 +
71573 +static void
71574 +free_variables(bool reload)
71575 +{
71576 + struct acl_subject_label *s;
71577 + struct acl_role_label *r;
71578 + struct task_struct *task, *task2;
71579 + unsigned int x;
71580 +
71581 + if (!reload) {
71582 + gr_clear_learn_entries();
71583 +
71584 + read_lock(&tasklist_lock);
71585 + do_each_thread(task2, task) {
71586 + task->acl_sp_role = 0;
71587 + task->acl_role_id = 0;
71588 + task->inherited = 0;
71589 + task->acl = NULL;
71590 + task->role = NULL;
71591 + } while_each_thread(task2, task);
71592 + read_unlock(&tasklist_lock);
71593 +
71594 + kfree(fakefs_obj_rw);
71595 + fakefs_obj_rw = NULL;
71596 + kfree(fakefs_obj_rwx);
71597 + fakefs_obj_rwx = NULL;
71598 +
71599 + /* release the reference to the real root dentry and vfsmount */
71600 + path_put(&gr_real_root);
71601 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71602 + }
71603 +
71604 + /* free all object hash tables */
71605 +
71606 + FOR_EACH_ROLE_START(r)
71607 + if (r->subj_hash == NULL)
71608 + goto next_role;
71609 + FOR_EACH_SUBJECT_START(r, s, x)
71610 + if (s->obj_hash == NULL)
71611 + break;
71612 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71613 + kfree(s->obj_hash);
71614 + else
71615 + vfree(s->obj_hash);
71616 + FOR_EACH_SUBJECT_END(s, x)
71617 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71618 + if (s->obj_hash == NULL)
71619 + break;
71620 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71621 + kfree(s->obj_hash);
71622 + else
71623 + vfree(s->obj_hash);
71624 + FOR_EACH_NESTED_SUBJECT_END(s)
71625 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71626 + kfree(r->subj_hash);
71627 + else
71628 + vfree(r->subj_hash);
71629 + r->subj_hash = NULL;
71630 +next_role:
71631 + FOR_EACH_ROLE_END(r)
71632 +
71633 + acl_free_all();
71634 +
71635 + if (polstate->acl_role_set.r_hash) {
71636 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71637 + PAGE_SIZE)
71638 + kfree(polstate->acl_role_set.r_hash);
71639 + else
71640 + vfree(polstate->acl_role_set.r_hash);
71641 + }
71642 + if (polstate->name_set.n_hash) {
71643 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71644 + PAGE_SIZE)
71645 + kfree(polstate->name_set.n_hash);
71646 + else
71647 + vfree(polstate->name_set.n_hash);
71648 + }
71649 +
71650 + if (polstate->inodev_set.i_hash) {
71651 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71652 + PAGE_SIZE)
71653 + kfree(polstate->inodev_set.i_hash);
71654 + else
71655 + vfree(polstate->inodev_set.i_hash);
71656 + }
71657 +
71658 + if (!reload)
71659 + gr_free_uidset();
71660 +
71661 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71662 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71663 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71664 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71665 +
71666 + polstate->default_role = NULL;
71667 + polstate->kernel_role = NULL;
71668 + polstate->role_list = NULL;
71669 +
71670 + return;
71671 +}
71672 +
71673 +static struct acl_subject_label *
71674 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71675 +
71676 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71677 +{
71678 + unsigned int len = strnlen_user(*name, maxlen);
71679 + char *tmp;
71680 +
71681 + if (!len || len >= maxlen)
71682 + return -EINVAL;
71683 +
71684 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71685 + return -ENOMEM;
71686 +
71687 + if (copy_from_user(tmp, *name, len))
71688 + return -EFAULT;
71689 +
71690 + tmp[len-1] = '\0';
71691 + *name = tmp;
71692 +
71693 + return 0;
71694 +}
71695 +
71696 +static int
71697 +copy_user_glob(struct acl_object_label *obj)
71698 +{
71699 + struct acl_object_label *g_tmp, **guser;
71700 + int error;
71701 +
71702 + if (obj->globbed == NULL)
71703 + return 0;
71704 +
71705 + guser = &obj->globbed;
71706 + while (*guser) {
71707 + g_tmp = (struct acl_object_label *)
71708 + acl_alloc(sizeof (struct acl_object_label));
71709 + if (g_tmp == NULL)
71710 + return -ENOMEM;
71711 +
71712 + if (copy_acl_object_label(g_tmp, *guser))
71713 + return -EFAULT;
71714 +
71715 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71716 + if (error)
71717 + return error;
71718 +
71719 + *guser = g_tmp;
71720 + guser = &(g_tmp->next);
71721 + }
71722 +
71723 + return 0;
71724 +}
71725 +
71726 +static int
71727 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71728 + struct acl_role_label *role)
71729 +{
71730 + struct acl_object_label *o_tmp;
71731 + int ret;
71732 +
71733 + while (userp) {
71734 + if ((o_tmp = (struct acl_object_label *)
71735 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71736 + return -ENOMEM;
71737 +
71738 + if (copy_acl_object_label(o_tmp, userp))
71739 + return -EFAULT;
71740 +
71741 + userp = o_tmp->prev;
71742 +
71743 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71744 + if (ret)
71745 + return ret;
71746 +
71747 + insert_acl_obj_label(o_tmp, subj);
71748 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71749 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71750 + return -ENOMEM;
71751 +
71752 + ret = copy_user_glob(o_tmp);
71753 + if (ret)
71754 + return ret;
71755 +
71756 + if (o_tmp->nested) {
71757 + int already_copied;
71758 +
71759 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71760 + if (IS_ERR(o_tmp->nested))
71761 + return PTR_ERR(o_tmp->nested);
71762 +
71763 + /* insert into nested subject list if we haven't copied this one yet
71764 + to prevent duplicate entries */
71765 + if (!already_copied) {
71766 + o_tmp->nested->next = role->hash->first;
71767 + role->hash->first = o_tmp->nested;
71768 + }
71769 + }
71770 + }
71771 +
71772 + return 0;
71773 +}
71774 +
71775 +static __u32
71776 +count_user_subjs(struct acl_subject_label *userp)
71777 +{
71778 + struct acl_subject_label s_tmp;
71779 + __u32 num = 0;
71780 +
71781 + while (userp) {
71782 + if (copy_acl_subject_label(&s_tmp, userp))
71783 + break;
71784 +
71785 + userp = s_tmp.prev;
71786 + }
71787 +
71788 + return num;
71789 +}
71790 +
71791 +static int
71792 +copy_user_allowedips(struct acl_role_label *rolep)
71793 +{
71794 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71795 +
71796 + ruserip = rolep->allowed_ips;
71797 +
71798 + while (ruserip) {
71799 + rlast = rtmp;
71800 +
71801 + if ((rtmp = (struct role_allowed_ip *)
71802 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71803 + return -ENOMEM;
71804 +
71805 + if (copy_role_allowed_ip(rtmp, ruserip))
71806 + return -EFAULT;
71807 +
71808 + ruserip = rtmp->prev;
71809 +
71810 + if (!rlast) {
71811 + rtmp->prev = NULL;
71812 + rolep->allowed_ips = rtmp;
71813 + } else {
71814 + rlast->next = rtmp;
71815 + rtmp->prev = rlast;
71816 + }
71817 +
71818 + if (!ruserip)
71819 + rtmp->next = NULL;
71820 + }
71821 +
71822 + return 0;
71823 +}
71824 +
71825 +static int
71826 +copy_user_transitions(struct acl_role_label *rolep)
71827 +{
71828 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71829 + int error;
71830 +
71831 + rusertp = rolep->transitions;
71832 +
71833 + while (rusertp) {
71834 + rlast = rtmp;
71835 +
71836 + if ((rtmp = (struct role_transition *)
71837 + acl_alloc(sizeof (struct role_transition))) == NULL)
71838 + return -ENOMEM;
71839 +
71840 + if (copy_role_transition(rtmp, rusertp))
71841 + return -EFAULT;
71842 +
71843 + rusertp = rtmp->prev;
71844 +
71845 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71846 + if (error)
71847 + return error;
71848 +
71849 + if (!rlast) {
71850 + rtmp->prev = NULL;
71851 + rolep->transitions = rtmp;
71852 + } else {
71853 + rlast->next = rtmp;
71854 + rtmp->prev = rlast;
71855 + }
71856 +
71857 + if (!rusertp)
71858 + rtmp->next = NULL;
71859 + }
71860 +
71861 + return 0;
71862 +}
71863 +
71864 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71865 +{
71866 + struct acl_object_label o_tmp;
71867 + __u32 num = 0;
71868 +
71869 + while (userp) {
71870 + if (copy_acl_object_label(&o_tmp, userp))
71871 + break;
71872 +
71873 + userp = o_tmp.prev;
71874 + num++;
71875 + }
71876 +
71877 + return num;
71878 +}
71879 +
71880 +static struct acl_subject_label *
71881 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71882 +{
71883 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71884 + __u32 num_objs;
71885 + struct acl_ip_label **i_tmp, *i_utmp2;
71886 + struct gr_hash_struct ghash;
71887 + struct subject_map *subjmap;
71888 + unsigned int i_num;
71889 + int err;
71890 +
71891 + if (already_copied != NULL)
71892 + *already_copied = 0;
71893 +
71894 + s_tmp = lookup_subject_map(userp);
71895 +
71896 + /* we've already copied this subject into the kernel, just return
71897 + the reference to it, and don't copy it over again
71898 + */
71899 + if (s_tmp) {
71900 + if (already_copied != NULL)
71901 + *already_copied = 1;
71902 + return(s_tmp);
71903 + }
71904 +
71905 + if ((s_tmp = (struct acl_subject_label *)
71906 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71907 + return ERR_PTR(-ENOMEM);
71908 +
71909 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71910 + if (subjmap == NULL)
71911 + return ERR_PTR(-ENOMEM);
71912 +
71913 + subjmap->user = userp;
71914 + subjmap->kernel = s_tmp;
71915 + insert_subj_map_entry(subjmap);
71916 +
71917 + if (copy_acl_subject_label(s_tmp, userp))
71918 + return ERR_PTR(-EFAULT);
71919 +
71920 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71921 + if (err)
71922 + return ERR_PTR(err);
71923 +
71924 + if (!strcmp(s_tmp->filename, "/"))
71925 + role->root_label = s_tmp;
71926 +
71927 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71928 + return ERR_PTR(-EFAULT);
71929 +
71930 + /* copy user and group transition tables */
71931 +
71932 + if (s_tmp->user_trans_num) {
71933 + uid_t *uidlist;
71934 +
71935 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71936 + if (uidlist == NULL)
71937 + return ERR_PTR(-ENOMEM);
71938 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71939 + return ERR_PTR(-EFAULT);
71940 +
71941 + s_tmp->user_transitions = uidlist;
71942 + }
71943 +
71944 + if (s_tmp->group_trans_num) {
71945 + gid_t *gidlist;
71946 +
71947 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71948 + if (gidlist == NULL)
71949 + return ERR_PTR(-ENOMEM);
71950 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71951 + return ERR_PTR(-EFAULT);
71952 +
71953 + s_tmp->group_transitions = gidlist;
71954 + }
71955 +
71956 + /* set up object hash table */
71957 + num_objs = count_user_objs(ghash.first);
71958 +
71959 + s_tmp->obj_hash_size = num_objs;
71960 + s_tmp->obj_hash =
71961 + (struct acl_object_label **)
71962 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71963 +
71964 + if (!s_tmp->obj_hash)
71965 + return ERR_PTR(-ENOMEM);
71966 +
71967 + memset(s_tmp->obj_hash, 0,
71968 + s_tmp->obj_hash_size *
71969 + sizeof (struct acl_object_label *));
71970 +
71971 + /* add in objects */
71972 + err = copy_user_objs(ghash.first, s_tmp, role);
71973 +
71974 + if (err)
71975 + return ERR_PTR(err);
71976 +
71977 + /* set pointer for parent subject */
71978 + if (s_tmp->parent_subject) {
71979 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71980 +
71981 + if (IS_ERR(s_tmp2))
71982 + return s_tmp2;
71983 +
71984 + s_tmp->parent_subject = s_tmp2;
71985 + }
71986 +
71987 + /* add in ip acls */
71988 +
71989 + if (!s_tmp->ip_num) {
71990 + s_tmp->ips = NULL;
71991 + goto insert;
71992 + }
71993 +
71994 + i_tmp =
71995 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71996 + sizeof (struct acl_ip_label *));
71997 +
71998 + if (!i_tmp)
71999 + return ERR_PTR(-ENOMEM);
72000 +
72001 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72002 + *(i_tmp + i_num) =
72003 + (struct acl_ip_label *)
72004 + acl_alloc(sizeof (struct acl_ip_label));
72005 + if (!*(i_tmp + i_num))
72006 + return ERR_PTR(-ENOMEM);
72007 +
72008 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72009 + return ERR_PTR(-EFAULT);
72010 +
72011 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72012 + return ERR_PTR(-EFAULT);
72013 +
72014 + if ((*(i_tmp + i_num))->iface == NULL)
72015 + continue;
72016 +
72017 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72018 + if (err)
72019 + return ERR_PTR(err);
72020 + }
72021 +
72022 + s_tmp->ips = i_tmp;
72023 +
72024 +insert:
72025 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72026 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72027 + return ERR_PTR(-ENOMEM);
72028 +
72029 + return s_tmp;
72030 +}
72031 +
72032 +static int
72033 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72034 +{
72035 + struct acl_subject_label s_pre;
72036 + struct acl_subject_label * ret;
72037 + int err;
72038 +
72039 + while (userp) {
72040 + if (copy_acl_subject_label(&s_pre, userp))
72041 + return -EFAULT;
72042 +
72043 + ret = do_copy_user_subj(userp, role, NULL);
72044 +
72045 + err = PTR_ERR(ret);
72046 + if (IS_ERR(ret))
72047 + return err;
72048 +
72049 + insert_acl_subj_label(ret, role);
72050 +
72051 + userp = s_pre.prev;
72052 + }
72053 +
72054 + return 0;
72055 +}
72056 +
72057 +static int
72058 +copy_user_acl(struct gr_arg *arg)
72059 +{
72060 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72061 + struct acl_subject_label *subj_list;
72062 + struct sprole_pw *sptmp;
72063 + struct gr_hash_struct *ghash;
72064 + uid_t *domainlist;
72065 + unsigned int r_num;
72066 + int err = 0;
72067 + __u16 i;
72068 + __u32 num_subjs;
72069 +
72070 + /* we need a default and kernel role */
72071 + if (arg->role_db.num_roles < 2)
72072 + return -EINVAL;
72073 +
72074 + /* copy special role authentication info from userspace */
72075 +
72076 + polstate->num_sprole_pws = arg->num_sprole_pws;
72077 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72078 +
72079 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72080 + return -ENOMEM;
72081 +
72082 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72083 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72084 + if (!sptmp)
72085 + return -ENOMEM;
72086 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72087 + return -EFAULT;
72088 +
72089 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72090 + if (err)
72091 + return err;
72092 +
72093 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72094 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72095 +#endif
72096 +
72097 + polstate->acl_special_roles[i] = sptmp;
72098 + }
72099 +
72100 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72101 +
72102 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72103 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72104 +
72105 + if (!r_tmp)
72106 + return -ENOMEM;
72107 +
72108 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72109 + return -EFAULT;
72110 +
72111 + if (copy_acl_role_label(r_tmp, r_utmp2))
72112 + return -EFAULT;
72113 +
72114 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72115 + if (err)
72116 + return err;
72117 +
72118 + if (!strcmp(r_tmp->rolename, "default")
72119 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72120 + polstate->default_role = r_tmp;
72121 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72122 + polstate->kernel_role = r_tmp;
72123 + }
72124 +
72125 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72126 + return -ENOMEM;
72127 +
72128 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72129 + return -EFAULT;
72130 +
72131 + r_tmp->hash = ghash;
72132 +
72133 + num_subjs = count_user_subjs(r_tmp->hash->first);
72134 +
72135 + r_tmp->subj_hash_size = num_subjs;
72136 + r_tmp->subj_hash =
72137 + (struct acl_subject_label **)
72138 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72139 +
72140 + if (!r_tmp->subj_hash)
72141 + return -ENOMEM;
72142 +
72143 + err = copy_user_allowedips(r_tmp);
72144 + if (err)
72145 + return err;
72146 +
72147 + /* copy domain info */
72148 + if (r_tmp->domain_children != NULL) {
72149 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72150 + if (domainlist == NULL)
72151 + return -ENOMEM;
72152 +
72153 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72154 + return -EFAULT;
72155 +
72156 + r_tmp->domain_children = domainlist;
72157 + }
72158 +
72159 + err = copy_user_transitions(r_tmp);
72160 + if (err)
72161 + return err;
72162 +
72163 + memset(r_tmp->subj_hash, 0,
72164 + r_tmp->subj_hash_size *
72165 + sizeof (struct acl_subject_label *));
72166 +
72167 + /* acquire the list of subjects, then NULL out
72168 + the list prior to parsing the subjects for this role,
72169 + as during this parsing the list is replaced with a list
72170 + of *nested* subjects for the role
72171 + */
72172 + subj_list = r_tmp->hash->first;
72173 +
72174 + /* set nested subject list to null */
72175 + r_tmp->hash->first = NULL;
72176 +
72177 + err = copy_user_subjs(subj_list, r_tmp);
72178 +
72179 + if (err)
72180 + return err;
72181 +
72182 + insert_acl_role_label(r_tmp);
72183 + }
72184 +
72185 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72186 + return -EINVAL;
72187 +
72188 + return err;
72189 +}
72190 +
72191 +static int gracl_reload_apply_policies(void *reload)
72192 +{
72193 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72194 + struct task_struct *task, *task2;
72195 + struct acl_role_label *role, *rtmp;
72196 + struct acl_subject_label *subj;
72197 + const struct cred *cred;
72198 + int role_applied;
72199 + int ret = 0;
72200 +
72201 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72202 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72203 +
72204 + /* first make sure we'll be able to apply the new policy cleanly */
72205 + do_each_thread(task2, task) {
72206 + if (task->exec_file == NULL)
72207 + continue;
72208 + role_applied = 0;
72209 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72210 + /* preserve special roles */
72211 + FOR_EACH_ROLE_START(role)
72212 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72213 + rtmp = task->role;
72214 + task->role = role;
72215 + role_applied = 1;
72216 + break;
72217 + }
72218 + FOR_EACH_ROLE_END(role)
72219 + }
72220 + if (!role_applied) {
72221 + cred = __task_cred(task);
72222 + rtmp = task->role;
72223 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72224 + }
72225 + /* this handles non-nested inherited subjects, nested subjects will still
72226 + be dropped currently */
72227 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72228 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72229 + /* change the role back so that we've made no modifications to the policy */
72230 + task->role = rtmp;
72231 +
72232 + if (subj == NULL || task->tmpacl == NULL) {
72233 + ret = -EINVAL;
72234 + goto out;
72235 + }
72236 + } while_each_thread(task2, task);
72237 +
72238 + /* now actually apply the policy */
72239 +
72240 + do_each_thread(task2, task) {
72241 + if (task->exec_file) {
72242 + role_applied = 0;
72243 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72244 + /* preserve special roles */
72245 + FOR_EACH_ROLE_START(role)
72246 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72247 + task->role = role;
72248 + role_applied = 1;
72249 + break;
72250 + }
72251 + FOR_EACH_ROLE_END(role)
72252 + }
72253 + if (!role_applied) {
72254 + cred = __task_cred(task);
72255 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72256 + }
72257 + /* this handles non-nested inherited subjects, nested subjects will still
72258 + be dropped currently */
72259 + if (!reload_state->oldmode && task->inherited)
72260 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72261 + else {
72262 + /* looked up and tagged to the task previously */
72263 + subj = task->tmpacl;
72264 + }
72265 + /* subj will be non-null */
72266 + __gr_apply_subject_to_task(polstate, task, subj);
72267 + if (reload_state->oldmode) {
72268 + task->acl_role_id = 0;
72269 + task->acl_sp_role = 0;
72270 + task->inherited = 0;
72271 + }
72272 + } else {
72273 + // it's a kernel process
72274 + task->role = polstate->kernel_role;
72275 + task->acl = polstate->kernel_role->root_label;
72276 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72277 + task->acl->mode &= ~GR_PROCFIND;
72278 +#endif
72279 + }
72280 + } while_each_thread(task2, task);
72281 +
72282 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72283 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72284 +
72285 +out:
72286 +
72287 + return ret;
72288 +}
72289 +
72290 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72291 +{
72292 + struct gr_reload_state new_reload_state = { };
72293 + int err;
72294 +
72295 + new_reload_state.oldpolicy_ptr = polstate;
72296 + new_reload_state.oldalloc_ptr = current_alloc_state;
72297 + new_reload_state.oldmode = oldmode;
72298 +
72299 + current_alloc_state = &new_reload_state.newalloc;
72300 + polstate = &new_reload_state.newpolicy;
72301 +
72302 + /* everything relevant is now saved off, copy in the new policy */
72303 + if (init_variables(args, true)) {
72304 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72305 + err = -ENOMEM;
72306 + goto error;
72307 + }
72308 +
72309 + err = copy_user_acl(args);
72310 + free_init_variables();
72311 + if (err)
72312 + goto error;
72313 + /* the new policy is copied in, with the old policy available via saved_state
72314 + first go through applying roles, making sure to preserve special roles
72315 + then apply new subjects, making sure to preserve inherited and nested subjects,
72316 + though currently only inherited subjects will be preserved
72317 + */
72318 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72319 + if (err)
72320 + goto error;
72321 +
72322 + /* we've now applied the new policy, so restore the old policy state to free it */
72323 + polstate = &new_reload_state.oldpolicy;
72324 + current_alloc_state = &new_reload_state.oldalloc;
72325 + free_variables(true);
72326 +
72327 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72328 + to running_polstate/current_alloc_state inside stop_machine
72329 + */
72330 + err = 0;
72331 + goto out;
72332 +error:
72333 + /* on error of loading the new policy, we'll just keep the previous
72334 + policy set around
72335 + */
72336 + free_variables(true);
72337 +
72338 + /* doesn't affect runtime, but maintains consistent state */
72339 +out:
72340 + polstate = new_reload_state.oldpolicy_ptr;
72341 + current_alloc_state = new_reload_state.oldalloc_ptr;
72342 +
72343 + return err;
72344 +}
72345 +
72346 +static int
72347 +gracl_init(struct gr_arg *args)
72348 +{
72349 + int error = 0;
72350 +
72351 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72352 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72353 +
72354 + if (init_variables(args, false)) {
72355 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72356 + error = -ENOMEM;
72357 + goto out;
72358 + }
72359 +
72360 + error = copy_user_acl(args);
72361 + free_init_variables();
72362 + if (error)
72363 + goto out;
72364 +
72365 + error = gr_set_acls(0);
72366 + if (error)
72367 + goto out;
72368 +
72369 + gr_enable_rbac_system();
72370 +
72371 + return 0;
72372 +
72373 +out:
72374 + free_variables(false);
72375 + return error;
72376 +}
72377 +
72378 +static int
72379 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72380 + unsigned char **sum)
72381 +{
72382 + struct acl_role_label *r;
72383 + struct role_allowed_ip *ipp;
72384 + struct role_transition *trans;
72385 + unsigned int i;
72386 + int found = 0;
72387 + u32 curr_ip = current->signal->curr_ip;
72388 +
72389 + current->signal->saved_ip = curr_ip;
72390 +
72391 + /* check transition table */
72392 +
72393 + for (trans = current->role->transitions; trans; trans = trans->next) {
72394 + if (!strcmp(rolename, trans->rolename)) {
72395 + found = 1;
72396 + break;
72397 + }
72398 + }
72399 +
72400 + if (!found)
72401 + return 0;
72402 +
72403 + /* handle special roles that do not require authentication
72404 + and check ip */
72405 +
72406 + FOR_EACH_ROLE_START(r)
72407 + if (!strcmp(rolename, r->rolename) &&
72408 + (r->roletype & GR_ROLE_SPECIAL)) {
72409 + found = 0;
72410 + if (r->allowed_ips != NULL) {
72411 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72412 + if ((ntohl(curr_ip) & ipp->netmask) ==
72413 + (ntohl(ipp->addr) & ipp->netmask))
72414 + found = 1;
72415 + }
72416 + } else
72417 + found = 2;
72418 + if (!found)
72419 + return 0;
72420 +
72421 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72422 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72423 + *salt = NULL;
72424 + *sum = NULL;
72425 + return 1;
72426 + }
72427 + }
72428 + FOR_EACH_ROLE_END(r)
72429 +
72430 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72431 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72432 + *salt = polstate->acl_special_roles[i]->salt;
72433 + *sum = polstate->acl_special_roles[i]->sum;
72434 + return 1;
72435 + }
72436 + }
72437 +
72438 + return 0;
72439 +}
72440 +
72441 +int gr_check_secure_terminal(struct task_struct *task)
72442 +{
72443 + struct task_struct *p, *p2, *p3;
72444 + struct files_struct *files;
72445 + struct fdtable *fdt;
72446 + struct file *our_file = NULL, *file;
72447 + int i;
72448 +
72449 + if (task->signal->tty == NULL)
72450 + return 1;
72451 +
72452 + files = get_files_struct(task);
72453 + if (files != NULL) {
72454 + rcu_read_lock();
72455 + fdt = files_fdtable(files);
72456 + for (i=0; i < fdt->max_fds; i++) {
72457 + file = fcheck_files(files, i);
72458 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72459 + get_file(file);
72460 + our_file = file;
72461 + }
72462 + }
72463 + rcu_read_unlock();
72464 + put_files_struct(files);
72465 + }
72466 +
72467 + if (our_file == NULL)
72468 + return 1;
72469 +
72470 + read_lock(&tasklist_lock);
72471 + do_each_thread(p2, p) {
72472 + files = get_files_struct(p);
72473 + if (files == NULL ||
72474 + (p->signal && p->signal->tty == task->signal->tty)) {
72475 + if (files != NULL)
72476 + put_files_struct(files);
72477 + continue;
72478 + }
72479 + rcu_read_lock();
72480 + fdt = files_fdtable(files);
72481 + for (i=0; i < fdt->max_fds; i++) {
72482 + file = fcheck_files(files, i);
72483 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72484 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72485 + p3 = task;
72486 + while (task_pid_nr(p3) > 0) {
72487 + if (p3 == p)
72488 + break;
72489 + p3 = p3->real_parent;
72490 + }
72491 + if (p3 == p)
72492 + break;
72493 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72494 + gr_handle_alertkill(p);
72495 + rcu_read_unlock();
72496 + put_files_struct(files);
72497 + read_unlock(&tasklist_lock);
72498 + fput(our_file);
72499 + return 0;
72500 + }
72501 + }
72502 + rcu_read_unlock();
72503 + put_files_struct(files);
72504 + } while_each_thread(p2, p);
72505 + read_unlock(&tasklist_lock);
72506 +
72507 + fput(our_file);
72508 + return 1;
72509 +}
72510 +
72511 +ssize_t
72512 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72513 +{
72514 + struct gr_arg_wrapper uwrap;
72515 + unsigned char *sprole_salt = NULL;
72516 + unsigned char *sprole_sum = NULL;
72517 + int error = 0;
72518 + int error2 = 0;
72519 + size_t req_count = 0;
72520 + unsigned char oldmode = 0;
72521 +
72522 + mutex_lock(&gr_dev_mutex);
72523 +
72524 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72525 + error = -EPERM;
72526 + goto out;
72527 + }
72528 +
72529 +#ifdef CONFIG_COMPAT
72530 + pax_open_kernel();
72531 + if (is_compat_task()) {
72532 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72533 + copy_gr_arg = &copy_gr_arg_compat;
72534 + copy_acl_object_label = &copy_acl_object_label_compat;
72535 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72536 + copy_acl_role_label = &copy_acl_role_label_compat;
72537 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72538 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72539 + copy_role_transition = &copy_role_transition_compat;
72540 + copy_sprole_pw = &copy_sprole_pw_compat;
72541 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72542 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72543 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72544 + } else {
72545 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72546 + copy_gr_arg = &copy_gr_arg_normal;
72547 + copy_acl_object_label = &copy_acl_object_label_normal;
72548 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72549 + copy_acl_role_label = &copy_acl_role_label_normal;
72550 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72551 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72552 + copy_role_transition = &copy_role_transition_normal;
72553 + copy_sprole_pw = &copy_sprole_pw_normal;
72554 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72555 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72556 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72557 + }
72558 + pax_close_kernel();
72559 +#endif
72560 +
72561 + req_count = get_gr_arg_wrapper_size();
72562 +
72563 + if (count != req_count) {
72564 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72565 + error = -EINVAL;
72566 + goto out;
72567 + }
72568 +
72569 +
72570 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72571 + gr_auth_expires = 0;
72572 + gr_auth_attempts = 0;
72573 + }
72574 +
72575 + error = copy_gr_arg_wrapper(buf, &uwrap);
72576 + if (error)
72577 + goto out;
72578 +
72579 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72580 + if (error)
72581 + goto out;
72582 +
72583 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72584 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72585 + time_after(gr_auth_expires, get_seconds())) {
72586 + error = -EBUSY;
72587 + goto out;
72588 + }
72589 +
72590 + /* if non-root trying to do anything other than use a special role,
72591 + do not attempt authentication, do not count towards authentication
72592 + locking
72593 + */
72594 +
72595 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72596 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72597 + gr_is_global_nonroot(current_uid())) {
72598 + error = -EPERM;
72599 + goto out;
72600 + }
72601 +
72602 + /* ensure pw and special role name are null terminated */
72603 +
72604 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72605 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72606 +
72607 + /* Okay.
72608 + * We have our enough of the argument structure..(we have yet
72609 + * to copy_from_user the tables themselves) . Copy the tables
72610 + * only if we need them, i.e. for loading operations. */
72611 +
72612 + switch (gr_usermode.mode) {
72613 + case GR_STATUS:
72614 + if (gr_acl_is_enabled()) {
72615 + error = 1;
72616 + if (!gr_check_secure_terminal(current))
72617 + error = 3;
72618 + } else
72619 + error = 2;
72620 + goto out;
72621 + case GR_SHUTDOWN:
72622 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72623 + stop_machine(gr_rbac_disable, NULL, NULL);
72624 + free_variables(false);
72625 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72626 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72627 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72628 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72629 + } else if (gr_acl_is_enabled()) {
72630 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72631 + error = -EPERM;
72632 + } else {
72633 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72634 + error = -EAGAIN;
72635 + }
72636 + break;
72637 + case GR_ENABLE:
72638 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72639 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72640 + else {
72641 + if (gr_acl_is_enabled())
72642 + error = -EAGAIN;
72643 + else
72644 + error = error2;
72645 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72646 + }
72647 + break;
72648 + case GR_OLDRELOAD:
72649 + oldmode = 1;
72650 + case GR_RELOAD:
72651 + if (!gr_acl_is_enabled()) {
72652 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72653 + error = -EAGAIN;
72654 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72655 + error2 = gracl_reload(&gr_usermode, oldmode);
72656 + if (!error2)
72657 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72658 + else {
72659 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72660 + error = error2;
72661 + }
72662 + } else {
72663 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72664 + error = -EPERM;
72665 + }
72666 + break;
72667 + case GR_SEGVMOD:
72668 + if (unlikely(!gr_acl_is_enabled())) {
72669 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72670 + error = -EAGAIN;
72671 + break;
72672 + }
72673 +
72674 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72675 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72676 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72677 + struct acl_subject_label *segvacl;
72678 + segvacl =
72679 + lookup_acl_subj_label(gr_usermode.segv_inode,
72680 + gr_usermode.segv_device,
72681 + current->role);
72682 + if (segvacl) {
72683 + segvacl->crashes = 0;
72684 + segvacl->expires = 0;
72685 + }
72686 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72687 + gr_remove_uid(gr_usermode.segv_uid);
72688 + }
72689 + } else {
72690 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72691 + error = -EPERM;
72692 + }
72693 + break;
72694 + case GR_SPROLE:
72695 + case GR_SPROLEPAM:
72696 + if (unlikely(!gr_acl_is_enabled())) {
72697 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72698 + error = -EAGAIN;
72699 + break;
72700 + }
72701 +
72702 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72703 + current->role->expires = 0;
72704 + current->role->auth_attempts = 0;
72705 + }
72706 +
72707 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72708 + time_after(current->role->expires, get_seconds())) {
72709 + error = -EBUSY;
72710 + goto out;
72711 + }
72712 +
72713 + if (lookup_special_role_auth
72714 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72715 + && ((!sprole_salt && !sprole_sum)
72716 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72717 + char *p = "";
72718 + assign_special_role(gr_usermode.sp_role);
72719 + read_lock(&tasklist_lock);
72720 + if (current->real_parent)
72721 + p = current->real_parent->role->rolename;
72722 + read_unlock(&tasklist_lock);
72723 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72724 + p, acl_sp_role_value);
72725 + } else {
72726 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72727 + error = -EPERM;
72728 + if(!(current->role->auth_attempts++))
72729 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72730 +
72731 + goto out;
72732 + }
72733 + break;
72734 + case GR_UNSPROLE:
72735 + if (unlikely(!gr_acl_is_enabled())) {
72736 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72737 + error = -EAGAIN;
72738 + break;
72739 + }
72740 +
72741 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72742 + char *p = "";
72743 + int i = 0;
72744 +
72745 + read_lock(&tasklist_lock);
72746 + if (current->real_parent) {
72747 + p = current->real_parent->role->rolename;
72748 + i = current->real_parent->acl_role_id;
72749 + }
72750 + read_unlock(&tasklist_lock);
72751 +
72752 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72753 + gr_set_acls(1);
72754 + } else {
72755 + error = -EPERM;
72756 + goto out;
72757 + }
72758 + break;
72759 + default:
72760 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72761 + error = -EINVAL;
72762 + break;
72763 + }
72764 +
72765 + if (error != -EPERM)
72766 + goto out;
72767 +
72768 + if(!(gr_auth_attempts++))
72769 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72770 +
72771 + out:
72772 + mutex_unlock(&gr_dev_mutex);
72773 +
72774 + if (!error)
72775 + error = req_count;
72776 +
72777 + return error;
72778 +}
72779 +
72780 +int
72781 +gr_set_acls(const int type)
72782 +{
72783 + struct task_struct *task, *task2;
72784 + struct acl_role_label *role = current->role;
72785 + struct acl_subject_label *subj;
72786 + __u16 acl_role_id = current->acl_role_id;
72787 + const struct cred *cred;
72788 + int ret;
72789 +
72790 + rcu_read_lock();
72791 + read_lock(&tasklist_lock);
72792 + read_lock(&grsec_exec_file_lock);
72793 + do_each_thread(task2, task) {
72794 + /* check to see if we're called from the exit handler,
72795 + if so, only replace ACLs that have inherited the admin
72796 + ACL */
72797 +
72798 + if (type && (task->role != role ||
72799 + task->acl_role_id != acl_role_id))
72800 + continue;
72801 +
72802 + task->acl_role_id = 0;
72803 + task->acl_sp_role = 0;
72804 + task->inherited = 0;
72805 +
72806 + if (task->exec_file) {
72807 + cred = __task_cred(task);
72808 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72809 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72810 + if (subj == NULL) {
72811 + ret = -EINVAL;
72812 + read_unlock(&grsec_exec_file_lock);
72813 + read_unlock(&tasklist_lock);
72814 + rcu_read_unlock();
72815 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72816 + return ret;
72817 + }
72818 + __gr_apply_subject_to_task(polstate, task, subj);
72819 + } else {
72820 + // it's a kernel process
72821 + task->role = polstate->kernel_role;
72822 + task->acl = polstate->kernel_role->root_label;
72823 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72824 + task->acl->mode &= ~GR_PROCFIND;
72825 +#endif
72826 + }
72827 + } while_each_thread(task2, task);
72828 + read_unlock(&grsec_exec_file_lock);
72829 + read_unlock(&tasklist_lock);
72830 + rcu_read_unlock();
72831 +
72832 + return 0;
72833 +}
72834 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72835 new file mode 100644
72836 index 0000000..39645c9
72837 --- /dev/null
72838 +++ b/grsecurity/gracl_res.c
72839 @@ -0,0 +1,68 @@
72840 +#include <linux/kernel.h>
72841 +#include <linux/sched.h>
72842 +#include <linux/gracl.h>
72843 +#include <linux/grinternal.h>
72844 +
72845 +static const char *restab_log[] = {
72846 + [RLIMIT_CPU] = "RLIMIT_CPU",
72847 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72848 + [RLIMIT_DATA] = "RLIMIT_DATA",
72849 + [RLIMIT_STACK] = "RLIMIT_STACK",
72850 + [RLIMIT_CORE] = "RLIMIT_CORE",
72851 + [RLIMIT_RSS] = "RLIMIT_RSS",
72852 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72853 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72854 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72855 + [RLIMIT_AS] = "RLIMIT_AS",
72856 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72857 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72858 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72859 + [RLIMIT_NICE] = "RLIMIT_NICE",
72860 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72861 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72862 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72863 +};
72864 +
72865 +void
72866 +gr_log_resource(const struct task_struct *task,
72867 + const int res, const unsigned long wanted, const int gt)
72868 +{
72869 + const struct cred *cred;
72870 + unsigned long rlim;
72871 +
72872 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72873 + return;
72874 +
72875 + // not yet supported resource
72876 + if (unlikely(!restab_log[res]))
72877 + return;
72878 +
72879 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72880 + rlim = task_rlimit_max(task, res);
72881 + else
72882 + rlim = task_rlimit(task, res);
72883 +
72884 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72885 + return;
72886 +
72887 + rcu_read_lock();
72888 + cred = __task_cred(task);
72889 +
72890 + if (res == RLIMIT_NPROC &&
72891 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72892 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72893 + goto out_rcu_unlock;
72894 + else if (res == RLIMIT_MEMLOCK &&
72895 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72896 + goto out_rcu_unlock;
72897 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72898 + goto out_rcu_unlock;
72899 + rcu_read_unlock();
72900 +
72901 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72902 +
72903 + return;
72904 +out_rcu_unlock:
72905 + rcu_read_unlock();
72906 + return;
72907 +}
72908 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72909 new file mode 100644
72910 index 0000000..2040e61
72911 --- /dev/null
72912 +++ b/grsecurity/gracl_segv.c
72913 @@ -0,0 +1,313 @@
72914 +#include <linux/kernel.h>
72915 +#include <linux/mm.h>
72916 +#include <asm/uaccess.h>
72917 +#include <asm/errno.h>
72918 +#include <asm/mman.h>
72919 +#include <net/sock.h>
72920 +#include <linux/file.h>
72921 +#include <linux/fs.h>
72922 +#include <linux/net.h>
72923 +#include <linux/in.h>
72924 +#include <linux/slab.h>
72925 +#include <linux/types.h>
72926 +#include <linux/sched.h>
72927 +#include <linux/timer.h>
72928 +#include <linux/gracl.h>
72929 +#include <linux/grsecurity.h>
72930 +#include <linux/grinternal.h>
72931 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72932 +#include <linux/magic.h>
72933 +#include <linux/pagemap.h>
72934 +#include "../fs/btrfs/async-thread.h"
72935 +#include "../fs/btrfs/ctree.h"
72936 +#include "../fs/btrfs/btrfs_inode.h"
72937 +#endif
72938 +
72939 +static struct crash_uid *uid_set;
72940 +static unsigned short uid_used;
72941 +static DEFINE_SPINLOCK(gr_uid_lock);
72942 +extern rwlock_t gr_inode_lock;
72943 +extern struct acl_subject_label *
72944 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72945 + struct acl_role_label *role);
72946 +
72947 +static inline dev_t __get_dev(const struct dentry *dentry)
72948 +{
72949 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72950 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72951 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72952 + else
72953 +#endif
72954 + return dentry->d_sb->s_dev;
72955 +}
72956 +
72957 +int
72958 +gr_init_uidset(void)
72959 +{
72960 + uid_set =
72961 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72962 + uid_used = 0;
72963 +
72964 + return uid_set ? 1 : 0;
72965 +}
72966 +
72967 +void
72968 +gr_free_uidset(void)
72969 +{
72970 + if (uid_set) {
72971 + struct crash_uid *tmpset;
72972 + spin_lock(&gr_uid_lock);
72973 + tmpset = uid_set;
72974 + uid_set = NULL;
72975 + uid_used = 0;
72976 + spin_unlock(&gr_uid_lock);
72977 + if (tmpset)
72978 + kfree(tmpset);
72979 + }
72980 +
72981 + return;
72982 +}
72983 +
72984 +int
72985 +gr_find_uid(const uid_t uid)
72986 +{
72987 + struct crash_uid *tmp = uid_set;
72988 + uid_t buid;
72989 + int low = 0, high = uid_used - 1, mid;
72990 +
72991 + while (high >= low) {
72992 + mid = (low + high) >> 1;
72993 + buid = tmp[mid].uid;
72994 + if (buid == uid)
72995 + return mid;
72996 + if (buid > uid)
72997 + high = mid - 1;
72998 + if (buid < uid)
72999 + low = mid + 1;
73000 + }
73001 +
73002 + return -1;
73003 +}
73004 +
73005 +static __inline__ void
73006 +gr_insertsort(void)
73007 +{
73008 + unsigned short i, j;
73009 + struct crash_uid index;
73010 +
73011 + for (i = 1; i < uid_used; i++) {
73012 + index = uid_set[i];
73013 + j = i;
73014 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73015 + uid_set[j] = uid_set[j - 1];
73016 + j--;
73017 + }
73018 + uid_set[j] = index;
73019 + }
73020 +
73021 + return;
73022 +}
73023 +
73024 +static __inline__ void
73025 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73026 +{
73027 + int loc;
73028 + uid_t uid = GR_GLOBAL_UID(kuid);
73029 +
73030 + if (uid_used == GR_UIDTABLE_MAX)
73031 + return;
73032 +
73033 + loc = gr_find_uid(uid);
73034 +
73035 + if (loc >= 0) {
73036 + uid_set[loc].expires = expires;
73037 + return;
73038 + }
73039 +
73040 + uid_set[uid_used].uid = uid;
73041 + uid_set[uid_used].expires = expires;
73042 + uid_used++;
73043 +
73044 + gr_insertsort();
73045 +
73046 + return;
73047 +}
73048 +
73049 +void
73050 +gr_remove_uid(const unsigned short loc)
73051 +{
73052 + unsigned short i;
73053 +
73054 + for (i = loc + 1; i < uid_used; i++)
73055 + uid_set[i - 1] = uid_set[i];
73056 +
73057 + uid_used--;
73058 +
73059 + return;
73060 +}
73061 +
73062 +int
73063 +gr_check_crash_uid(const kuid_t kuid)
73064 +{
73065 + int loc;
73066 + int ret = 0;
73067 + uid_t uid;
73068 +
73069 + if (unlikely(!gr_acl_is_enabled()))
73070 + return 0;
73071 +
73072 + uid = GR_GLOBAL_UID(kuid);
73073 +
73074 + spin_lock(&gr_uid_lock);
73075 + loc = gr_find_uid(uid);
73076 +
73077 + if (loc < 0)
73078 + goto out_unlock;
73079 +
73080 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73081 + gr_remove_uid(loc);
73082 + else
73083 + ret = 1;
73084 +
73085 +out_unlock:
73086 + spin_unlock(&gr_uid_lock);
73087 + return ret;
73088 +}
73089 +
73090 +static __inline__ int
73091 +proc_is_setxid(const struct cred *cred)
73092 +{
73093 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73094 + !uid_eq(cred->uid, cred->fsuid))
73095 + return 1;
73096 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73097 + !gid_eq(cred->gid, cred->fsgid))
73098 + return 1;
73099 +
73100 + return 0;
73101 +}
73102 +
73103 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73104 +
73105 +void
73106 +gr_handle_crash(struct task_struct *task, const int sig)
73107 +{
73108 + struct acl_subject_label *curr;
73109 + struct task_struct *tsk, *tsk2;
73110 + const struct cred *cred;
73111 + const struct cred *cred2;
73112 +
73113 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73114 + return;
73115 +
73116 + if (unlikely(!gr_acl_is_enabled()))
73117 + return;
73118 +
73119 + curr = task->acl;
73120 +
73121 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73122 + return;
73123 +
73124 + if (time_before_eq(curr->expires, get_seconds())) {
73125 + curr->expires = 0;
73126 + curr->crashes = 0;
73127 + }
73128 +
73129 + curr->crashes++;
73130 +
73131 + if (!curr->expires)
73132 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73133 +
73134 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73135 + time_after(curr->expires, get_seconds())) {
73136 + rcu_read_lock();
73137 + cred = __task_cred(task);
73138 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73139 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73140 + spin_lock(&gr_uid_lock);
73141 + gr_insert_uid(cred->uid, curr->expires);
73142 + spin_unlock(&gr_uid_lock);
73143 + curr->expires = 0;
73144 + curr->crashes = 0;
73145 + read_lock(&tasklist_lock);
73146 + do_each_thread(tsk2, tsk) {
73147 + cred2 = __task_cred(tsk);
73148 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73149 + gr_fake_force_sig(SIGKILL, tsk);
73150 + } while_each_thread(tsk2, tsk);
73151 + read_unlock(&tasklist_lock);
73152 + } else {
73153 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73154 + read_lock(&tasklist_lock);
73155 + read_lock(&grsec_exec_file_lock);
73156 + do_each_thread(tsk2, tsk) {
73157 + if (likely(tsk != task)) {
73158 + // if this thread has the same subject as the one that triggered
73159 + // RES_CRASH and it's the same binary, kill it
73160 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73161 + gr_fake_force_sig(SIGKILL, tsk);
73162 + }
73163 + } while_each_thread(tsk2, tsk);
73164 + read_unlock(&grsec_exec_file_lock);
73165 + read_unlock(&tasklist_lock);
73166 + }
73167 + rcu_read_unlock();
73168 + }
73169 +
73170 + return;
73171 +}
73172 +
73173 +int
73174 +gr_check_crash_exec(const struct file *filp)
73175 +{
73176 + struct acl_subject_label *curr;
73177 +
73178 + if (unlikely(!gr_acl_is_enabled()))
73179 + return 0;
73180 +
73181 + read_lock(&gr_inode_lock);
73182 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73183 + __get_dev(filp->f_path.dentry),
73184 + current->role);
73185 + read_unlock(&gr_inode_lock);
73186 +
73187 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73188 + (!curr->crashes && !curr->expires))
73189 + return 0;
73190 +
73191 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73192 + time_after(curr->expires, get_seconds()))
73193 + return 1;
73194 + else if (time_before_eq(curr->expires, get_seconds())) {
73195 + curr->crashes = 0;
73196 + curr->expires = 0;
73197 + }
73198 +
73199 + return 0;
73200 +}
73201 +
73202 +void
73203 +gr_handle_alertkill(struct task_struct *task)
73204 +{
73205 + struct acl_subject_label *curracl;
73206 + __u32 curr_ip;
73207 + struct task_struct *p, *p2;
73208 +
73209 + if (unlikely(!gr_acl_is_enabled()))
73210 + return;
73211 +
73212 + curracl = task->acl;
73213 + curr_ip = task->signal->curr_ip;
73214 +
73215 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73216 + read_lock(&tasklist_lock);
73217 + do_each_thread(p2, p) {
73218 + if (p->signal->curr_ip == curr_ip)
73219 + gr_fake_force_sig(SIGKILL, p);
73220 + } while_each_thread(p2, p);
73221 + read_unlock(&tasklist_lock);
73222 + } else if (curracl->mode & GR_KILLPROC)
73223 + gr_fake_force_sig(SIGKILL, task);
73224 +
73225 + return;
73226 +}
73227 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73228 new file mode 100644
73229 index 0000000..98011b0
73230 --- /dev/null
73231 +++ b/grsecurity/gracl_shm.c
73232 @@ -0,0 +1,40 @@
73233 +#include <linux/kernel.h>
73234 +#include <linux/mm.h>
73235 +#include <linux/sched.h>
73236 +#include <linux/file.h>
73237 +#include <linux/ipc.h>
73238 +#include <linux/gracl.h>
73239 +#include <linux/grsecurity.h>
73240 +#include <linux/grinternal.h>
73241 +
73242 +int
73243 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73244 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73245 +{
73246 + struct task_struct *task;
73247 +
73248 + if (!gr_acl_is_enabled())
73249 + return 1;
73250 +
73251 + rcu_read_lock();
73252 + read_lock(&tasklist_lock);
73253 +
73254 + task = find_task_by_vpid(shm_cprid);
73255 +
73256 + if (unlikely(!task))
73257 + task = find_task_by_vpid(shm_lapid);
73258 +
73259 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73260 + (task_pid_nr(task) == shm_lapid)) &&
73261 + (task->acl->mode & GR_PROTSHM) &&
73262 + (task->acl != current->acl))) {
73263 + read_unlock(&tasklist_lock);
73264 + rcu_read_unlock();
73265 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73266 + return 0;
73267 + }
73268 + read_unlock(&tasklist_lock);
73269 + rcu_read_unlock();
73270 +
73271 + return 1;
73272 +}
73273 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73274 new file mode 100644
73275 index 0000000..bc0be01
73276 --- /dev/null
73277 +++ b/grsecurity/grsec_chdir.c
73278 @@ -0,0 +1,19 @@
73279 +#include <linux/kernel.h>
73280 +#include <linux/sched.h>
73281 +#include <linux/fs.h>
73282 +#include <linux/file.h>
73283 +#include <linux/grsecurity.h>
73284 +#include <linux/grinternal.h>
73285 +
73286 +void
73287 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73288 +{
73289 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73290 + if ((grsec_enable_chdir && grsec_enable_group &&
73291 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73292 + !grsec_enable_group)) {
73293 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73294 + }
73295 +#endif
73296 + return;
73297 +}
73298 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73299 new file mode 100644
73300 index 0000000..baa635c
73301 --- /dev/null
73302 +++ b/grsecurity/grsec_chroot.c
73303 @@ -0,0 +1,387 @@
73304 +#include <linux/kernel.h>
73305 +#include <linux/module.h>
73306 +#include <linux/sched.h>
73307 +#include <linux/file.h>
73308 +#include <linux/fs.h>
73309 +#include <linux/mount.h>
73310 +#include <linux/types.h>
73311 +#include "../fs/mount.h"
73312 +#include <linux/grsecurity.h>
73313 +#include <linux/grinternal.h>
73314 +
73315 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73316 +int gr_init_ran;
73317 +#endif
73318 +
73319 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73320 +{
73321 +#ifdef CONFIG_GRKERNSEC
73322 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73323 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73324 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73325 + && gr_init_ran
73326 +#endif
73327 + )
73328 + task->gr_is_chrooted = 1;
73329 + else {
73330 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73331 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73332 + gr_init_ran = 1;
73333 +#endif
73334 + task->gr_is_chrooted = 0;
73335 + }
73336 +
73337 + task->gr_chroot_dentry = path->dentry;
73338 +#endif
73339 + return;
73340 +}
73341 +
73342 +void gr_clear_chroot_entries(struct task_struct *task)
73343 +{
73344 +#ifdef CONFIG_GRKERNSEC
73345 + task->gr_is_chrooted = 0;
73346 + task->gr_chroot_dentry = NULL;
73347 +#endif
73348 + return;
73349 +}
73350 +
73351 +int
73352 +gr_handle_chroot_unix(const pid_t pid)
73353 +{
73354 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73355 + struct task_struct *p;
73356 +
73357 + if (unlikely(!grsec_enable_chroot_unix))
73358 + return 1;
73359 +
73360 + if (likely(!proc_is_chrooted(current)))
73361 + return 1;
73362 +
73363 + rcu_read_lock();
73364 + read_lock(&tasklist_lock);
73365 + p = find_task_by_vpid_unrestricted(pid);
73366 + if (unlikely(p && !have_same_root(current, p))) {
73367 + read_unlock(&tasklist_lock);
73368 + rcu_read_unlock();
73369 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73370 + return 0;
73371 + }
73372 + read_unlock(&tasklist_lock);
73373 + rcu_read_unlock();
73374 +#endif
73375 + return 1;
73376 +}
73377 +
73378 +int
73379 +gr_handle_chroot_nice(void)
73380 +{
73381 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73382 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73383 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73384 + return -EPERM;
73385 + }
73386 +#endif
73387 + return 0;
73388 +}
73389 +
73390 +int
73391 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73392 +{
73393 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73394 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73395 + && proc_is_chrooted(current)) {
73396 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73397 + return -EACCES;
73398 + }
73399 +#endif
73400 + return 0;
73401 +}
73402 +
73403 +int
73404 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73405 +{
73406 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73407 + struct task_struct *p;
73408 + int ret = 0;
73409 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73410 + return ret;
73411 +
73412 + read_lock(&tasklist_lock);
73413 + do_each_pid_task(pid, type, p) {
73414 + if (!have_same_root(current, p)) {
73415 + ret = 1;
73416 + goto out;
73417 + }
73418 + } while_each_pid_task(pid, type, p);
73419 +out:
73420 + read_unlock(&tasklist_lock);
73421 + return ret;
73422 +#endif
73423 + return 0;
73424 +}
73425 +
73426 +int
73427 +gr_pid_is_chrooted(struct task_struct *p)
73428 +{
73429 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73430 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73431 + return 0;
73432 +
73433 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73434 + !have_same_root(current, p)) {
73435 + return 1;
73436 + }
73437 +#endif
73438 + return 0;
73439 +}
73440 +
73441 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73442 +
73443 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73444 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73445 +{
73446 + struct path path, currentroot;
73447 + int ret = 0;
73448 +
73449 + path.dentry = (struct dentry *)u_dentry;
73450 + path.mnt = (struct vfsmount *)u_mnt;
73451 + get_fs_root(current->fs, &currentroot);
73452 + if (path_is_under(&path, &currentroot))
73453 + ret = 1;
73454 + path_put(&currentroot);
73455 +
73456 + return ret;
73457 +}
73458 +#endif
73459 +
73460 +int
73461 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73462 +{
73463 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73464 + if (!grsec_enable_chroot_fchdir)
73465 + return 1;
73466 +
73467 + if (!proc_is_chrooted(current))
73468 + return 1;
73469 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73470 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73471 + return 0;
73472 + }
73473 +#endif
73474 + return 1;
73475 +}
73476 +
73477 +int
73478 +gr_chroot_fhandle(void)
73479 +{
73480 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73481 + if (!grsec_enable_chroot_fchdir)
73482 + return 1;
73483 +
73484 + if (!proc_is_chrooted(current))
73485 + return 1;
73486 + else {
73487 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73488 + return 0;
73489 + }
73490 +#endif
73491 + return 1;
73492 +}
73493 +
73494 +int
73495 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73496 + const time_t shm_createtime)
73497 +{
73498 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73499 + struct task_struct *p;
73500 + time_t starttime;
73501 +
73502 + if (unlikely(!grsec_enable_chroot_shmat))
73503 + return 1;
73504 +
73505 + if (likely(!proc_is_chrooted(current)))
73506 + return 1;
73507 +
73508 + rcu_read_lock();
73509 + read_lock(&tasklist_lock);
73510 +
73511 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73512 + starttime = p->start_time.tv_sec;
73513 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73514 + if (have_same_root(current, p)) {
73515 + goto allow;
73516 + } else {
73517 + read_unlock(&tasklist_lock);
73518 + rcu_read_unlock();
73519 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73520 + return 0;
73521 + }
73522 + }
73523 + /* creator exited, pid reuse, fall through to next check */
73524 + }
73525 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73526 + if (unlikely(!have_same_root(current, p))) {
73527 + read_unlock(&tasklist_lock);
73528 + rcu_read_unlock();
73529 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73530 + return 0;
73531 + }
73532 + }
73533 +
73534 +allow:
73535 + read_unlock(&tasklist_lock);
73536 + rcu_read_unlock();
73537 +#endif
73538 + return 1;
73539 +}
73540 +
73541 +void
73542 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73543 +{
73544 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73545 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73546 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73547 +#endif
73548 + return;
73549 +}
73550 +
73551 +int
73552 +gr_handle_chroot_mknod(const struct dentry *dentry,
73553 + const struct vfsmount *mnt, const int mode)
73554 +{
73555 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73556 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73557 + proc_is_chrooted(current)) {
73558 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73559 + return -EPERM;
73560 + }
73561 +#endif
73562 + return 0;
73563 +}
73564 +
73565 +int
73566 +gr_handle_chroot_mount(const struct dentry *dentry,
73567 + const struct vfsmount *mnt, const char *dev_name)
73568 +{
73569 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73570 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73571 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73572 + return -EPERM;
73573 + }
73574 +#endif
73575 + return 0;
73576 +}
73577 +
73578 +int
73579 +gr_handle_chroot_pivot(void)
73580 +{
73581 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73582 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73583 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73584 + return -EPERM;
73585 + }
73586 +#endif
73587 + return 0;
73588 +}
73589 +
73590 +int
73591 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73592 +{
73593 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73594 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73595 + !gr_is_outside_chroot(dentry, mnt)) {
73596 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73597 + return -EPERM;
73598 + }
73599 +#endif
73600 + return 0;
73601 +}
73602 +
73603 +extern const char *captab_log[];
73604 +extern int captab_log_entries;
73605 +
73606 +int
73607 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73608 +{
73609 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73610 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73611 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73612 + if (cap_raised(chroot_caps, cap)) {
73613 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73614 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73615 + }
73616 + return 0;
73617 + }
73618 + }
73619 +#endif
73620 + return 1;
73621 +}
73622 +
73623 +int
73624 +gr_chroot_is_capable(const int cap)
73625 +{
73626 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73627 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73628 +#endif
73629 + return 1;
73630 +}
73631 +
73632 +int
73633 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73634 +{
73635 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73636 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73637 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73638 + if (cap_raised(chroot_caps, cap)) {
73639 + return 0;
73640 + }
73641 + }
73642 +#endif
73643 + return 1;
73644 +}
73645 +
73646 +int
73647 +gr_chroot_is_capable_nolog(const int cap)
73648 +{
73649 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73650 + return gr_task_chroot_is_capable_nolog(current, cap);
73651 +#endif
73652 + return 1;
73653 +}
73654 +
73655 +int
73656 +gr_handle_chroot_sysctl(const int op)
73657 +{
73658 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73659 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73660 + proc_is_chrooted(current))
73661 + return -EACCES;
73662 +#endif
73663 + return 0;
73664 +}
73665 +
73666 +void
73667 +gr_handle_chroot_chdir(const struct path *path)
73668 +{
73669 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73670 + if (grsec_enable_chroot_chdir)
73671 + set_fs_pwd(current->fs, path);
73672 +#endif
73673 + return;
73674 +}
73675 +
73676 +int
73677 +gr_handle_chroot_chmod(const struct dentry *dentry,
73678 + const struct vfsmount *mnt, const int mode)
73679 +{
73680 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73681 + /* allow chmod +s on directories, but not files */
73682 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73683 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73684 + proc_is_chrooted(current)) {
73685 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73686 + return -EPERM;
73687 + }
73688 +#endif
73689 + return 0;
73690 +}
73691 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73692 new file mode 100644
73693 index 0000000..de31e65
73694 --- /dev/null
73695 +++ b/grsecurity/grsec_disabled.c
73696 @@ -0,0 +1,434 @@
73697 +#include <linux/kernel.h>
73698 +#include <linux/module.h>
73699 +#include <linux/sched.h>
73700 +#include <linux/file.h>
73701 +#include <linux/fs.h>
73702 +#include <linux/kdev_t.h>
73703 +#include <linux/net.h>
73704 +#include <linux/in.h>
73705 +#include <linux/ip.h>
73706 +#include <linux/skbuff.h>
73707 +#include <linux/sysctl.h>
73708 +
73709 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73710 +void
73711 +pax_set_initial_flags(struct linux_binprm *bprm)
73712 +{
73713 + return;
73714 +}
73715 +#endif
73716 +
73717 +#ifdef CONFIG_SYSCTL
73718 +__u32
73719 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73720 +{
73721 + return 0;
73722 +}
73723 +#endif
73724 +
73725 +#ifdef CONFIG_TASKSTATS
73726 +int gr_is_taskstats_denied(int pid)
73727 +{
73728 + return 0;
73729 +}
73730 +#endif
73731 +
73732 +int
73733 +gr_acl_is_enabled(void)
73734 +{
73735 + return 0;
73736 +}
73737 +
73738 +void
73739 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73740 +{
73741 + return;
73742 +}
73743 +
73744 +int
73745 +gr_handle_rawio(const struct inode *inode)
73746 +{
73747 + return 0;
73748 +}
73749 +
73750 +void
73751 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73752 +{
73753 + return;
73754 +}
73755 +
73756 +int
73757 +gr_handle_ptrace(struct task_struct *task, const long request)
73758 +{
73759 + return 0;
73760 +}
73761 +
73762 +int
73763 +gr_handle_proc_ptrace(struct task_struct *task)
73764 +{
73765 + return 0;
73766 +}
73767 +
73768 +int
73769 +gr_set_acls(const int type)
73770 +{
73771 + return 0;
73772 +}
73773 +
73774 +int
73775 +gr_check_hidden_task(const struct task_struct *tsk)
73776 +{
73777 + return 0;
73778 +}
73779 +
73780 +int
73781 +gr_check_protected_task(const struct task_struct *task)
73782 +{
73783 + return 0;
73784 +}
73785 +
73786 +int
73787 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73788 +{
73789 + return 0;
73790 +}
73791 +
73792 +void
73793 +gr_copy_label(struct task_struct *tsk)
73794 +{
73795 + return;
73796 +}
73797 +
73798 +void
73799 +gr_set_pax_flags(struct task_struct *task)
73800 +{
73801 + return;
73802 +}
73803 +
73804 +int
73805 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73806 + const int unsafe_share)
73807 +{
73808 + return 0;
73809 +}
73810 +
73811 +void
73812 +gr_handle_delete(const ino_t ino, const dev_t dev)
73813 +{
73814 + return;
73815 +}
73816 +
73817 +void
73818 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73819 +{
73820 + return;
73821 +}
73822 +
73823 +void
73824 +gr_handle_crash(struct task_struct *task, const int sig)
73825 +{
73826 + return;
73827 +}
73828 +
73829 +int
73830 +gr_check_crash_exec(const struct file *filp)
73831 +{
73832 + return 0;
73833 +}
73834 +
73835 +int
73836 +gr_check_crash_uid(const kuid_t uid)
73837 +{
73838 + return 0;
73839 +}
73840 +
73841 +void
73842 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73843 + struct dentry *old_dentry,
73844 + struct dentry *new_dentry,
73845 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
73846 +{
73847 + return;
73848 +}
73849 +
73850 +int
73851 +gr_search_socket(const int family, const int type, const int protocol)
73852 +{
73853 + return 1;
73854 +}
73855 +
73856 +int
73857 +gr_search_connectbind(const int mode, const struct socket *sock,
73858 + const struct sockaddr_in *addr)
73859 +{
73860 + return 0;
73861 +}
73862 +
73863 +void
73864 +gr_handle_alertkill(struct task_struct *task)
73865 +{
73866 + return;
73867 +}
73868 +
73869 +__u32
73870 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73871 +{
73872 + return 1;
73873 +}
73874 +
73875 +__u32
73876 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73877 + const struct vfsmount * mnt)
73878 +{
73879 + return 1;
73880 +}
73881 +
73882 +__u32
73883 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73884 + int acc_mode)
73885 +{
73886 + return 1;
73887 +}
73888 +
73889 +__u32
73890 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73891 +{
73892 + return 1;
73893 +}
73894 +
73895 +__u32
73896 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73897 +{
73898 + return 1;
73899 +}
73900 +
73901 +int
73902 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73903 + unsigned int *vm_flags)
73904 +{
73905 + return 1;
73906 +}
73907 +
73908 +__u32
73909 +gr_acl_handle_truncate(const struct dentry * dentry,
73910 + const struct vfsmount * mnt)
73911 +{
73912 + return 1;
73913 +}
73914 +
73915 +__u32
73916 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73917 +{
73918 + return 1;
73919 +}
73920 +
73921 +__u32
73922 +gr_acl_handle_access(const struct dentry * dentry,
73923 + const struct vfsmount * mnt, const int fmode)
73924 +{
73925 + return 1;
73926 +}
73927 +
73928 +__u32
73929 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73930 + umode_t *mode)
73931 +{
73932 + return 1;
73933 +}
73934 +
73935 +__u32
73936 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73937 +{
73938 + return 1;
73939 +}
73940 +
73941 +__u32
73942 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73943 +{
73944 + return 1;
73945 +}
73946 +
73947 +__u32
73948 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73949 +{
73950 + return 1;
73951 +}
73952 +
73953 +void
73954 +grsecurity_init(void)
73955 +{
73956 + return;
73957 +}
73958 +
73959 +umode_t gr_acl_umask(void)
73960 +{
73961 + return 0;
73962 +}
73963 +
73964 +__u32
73965 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73966 + const struct dentry * parent_dentry,
73967 + const struct vfsmount * parent_mnt,
73968 + const int mode)
73969 +{
73970 + return 1;
73971 +}
73972 +
73973 +__u32
73974 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73975 + const struct dentry * parent_dentry,
73976 + const struct vfsmount * parent_mnt)
73977 +{
73978 + return 1;
73979 +}
73980 +
73981 +__u32
73982 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73983 + const struct dentry * parent_dentry,
73984 + const struct vfsmount * parent_mnt, const struct filename *from)
73985 +{
73986 + return 1;
73987 +}
73988 +
73989 +__u32
73990 +gr_acl_handle_link(const struct dentry * new_dentry,
73991 + const struct dentry * parent_dentry,
73992 + const struct vfsmount * parent_mnt,
73993 + const struct dentry * old_dentry,
73994 + const struct vfsmount * old_mnt, const struct filename *to)
73995 +{
73996 + return 1;
73997 +}
73998 +
73999 +int
74000 +gr_acl_handle_rename(const struct dentry *new_dentry,
74001 + const struct dentry *parent_dentry,
74002 + const struct vfsmount *parent_mnt,
74003 + const struct dentry *old_dentry,
74004 + const struct inode *old_parent_inode,
74005 + const struct vfsmount *old_mnt, const struct filename *newname,
74006 + unsigned int flags)
74007 +{
74008 + return 0;
74009 +}
74010 +
74011 +int
74012 +gr_acl_handle_filldir(const struct file *file, const char *name,
74013 + const int namelen, const ino_t ino)
74014 +{
74015 + return 1;
74016 +}
74017 +
74018 +int
74019 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74020 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74021 +{
74022 + return 1;
74023 +}
74024 +
74025 +int
74026 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74027 +{
74028 + return 0;
74029 +}
74030 +
74031 +int
74032 +gr_search_accept(const struct socket *sock)
74033 +{
74034 + return 0;
74035 +}
74036 +
74037 +int
74038 +gr_search_listen(const struct socket *sock)
74039 +{
74040 + return 0;
74041 +}
74042 +
74043 +int
74044 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74045 +{
74046 + return 0;
74047 +}
74048 +
74049 +__u32
74050 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74051 +{
74052 + return 1;
74053 +}
74054 +
74055 +__u32
74056 +gr_acl_handle_creat(const struct dentry * dentry,
74057 + const struct dentry * p_dentry,
74058 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74059 + const int imode)
74060 +{
74061 + return 1;
74062 +}
74063 +
74064 +void
74065 +gr_acl_handle_exit(void)
74066 +{
74067 + return;
74068 +}
74069 +
74070 +int
74071 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74072 +{
74073 + return 1;
74074 +}
74075 +
74076 +void
74077 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74078 +{
74079 + return;
74080 +}
74081 +
74082 +int
74083 +gr_acl_handle_procpidmem(const struct task_struct *task)
74084 +{
74085 + return 0;
74086 +}
74087 +
74088 +int
74089 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74090 +{
74091 + return 0;
74092 +}
74093 +
74094 +int
74095 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74096 +{
74097 + return 0;
74098 +}
74099 +
74100 +int
74101 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74102 +{
74103 + return 0;
74104 +}
74105 +
74106 +int
74107 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74108 +{
74109 + return 0;
74110 +}
74111 +
74112 +int gr_acl_enable_at_secure(void)
74113 +{
74114 + return 0;
74115 +}
74116 +
74117 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74118 +{
74119 + return dentry->d_sb->s_dev;
74120 +}
74121 +
74122 +void gr_put_exec_file(struct task_struct *task)
74123 +{
74124 + return;
74125 +}
74126 +
74127 +#ifdef CONFIG_SECURITY
74128 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74129 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74130 +#endif
74131 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74132 new file mode 100644
74133 index 0000000..f35f454
74134 --- /dev/null
74135 +++ b/grsecurity/grsec_exec.c
74136 @@ -0,0 +1,187 @@
74137 +#include <linux/kernel.h>
74138 +#include <linux/sched.h>
74139 +#include <linux/file.h>
74140 +#include <linux/binfmts.h>
74141 +#include <linux/fs.h>
74142 +#include <linux/types.h>
74143 +#include <linux/grdefs.h>
74144 +#include <linux/grsecurity.h>
74145 +#include <linux/grinternal.h>
74146 +#include <linux/capability.h>
74147 +#include <linux/module.h>
74148 +#include <linux/compat.h>
74149 +
74150 +#include <asm/uaccess.h>
74151 +
74152 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74153 +static char gr_exec_arg_buf[132];
74154 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74155 +#endif
74156 +
74157 +struct user_arg_ptr {
74158 +#ifdef CONFIG_COMPAT
74159 + bool is_compat;
74160 +#endif
74161 + union {
74162 + const char __user *const __user *native;
74163 +#ifdef CONFIG_COMPAT
74164 + const compat_uptr_t __user *compat;
74165 +#endif
74166 + } ptr;
74167 +};
74168 +
74169 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74170 +
74171 +void
74172 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74173 +{
74174 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74175 + char *grarg = gr_exec_arg_buf;
74176 + unsigned int i, x, execlen = 0;
74177 + char c;
74178 +
74179 + if (!((grsec_enable_execlog && grsec_enable_group &&
74180 + in_group_p(grsec_audit_gid))
74181 + || (grsec_enable_execlog && !grsec_enable_group)))
74182 + return;
74183 +
74184 + mutex_lock(&gr_exec_arg_mutex);
74185 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74186 +
74187 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74188 + const char __user *p;
74189 + unsigned int len;
74190 +
74191 + p = get_user_arg_ptr(argv, i);
74192 + if (IS_ERR(p))
74193 + goto log;
74194 +
74195 + len = strnlen_user(p, 128 - execlen);
74196 + if (len > 128 - execlen)
74197 + len = 128 - execlen;
74198 + else if (len > 0)
74199 + len--;
74200 + if (copy_from_user(grarg + execlen, p, len))
74201 + goto log;
74202 +
74203 + /* rewrite unprintable characters */
74204 + for (x = 0; x < len; x++) {
74205 + c = *(grarg + execlen + x);
74206 + if (c < 32 || c > 126)
74207 + *(grarg + execlen + x) = ' ';
74208 + }
74209 +
74210 + execlen += len;
74211 + *(grarg + execlen) = ' ';
74212 + *(grarg + execlen + 1) = '\0';
74213 + execlen++;
74214 + }
74215 +
74216 + log:
74217 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74218 + bprm->file->f_path.mnt, grarg);
74219 + mutex_unlock(&gr_exec_arg_mutex);
74220 +#endif
74221 + return;
74222 +}
74223 +
74224 +#ifdef CONFIG_GRKERNSEC
74225 +extern int gr_acl_is_capable(const int cap);
74226 +extern int gr_acl_is_capable_nolog(const int cap);
74227 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74228 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74229 +extern int gr_chroot_is_capable(const int cap);
74230 +extern int gr_chroot_is_capable_nolog(const int cap);
74231 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74232 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74233 +#endif
74234 +
74235 +const char *captab_log[] = {
74236 + "CAP_CHOWN",
74237 + "CAP_DAC_OVERRIDE",
74238 + "CAP_DAC_READ_SEARCH",
74239 + "CAP_FOWNER",
74240 + "CAP_FSETID",
74241 + "CAP_KILL",
74242 + "CAP_SETGID",
74243 + "CAP_SETUID",
74244 + "CAP_SETPCAP",
74245 + "CAP_LINUX_IMMUTABLE",
74246 + "CAP_NET_BIND_SERVICE",
74247 + "CAP_NET_BROADCAST",
74248 + "CAP_NET_ADMIN",
74249 + "CAP_NET_RAW",
74250 + "CAP_IPC_LOCK",
74251 + "CAP_IPC_OWNER",
74252 + "CAP_SYS_MODULE",
74253 + "CAP_SYS_RAWIO",
74254 + "CAP_SYS_CHROOT",
74255 + "CAP_SYS_PTRACE",
74256 + "CAP_SYS_PACCT",
74257 + "CAP_SYS_ADMIN",
74258 + "CAP_SYS_BOOT",
74259 + "CAP_SYS_NICE",
74260 + "CAP_SYS_RESOURCE",
74261 + "CAP_SYS_TIME",
74262 + "CAP_SYS_TTY_CONFIG",
74263 + "CAP_MKNOD",
74264 + "CAP_LEASE",
74265 + "CAP_AUDIT_WRITE",
74266 + "CAP_AUDIT_CONTROL",
74267 + "CAP_SETFCAP",
74268 + "CAP_MAC_OVERRIDE",
74269 + "CAP_MAC_ADMIN",
74270 + "CAP_SYSLOG",
74271 + "CAP_WAKE_ALARM"
74272 +};
74273 +
74274 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74275 +
74276 +int gr_is_capable(const int cap)
74277 +{
74278 +#ifdef CONFIG_GRKERNSEC
74279 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74280 + return 1;
74281 + return 0;
74282 +#else
74283 + return 1;
74284 +#endif
74285 +}
74286 +
74287 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74288 +{
74289 +#ifdef CONFIG_GRKERNSEC
74290 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74291 + return 1;
74292 + return 0;
74293 +#else
74294 + return 1;
74295 +#endif
74296 +}
74297 +
74298 +int gr_is_capable_nolog(const int cap)
74299 +{
74300 +#ifdef CONFIG_GRKERNSEC
74301 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74302 + return 1;
74303 + return 0;
74304 +#else
74305 + return 1;
74306 +#endif
74307 +}
74308 +
74309 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74310 +{
74311 +#ifdef CONFIG_GRKERNSEC
74312 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74313 + return 1;
74314 + return 0;
74315 +#else
74316 + return 1;
74317 +#endif
74318 +}
74319 +
74320 +EXPORT_SYMBOL_GPL(gr_is_capable);
74321 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74322 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
74323 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74324 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74325 new file mode 100644
74326 index 0000000..06cc6ea
74327 --- /dev/null
74328 +++ b/grsecurity/grsec_fifo.c
74329 @@ -0,0 +1,24 @@
74330 +#include <linux/kernel.h>
74331 +#include <linux/sched.h>
74332 +#include <linux/fs.h>
74333 +#include <linux/file.h>
74334 +#include <linux/grinternal.h>
74335 +
74336 +int
74337 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74338 + const struct dentry *dir, const int flag, const int acc_mode)
74339 +{
74340 +#ifdef CONFIG_GRKERNSEC_FIFO
74341 + const struct cred *cred = current_cred();
74342 +
74343 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74344 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74345 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74346 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74347 + if (!inode_permission(dentry->d_inode, acc_mode))
74348 + 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));
74349 + return -EACCES;
74350 + }
74351 +#endif
74352 + return 0;
74353 +}
74354 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74355 new file mode 100644
74356 index 0000000..8ca18bf
74357 --- /dev/null
74358 +++ b/grsecurity/grsec_fork.c
74359 @@ -0,0 +1,23 @@
74360 +#include <linux/kernel.h>
74361 +#include <linux/sched.h>
74362 +#include <linux/grsecurity.h>
74363 +#include <linux/grinternal.h>
74364 +#include <linux/errno.h>
74365 +
74366 +void
74367 +gr_log_forkfail(const int retval)
74368 +{
74369 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74370 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74371 + switch (retval) {
74372 + case -EAGAIN:
74373 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74374 + break;
74375 + case -ENOMEM:
74376 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74377 + break;
74378 + }
74379 + }
74380 +#endif
74381 + return;
74382 +}
74383 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74384 new file mode 100644
74385 index 0000000..ae6c028
74386 --- /dev/null
74387 +++ b/grsecurity/grsec_init.c
74388 @@ -0,0 +1,272 @@
74389 +#include <linux/kernel.h>
74390 +#include <linux/sched.h>
74391 +#include <linux/mm.h>
74392 +#include <linux/gracl.h>
74393 +#include <linux/slab.h>
74394 +#include <linux/vmalloc.h>
74395 +#include <linux/percpu.h>
74396 +#include <linux/module.h>
74397 +
74398 +int grsec_enable_ptrace_readexec;
74399 +int grsec_enable_setxid;
74400 +int grsec_enable_symlinkown;
74401 +kgid_t grsec_symlinkown_gid;
74402 +int grsec_enable_brute;
74403 +int grsec_enable_link;
74404 +int grsec_enable_dmesg;
74405 +int grsec_enable_harden_ptrace;
74406 +int grsec_enable_harden_ipc;
74407 +int grsec_enable_fifo;
74408 +int grsec_enable_execlog;
74409 +int grsec_enable_signal;
74410 +int grsec_enable_forkfail;
74411 +int grsec_enable_audit_ptrace;
74412 +int grsec_enable_time;
74413 +int grsec_enable_group;
74414 +kgid_t grsec_audit_gid;
74415 +int grsec_enable_chdir;
74416 +int grsec_enable_mount;
74417 +int grsec_enable_rofs;
74418 +int grsec_deny_new_usb;
74419 +int grsec_enable_chroot_findtask;
74420 +int grsec_enable_chroot_mount;
74421 +int grsec_enable_chroot_shmat;
74422 +int grsec_enable_chroot_fchdir;
74423 +int grsec_enable_chroot_double;
74424 +int grsec_enable_chroot_pivot;
74425 +int grsec_enable_chroot_chdir;
74426 +int grsec_enable_chroot_chmod;
74427 +int grsec_enable_chroot_mknod;
74428 +int grsec_enable_chroot_nice;
74429 +int grsec_enable_chroot_execlog;
74430 +int grsec_enable_chroot_caps;
74431 +int grsec_enable_chroot_sysctl;
74432 +int grsec_enable_chroot_unix;
74433 +int grsec_enable_tpe;
74434 +kgid_t grsec_tpe_gid;
74435 +int grsec_enable_blackhole;
74436 +#ifdef CONFIG_IPV6_MODULE
74437 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74438 +#endif
74439 +int grsec_lastack_retries;
74440 +int grsec_enable_tpe_all;
74441 +int grsec_enable_tpe_invert;
74442 +int grsec_enable_socket_all;
74443 +kgid_t grsec_socket_all_gid;
74444 +int grsec_enable_socket_client;
74445 +kgid_t grsec_socket_client_gid;
74446 +int grsec_enable_socket_server;
74447 +kgid_t grsec_socket_server_gid;
74448 +int grsec_resource_logging;
74449 +int grsec_disable_privio;
74450 +int grsec_enable_log_rwxmaps;
74451 +int grsec_lock;
74452 +
74453 +DEFINE_SPINLOCK(grsec_alert_lock);
74454 +unsigned long grsec_alert_wtime = 0;
74455 +unsigned long grsec_alert_fyet = 0;
74456 +
74457 +DEFINE_SPINLOCK(grsec_audit_lock);
74458 +
74459 +DEFINE_RWLOCK(grsec_exec_file_lock);
74460 +
74461 +char *gr_shared_page[4];
74462 +
74463 +char *gr_alert_log_fmt;
74464 +char *gr_audit_log_fmt;
74465 +char *gr_alert_log_buf;
74466 +char *gr_audit_log_buf;
74467 +
74468 +void __init
74469 +grsecurity_init(void)
74470 +{
74471 + int j;
74472 + /* create the per-cpu shared pages */
74473 +
74474 +#ifdef CONFIG_X86
74475 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74476 +#endif
74477 +
74478 + for (j = 0; j < 4; j++) {
74479 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74480 + if (gr_shared_page[j] == NULL) {
74481 + panic("Unable to allocate grsecurity shared page");
74482 + return;
74483 + }
74484 + }
74485 +
74486 + /* allocate log buffers */
74487 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74488 + if (!gr_alert_log_fmt) {
74489 + panic("Unable to allocate grsecurity alert log format buffer");
74490 + return;
74491 + }
74492 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74493 + if (!gr_audit_log_fmt) {
74494 + panic("Unable to allocate grsecurity audit log format buffer");
74495 + return;
74496 + }
74497 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74498 + if (!gr_alert_log_buf) {
74499 + panic("Unable to allocate grsecurity alert log buffer");
74500 + return;
74501 + }
74502 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74503 + if (!gr_audit_log_buf) {
74504 + panic("Unable to allocate grsecurity audit log buffer");
74505 + return;
74506 + }
74507 +
74508 +#ifdef CONFIG_GRKERNSEC_IO
74509 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74510 + grsec_disable_privio = 1;
74511 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74512 + grsec_disable_privio = 1;
74513 +#else
74514 + grsec_disable_privio = 0;
74515 +#endif
74516 +#endif
74517 +
74518 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74519 + /* for backward compatibility, tpe_invert always defaults to on if
74520 + enabled in the kernel
74521 + */
74522 + grsec_enable_tpe_invert = 1;
74523 +#endif
74524 +
74525 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74526 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74527 + grsec_lock = 1;
74528 +#endif
74529 +
74530 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74531 + grsec_enable_log_rwxmaps = 1;
74532 +#endif
74533 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74534 + grsec_enable_group = 1;
74535 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74536 +#endif
74537 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74538 + grsec_enable_ptrace_readexec = 1;
74539 +#endif
74540 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74541 + grsec_enable_chdir = 1;
74542 +#endif
74543 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74544 + grsec_enable_harden_ptrace = 1;
74545 +#endif
74546 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74547 + grsec_enable_harden_ipc = 1;
74548 +#endif
74549 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74550 + grsec_enable_mount = 1;
74551 +#endif
74552 +#ifdef CONFIG_GRKERNSEC_LINK
74553 + grsec_enable_link = 1;
74554 +#endif
74555 +#ifdef CONFIG_GRKERNSEC_BRUTE
74556 + grsec_enable_brute = 1;
74557 +#endif
74558 +#ifdef CONFIG_GRKERNSEC_DMESG
74559 + grsec_enable_dmesg = 1;
74560 +#endif
74561 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74562 + grsec_enable_blackhole = 1;
74563 + grsec_lastack_retries = 4;
74564 +#endif
74565 +#ifdef CONFIG_GRKERNSEC_FIFO
74566 + grsec_enable_fifo = 1;
74567 +#endif
74568 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74569 + grsec_enable_execlog = 1;
74570 +#endif
74571 +#ifdef CONFIG_GRKERNSEC_SETXID
74572 + grsec_enable_setxid = 1;
74573 +#endif
74574 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74575 + grsec_enable_signal = 1;
74576 +#endif
74577 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74578 + grsec_enable_forkfail = 1;
74579 +#endif
74580 +#ifdef CONFIG_GRKERNSEC_TIME
74581 + grsec_enable_time = 1;
74582 +#endif
74583 +#ifdef CONFIG_GRKERNSEC_RESLOG
74584 + grsec_resource_logging = 1;
74585 +#endif
74586 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74587 + grsec_enable_chroot_findtask = 1;
74588 +#endif
74589 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74590 + grsec_enable_chroot_unix = 1;
74591 +#endif
74592 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74593 + grsec_enable_chroot_mount = 1;
74594 +#endif
74595 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74596 + grsec_enable_chroot_fchdir = 1;
74597 +#endif
74598 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74599 + grsec_enable_chroot_shmat = 1;
74600 +#endif
74601 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74602 + grsec_enable_audit_ptrace = 1;
74603 +#endif
74604 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74605 + grsec_enable_chroot_double = 1;
74606 +#endif
74607 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74608 + grsec_enable_chroot_pivot = 1;
74609 +#endif
74610 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74611 + grsec_enable_chroot_chdir = 1;
74612 +#endif
74613 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74614 + grsec_enable_chroot_chmod = 1;
74615 +#endif
74616 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74617 + grsec_enable_chroot_mknod = 1;
74618 +#endif
74619 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74620 + grsec_enable_chroot_nice = 1;
74621 +#endif
74622 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74623 + grsec_enable_chroot_execlog = 1;
74624 +#endif
74625 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74626 + grsec_enable_chroot_caps = 1;
74627 +#endif
74628 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74629 + grsec_enable_chroot_sysctl = 1;
74630 +#endif
74631 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74632 + grsec_enable_symlinkown = 1;
74633 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74634 +#endif
74635 +#ifdef CONFIG_GRKERNSEC_TPE
74636 + grsec_enable_tpe = 1;
74637 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74638 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74639 + grsec_enable_tpe_all = 1;
74640 +#endif
74641 +#endif
74642 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74643 + grsec_enable_socket_all = 1;
74644 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74645 +#endif
74646 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74647 + grsec_enable_socket_client = 1;
74648 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74649 +#endif
74650 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74651 + grsec_enable_socket_server = 1;
74652 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74653 +#endif
74654 +#endif
74655 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74656 + grsec_deny_new_usb = 1;
74657 +#endif
74658 +
74659 + return;
74660 +}
74661 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74662 new file mode 100644
74663 index 0000000..1773300
74664 --- /dev/null
74665 +++ b/grsecurity/grsec_ipc.c
74666 @@ -0,0 +1,48 @@
74667 +#include <linux/kernel.h>
74668 +#include <linux/mm.h>
74669 +#include <linux/sched.h>
74670 +#include <linux/file.h>
74671 +#include <linux/ipc.h>
74672 +#include <linux/ipc_namespace.h>
74673 +#include <linux/grsecurity.h>
74674 +#include <linux/grinternal.h>
74675 +
74676 +int
74677 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74678 +{
74679 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74680 + int write;
74681 + int orig_granted_mode;
74682 + kuid_t euid;
74683 + kgid_t egid;
74684 +
74685 + if (!grsec_enable_harden_ipc)
74686 + return 1;
74687 +
74688 + euid = current_euid();
74689 + egid = current_egid();
74690 +
74691 + write = requested_mode & 00002;
74692 + orig_granted_mode = ipcp->mode;
74693 +
74694 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74695 + orig_granted_mode >>= 6;
74696 + else {
74697 + /* if likely wrong permissions, lock to user */
74698 + if (orig_granted_mode & 0007)
74699 + orig_granted_mode = 0;
74700 + /* otherwise do a egid-only check */
74701 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74702 + orig_granted_mode >>= 3;
74703 + /* otherwise, no access */
74704 + else
74705 + orig_granted_mode = 0;
74706 + }
74707 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74708 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74709 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74710 + return 0;
74711 + }
74712 +#endif
74713 + return 1;
74714 +}
74715 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74716 new file mode 100644
74717 index 0000000..5e05e20
74718 --- /dev/null
74719 +++ b/grsecurity/grsec_link.c
74720 @@ -0,0 +1,58 @@
74721 +#include <linux/kernel.h>
74722 +#include <linux/sched.h>
74723 +#include <linux/fs.h>
74724 +#include <linux/file.h>
74725 +#include <linux/grinternal.h>
74726 +
74727 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74728 +{
74729 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74730 + const struct inode *link_inode = link->dentry->d_inode;
74731 +
74732 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74733 + /* ignore root-owned links, e.g. /proc/self */
74734 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74735 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74736 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74737 + return 1;
74738 + }
74739 +#endif
74740 + return 0;
74741 +}
74742 +
74743 +int
74744 +gr_handle_follow_link(const struct inode *parent,
74745 + const struct inode *inode,
74746 + const struct dentry *dentry, const struct vfsmount *mnt)
74747 +{
74748 +#ifdef CONFIG_GRKERNSEC_LINK
74749 + const struct cred *cred = current_cred();
74750 +
74751 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74752 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74753 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74754 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74755 + return -EACCES;
74756 + }
74757 +#endif
74758 + return 0;
74759 +}
74760 +
74761 +int
74762 +gr_handle_hardlink(const struct dentry *dentry,
74763 + const struct vfsmount *mnt,
74764 + struct inode *inode, const int mode, const struct filename *to)
74765 +{
74766 +#ifdef CONFIG_GRKERNSEC_LINK
74767 + const struct cred *cred = current_cred();
74768 +
74769 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74770 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74771 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74772 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74773 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74774 + return -EPERM;
74775 + }
74776 +#endif
74777 + return 0;
74778 +}
74779 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74780 new file mode 100644
74781 index 0000000..dbe0a6b
74782 --- /dev/null
74783 +++ b/grsecurity/grsec_log.c
74784 @@ -0,0 +1,341 @@
74785 +#include <linux/kernel.h>
74786 +#include <linux/sched.h>
74787 +#include <linux/file.h>
74788 +#include <linux/tty.h>
74789 +#include <linux/fs.h>
74790 +#include <linux/mm.h>
74791 +#include <linux/grinternal.h>
74792 +
74793 +#ifdef CONFIG_TREE_PREEMPT_RCU
74794 +#define DISABLE_PREEMPT() preempt_disable()
74795 +#define ENABLE_PREEMPT() preempt_enable()
74796 +#else
74797 +#define DISABLE_PREEMPT()
74798 +#define ENABLE_PREEMPT()
74799 +#endif
74800 +
74801 +#define BEGIN_LOCKS(x) \
74802 + DISABLE_PREEMPT(); \
74803 + rcu_read_lock(); \
74804 + read_lock(&tasklist_lock); \
74805 + read_lock(&grsec_exec_file_lock); \
74806 + if (x != GR_DO_AUDIT) \
74807 + spin_lock(&grsec_alert_lock); \
74808 + else \
74809 + spin_lock(&grsec_audit_lock)
74810 +
74811 +#define END_LOCKS(x) \
74812 + if (x != GR_DO_AUDIT) \
74813 + spin_unlock(&grsec_alert_lock); \
74814 + else \
74815 + spin_unlock(&grsec_audit_lock); \
74816 + read_unlock(&grsec_exec_file_lock); \
74817 + read_unlock(&tasklist_lock); \
74818 + rcu_read_unlock(); \
74819 + ENABLE_PREEMPT(); \
74820 + if (x == GR_DONT_AUDIT) \
74821 + gr_handle_alertkill(current)
74822 +
74823 +enum {
74824 + FLOODING,
74825 + NO_FLOODING
74826 +};
74827 +
74828 +extern char *gr_alert_log_fmt;
74829 +extern char *gr_audit_log_fmt;
74830 +extern char *gr_alert_log_buf;
74831 +extern char *gr_audit_log_buf;
74832 +
74833 +static int gr_log_start(int audit)
74834 +{
74835 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74836 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74837 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74838 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74839 + unsigned long curr_secs = get_seconds();
74840 +
74841 + if (audit == GR_DO_AUDIT)
74842 + goto set_fmt;
74843 +
74844 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74845 + grsec_alert_wtime = curr_secs;
74846 + grsec_alert_fyet = 0;
74847 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74848 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74849 + grsec_alert_fyet++;
74850 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74851 + grsec_alert_wtime = curr_secs;
74852 + grsec_alert_fyet++;
74853 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74854 + return FLOODING;
74855 + }
74856 + else return FLOODING;
74857 +
74858 +set_fmt:
74859 +#endif
74860 + memset(buf, 0, PAGE_SIZE);
74861 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74862 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74863 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74864 + } else if (current->signal->curr_ip) {
74865 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74866 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74867 + } else if (gr_acl_is_enabled()) {
74868 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74869 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74870 + } else {
74871 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74872 + strcpy(buf, fmt);
74873 + }
74874 +
74875 + return NO_FLOODING;
74876 +}
74877 +
74878 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74879 + __attribute__ ((format (printf, 2, 0)));
74880 +
74881 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74882 +{
74883 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74884 + unsigned int len = strlen(buf);
74885 +
74886 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74887 +
74888 + return;
74889 +}
74890 +
74891 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74892 + __attribute__ ((format (printf, 2, 3)));
74893 +
74894 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74895 +{
74896 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74897 + unsigned int len = strlen(buf);
74898 + va_list ap;
74899 +
74900 + va_start(ap, msg);
74901 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74902 + va_end(ap);
74903 +
74904 + return;
74905 +}
74906 +
74907 +static void gr_log_end(int audit, int append_default)
74908 +{
74909 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74910 + if (append_default) {
74911 + struct task_struct *task = current;
74912 + struct task_struct *parent = task->real_parent;
74913 + const struct cred *cred = __task_cred(task);
74914 + const struct cred *pcred = __task_cred(parent);
74915 + unsigned int len = strlen(buf);
74916 +
74917 + 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));
74918 + }
74919 +
74920 + printk("%s\n", buf);
74921 +
74922 + return;
74923 +}
74924 +
74925 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74926 +{
74927 + int logtype;
74928 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74929 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74930 + void *voidptr = NULL;
74931 + int num1 = 0, num2 = 0;
74932 + unsigned long ulong1 = 0, ulong2 = 0;
74933 + struct dentry *dentry = NULL;
74934 + struct vfsmount *mnt = NULL;
74935 + struct file *file = NULL;
74936 + struct task_struct *task = NULL;
74937 + struct vm_area_struct *vma = NULL;
74938 + const struct cred *cred, *pcred;
74939 + va_list ap;
74940 +
74941 + BEGIN_LOCKS(audit);
74942 + logtype = gr_log_start(audit);
74943 + if (logtype == FLOODING) {
74944 + END_LOCKS(audit);
74945 + return;
74946 + }
74947 + va_start(ap, argtypes);
74948 + switch (argtypes) {
74949 + case GR_TTYSNIFF:
74950 + task = va_arg(ap, struct task_struct *);
74951 + 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));
74952 + break;
74953 + case GR_SYSCTL_HIDDEN:
74954 + str1 = va_arg(ap, char *);
74955 + gr_log_middle_varargs(audit, msg, result, str1);
74956 + break;
74957 + case GR_RBAC:
74958 + dentry = va_arg(ap, struct dentry *);
74959 + mnt = va_arg(ap, struct vfsmount *);
74960 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74961 + break;
74962 + case GR_RBAC_STR:
74963 + dentry = va_arg(ap, struct dentry *);
74964 + mnt = va_arg(ap, struct vfsmount *);
74965 + str1 = va_arg(ap, char *);
74966 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74967 + break;
74968 + case GR_STR_RBAC:
74969 + str1 = va_arg(ap, char *);
74970 + dentry = va_arg(ap, struct dentry *);
74971 + mnt = va_arg(ap, struct vfsmount *);
74972 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74973 + break;
74974 + case GR_RBAC_MODE2:
74975 + dentry = va_arg(ap, struct dentry *);
74976 + mnt = va_arg(ap, struct vfsmount *);
74977 + str1 = va_arg(ap, char *);
74978 + str2 = va_arg(ap, char *);
74979 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74980 + break;
74981 + case GR_RBAC_MODE3:
74982 + dentry = va_arg(ap, struct dentry *);
74983 + mnt = va_arg(ap, struct vfsmount *);
74984 + str1 = va_arg(ap, char *);
74985 + str2 = va_arg(ap, char *);
74986 + str3 = va_arg(ap, char *);
74987 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74988 + break;
74989 + case GR_FILENAME:
74990 + dentry = va_arg(ap, struct dentry *);
74991 + mnt = va_arg(ap, struct vfsmount *);
74992 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74993 + break;
74994 + case GR_STR_FILENAME:
74995 + str1 = va_arg(ap, char *);
74996 + dentry = va_arg(ap, struct dentry *);
74997 + mnt = va_arg(ap, struct vfsmount *);
74998 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74999 + break;
75000 + case GR_FILENAME_STR:
75001 + dentry = va_arg(ap, struct dentry *);
75002 + mnt = va_arg(ap, struct vfsmount *);
75003 + str1 = va_arg(ap, char *);
75004 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75005 + break;
75006 + case GR_FILENAME_TWO_INT:
75007 + dentry = va_arg(ap, struct dentry *);
75008 + mnt = va_arg(ap, struct vfsmount *);
75009 + num1 = va_arg(ap, int);
75010 + num2 = va_arg(ap, int);
75011 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75012 + break;
75013 + case GR_FILENAME_TWO_INT_STR:
75014 + dentry = va_arg(ap, struct dentry *);
75015 + mnt = va_arg(ap, struct vfsmount *);
75016 + num1 = va_arg(ap, int);
75017 + num2 = va_arg(ap, int);
75018 + str1 = va_arg(ap, char *);
75019 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75020 + break;
75021 + case GR_TEXTREL:
75022 + file = va_arg(ap, struct file *);
75023 + ulong1 = va_arg(ap, unsigned long);
75024 + ulong2 = va_arg(ap, unsigned long);
75025 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75026 + break;
75027 + case GR_PTRACE:
75028 + task = va_arg(ap, struct task_struct *);
75029 + 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));
75030 + break;
75031 + case GR_RESOURCE:
75032 + task = va_arg(ap, struct task_struct *);
75033 + cred = __task_cred(task);
75034 + pcred = __task_cred(task->real_parent);
75035 + ulong1 = va_arg(ap, unsigned long);
75036 + str1 = va_arg(ap, char *);
75037 + ulong2 = va_arg(ap, unsigned long);
75038 + 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));
75039 + break;
75040 + case GR_CAP:
75041 + task = va_arg(ap, struct task_struct *);
75042 + cred = __task_cred(task);
75043 + pcred = __task_cred(task->real_parent);
75044 + str1 = va_arg(ap, char *);
75045 + 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));
75046 + break;
75047 + case GR_SIG:
75048 + str1 = va_arg(ap, char *);
75049 + voidptr = va_arg(ap, void *);
75050 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75051 + break;
75052 + case GR_SIG2:
75053 + task = va_arg(ap, struct task_struct *);
75054 + cred = __task_cred(task);
75055 + pcred = __task_cred(task->real_parent);
75056 + num1 = va_arg(ap, int);
75057 + 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));
75058 + break;
75059 + case GR_CRASH1:
75060 + task = va_arg(ap, struct task_struct *);
75061 + cred = __task_cred(task);
75062 + pcred = __task_cred(task->real_parent);
75063 + ulong1 = va_arg(ap, unsigned long);
75064 + 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);
75065 + break;
75066 + case GR_CRASH2:
75067 + task = va_arg(ap, struct task_struct *);
75068 + cred = __task_cred(task);
75069 + pcred = __task_cred(task->real_parent);
75070 + ulong1 = va_arg(ap, unsigned long);
75071 + 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);
75072 + break;
75073 + case GR_RWXMAP:
75074 + file = va_arg(ap, struct file *);
75075 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75076 + break;
75077 + case GR_RWXMAPVMA:
75078 + vma = va_arg(ap, struct vm_area_struct *);
75079 + if (vma->vm_file)
75080 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75081 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75082 + str1 = "<stack>";
75083 + else if (vma->vm_start <= current->mm->brk &&
75084 + vma->vm_end >= current->mm->start_brk)
75085 + str1 = "<heap>";
75086 + else
75087 + str1 = "<anonymous mapping>";
75088 + gr_log_middle_varargs(audit, msg, str1);
75089 + break;
75090 + case GR_PSACCT:
75091 + {
75092 + unsigned int wday, cday;
75093 + __u8 whr, chr;
75094 + __u8 wmin, cmin;
75095 + __u8 wsec, csec;
75096 + char cur_tty[64] = { 0 };
75097 + char parent_tty[64] = { 0 };
75098 +
75099 + task = va_arg(ap, struct task_struct *);
75100 + wday = va_arg(ap, unsigned int);
75101 + cday = va_arg(ap, unsigned int);
75102 + whr = va_arg(ap, int);
75103 + chr = va_arg(ap, int);
75104 + wmin = va_arg(ap, int);
75105 + cmin = va_arg(ap, int);
75106 + wsec = va_arg(ap, int);
75107 + csec = va_arg(ap, int);
75108 + ulong1 = va_arg(ap, unsigned long);
75109 + cred = __task_cred(task);
75110 + pcred = __task_cred(task->real_parent);
75111 +
75112 + 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));
75113 + }
75114 + break;
75115 + default:
75116 + gr_log_middle(audit, msg, ap);
75117 + }
75118 + va_end(ap);
75119 + // these don't need DEFAULTSECARGS printed on the end
75120 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75121 + gr_log_end(audit, 0);
75122 + else
75123 + gr_log_end(audit, 1);
75124 + END_LOCKS(audit);
75125 +}
75126 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75127 new file mode 100644
75128 index 0000000..0e39d8c
75129 --- /dev/null
75130 +++ b/grsecurity/grsec_mem.c
75131 @@ -0,0 +1,48 @@
75132 +#include <linux/kernel.h>
75133 +#include <linux/sched.h>
75134 +#include <linux/mm.h>
75135 +#include <linux/mman.h>
75136 +#include <linux/module.h>
75137 +#include <linux/grinternal.h>
75138 +
75139 +void gr_handle_msr_write(void)
75140 +{
75141 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75142 + return;
75143 +}
75144 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75145 +
75146 +void
75147 +gr_handle_ioperm(void)
75148 +{
75149 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75150 + return;
75151 +}
75152 +
75153 +void
75154 +gr_handle_iopl(void)
75155 +{
75156 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75157 + return;
75158 +}
75159 +
75160 +void
75161 +gr_handle_mem_readwrite(u64 from, u64 to)
75162 +{
75163 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75164 + return;
75165 +}
75166 +
75167 +void
75168 +gr_handle_vm86(void)
75169 +{
75170 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75171 + return;
75172 +}
75173 +
75174 +void
75175 +gr_log_badprocpid(const char *entry)
75176 +{
75177 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75178 + return;
75179 +}
75180 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75181 new file mode 100644
75182 index 0000000..cd9e124
75183 --- /dev/null
75184 +++ b/grsecurity/grsec_mount.c
75185 @@ -0,0 +1,65 @@
75186 +#include <linux/kernel.h>
75187 +#include <linux/sched.h>
75188 +#include <linux/mount.h>
75189 +#include <linux/major.h>
75190 +#include <linux/grsecurity.h>
75191 +#include <linux/grinternal.h>
75192 +
75193 +void
75194 +gr_log_remount(const char *devname, const int retval)
75195 +{
75196 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75197 + if (grsec_enable_mount && (retval >= 0))
75198 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75199 +#endif
75200 + return;
75201 +}
75202 +
75203 +void
75204 +gr_log_unmount(const char *devname, const int retval)
75205 +{
75206 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75207 + if (grsec_enable_mount && (retval >= 0))
75208 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75209 +#endif
75210 + return;
75211 +}
75212 +
75213 +void
75214 +gr_log_mount(const char *from, const char *to, const int retval)
75215 +{
75216 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75217 + if (grsec_enable_mount && (retval >= 0))
75218 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75219 +#endif
75220 + return;
75221 +}
75222 +
75223 +int
75224 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75225 +{
75226 +#ifdef CONFIG_GRKERNSEC_ROFS
75227 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75228 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75229 + return -EPERM;
75230 + } else
75231 + return 0;
75232 +#endif
75233 + return 0;
75234 +}
75235 +
75236 +int
75237 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75238 +{
75239 +#ifdef CONFIG_GRKERNSEC_ROFS
75240 + struct inode *inode = dentry->d_inode;
75241 +
75242 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75243 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75244 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75245 + return -EPERM;
75246 + } else
75247 + return 0;
75248 +#endif
75249 + return 0;
75250 +}
75251 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75252 new file mode 100644
75253 index 0000000..6ee9d50
75254 --- /dev/null
75255 +++ b/grsecurity/grsec_pax.c
75256 @@ -0,0 +1,45 @@
75257 +#include <linux/kernel.h>
75258 +#include <linux/sched.h>
75259 +#include <linux/mm.h>
75260 +#include <linux/file.h>
75261 +#include <linux/grinternal.h>
75262 +#include <linux/grsecurity.h>
75263 +
75264 +void
75265 +gr_log_textrel(struct vm_area_struct * vma)
75266 +{
75267 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75268 + if (grsec_enable_log_rwxmaps)
75269 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75270 +#endif
75271 + return;
75272 +}
75273 +
75274 +void gr_log_ptgnustack(struct file *file)
75275 +{
75276 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75277 + if (grsec_enable_log_rwxmaps)
75278 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75279 +#endif
75280 + return;
75281 +}
75282 +
75283 +void
75284 +gr_log_rwxmmap(struct file *file)
75285 +{
75286 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75287 + if (grsec_enable_log_rwxmaps)
75288 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75289 +#endif
75290 + return;
75291 +}
75292 +
75293 +void
75294 +gr_log_rwxmprotect(struct vm_area_struct *vma)
75295 +{
75296 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75297 + if (grsec_enable_log_rwxmaps)
75298 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75299 +#endif
75300 + return;
75301 +}
75302 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75303 new file mode 100644
75304 index 0000000..2005a3a
75305 --- /dev/null
75306 +++ b/grsecurity/grsec_proc.c
75307 @@ -0,0 +1,20 @@
75308 +#include <linux/kernel.h>
75309 +#include <linux/sched.h>
75310 +#include <linux/grsecurity.h>
75311 +#include <linux/grinternal.h>
75312 +
75313 +int gr_proc_is_restricted(void)
75314 +{
75315 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75316 + const struct cred *cred = current_cred();
75317 +#endif
75318 +
75319 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75320 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75321 + return -EACCES;
75322 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75323 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75324 + return -EACCES;
75325 +#endif
75326 + return 0;
75327 +}
75328 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75329 new file mode 100644
75330 index 0000000..f7f29aa
75331 --- /dev/null
75332 +++ b/grsecurity/grsec_ptrace.c
75333 @@ -0,0 +1,30 @@
75334 +#include <linux/kernel.h>
75335 +#include <linux/sched.h>
75336 +#include <linux/grinternal.h>
75337 +#include <linux/security.h>
75338 +
75339 +void
75340 +gr_audit_ptrace(struct task_struct *task)
75341 +{
75342 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75343 + if (grsec_enable_audit_ptrace)
75344 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75345 +#endif
75346 + return;
75347 +}
75348 +
75349 +int
75350 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
75351 +{
75352 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75353 + const struct dentry *dentry = file->f_path.dentry;
75354 + const struct vfsmount *mnt = file->f_path.mnt;
75355 +
75356 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75357 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75358 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75359 + return -EACCES;
75360 + }
75361 +#endif
75362 + return 0;
75363 +}
75364 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75365 new file mode 100644
75366 index 0000000..3860c7e
75367 --- /dev/null
75368 +++ b/grsecurity/grsec_sig.c
75369 @@ -0,0 +1,236 @@
75370 +#include <linux/kernel.h>
75371 +#include <linux/sched.h>
75372 +#include <linux/fs.h>
75373 +#include <linux/delay.h>
75374 +#include <linux/grsecurity.h>
75375 +#include <linux/grinternal.h>
75376 +#include <linux/hardirq.h>
75377 +
75378 +char *signames[] = {
75379 + [SIGSEGV] = "Segmentation fault",
75380 + [SIGILL] = "Illegal instruction",
75381 + [SIGABRT] = "Abort",
75382 + [SIGBUS] = "Invalid alignment/Bus error"
75383 +};
75384 +
75385 +void
75386 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75387 +{
75388 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75389 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75390 + (sig == SIGABRT) || (sig == SIGBUS))) {
75391 + if (task_pid_nr(t) == task_pid_nr(current)) {
75392 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75393 + } else {
75394 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75395 + }
75396 + }
75397 +#endif
75398 + return;
75399 +}
75400 +
75401 +int
75402 +gr_handle_signal(const struct task_struct *p, const int sig)
75403 +{
75404 +#ifdef CONFIG_GRKERNSEC
75405 + /* ignore the 0 signal for protected task checks */
75406 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75407 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75408 + return -EPERM;
75409 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75410 + return -EPERM;
75411 + }
75412 +#endif
75413 + return 0;
75414 +}
75415 +
75416 +#ifdef CONFIG_GRKERNSEC
75417 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75418 +
75419 +int gr_fake_force_sig(int sig, struct task_struct *t)
75420 +{
75421 + unsigned long int flags;
75422 + int ret, blocked, ignored;
75423 + struct k_sigaction *action;
75424 +
75425 + spin_lock_irqsave(&t->sighand->siglock, flags);
75426 + action = &t->sighand->action[sig-1];
75427 + ignored = action->sa.sa_handler == SIG_IGN;
75428 + blocked = sigismember(&t->blocked, sig);
75429 + if (blocked || ignored) {
75430 + action->sa.sa_handler = SIG_DFL;
75431 + if (blocked) {
75432 + sigdelset(&t->blocked, sig);
75433 + recalc_sigpending_and_wake(t);
75434 + }
75435 + }
75436 + if (action->sa.sa_handler == SIG_DFL)
75437 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75438 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75439 +
75440 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75441 +
75442 + return ret;
75443 +}
75444 +#endif
75445 +
75446 +#define GR_USER_BAN_TIME (15 * 60)
75447 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75448 +
75449 +void gr_handle_brute_attach(int dumpable)
75450 +{
75451 +#ifdef CONFIG_GRKERNSEC_BRUTE
75452 + struct task_struct *p = current;
75453 + kuid_t uid = GLOBAL_ROOT_UID;
75454 + int daemon = 0;
75455 +
75456 + if (!grsec_enable_brute)
75457 + return;
75458 +
75459 + rcu_read_lock();
75460 + read_lock(&tasklist_lock);
75461 + read_lock(&grsec_exec_file_lock);
75462 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75463 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75464 + p->real_parent->brute = 1;
75465 + daemon = 1;
75466 + } else {
75467 + const struct cred *cred = __task_cred(p), *cred2;
75468 + struct task_struct *tsk, *tsk2;
75469 +
75470 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75471 + struct user_struct *user;
75472 +
75473 + uid = cred->uid;
75474 +
75475 + /* this is put upon execution past expiration */
75476 + user = find_user(uid);
75477 + if (user == NULL)
75478 + goto unlock;
75479 + user->suid_banned = 1;
75480 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75481 + if (user->suid_ban_expires == ~0UL)
75482 + user->suid_ban_expires--;
75483 +
75484 + /* only kill other threads of the same binary, from the same user */
75485 + do_each_thread(tsk2, tsk) {
75486 + cred2 = __task_cred(tsk);
75487 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75488 + gr_fake_force_sig(SIGKILL, tsk);
75489 + } while_each_thread(tsk2, tsk);
75490 + }
75491 + }
75492 +unlock:
75493 + read_unlock(&grsec_exec_file_lock);
75494 + read_unlock(&tasklist_lock);
75495 + rcu_read_unlock();
75496 +
75497 + if (gr_is_global_nonroot(uid))
75498 + 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);
75499 + else if (daemon)
75500 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75501 +
75502 +#endif
75503 + return;
75504 +}
75505 +
75506 +void gr_handle_brute_check(void)
75507 +{
75508 +#ifdef CONFIG_GRKERNSEC_BRUTE
75509 + struct task_struct *p = current;
75510 +
75511 + if (unlikely(p->brute)) {
75512 + if (!grsec_enable_brute)
75513 + p->brute = 0;
75514 + else if (time_before(get_seconds(), p->brute_expires))
75515 + msleep(30 * 1000);
75516 + }
75517 +#endif
75518 + return;
75519 +}
75520 +
75521 +void gr_handle_kernel_exploit(void)
75522 +{
75523 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75524 + const struct cred *cred;
75525 + struct task_struct *tsk, *tsk2;
75526 + struct user_struct *user;
75527 + kuid_t uid;
75528 +
75529 + if (in_irq() || in_serving_softirq() || in_nmi())
75530 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75531 +
75532 + uid = current_uid();
75533 +
75534 + if (gr_is_global_root(uid))
75535 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75536 + else {
75537 + /* kill all the processes of this user, hold a reference
75538 + to their creds struct, and prevent them from creating
75539 + another process until system reset
75540 + */
75541 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75542 + GR_GLOBAL_UID(uid));
75543 + /* we intentionally leak this ref */
75544 + user = get_uid(current->cred->user);
75545 + if (user)
75546 + user->kernel_banned = 1;
75547 +
75548 + /* kill all processes of this user */
75549 + read_lock(&tasklist_lock);
75550 + do_each_thread(tsk2, tsk) {
75551 + cred = __task_cred(tsk);
75552 + if (uid_eq(cred->uid, uid))
75553 + gr_fake_force_sig(SIGKILL, tsk);
75554 + } while_each_thread(tsk2, tsk);
75555 + read_unlock(&tasklist_lock);
75556 + }
75557 +#endif
75558 +}
75559 +
75560 +#ifdef CONFIG_GRKERNSEC_BRUTE
75561 +static bool suid_ban_expired(struct user_struct *user)
75562 +{
75563 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75564 + user->suid_banned = 0;
75565 + user->suid_ban_expires = 0;
75566 + free_uid(user);
75567 + return true;
75568 + }
75569 +
75570 + return false;
75571 +}
75572 +#endif
75573 +
75574 +int gr_process_kernel_exec_ban(void)
75575 +{
75576 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75577 + if (unlikely(current->cred->user->kernel_banned))
75578 + return -EPERM;
75579 +#endif
75580 + return 0;
75581 +}
75582 +
75583 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75584 +{
75585 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75586 + if (unlikely(user->kernel_banned))
75587 + gr_fake_force_sig(SIGKILL, current);
75588 +#endif
75589 + return 0;
75590 +}
75591 +
75592 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75593 +{
75594 +#ifdef CONFIG_GRKERNSEC_BRUTE
75595 + struct user_struct *user = current->cred->user;
75596 + if (unlikely(user->suid_banned)) {
75597 + if (suid_ban_expired(user))
75598 + return 0;
75599 + /* disallow execution of suid binaries only */
75600 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75601 + return -EPERM;
75602 + }
75603 +#endif
75604 + return 0;
75605 +}
75606 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75607 new file mode 100644
75608 index 0000000..c0aef3a
75609 --- /dev/null
75610 +++ b/grsecurity/grsec_sock.c
75611 @@ -0,0 +1,244 @@
75612 +#include <linux/kernel.h>
75613 +#include <linux/module.h>
75614 +#include <linux/sched.h>
75615 +#include <linux/file.h>
75616 +#include <linux/net.h>
75617 +#include <linux/in.h>
75618 +#include <linux/ip.h>
75619 +#include <net/sock.h>
75620 +#include <net/inet_sock.h>
75621 +#include <linux/grsecurity.h>
75622 +#include <linux/grinternal.h>
75623 +#include <linux/gracl.h>
75624 +
75625 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75626 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75627 +
75628 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75629 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75630 +
75631 +#ifdef CONFIG_UNIX_MODULE
75632 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75633 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75634 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75635 +EXPORT_SYMBOL_GPL(gr_handle_create);
75636 +#endif
75637 +
75638 +#ifdef CONFIG_GRKERNSEC
75639 +#define gr_conn_table_size 32749
75640 +struct conn_table_entry {
75641 + struct conn_table_entry *next;
75642 + struct signal_struct *sig;
75643 +};
75644 +
75645 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75646 +DEFINE_SPINLOCK(gr_conn_table_lock);
75647 +
75648 +extern const char * gr_socktype_to_name(unsigned char type);
75649 +extern const char * gr_proto_to_name(unsigned char proto);
75650 +extern const char * gr_sockfamily_to_name(unsigned char family);
75651 +
75652 +static __inline__ int
75653 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75654 +{
75655 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75656 +}
75657 +
75658 +static __inline__ int
75659 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75660 + __u16 sport, __u16 dport)
75661 +{
75662 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75663 + sig->gr_sport == sport && sig->gr_dport == dport))
75664 + return 1;
75665 + else
75666 + return 0;
75667 +}
75668 +
75669 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75670 +{
75671 + struct conn_table_entry **match;
75672 + unsigned int index;
75673 +
75674 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75675 + sig->gr_sport, sig->gr_dport,
75676 + gr_conn_table_size);
75677 +
75678 + newent->sig = sig;
75679 +
75680 + match = &gr_conn_table[index];
75681 + newent->next = *match;
75682 + *match = newent;
75683 +
75684 + return;
75685 +}
75686 +
75687 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75688 +{
75689 + struct conn_table_entry *match, *last = NULL;
75690 + unsigned int index;
75691 +
75692 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75693 + sig->gr_sport, sig->gr_dport,
75694 + gr_conn_table_size);
75695 +
75696 + match = gr_conn_table[index];
75697 + while (match && !conn_match(match->sig,
75698 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75699 + sig->gr_dport)) {
75700 + last = match;
75701 + match = match->next;
75702 + }
75703 +
75704 + if (match) {
75705 + if (last)
75706 + last->next = match->next;
75707 + else
75708 + gr_conn_table[index] = NULL;
75709 + kfree(match);
75710 + }
75711 +
75712 + return;
75713 +}
75714 +
75715 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75716 + __u16 sport, __u16 dport)
75717 +{
75718 + struct conn_table_entry *match;
75719 + unsigned int index;
75720 +
75721 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75722 +
75723 + match = gr_conn_table[index];
75724 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75725 + match = match->next;
75726 +
75727 + if (match)
75728 + return match->sig;
75729 + else
75730 + return NULL;
75731 +}
75732 +
75733 +#endif
75734 +
75735 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75736 +{
75737 +#ifdef CONFIG_GRKERNSEC
75738 + struct signal_struct *sig = task->signal;
75739 + struct conn_table_entry *newent;
75740 +
75741 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75742 + if (newent == NULL)
75743 + return;
75744 + /* no bh lock needed since we are called with bh disabled */
75745 + spin_lock(&gr_conn_table_lock);
75746 + gr_del_task_from_ip_table_nolock(sig);
75747 + sig->gr_saddr = inet->inet_rcv_saddr;
75748 + sig->gr_daddr = inet->inet_daddr;
75749 + sig->gr_sport = inet->inet_sport;
75750 + sig->gr_dport = inet->inet_dport;
75751 + gr_add_to_task_ip_table_nolock(sig, newent);
75752 + spin_unlock(&gr_conn_table_lock);
75753 +#endif
75754 + return;
75755 +}
75756 +
75757 +void gr_del_task_from_ip_table(struct task_struct *task)
75758 +{
75759 +#ifdef CONFIG_GRKERNSEC
75760 + spin_lock_bh(&gr_conn_table_lock);
75761 + gr_del_task_from_ip_table_nolock(task->signal);
75762 + spin_unlock_bh(&gr_conn_table_lock);
75763 +#endif
75764 + return;
75765 +}
75766 +
75767 +void
75768 +gr_attach_curr_ip(const struct sock *sk)
75769 +{
75770 +#ifdef CONFIG_GRKERNSEC
75771 + struct signal_struct *p, *set;
75772 + const struct inet_sock *inet = inet_sk(sk);
75773 +
75774 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75775 + return;
75776 +
75777 + set = current->signal;
75778 +
75779 + spin_lock_bh(&gr_conn_table_lock);
75780 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75781 + inet->inet_dport, inet->inet_sport);
75782 + if (unlikely(p != NULL)) {
75783 + set->curr_ip = p->curr_ip;
75784 + set->used_accept = 1;
75785 + gr_del_task_from_ip_table_nolock(p);
75786 + spin_unlock_bh(&gr_conn_table_lock);
75787 + return;
75788 + }
75789 + spin_unlock_bh(&gr_conn_table_lock);
75790 +
75791 + set->curr_ip = inet->inet_daddr;
75792 + set->used_accept = 1;
75793 +#endif
75794 + return;
75795 +}
75796 +
75797 +int
75798 +gr_handle_sock_all(const int family, const int type, const int protocol)
75799 +{
75800 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75801 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75802 + (family != AF_UNIX)) {
75803 + if (family == AF_INET)
75804 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75805 + else
75806 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75807 + return -EACCES;
75808 + }
75809 +#endif
75810 + return 0;
75811 +}
75812 +
75813 +int
75814 +gr_handle_sock_server(const struct sockaddr *sck)
75815 +{
75816 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75817 + if (grsec_enable_socket_server &&
75818 + in_group_p(grsec_socket_server_gid) &&
75819 + sck && (sck->sa_family != AF_UNIX) &&
75820 + (sck->sa_family != AF_LOCAL)) {
75821 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75822 + return -EACCES;
75823 + }
75824 +#endif
75825 + return 0;
75826 +}
75827 +
75828 +int
75829 +gr_handle_sock_server_other(const struct sock *sck)
75830 +{
75831 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75832 + if (grsec_enable_socket_server &&
75833 + in_group_p(grsec_socket_server_gid) &&
75834 + sck && (sck->sk_family != AF_UNIX) &&
75835 + (sck->sk_family != AF_LOCAL)) {
75836 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75837 + return -EACCES;
75838 + }
75839 +#endif
75840 + return 0;
75841 +}
75842 +
75843 +int
75844 +gr_handle_sock_client(const struct sockaddr *sck)
75845 +{
75846 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75847 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75848 + sck && (sck->sa_family != AF_UNIX) &&
75849 + (sck->sa_family != AF_LOCAL)) {
75850 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75851 + return -EACCES;
75852 + }
75853 +#endif
75854 + return 0;
75855 +}
75856 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75857 new file mode 100644
75858 index 0000000..8159888
75859 --- /dev/null
75860 +++ b/grsecurity/grsec_sysctl.c
75861 @@ -0,0 +1,479 @@
75862 +#include <linux/kernel.h>
75863 +#include <linux/sched.h>
75864 +#include <linux/sysctl.h>
75865 +#include <linux/grsecurity.h>
75866 +#include <linux/grinternal.h>
75867 +
75868 +int
75869 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75870 +{
75871 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75872 + if (dirname == NULL || name == NULL)
75873 + return 0;
75874 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75875 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75876 + return -EACCES;
75877 + }
75878 +#endif
75879 + return 0;
75880 +}
75881 +
75882 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75883 +static int __maybe_unused __read_only one = 1;
75884 +#endif
75885 +
75886 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75887 + defined(CONFIG_GRKERNSEC_DENYUSB)
75888 +struct ctl_table grsecurity_table[] = {
75889 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75890 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75891 +#ifdef CONFIG_GRKERNSEC_IO
75892 + {
75893 + .procname = "disable_priv_io",
75894 + .data = &grsec_disable_privio,
75895 + .maxlen = sizeof(int),
75896 + .mode = 0600,
75897 + .proc_handler = &proc_dointvec,
75898 + },
75899 +#endif
75900 +#endif
75901 +#ifdef CONFIG_GRKERNSEC_LINK
75902 + {
75903 + .procname = "linking_restrictions",
75904 + .data = &grsec_enable_link,
75905 + .maxlen = sizeof(int),
75906 + .mode = 0600,
75907 + .proc_handler = &proc_dointvec,
75908 + },
75909 +#endif
75910 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75911 + {
75912 + .procname = "enforce_symlinksifowner",
75913 + .data = &grsec_enable_symlinkown,
75914 + .maxlen = sizeof(int),
75915 + .mode = 0600,
75916 + .proc_handler = &proc_dointvec,
75917 + },
75918 + {
75919 + .procname = "symlinkown_gid",
75920 + .data = &grsec_symlinkown_gid,
75921 + .maxlen = sizeof(int),
75922 + .mode = 0600,
75923 + .proc_handler = &proc_dointvec,
75924 + },
75925 +#endif
75926 +#ifdef CONFIG_GRKERNSEC_BRUTE
75927 + {
75928 + .procname = "deter_bruteforce",
75929 + .data = &grsec_enable_brute,
75930 + .maxlen = sizeof(int),
75931 + .mode = 0600,
75932 + .proc_handler = &proc_dointvec,
75933 + },
75934 +#endif
75935 +#ifdef CONFIG_GRKERNSEC_FIFO
75936 + {
75937 + .procname = "fifo_restrictions",
75938 + .data = &grsec_enable_fifo,
75939 + .maxlen = sizeof(int),
75940 + .mode = 0600,
75941 + .proc_handler = &proc_dointvec,
75942 + },
75943 +#endif
75944 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75945 + {
75946 + .procname = "ptrace_readexec",
75947 + .data = &grsec_enable_ptrace_readexec,
75948 + .maxlen = sizeof(int),
75949 + .mode = 0600,
75950 + .proc_handler = &proc_dointvec,
75951 + },
75952 +#endif
75953 +#ifdef CONFIG_GRKERNSEC_SETXID
75954 + {
75955 + .procname = "consistent_setxid",
75956 + .data = &grsec_enable_setxid,
75957 + .maxlen = sizeof(int),
75958 + .mode = 0600,
75959 + .proc_handler = &proc_dointvec,
75960 + },
75961 +#endif
75962 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75963 + {
75964 + .procname = "ip_blackhole",
75965 + .data = &grsec_enable_blackhole,
75966 + .maxlen = sizeof(int),
75967 + .mode = 0600,
75968 + .proc_handler = &proc_dointvec,
75969 + },
75970 + {
75971 + .procname = "lastack_retries",
75972 + .data = &grsec_lastack_retries,
75973 + .maxlen = sizeof(int),
75974 + .mode = 0600,
75975 + .proc_handler = &proc_dointvec,
75976 + },
75977 +#endif
75978 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75979 + {
75980 + .procname = "exec_logging",
75981 + .data = &grsec_enable_execlog,
75982 + .maxlen = sizeof(int),
75983 + .mode = 0600,
75984 + .proc_handler = &proc_dointvec,
75985 + },
75986 +#endif
75987 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75988 + {
75989 + .procname = "rwxmap_logging",
75990 + .data = &grsec_enable_log_rwxmaps,
75991 + .maxlen = sizeof(int),
75992 + .mode = 0600,
75993 + .proc_handler = &proc_dointvec,
75994 + },
75995 +#endif
75996 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75997 + {
75998 + .procname = "signal_logging",
75999 + .data = &grsec_enable_signal,
76000 + .maxlen = sizeof(int),
76001 + .mode = 0600,
76002 + .proc_handler = &proc_dointvec,
76003 + },
76004 +#endif
76005 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76006 + {
76007 + .procname = "forkfail_logging",
76008 + .data = &grsec_enable_forkfail,
76009 + .maxlen = sizeof(int),
76010 + .mode = 0600,
76011 + .proc_handler = &proc_dointvec,
76012 + },
76013 +#endif
76014 +#ifdef CONFIG_GRKERNSEC_TIME
76015 + {
76016 + .procname = "timechange_logging",
76017 + .data = &grsec_enable_time,
76018 + .maxlen = sizeof(int),
76019 + .mode = 0600,
76020 + .proc_handler = &proc_dointvec,
76021 + },
76022 +#endif
76023 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76024 + {
76025 + .procname = "chroot_deny_shmat",
76026 + .data = &grsec_enable_chroot_shmat,
76027 + .maxlen = sizeof(int),
76028 + .mode = 0600,
76029 + .proc_handler = &proc_dointvec,
76030 + },
76031 +#endif
76032 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76033 + {
76034 + .procname = "chroot_deny_unix",
76035 + .data = &grsec_enable_chroot_unix,
76036 + .maxlen = sizeof(int),
76037 + .mode = 0600,
76038 + .proc_handler = &proc_dointvec,
76039 + },
76040 +#endif
76041 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76042 + {
76043 + .procname = "chroot_deny_mount",
76044 + .data = &grsec_enable_chroot_mount,
76045 + .maxlen = sizeof(int),
76046 + .mode = 0600,
76047 + .proc_handler = &proc_dointvec,
76048 + },
76049 +#endif
76050 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76051 + {
76052 + .procname = "chroot_deny_fchdir",
76053 + .data = &grsec_enable_chroot_fchdir,
76054 + .maxlen = sizeof(int),
76055 + .mode = 0600,
76056 + .proc_handler = &proc_dointvec,
76057 + },
76058 +#endif
76059 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76060 + {
76061 + .procname = "chroot_deny_chroot",
76062 + .data = &grsec_enable_chroot_double,
76063 + .maxlen = sizeof(int),
76064 + .mode = 0600,
76065 + .proc_handler = &proc_dointvec,
76066 + },
76067 +#endif
76068 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76069 + {
76070 + .procname = "chroot_deny_pivot",
76071 + .data = &grsec_enable_chroot_pivot,
76072 + .maxlen = sizeof(int),
76073 + .mode = 0600,
76074 + .proc_handler = &proc_dointvec,
76075 + },
76076 +#endif
76077 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76078 + {
76079 + .procname = "chroot_enforce_chdir",
76080 + .data = &grsec_enable_chroot_chdir,
76081 + .maxlen = sizeof(int),
76082 + .mode = 0600,
76083 + .proc_handler = &proc_dointvec,
76084 + },
76085 +#endif
76086 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76087 + {
76088 + .procname = "chroot_deny_chmod",
76089 + .data = &grsec_enable_chroot_chmod,
76090 + .maxlen = sizeof(int),
76091 + .mode = 0600,
76092 + .proc_handler = &proc_dointvec,
76093 + },
76094 +#endif
76095 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76096 + {
76097 + .procname = "chroot_deny_mknod",
76098 + .data = &grsec_enable_chroot_mknod,
76099 + .maxlen = sizeof(int),
76100 + .mode = 0600,
76101 + .proc_handler = &proc_dointvec,
76102 + },
76103 +#endif
76104 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76105 + {
76106 + .procname = "chroot_restrict_nice",
76107 + .data = &grsec_enable_chroot_nice,
76108 + .maxlen = sizeof(int),
76109 + .mode = 0600,
76110 + .proc_handler = &proc_dointvec,
76111 + },
76112 +#endif
76113 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76114 + {
76115 + .procname = "chroot_execlog",
76116 + .data = &grsec_enable_chroot_execlog,
76117 + .maxlen = sizeof(int),
76118 + .mode = 0600,
76119 + .proc_handler = &proc_dointvec,
76120 + },
76121 +#endif
76122 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76123 + {
76124 + .procname = "chroot_caps",
76125 + .data = &grsec_enable_chroot_caps,
76126 + .maxlen = sizeof(int),
76127 + .mode = 0600,
76128 + .proc_handler = &proc_dointvec,
76129 + },
76130 +#endif
76131 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76132 + {
76133 + .procname = "chroot_deny_sysctl",
76134 + .data = &grsec_enable_chroot_sysctl,
76135 + .maxlen = sizeof(int),
76136 + .mode = 0600,
76137 + .proc_handler = &proc_dointvec,
76138 + },
76139 +#endif
76140 +#ifdef CONFIG_GRKERNSEC_TPE
76141 + {
76142 + .procname = "tpe",
76143 + .data = &grsec_enable_tpe,
76144 + .maxlen = sizeof(int),
76145 + .mode = 0600,
76146 + .proc_handler = &proc_dointvec,
76147 + },
76148 + {
76149 + .procname = "tpe_gid",
76150 + .data = &grsec_tpe_gid,
76151 + .maxlen = sizeof(int),
76152 + .mode = 0600,
76153 + .proc_handler = &proc_dointvec,
76154 + },
76155 +#endif
76156 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76157 + {
76158 + .procname = "tpe_invert",
76159 + .data = &grsec_enable_tpe_invert,
76160 + .maxlen = sizeof(int),
76161 + .mode = 0600,
76162 + .proc_handler = &proc_dointvec,
76163 + },
76164 +#endif
76165 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76166 + {
76167 + .procname = "tpe_restrict_all",
76168 + .data = &grsec_enable_tpe_all,
76169 + .maxlen = sizeof(int),
76170 + .mode = 0600,
76171 + .proc_handler = &proc_dointvec,
76172 + },
76173 +#endif
76174 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76175 + {
76176 + .procname = "socket_all",
76177 + .data = &grsec_enable_socket_all,
76178 + .maxlen = sizeof(int),
76179 + .mode = 0600,
76180 + .proc_handler = &proc_dointvec,
76181 + },
76182 + {
76183 + .procname = "socket_all_gid",
76184 + .data = &grsec_socket_all_gid,
76185 + .maxlen = sizeof(int),
76186 + .mode = 0600,
76187 + .proc_handler = &proc_dointvec,
76188 + },
76189 +#endif
76190 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76191 + {
76192 + .procname = "socket_client",
76193 + .data = &grsec_enable_socket_client,
76194 + .maxlen = sizeof(int),
76195 + .mode = 0600,
76196 + .proc_handler = &proc_dointvec,
76197 + },
76198 + {
76199 + .procname = "socket_client_gid",
76200 + .data = &grsec_socket_client_gid,
76201 + .maxlen = sizeof(int),
76202 + .mode = 0600,
76203 + .proc_handler = &proc_dointvec,
76204 + },
76205 +#endif
76206 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76207 + {
76208 + .procname = "socket_server",
76209 + .data = &grsec_enable_socket_server,
76210 + .maxlen = sizeof(int),
76211 + .mode = 0600,
76212 + .proc_handler = &proc_dointvec,
76213 + },
76214 + {
76215 + .procname = "socket_server_gid",
76216 + .data = &grsec_socket_server_gid,
76217 + .maxlen = sizeof(int),
76218 + .mode = 0600,
76219 + .proc_handler = &proc_dointvec,
76220 + },
76221 +#endif
76222 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76223 + {
76224 + .procname = "audit_group",
76225 + .data = &grsec_enable_group,
76226 + .maxlen = sizeof(int),
76227 + .mode = 0600,
76228 + .proc_handler = &proc_dointvec,
76229 + },
76230 + {
76231 + .procname = "audit_gid",
76232 + .data = &grsec_audit_gid,
76233 + .maxlen = sizeof(int),
76234 + .mode = 0600,
76235 + .proc_handler = &proc_dointvec,
76236 + },
76237 +#endif
76238 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76239 + {
76240 + .procname = "audit_chdir",
76241 + .data = &grsec_enable_chdir,
76242 + .maxlen = sizeof(int),
76243 + .mode = 0600,
76244 + .proc_handler = &proc_dointvec,
76245 + },
76246 +#endif
76247 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76248 + {
76249 + .procname = "audit_mount",
76250 + .data = &grsec_enable_mount,
76251 + .maxlen = sizeof(int),
76252 + .mode = 0600,
76253 + .proc_handler = &proc_dointvec,
76254 + },
76255 +#endif
76256 +#ifdef CONFIG_GRKERNSEC_DMESG
76257 + {
76258 + .procname = "dmesg",
76259 + .data = &grsec_enable_dmesg,
76260 + .maxlen = sizeof(int),
76261 + .mode = 0600,
76262 + .proc_handler = &proc_dointvec,
76263 + },
76264 +#endif
76265 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76266 + {
76267 + .procname = "chroot_findtask",
76268 + .data = &grsec_enable_chroot_findtask,
76269 + .maxlen = sizeof(int),
76270 + .mode = 0600,
76271 + .proc_handler = &proc_dointvec,
76272 + },
76273 +#endif
76274 +#ifdef CONFIG_GRKERNSEC_RESLOG
76275 + {
76276 + .procname = "resource_logging",
76277 + .data = &grsec_resource_logging,
76278 + .maxlen = sizeof(int),
76279 + .mode = 0600,
76280 + .proc_handler = &proc_dointvec,
76281 + },
76282 +#endif
76283 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76284 + {
76285 + .procname = "audit_ptrace",
76286 + .data = &grsec_enable_audit_ptrace,
76287 + .maxlen = sizeof(int),
76288 + .mode = 0600,
76289 + .proc_handler = &proc_dointvec,
76290 + },
76291 +#endif
76292 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76293 + {
76294 + .procname = "harden_ptrace",
76295 + .data = &grsec_enable_harden_ptrace,
76296 + .maxlen = sizeof(int),
76297 + .mode = 0600,
76298 + .proc_handler = &proc_dointvec,
76299 + },
76300 +#endif
76301 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76302 + {
76303 + .procname = "harden_ipc",
76304 + .data = &grsec_enable_harden_ipc,
76305 + .maxlen = sizeof(int),
76306 + .mode = 0600,
76307 + .proc_handler = &proc_dointvec,
76308 + },
76309 +#endif
76310 + {
76311 + .procname = "grsec_lock",
76312 + .data = &grsec_lock,
76313 + .maxlen = sizeof(int),
76314 + .mode = 0600,
76315 + .proc_handler = &proc_dointvec,
76316 + },
76317 +#endif
76318 +#ifdef CONFIG_GRKERNSEC_ROFS
76319 + {
76320 + .procname = "romount_protect",
76321 + .data = &grsec_enable_rofs,
76322 + .maxlen = sizeof(int),
76323 + .mode = 0600,
76324 + .proc_handler = &proc_dointvec_minmax,
76325 + .extra1 = &one,
76326 + .extra2 = &one,
76327 + },
76328 +#endif
76329 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76330 + {
76331 + .procname = "deny_new_usb",
76332 + .data = &grsec_deny_new_usb,
76333 + .maxlen = sizeof(int),
76334 + .mode = 0600,
76335 + .proc_handler = &proc_dointvec,
76336 + },
76337 +#endif
76338 + { }
76339 +};
76340 +#endif
76341 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76342 new file mode 100644
76343 index 0000000..61b514e
76344 --- /dev/null
76345 +++ b/grsecurity/grsec_time.c
76346 @@ -0,0 +1,16 @@
76347 +#include <linux/kernel.h>
76348 +#include <linux/sched.h>
76349 +#include <linux/grinternal.h>
76350 +#include <linux/module.h>
76351 +
76352 +void
76353 +gr_log_timechange(void)
76354 +{
76355 +#ifdef CONFIG_GRKERNSEC_TIME
76356 + if (grsec_enable_time)
76357 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76358 +#endif
76359 + return;
76360 +}
76361 +
76362 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76363 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76364 new file mode 100644
76365 index 0000000..d1953de
76366 --- /dev/null
76367 +++ b/grsecurity/grsec_tpe.c
76368 @@ -0,0 +1,78 @@
76369 +#include <linux/kernel.h>
76370 +#include <linux/sched.h>
76371 +#include <linux/file.h>
76372 +#include <linux/fs.h>
76373 +#include <linux/grinternal.h>
76374 +
76375 +extern int gr_acl_tpe_check(void);
76376 +
76377 +int
76378 +gr_tpe_allow(const struct file *file)
76379 +{
76380 +#ifdef CONFIG_GRKERNSEC
76381 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76382 + struct inode *file_inode = file->f_path.dentry->d_inode;
76383 + const struct cred *cred = current_cred();
76384 + char *msg = NULL;
76385 + char *msg2 = NULL;
76386 +
76387 + // never restrict root
76388 + if (gr_is_global_root(cred->uid))
76389 + return 1;
76390 +
76391 + if (grsec_enable_tpe) {
76392 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76393 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76394 + msg = "not being in trusted group";
76395 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76396 + msg = "being in untrusted group";
76397 +#else
76398 + if (in_group_p(grsec_tpe_gid))
76399 + msg = "being in untrusted group";
76400 +#endif
76401 + }
76402 + if (!msg && gr_acl_tpe_check())
76403 + msg = "being in untrusted role";
76404 +
76405 + // not in any affected group/role
76406 + if (!msg)
76407 + goto next_check;
76408 +
76409 + if (gr_is_global_nonroot(inode->i_uid))
76410 + msg2 = "file in non-root-owned directory";
76411 + else if (inode->i_mode & S_IWOTH)
76412 + msg2 = "file in world-writable directory";
76413 + else if (inode->i_mode & S_IWGRP)
76414 + msg2 = "file in group-writable directory";
76415 + else if (file_inode->i_mode & S_IWOTH)
76416 + msg2 = "file is world-writable";
76417 +
76418 + if (msg && msg2) {
76419 + char fullmsg[70] = {0};
76420 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76421 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76422 + return 0;
76423 + }
76424 + msg = NULL;
76425 +next_check:
76426 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76427 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76428 + return 1;
76429 +
76430 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76431 + msg = "directory not owned by user";
76432 + else if (inode->i_mode & S_IWOTH)
76433 + msg = "file in world-writable directory";
76434 + else if (inode->i_mode & S_IWGRP)
76435 + msg = "file in group-writable directory";
76436 + else if (file_inode->i_mode & S_IWOTH)
76437 + msg = "file is world-writable";
76438 +
76439 + if (msg) {
76440 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76441 + return 0;
76442 + }
76443 +#endif
76444 +#endif
76445 + return 1;
76446 +}
76447 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76448 new file mode 100644
76449 index 0000000..ae02d8e
76450 --- /dev/null
76451 +++ b/grsecurity/grsec_usb.c
76452 @@ -0,0 +1,15 @@
76453 +#include <linux/kernel.h>
76454 +#include <linux/grinternal.h>
76455 +#include <linux/module.h>
76456 +
76457 +int gr_handle_new_usb(void)
76458 +{
76459 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76460 + if (grsec_deny_new_usb) {
76461 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76462 + return 1;
76463 + }
76464 +#endif
76465 + return 0;
76466 +}
76467 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76468 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76469 new file mode 100644
76470 index 0000000..9f7b1ac
76471 --- /dev/null
76472 +++ b/grsecurity/grsum.c
76473 @@ -0,0 +1,61 @@
76474 +#include <linux/err.h>
76475 +#include <linux/kernel.h>
76476 +#include <linux/sched.h>
76477 +#include <linux/mm.h>
76478 +#include <linux/scatterlist.h>
76479 +#include <linux/crypto.h>
76480 +#include <linux/gracl.h>
76481 +
76482 +
76483 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76484 +#error "crypto and sha256 must be built into the kernel"
76485 +#endif
76486 +
76487 +int
76488 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76489 +{
76490 + char *p;
76491 + struct crypto_hash *tfm;
76492 + struct hash_desc desc;
76493 + struct scatterlist sg;
76494 + unsigned char temp_sum[GR_SHA_LEN];
76495 + volatile int retval = 0;
76496 + volatile int dummy = 0;
76497 + unsigned int i;
76498 +
76499 + sg_init_table(&sg, 1);
76500 +
76501 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76502 + if (IS_ERR(tfm)) {
76503 + /* should never happen, since sha256 should be built in */
76504 + return 1;
76505 + }
76506 +
76507 + desc.tfm = tfm;
76508 + desc.flags = 0;
76509 +
76510 + crypto_hash_init(&desc);
76511 +
76512 + p = salt;
76513 + sg_set_buf(&sg, p, GR_SALT_LEN);
76514 + crypto_hash_update(&desc, &sg, sg.length);
76515 +
76516 + p = entry->pw;
76517 + sg_set_buf(&sg, p, strlen(p));
76518 +
76519 + crypto_hash_update(&desc, &sg, sg.length);
76520 +
76521 + crypto_hash_final(&desc, temp_sum);
76522 +
76523 + memset(entry->pw, 0, GR_PW_LEN);
76524 +
76525 + for (i = 0; i < GR_SHA_LEN; i++)
76526 + if (sum[i] != temp_sum[i])
76527 + retval = 1;
76528 + else
76529 + dummy = 1; // waste a cycle
76530 +
76531 + crypto_free_hash(tfm);
76532 +
76533 + return retval;
76534 +}
76535 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76536 index 77ff547..181834f 100644
76537 --- a/include/asm-generic/4level-fixup.h
76538 +++ b/include/asm-generic/4level-fixup.h
76539 @@ -13,8 +13,10 @@
76540 #define pmd_alloc(mm, pud, address) \
76541 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76542 NULL: pmd_offset(pud, address))
76543 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76544
76545 #define pud_alloc(mm, pgd, address) (pgd)
76546 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76547 #define pud_offset(pgd, start) (pgd)
76548 #define pud_none(pud) 0
76549 #define pud_bad(pud) 0
76550 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76551 index b7babf0..97f4c4f 100644
76552 --- a/include/asm-generic/atomic-long.h
76553 +++ b/include/asm-generic/atomic-long.h
76554 @@ -22,6 +22,12 @@
76555
76556 typedef atomic64_t atomic_long_t;
76557
76558 +#ifdef CONFIG_PAX_REFCOUNT
76559 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76560 +#else
76561 +typedef atomic64_t atomic_long_unchecked_t;
76562 +#endif
76563 +
76564 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76565
76566 static inline long atomic_long_read(atomic_long_t *l)
76567 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76568 return (long)atomic64_read(v);
76569 }
76570
76571 +#ifdef CONFIG_PAX_REFCOUNT
76572 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76573 +{
76574 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76575 +
76576 + return (long)atomic64_read_unchecked(v);
76577 +}
76578 +#endif
76579 +
76580 static inline void atomic_long_set(atomic_long_t *l, long i)
76581 {
76582 atomic64_t *v = (atomic64_t *)l;
76583 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76584 atomic64_set(v, i);
76585 }
76586
76587 +#ifdef CONFIG_PAX_REFCOUNT
76588 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76589 +{
76590 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76591 +
76592 + atomic64_set_unchecked(v, i);
76593 +}
76594 +#endif
76595 +
76596 static inline void atomic_long_inc(atomic_long_t *l)
76597 {
76598 atomic64_t *v = (atomic64_t *)l;
76599 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76600 atomic64_inc(v);
76601 }
76602
76603 +#ifdef CONFIG_PAX_REFCOUNT
76604 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76605 +{
76606 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76607 +
76608 + atomic64_inc_unchecked(v);
76609 +}
76610 +#endif
76611 +
76612 static inline void atomic_long_dec(atomic_long_t *l)
76613 {
76614 atomic64_t *v = (atomic64_t *)l;
76615 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76616 atomic64_dec(v);
76617 }
76618
76619 +#ifdef CONFIG_PAX_REFCOUNT
76620 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76621 +{
76622 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76623 +
76624 + atomic64_dec_unchecked(v);
76625 +}
76626 +#endif
76627 +
76628 static inline void atomic_long_add(long i, atomic_long_t *l)
76629 {
76630 atomic64_t *v = (atomic64_t *)l;
76631 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76632 atomic64_add(i, v);
76633 }
76634
76635 +#ifdef CONFIG_PAX_REFCOUNT
76636 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76637 +{
76638 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76639 +
76640 + atomic64_add_unchecked(i, v);
76641 +}
76642 +#endif
76643 +
76644 static inline void atomic_long_sub(long i, atomic_long_t *l)
76645 {
76646 atomic64_t *v = (atomic64_t *)l;
76647 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76648 atomic64_sub(i, v);
76649 }
76650
76651 +#ifdef CONFIG_PAX_REFCOUNT
76652 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76653 +{
76654 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76655 +
76656 + atomic64_sub_unchecked(i, v);
76657 +}
76658 +#endif
76659 +
76660 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76661 {
76662 atomic64_t *v = (atomic64_t *)l;
76663 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76664 return atomic64_add_negative(i, v);
76665 }
76666
76667 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76668 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76669 {
76670 atomic64_t *v = (atomic64_t *)l;
76671
76672 return (long)atomic64_add_return(i, v);
76673 }
76674
76675 +#ifdef CONFIG_PAX_REFCOUNT
76676 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76677 +{
76678 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76679 +
76680 + return (long)atomic64_add_return_unchecked(i, v);
76681 +}
76682 +#endif
76683 +
76684 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76685 {
76686 atomic64_t *v = (atomic64_t *)l;
76687 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76688 return (long)atomic64_inc_return(v);
76689 }
76690
76691 +#ifdef CONFIG_PAX_REFCOUNT
76692 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76693 +{
76694 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76695 +
76696 + return (long)atomic64_inc_return_unchecked(v);
76697 +}
76698 +#endif
76699 +
76700 static inline long atomic_long_dec_return(atomic_long_t *l)
76701 {
76702 atomic64_t *v = (atomic64_t *)l;
76703 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76704
76705 typedef atomic_t atomic_long_t;
76706
76707 +#ifdef CONFIG_PAX_REFCOUNT
76708 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76709 +#else
76710 +typedef atomic_t atomic_long_unchecked_t;
76711 +#endif
76712 +
76713 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76714 static inline long atomic_long_read(atomic_long_t *l)
76715 {
76716 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76717 return (long)atomic_read(v);
76718 }
76719
76720 +#ifdef CONFIG_PAX_REFCOUNT
76721 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76722 +{
76723 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76724 +
76725 + return (long)atomic_read_unchecked(v);
76726 +}
76727 +#endif
76728 +
76729 static inline void atomic_long_set(atomic_long_t *l, long i)
76730 {
76731 atomic_t *v = (atomic_t *)l;
76732 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76733 atomic_set(v, i);
76734 }
76735
76736 +#ifdef CONFIG_PAX_REFCOUNT
76737 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76738 +{
76739 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76740 +
76741 + atomic_set_unchecked(v, i);
76742 +}
76743 +#endif
76744 +
76745 static inline void atomic_long_inc(atomic_long_t *l)
76746 {
76747 atomic_t *v = (atomic_t *)l;
76748 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76749 atomic_inc(v);
76750 }
76751
76752 +#ifdef CONFIG_PAX_REFCOUNT
76753 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76754 +{
76755 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76756 +
76757 + atomic_inc_unchecked(v);
76758 +}
76759 +#endif
76760 +
76761 static inline void atomic_long_dec(atomic_long_t *l)
76762 {
76763 atomic_t *v = (atomic_t *)l;
76764 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76765 atomic_dec(v);
76766 }
76767
76768 +#ifdef CONFIG_PAX_REFCOUNT
76769 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76770 +{
76771 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76772 +
76773 + atomic_dec_unchecked(v);
76774 +}
76775 +#endif
76776 +
76777 static inline void atomic_long_add(long i, atomic_long_t *l)
76778 {
76779 atomic_t *v = (atomic_t *)l;
76780 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76781 atomic_add(i, v);
76782 }
76783
76784 +#ifdef CONFIG_PAX_REFCOUNT
76785 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76786 +{
76787 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76788 +
76789 + atomic_add_unchecked(i, v);
76790 +}
76791 +#endif
76792 +
76793 static inline void atomic_long_sub(long i, atomic_long_t *l)
76794 {
76795 atomic_t *v = (atomic_t *)l;
76796 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76797 atomic_sub(i, v);
76798 }
76799
76800 +#ifdef CONFIG_PAX_REFCOUNT
76801 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76802 +{
76803 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76804 +
76805 + atomic_sub_unchecked(i, v);
76806 +}
76807 +#endif
76808 +
76809 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76810 {
76811 atomic_t *v = (atomic_t *)l;
76812 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76813 return (long)atomic_add_return(i, v);
76814 }
76815
76816 +#ifdef CONFIG_PAX_REFCOUNT
76817 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76818 +{
76819 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76820 +
76821 + return (long)atomic_add_return_unchecked(i, v);
76822 +}
76823 +
76824 +#endif
76825 +
76826 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76827 {
76828 atomic_t *v = (atomic_t *)l;
76829 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76830 return (long)atomic_inc_return(v);
76831 }
76832
76833 +#ifdef CONFIG_PAX_REFCOUNT
76834 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76835 +{
76836 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76837 +
76838 + return (long)atomic_inc_return_unchecked(v);
76839 +}
76840 +#endif
76841 +
76842 static inline long atomic_long_dec_return(atomic_long_t *l)
76843 {
76844 atomic_t *v = (atomic_t *)l;
76845 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76846
76847 #endif /* BITS_PER_LONG == 64 */
76848
76849 +#ifdef CONFIG_PAX_REFCOUNT
76850 +static inline void pax_refcount_needs_these_functions(void)
76851 +{
76852 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76853 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76854 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76855 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76856 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76857 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76858 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76859 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76860 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76861 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76862 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76863 +#ifdef CONFIG_X86
76864 + atomic_clear_mask_unchecked(0, NULL);
76865 + atomic_set_mask_unchecked(0, NULL);
76866 +#endif
76867 +
76868 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76869 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76870 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76871 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76872 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76873 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76874 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76875 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76876 +}
76877 +#else
76878 +#define atomic_read_unchecked(v) atomic_read(v)
76879 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76880 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76881 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76882 +#define atomic_inc_unchecked(v) atomic_inc(v)
76883 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76884 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76885 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76886 +#define atomic_dec_unchecked(v) atomic_dec(v)
76887 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76888 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76889 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76890 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76891 +
76892 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76893 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76894 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76895 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76896 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76897 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76898 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76899 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76900 +#endif
76901 +
76902 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76903 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76904 index 33bd2de..f31bff97 100644
76905 --- a/include/asm-generic/atomic.h
76906 +++ b/include/asm-generic/atomic.h
76907 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76908 * Atomically clears the bits set in @mask from @v
76909 */
76910 #ifndef atomic_clear_mask
76911 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76912 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76913 {
76914 unsigned long flags;
76915
76916 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76917 index b18ce4f..2ee2843 100644
76918 --- a/include/asm-generic/atomic64.h
76919 +++ b/include/asm-generic/atomic64.h
76920 @@ -16,6 +16,8 @@ typedef struct {
76921 long long counter;
76922 } atomic64_t;
76923
76924 +typedef atomic64_t atomic64_unchecked_t;
76925 +
76926 #define ATOMIC64_INIT(i) { (i) }
76927
76928 extern long long atomic64_read(const atomic64_t *v);
76929 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76930 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76931 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76932
76933 +#define atomic64_read_unchecked(v) atomic64_read(v)
76934 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76935 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76936 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76937 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76938 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76939 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76940 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76941 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76942 +
76943 #endif /* _ASM_GENERIC_ATOMIC64_H */
76944 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
76945 index 6f692f8..2ad9dd2 100644
76946 --- a/include/asm-generic/barrier.h
76947 +++ b/include/asm-generic/barrier.h
76948 @@ -66,7 +66,7 @@
76949 do { \
76950 compiletime_assert_atomic_type(*p); \
76951 smp_mb(); \
76952 - ACCESS_ONCE(*p) = (v); \
76953 + ACCESS_ONCE_RW(*p) = (v); \
76954 } while (0)
76955
76956 #define smp_load_acquire(p) \
76957 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76958 index a60a7cc..0fe12f2 100644
76959 --- a/include/asm-generic/bitops/__fls.h
76960 +++ b/include/asm-generic/bitops/__fls.h
76961 @@ -9,7 +9,7 @@
76962 *
76963 * Undefined if no set bit exists, so code should check against 0 first.
76964 */
76965 -static __always_inline unsigned long __fls(unsigned long word)
76966 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76967 {
76968 int num = BITS_PER_LONG - 1;
76969
76970 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76971 index 0576d1f..dad6c71 100644
76972 --- a/include/asm-generic/bitops/fls.h
76973 +++ b/include/asm-generic/bitops/fls.h
76974 @@ -9,7 +9,7 @@
76975 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76976 */
76977
76978 -static __always_inline int fls(int x)
76979 +static __always_inline int __intentional_overflow(-1) fls(int x)
76980 {
76981 int r = 32;
76982
76983 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76984 index b097cf8..3d40e14 100644
76985 --- a/include/asm-generic/bitops/fls64.h
76986 +++ b/include/asm-generic/bitops/fls64.h
76987 @@ -15,7 +15,7 @@
76988 * at position 64.
76989 */
76990 #if BITS_PER_LONG == 32
76991 -static __always_inline int fls64(__u64 x)
76992 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76993 {
76994 __u32 h = x >> 32;
76995 if (h)
76996 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76997 return fls(x);
76998 }
76999 #elif BITS_PER_LONG == 64
77000 -static __always_inline int fls64(__u64 x)
77001 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77002 {
77003 if (x == 0)
77004 return 0;
77005 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77006 index 1bfcfe5..e04c5c9 100644
77007 --- a/include/asm-generic/cache.h
77008 +++ b/include/asm-generic/cache.h
77009 @@ -6,7 +6,7 @@
77010 * cache lines need to provide their own cache.h.
77011 */
77012
77013 -#define L1_CACHE_SHIFT 5
77014 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77015 +#define L1_CACHE_SHIFT 5UL
77016 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77017
77018 #endif /* __ASM_GENERIC_CACHE_H */
77019 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77020 index 0d68a1e..b74a761 100644
77021 --- a/include/asm-generic/emergency-restart.h
77022 +++ b/include/asm-generic/emergency-restart.h
77023 @@ -1,7 +1,7 @@
77024 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77025 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77026
77027 -static inline void machine_emergency_restart(void)
77028 +static inline __noreturn void machine_emergency_restart(void)
77029 {
77030 machine_restart(NULL);
77031 }
77032 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77033 index 975e1cc..0b8a083 100644
77034 --- a/include/asm-generic/io.h
77035 +++ b/include/asm-generic/io.h
77036 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77037 * These are pretty trivial
77038 */
77039 #ifndef virt_to_phys
77040 -static inline unsigned long virt_to_phys(volatile void *address)
77041 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77042 {
77043 return __pa((unsigned long)address);
77044 }
77045 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77046 index 90f99c7..00ce236 100644
77047 --- a/include/asm-generic/kmap_types.h
77048 +++ b/include/asm-generic/kmap_types.h
77049 @@ -2,9 +2,9 @@
77050 #define _ASM_GENERIC_KMAP_TYPES_H
77051
77052 #ifdef __WITH_KM_FENCE
77053 -# define KM_TYPE_NR 41
77054 +# define KM_TYPE_NR 42
77055 #else
77056 -# define KM_TYPE_NR 20
77057 +# define KM_TYPE_NR 21
77058 #endif
77059
77060 #endif
77061 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77062 index 9ceb03b..62b0b8f 100644
77063 --- a/include/asm-generic/local.h
77064 +++ b/include/asm-generic/local.h
77065 @@ -23,24 +23,37 @@ typedef struct
77066 atomic_long_t a;
77067 } local_t;
77068
77069 +typedef struct {
77070 + atomic_long_unchecked_t a;
77071 +} local_unchecked_t;
77072 +
77073 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77074
77075 #define local_read(l) atomic_long_read(&(l)->a)
77076 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77077 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77078 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77079 #define local_inc(l) atomic_long_inc(&(l)->a)
77080 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77081 #define local_dec(l) atomic_long_dec(&(l)->a)
77082 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77083 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77084 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77085 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77086 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77087
77088 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77089 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77090 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77091 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77092 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77093 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77094 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77095 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77096 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77097
77098 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77099 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77100 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77101 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77102 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77103 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77104 index 725612b..9cc513a 100644
77105 --- a/include/asm-generic/pgtable-nopmd.h
77106 +++ b/include/asm-generic/pgtable-nopmd.h
77107 @@ -1,14 +1,19 @@
77108 #ifndef _PGTABLE_NOPMD_H
77109 #define _PGTABLE_NOPMD_H
77110
77111 -#ifndef __ASSEMBLY__
77112 -
77113 #include <asm-generic/pgtable-nopud.h>
77114
77115 -struct mm_struct;
77116 -
77117 #define __PAGETABLE_PMD_FOLDED
77118
77119 +#define PMD_SHIFT PUD_SHIFT
77120 +#define PTRS_PER_PMD 1
77121 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77122 +#define PMD_MASK (~(PMD_SIZE-1))
77123 +
77124 +#ifndef __ASSEMBLY__
77125 +
77126 +struct mm_struct;
77127 +
77128 /*
77129 * Having the pmd type consist of a pud gets the size right, and allows
77130 * us to conceptually access the pud entry that this pmd is folded into
77131 @@ -16,11 +21,6 @@ struct mm_struct;
77132 */
77133 typedef struct { pud_t pud; } pmd_t;
77134
77135 -#define PMD_SHIFT PUD_SHIFT
77136 -#define PTRS_PER_PMD 1
77137 -#define PMD_SIZE (1UL << PMD_SHIFT)
77138 -#define PMD_MASK (~(PMD_SIZE-1))
77139 -
77140 /*
77141 * The "pud_xxx()" functions here are trivial for a folded two-level
77142 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77143 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77144 index 810431d..0ec4804f 100644
77145 --- a/include/asm-generic/pgtable-nopud.h
77146 +++ b/include/asm-generic/pgtable-nopud.h
77147 @@ -1,10 +1,15 @@
77148 #ifndef _PGTABLE_NOPUD_H
77149 #define _PGTABLE_NOPUD_H
77150
77151 -#ifndef __ASSEMBLY__
77152 -
77153 #define __PAGETABLE_PUD_FOLDED
77154
77155 +#define PUD_SHIFT PGDIR_SHIFT
77156 +#define PTRS_PER_PUD 1
77157 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77158 +#define PUD_MASK (~(PUD_SIZE-1))
77159 +
77160 +#ifndef __ASSEMBLY__
77161 +
77162 /*
77163 * Having the pud type consist of a pgd gets the size right, and allows
77164 * us to conceptually access the pgd entry that this pud is folded into
77165 @@ -12,11 +17,6 @@
77166 */
77167 typedef struct { pgd_t pgd; } pud_t;
77168
77169 -#define PUD_SHIFT PGDIR_SHIFT
77170 -#define PTRS_PER_PUD 1
77171 -#define PUD_SIZE (1UL << PUD_SHIFT)
77172 -#define PUD_MASK (~(PUD_SIZE-1))
77173 -
77174 /*
77175 * The "pgd_xxx()" functions here are trivial for a folded two-level
77176 * setup: the pud is never bad, and a pud always exists (as it's folded
77177 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77178 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77179
77180 #define pgd_populate(mm, pgd, pud) do { } while (0)
77181 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77182 /*
77183 * (puds are folded into pgds so this doesn't get actually called,
77184 * but the define is needed for a generic inline function.)
77185 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77186 index a8015a7..7a4407b 100644
77187 --- a/include/asm-generic/pgtable.h
77188 +++ b/include/asm-generic/pgtable.h
77189 @@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77190 }
77191 #endif /* CONFIG_NUMA_BALANCING */
77192
77193 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77194 +#ifdef CONFIG_PAX_KERNEXEC
77195 +#error KERNEXEC requires pax_open_kernel
77196 +#else
77197 +static inline unsigned long pax_open_kernel(void) { return 0; }
77198 +#endif
77199 +#endif
77200 +
77201 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77202 +#ifdef CONFIG_PAX_KERNEXEC
77203 +#error KERNEXEC requires pax_close_kernel
77204 +#else
77205 +static inline unsigned long pax_close_kernel(void) { return 0; }
77206 +#endif
77207 +#endif
77208 +
77209 #endif /* CONFIG_MMU */
77210
77211 #endif /* !__ASSEMBLY__ */
77212 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77213 index 72d8803..cb9749c 100644
77214 --- a/include/asm-generic/uaccess.h
77215 +++ b/include/asm-generic/uaccess.h
77216 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77217 return __clear_user(to, n);
77218 }
77219
77220 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77221 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77222 +#error UDEREF requires pax_open_userland
77223 +#else
77224 +static inline unsigned long pax_open_userland(void) { return 0; }
77225 +#endif
77226 +#endif
77227 +
77228 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77229 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77230 +#error UDEREF requires pax_close_userland
77231 +#else
77232 +static inline unsigned long pax_close_userland(void) { return 0; }
77233 +#endif
77234 +#endif
77235 +
77236 #endif /* __ASM_GENERIC_UACCESS_H */
77237 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77238 index 146e4ff..f4f9609 100644
77239 --- a/include/asm-generic/vmlinux.lds.h
77240 +++ b/include/asm-generic/vmlinux.lds.h
77241 @@ -251,6 +251,7 @@
77242 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77243 VMLINUX_SYMBOL(__start_rodata) = .; \
77244 *(.rodata) *(.rodata.*) \
77245 + *(.data..read_only) \
77246 *(__vermagic) /* Kernel version magic */ \
77247 . = ALIGN(8); \
77248 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77249 @@ -737,17 +738,18 @@
77250 * section in the linker script will go there too. @phdr should have
77251 * a leading colon.
77252 *
77253 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77254 + * Note that this macros defines per_cpu_load as an absolute symbol.
77255 * If there is no need to put the percpu section at a predetermined
77256 * address, use PERCPU_SECTION.
77257 */
77258 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77259 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77260 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77261 + per_cpu_load = .; \
77262 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77263 - LOAD_OFFSET) { \
77264 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77265 PERCPU_INPUT(cacheline) \
77266 } phdr \
77267 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77268 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77269
77270 /**
77271 * PERCPU_SECTION - define output section for percpu area, simple version
77272 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77273 index 016c2f1..c4baa98 100644
77274 --- a/include/crypto/algapi.h
77275 +++ b/include/crypto/algapi.h
77276 @@ -34,7 +34,7 @@ struct crypto_type {
77277 unsigned int maskclear;
77278 unsigned int maskset;
77279 unsigned int tfmsize;
77280 -};
77281 +} __do_const;
77282
77283 struct crypto_instance {
77284 struct crypto_alg alg;
77285 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77286 index a7c2a86..078f1b6 100644
77287 --- a/include/drm/drmP.h
77288 +++ b/include/drm/drmP.h
77289 @@ -68,6 +68,7 @@
77290 #include <linux/workqueue.h>
77291 #include <linux/poll.h>
77292 #include <asm/pgalloc.h>
77293 +#include <asm/local.h>
77294 #include <drm/drm.h>
77295 #include <drm/drm_sarea.h>
77296 #include <drm/drm_vma_manager.h>
77297 @@ -268,10 +269,12 @@ do { \
77298 * \param cmd command.
77299 * \param arg argument.
77300 */
77301 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77302 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77303 + struct drm_file *file_priv);
77304 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77305 struct drm_file *file_priv);
77306
77307 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77308 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77309 unsigned long arg);
77310
77311 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77312 @@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77313 struct drm_ioctl_desc {
77314 unsigned int cmd;
77315 int flags;
77316 - drm_ioctl_t *func;
77317 + drm_ioctl_t func;
77318 unsigned int cmd_drv;
77319 const char *name;
77320 -};
77321 +} __do_const;
77322
77323 /**
77324 * Creates a driver or general drm_ioctl_desc array entry for the given
77325 @@ -1001,7 +1004,8 @@ struct drm_info_list {
77326 int (*show)(struct seq_file*, void*); /** show callback */
77327 u32 driver_features; /**< Required driver features for this entry */
77328 void *data;
77329 -};
77330 +} __do_const;
77331 +typedef struct drm_info_list __no_const drm_info_list_no_const;
77332
77333 /**
77334 * debugfs node structure. This structure represents a debugfs file.
77335 @@ -1083,7 +1087,7 @@ struct drm_device {
77336
77337 /** \name Usage Counters */
77338 /*@{ */
77339 - int open_count; /**< Outstanding files open */
77340 + local_t open_count; /**< Outstanding files open */
77341 int buf_use; /**< Buffers in use -- cannot alloc */
77342 atomic_t buf_alloc; /**< Buffer allocation in progress */
77343 /*@} */
77344 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77345 index 36a5feb..d9f01aa 100644
77346 --- a/include/drm/drm_crtc_helper.h
77347 +++ b/include/drm/drm_crtc_helper.h
77348 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77349 struct drm_connector *connector);
77350 /* disable encoder when not in use - more explicit than dpms off */
77351 void (*disable)(struct drm_encoder *encoder);
77352 -};
77353 +} __no_const;
77354
77355 /**
77356 * drm_connector_helper_funcs - helper operations for connectors
77357 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77358 index 012d58f..d0a0642 100644
77359 --- a/include/drm/i915_pciids.h
77360 +++ b/include/drm/i915_pciids.h
77361 @@ -37,7 +37,7 @@
77362 */
77363 #define INTEL_VGA_DEVICE(id, info) { \
77364 0x8086, id, \
77365 - ~0, ~0, \
77366 + PCI_ANY_ID, PCI_ANY_ID, \
77367 0x030000, 0xff0000, \
77368 (unsigned long) info }
77369
77370 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77371 index 72dcbe8..8db58d7 100644
77372 --- a/include/drm/ttm/ttm_memory.h
77373 +++ b/include/drm/ttm/ttm_memory.h
77374 @@ -48,7 +48,7 @@
77375
77376 struct ttm_mem_shrink {
77377 int (*do_shrink) (struct ttm_mem_shrink *);
77378 -};
77379 +} __no_const;
77380
77381 /**
77382 * struct ttm_mem_global - Global memory accounting structure.
77383 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77384 index 49a8284..9643967 100644
77385 --- a/include/drm/ttm/ttm_page_alloc.h
77386 +++ b/include/drm/ttm/ttm_page_alloc.h
77387 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77388 */
77389 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77390
77391 +struct device;
77392 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77393 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77394
77395 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77396 index 4b840e8..155d235 100644
77397 --- a/include/keys/asymmetric-subtype.h
77398 +++ b/include/keys/asymmetric-subtype.h
77399 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77400 /* Verify the signature on a key of this subtype (optional) */
77401 int (*verify_signature)(const struct key *key,
77402 const struct public_key_signature *sig);
77403 -};
77404 +} __do_const;
77405
77406 /**
77407 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77408 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77409 index c1da539..1dcec55 100644
77410 --- a/include/linux/atmdev.h
77411 +++ b/include/linux/atmdev.h
77412 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77413 #endif
77414
77415 struct k_atm_aal_stats {
77416 -#define __HANDLE_ITEM(i) atomic_t i
77417 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77418 __AAL_STAT_ITEMS
77419 #undef __HANDLE_ITEM
77420 };
77421 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77422 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77423 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77424 struct module *owner;
77425 -};
77426 +} __do_const ;
77427
77428 struct atmphy_ops {
77429 int (*start)(struct atm_dev *dev);
77430 diff --git a/include/linux/audit.h b/include/linux/audit.h
77431 index 22cfddb..ab759e8 100644
77432 --- a/include/linux/audit.h
77433 +++ b/include/linux/audit.h
77434 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77435 extern unsigned int audit_serial(void);
77436 extern int auditsc_get_stamp(struct audit_context *ctx,
77437 struct timespec *t, unsigned int *serial);
77438 -extern int audit_set_loginuid(kuid_t loginuid);
77439 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77440
77441 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77442 {
77443 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77444 index 61f29e5..e67c658 100644
77445 --- a/include/linux/binfmts.h
77446 +++ b/include/linux/binfmts.h
77447 @@ -44,7 +44,7 @@ struct linux_binprm {
77448 unsigned interp_flags;
77449 unsigned interp_data;
77450 unsigned long loader, exec;
77451 -};
77452 +} __randomize_layout;
77453
77454 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77455 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77456 @@ -73,8 +73,10 @@ struct linux_binfmt {
77457 int (*load_binary)(struct linux_binprm *);
77458 int (*load_shlib)(struct file *);
77459 int (*core_dump)(struct coredump_params *cprm);
77460 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77461 + void (*handle_mmap)(struct file *);
77462 unsigned long min_coredump; /* minimal dump size */
77463 -};
77464 +} __do_const __randomize_layout;
77465
77466 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77467
77468 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77469 index be5fd38..d71192a 100644
77470 --- a/include/linux/bitops.h
77471 +++ b/include/linux/bitops.h
77472 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77473 * @word: value to rotate
77474 * @shift: bits to roll
77475 */
77476 -static inline __u32 rol32(__u32 word, unsigned int shift)
77477 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77478 {
77479 return (word << shift) | (word >> (32 - shift));
77480 }
77481 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77482 * @word: value to rotate
77483 * @shift: bits to roll
77484 */
77485 -static inline __u32 ror32(__u32 word, unsigned int shift)
77486 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77487 {
77488 return (word >> shift) | (word << (32 - shift));
77489 }
77490 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77491 return (__s32)(value << shift) >> shift;
77492 }
77493
77494 -static inline unsigned fls_long(unsigned long l)
77495 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77496 {
77497 if (sizeof(l) == 4)
77498 return fls(l);
77499 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77500 index 0d84981..bb741c0 100644
77501 --- a/include/linux/blkdev.h
77502 +++ b/include/linux/blkdev.h
77503 @@ -1584,7 +1584,7 @@ struct block_device_operations {
77504 /* this callback is with swap_lock and sometimes page table lock held */
77505 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77506 struct module *owner;
77507 -};
77508 +} __do_const;
77509
77510 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77511 unsigned long);
77512 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77513 index afc1343..9735539 100644
77514 --- a/include/linux/blktrace_api.h
77515 +++ b/include/linux/blktrace_api.h
77516 @@ -25,7 +25,7 @@ struct blk_trace {
77517 struct dentry *dropped_file;
77518 struct dentry *msg_file;
77519 struct list_head running_list;
77520 - atomic_t dropped;
77521 + atomic_unchecked_t dropped;
77522 };
77523
77524 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77525 diff --git a/include/linux/cache.h b/include/linux/cache.h
77526 index 17e7e82..1d7da26 100644
77527 --- a/include/linux/cache.h
77528 +++ b/include/linux/cache.h
77529 @@ -16,6 +16,14 @@
77530 #define __read_mostly
77531 #endif
77532
77533 +#ifndef __read_only
77534 +#ifdef CONFIG_PAX_KERNEXEC
77535 +#error KERNEXEC requires __read_only
77536 +#else
77537 +#define __read_only __read_mostly
77538 +#endif
77539 +#endif
77540 +
77541 #ifndef ____cacheline_aligned
77542 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77543 #endif
77544 diff --git a/include/linux/capability.h b/include/linux/capability.h
77545 index 84b13ad..172cdee 100644
77546 --- a/include/linux/capability.h
77547 +++ b/include/linux/capability.h
77548 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77549 extern bool capable(int cap);
77550 extern bool ns_capable(struct user_namespace *ns, int cap);
77551 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77552 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77553 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77554 +extern bool capable_nolog(int cap);
77555 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77556
77557 /* audit system wants to get cap info from files as well */
77558 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77559
77560 +extern int is_privileged_binary(const struct dentry *dentry);
77561 +
77562 #endif /* !_LINUX_CAPABILITY_H */
77563 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77564 index 8609d57..86e4d79 100644
77565 --- a/include/linux/cdrom.h
77566 +++ b/include/linux/cdrom.h
77567 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77568
77569 /* driver specifications */
77570 const int capability; /* capability flags */
77571 - int n_minors; /* number of active minor devices */
77572 /* handle uniform packets for scsi type devices (scsi,atapi) */
77573 int (*generic_packet) (struct cdrom_device_info *,
77574 struct packet_command *);
77575 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77576 index 4ce9056..86caac6 100644
77577 --- a/include/linux/cleancache.h
77578 +++ b/include/linux/cleancache.h
77579 @@ -31,7 +31,7 @@ struct cleancache_ops {
77580 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77581 void (*invalidate_inode)(int, struct cleancache_filekey);
77582 void (*invalidate_fs)(int);
77583 -};
77584 +} __no_const;
77585
77586 extern struct cleancache_ops *
77587 cleancache_register_ops(struct cleancache_ops *ops);
77588 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77589 index 5119174..8e264f8 100644
77590 --- a/include/linux/clk-provider.h
77591 +++ b/include/linux/clk-provider.h
77592 @@ -174,6 +174,7 @@ struct clk_ops {
77593 void (*init)(struct clk_hw *hw);
77594 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77595 };
77596 +typedef struct clk_ops __no_const clk_ops_no_const;
77597
77598 /**
77599 * struct clk_init_data - holds init data that's common to all clocks and is
77600 diff --git a/include/linux/compat.h b/include/linux/compat.h
77601 index e649426..a74047b 100644
77602 --- a/include/linux/compat.h
77603 +++ b/include/linux/compat.h
77604 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77605 compat_size_t __user *len_ptr);
77606
77607 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77608 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77609 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77610 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77611 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77612 compat_ssize_t msgsz, int msgflg);
77613 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77614 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77615 compat_ulong_t addr, compat_ulong_t data);
77616 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77617 - compat_long_t addr, compat_long_t data);
77618 + compat_ulong_t addr, compat_ulong_t data);
77619
77620 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77621 /*
77622 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77623 index 2507fd2..55203f8 100644
77624 --- a/include/linux/compiler-gcc4.h
77625 +++ b/include/linux/compiler-gcc4.h
77626 @@ -39,9 +39,34 @@
77627 # define __compiletime_warning(message) __attribute__((warning(message)))
77628 # define __compiletime_error(message) __attribute__((error(message)))
77629 #endif /* __CHECKER__ */
77630 +
77631 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77632 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77633 +#define __bos0(ptr) __bos((ptr), 0)
77634 +#define __bos1(ptr) __bos((ptr), 1)
77635 #endif /* GCC_VERSION >= 40300 */
77636
77637 #if GCC_VERSION >= 40500
77638 +
77639 +#ifdef RANDSTRUCT_PLUGIN
77640 +#define __randomize_layout __attribute__((randomize_layout))
77641 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77642 +#endif
77643 +
77644 +#ifdef CONSTIFY_PLUGIN
77645 +#define __no_const __attribute__((no_const))
77646 +#define __do_const __attribute__((do_const))
77647 +#endif
77648 +
77649 +#ifdef SIZE_OVERFLOW_PLUGIN
77650 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77651 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77652 +#endif
77653 +
77654 +#ifdef LATENT_ENTROPY_PLUGIN
77655 +#define __latent_entropy __attribute__((latent_entropy))
77656 +#endif
77657 +
77658 /*
77659 * Mark a position in code as unreachable. This can be used to
77660 * suppress control flow warnings after asm blocks that transfer
77661 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77662 index ee7239e..7c11769 100644
77663 --- a/include/linux/compiler.h
77664 +++ b/include/linux/compiler.h
77665 @@ -5,11 +5,14 @@
77666
77667 #ifdef __CHECKER__
77668 # define __user __attribute__((noderef, address_space(1)))
77669 +# define __force_user __force __user
77670 # define __kernel __attribute__((address_space(0)))
77671 +# define __force_kernel __force __kernel
77672 # define __safe __attribute__((safe))
77673 # define __force __attribute__((force))
77674 # define __nocast __attribute__((nocast))
77675 # define __iomem __attribute__((noderef, address_space(2)))
77676 +# define __force_iomem __force __iomem
77677 # define __must_hold(x) __attribute__((context(x,1,1)))
77678 # define __acquires(x) __attribute__((context(x,0,1)))
77679 # define __releases(x) __attribute__((context(x,1,0)))
77680 @@ -17,20 +20,37 @@
77681 # define __release(x) __context__(x,-1)
77682 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77683 # define __percpu __attribute__((noderef, address_space(3)))
77684 +# define __force_percpu __force __percpu
77685 #ifdef CONFIG_SPARSE_RCU_POINTER
77686 # define __rcu __attribute__((noderef, address_space(4)))
77687 +# define __force_rcu __force __rcu
77688 #else
77689 # define __rcu
77690 +# define __force_rcu
77691 #endif
77692 extern void __chk_user_ptr(const volatile void __user *);
77693 extern void __chk_io_ptr(const volatile void __iomem *);
77694 #else
77695 -# define __user
77696 -# define __kernel
77697 +# ifdef CHECKER_PLUGIN
77698 +//# define __user
77699 +//# define __force_user
77700 +//# define __kernel
77701 +//# define __force_kernel
77702 +# else
77703 +# ifdef STRUCTLEAK_PLUGIN
77704 +# define __user __attribute__((user))
77705 +# else
77706 +# define __user
77707 +# endif
77708 +# define __force_user
77709 +# define __kernel
77710 +# define __force_kernel
77711 +# endif
77712 # define __safe
77713 # define __force
77714 # define __nocast
77715 # define __iomem
77716 +# define __force_iomem
77717 # define __chk_user_ptr(x) (void)0
77718 # define __chk_io_ptr(x) (void)0
77719 # define __builtin_warning(x, y...) (1)
77720 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77721 # define __release(x) (void)0
77722 # define __cond_lock(x,c) (c)
77723 # define __percpu
77724 +# define __force_percpu
77725 # define __rcu
77726 +# define __force_rcu
77727 #endif
77728
77729 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77730 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77731 # define __attribute_const__ /* unimplemented */
77732 #endif
77733
77734 +#ifndef __randomize_layout
77735 +# define __randomize_layout
77736 +#endif
77737 +
77738 +#ifndef __no_randomize_layout
77739 +# define __no_randomize_layout
77740 +#endif
77741 +
77742 +#ifndef __no_const
77743 +# define __no_const
77744 +#endif
77745 +
77746 +#ifndef __do_const
77747 +# define __do_const
77748 +#endif
77749 +
77750 +#ifndef __size_overflow
77751 +# define __size_overflow(...)
77752 +#endif
77753 +
77754 +#ifndef __intentional_overflow
77755 +# define __intentional_overflow(...)
77756 +#endif
77757 +
77758 +#ifndef __latent_entropy
77759 +# define __latent_entropy
77760 +#endif
77761 +
77762 /*
77763 * Tell gcc if a function is cold. The compiler will assume any path
77764 * directly leading to the call is unlikely.
77765 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77766 #define __cold
77767 #endif
77768
77769 +#ifndef __alloc_size
77770 +#define __alloc_size(...)
77771 +#endif
77772 +
77773 +#ifndef __bos
77774 +#define __bos(ptr, arg)
77775 +#endif
77776 +
77777 +#ifndef __bos0
77778 +#define __bos0(ptr)
77779 +#endif
77780 +
77781 +#ifndef __bos1
77782 +#define __bos1(ptr)
77783 +#endif
77784 +
77785 /* Simple shorthand for a section definition */
77786 #ifndef __section
77787 # define __section(S) __attribute__ ((__section__(#S)))
77788 @@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77789 * use is to mediate communication between process-level code and irq/NMI
77790 * handlers, all running on the same CPU.
77791 */
77792 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77793 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77794 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77795
77796 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77797 #ifdef CONFIG_KPROBES
77798 diff --git a/include/linux/completion.h b/include/linux/completion.h
77799 index 5d5aaae..0ea9b84 100644
77800 --- a/include/linux/completion.h
77801 +++ b/include/linux/completion.h
77802 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77803
77804 extern void wait_for_completion(struct completion *);
77805 extern void wait_for_completion_io(struct completion *);
77806 -extern int wait_for_completion_interruptible(struct completion *x);
77807 -extern int wait_for_completion_killable(struct completion *x);
77808 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77809 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77810 extern unsigned long wait_for_completion_timeout(struct completion *x,
77811 - unsigned long timeout);
77812 + unsigned long timeout) __intentional_overflow(-1);
77813 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77814 - unsigned long timeout);
77815 + unsigned long timeout) __intentional_overflow(-1);
77816 extern long wait_for_completion_interruptible_timeout(
77817 - struct completion *x, unsigned long timeout);
77818 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77819 extern long wait_for_completion_killable_timeout(
77820 - struct completion *x, unsigned long timeout);
77821 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77822 extern bool try_wait_for_completion(struct completion *x);
77823 extern bool completion_done(struct completion *x);
77824
77825 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77826 index 34025df..d94bbbc 100644
77827 --- a/include/linux/configfs.h
77828 +++ b/include/linux/configfs.h
77829 @@ -125,7 +125,7 @@ struct configfs_attribute {
77830 const char *ca_name;
77831 struct module *ca_owner;
77832 umode_t ca_mode;
77833 -};
77834 +} __do_const;
77835
77836 /*
77837 * Users often need to create attribute structures for their configurable
77838 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77839 index 5ae5100..b809662 100644
77840 --- a/include/linux/cpufreq.h
77841 +++ b/include/linux/cpufreq.h
77842 @@ -200,6 +200,7 @@ struct global_attr {
77843 ssize_t (*store)(struct kobject *a, struct attribute *b,
77844 const char *c, size_t count);
77845 };
77846 +typedef struct global_attr __no_const global_attr_no_const;
77847
77848 #define define_one_global_ro(_name) \
77849 static struct global_attr _name = \
77850 @@ -242,7 +243,7 @@ struct cpufreq_driver {
77851 bool boost_supported;
77852 bool boost_enabled;
77853 int (*set_boost) (int state);
77854 -};
77855 +} __do_const;
77856
77857 /* flags */
77858 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77859 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77860 index b0238cb..db89e1e 100644
77861 --- a/include/linux/cpuidle.h
77862 +++ b/include/linux/cpuidle.h
77863 @@ -50,7 +50,8 @@ struct cpuidle_state {
77864 int index);
77865
77866 int (*enter_dead) (struct cpuidle_device *dev, int index);
77867 -};
77868 +} __do_const;
77869 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77870
77871 /* Idle State Flags */
77872 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77873 @@ -211,7 +212,7 @@ struct cpuidle_governor {
77874 void (*reflect) (struct cpuidle_device *dev, int index);
77875
77876 struct module *owner;
77877 -};
77878 +} __do_const;
77879
77880 #ifdef CONFIG_CPU_IDLE
77881 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77882 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77883 index d08e4d2..95fad61 100644
77884 --- a/include/linux/cpumask.h
77885 +++ b/include/linux/cpumask.h
77886 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77887 }
77888
77889 /* Valid inputs for n are -1 and 0. */
77890 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77891 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77892 {
77893 return n+1;
77894 }
77895
77896 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77897 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77898 {
77899 return n+1;
77900 }
77901
77902 -static inline unsigned int cpumask_next_and(int n,
77903 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77904 const struct cpumask *srcp,
77905 const struct cpumask *andp)
77906 {
77907 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77908 *
77909 * Returns >= nr_cpu_ids if no further cpus set.
77910 */
77911 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77912 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77913 {
77914 /* -1 is a legal arg here. */
77915 if (n != -1)
77916 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77917 *
77918 * Returns >= nr_cpu_ids if no further cpus unset.
77919 */
77920 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77921 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77922 {
77923 /* -1 is a legal arg here. */
77924 if (n != -1)
77925 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77926 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77927 }
77928
77929 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77930 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77931 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77932
77933 /**
77934 diff --git a/include/linux/cred.h b/include/linux/cred.h
77935 index f61d6c8..d372d95 100644
77936 --- a/include/linux/cred.h
77937 +++ b/include/linux/cred.h
77938 @@ -35,7 +35,7 @@ struct group_info {
77939 int nblocks;
77940 kgid_t small_block[NGROUPS_SMALL];
77941 kgid_t *blocks[0];
77942 -};
77943 +} __randomize_layout;
77944
77945 /**
77946 * get_group_info - Get a reference to a group info structure
77947 @@ -136,7 +136,7 @@ struct cred {
77948 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77949 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77950 struct rcu_head rcu; /* RCU deletion hook */
77951 -};
77952 +} __randomize_layout;
77953
77954 extern void __put_cred(struct cred *);
77955 extern void exit_creds(struct task_struct *);
77956 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77957 static inline void validate_process_creds(void)
77958 {
77959 }
77960 +static inline void validate_task_creds(struct task_struct *task)
77961 +{
77962 +}
77963 #endif
77964
77965 /**
77966 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
77967
77968 #define task_uid(task) (task_cred_xxx((task), uid))
77969 #define task_euid(task) (task_cred_xxx((task), euid))
77970 +#define task_securebits(task) (task_cred_xxx((task), securebits))
77971
77972 #define current_cred_xxx(xxx) \
77973 ({ \
77974 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77975 index b92eadf..b4ecdc1 100644
77976 --- a/include/linux/crypto.h
77977 +++ b/include/linux/crypto.h
77978 @@ -373,7 +373,7 @@ struct cipher_tfm {
77979 const u8 *key, unsigned int keylen);
77980 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77981 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77982 -};
77983 +} __no_const;
77984
77985 struct hash_tfm {
77986 int (*init)(struct hash_desc *desc);
77987 @@ -394,13 +394,13 @@ struct compress_tfm {
77988 int (*cot_decompress)(struct crypto_tfm *tfm,
77989 const u8 *src, unsigned int slen,
77990 u8 *dst, unsigned int *dlen);
77991 -};
77992 +} __no_const;
77993
77994 struct rng_tfm {
77995 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77996 unsigned int dlen);
77997 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77998 -};
77999 +} __no_const;
78000
78001 #define crt_ablkcipher crt_u.ablkcipher
78002 #define crt_aead crt_u.aead
78003 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78004 index 653589e..4ef254a 100644
78005 --- a/include/linux/ctype.h
78006 +++ b/include/linux/ctype.h
78007 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78008 * Fast implementation of tolower() for internal usage. Do not use in your
78009 * code.
78010 */
78011 -static inline char _tolower(const char c)
78012 +static inline unsigned char _tolower(const unsigned char c)
78013 {
78014 return c | 0x20;
78015 }
78016 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78017 index 3c7ec32..4ca97cc 100644
78018 --- a/include/linux/dcache.h
78019 +++ b/include/linux/dcache.h
78020 @@ -133,7 +133,7 @@ struct dentry {
78021 } d_u;
78022 struct list_head d_subdirs; /* our children */
78023 struct hlist_node d_alias; /* inode alias list */
78024 -};
78025 +} __randomize_layout;
78026
78027 /*
78028 * dentry->d_lock spinlock nesting subclasses:
78029 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78030 index 7925bf0..d5143d2 100644
78031 --- a/include/linux/decompress/mm.h
78032 +++ b/include/linux/decompress/mm.h
78033 @@ -77,7 +77,7 @@ static void free(void *where)
78034 * warnings when not needed (indeed large_malloc / large_free are not
78035 * needed by inflate */
78036
78037 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78038 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78039 #define free(a) kfree(a)
78040
78041 #define large_malloc(a) vmalloc(a)
78042 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78043 index d48dc00..211ee54 100644
78044 --- a/include/linux/devfreq.h
78045 +++ b/include/linux/devfreq.h
78046 @@ -114,7 +114,7 @@ struct devfreq_governor {
78047 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78048 int (*event_handler)(struct devfreq *devfreq,
78049 unsigned int event, void *data);
78050 -};
78051 +} __do_const;
78052
78053 /**
78054 * struct devfreq - Device devfreq structure
78055 diff --git a/include/linux/device.h b/include/linux/device.h
78056 index d1d1c05..a90fdb0 100644
78057 --- a/include/linux/device.h
78058 +++ b/include/linux/device.h
78059 @@ -310,7 +310,7 @@ struct subsys_interface {
78060 struct list_head node;
78061 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78062 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78063 -};
78064 +} __do_const;
78065
78066 int subsys_interface_register(struct subsys_interface *sif);
78067 void subsys_interface_unregister(struct subsys_interface *sif);
78068 @@ -506,7 +506,7 @@ struct device_type {
78069 void (*release)(struct device *dev);
78070
78071 const struct dev_pm_ops *pm;
78072 -};
78073 +} __do_const;
78074
78075 /* interface for exporting device attributes */
78076 struct device_attribute {
78077 @@ -516,11 +516,12 @@ struct device_attribute {
78078 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78079 const char *buf, size_t count);
78080 };
78081 +typedef struct device_attribute __no_const device_attribute_no_const;
78082
78083 struct dev_ext_attribute {
78084 struct device_attribute attr;
78085 void *var;
78086 -};
78087 +} __do_const;
78088
78089 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78090 char *buf);
78091 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78092 index fd4aee2..1f28db9 100644
78093 --- a/include/linux/dma-mapping.h
78094 +++ b/include/linux/dma-mapping.h
78095 @@ -54,7 +54,7 @@ struct dma_map_ops {
78096 u64 (*get_required_mask)(struct device *dev);
78097 #endif
78098 int is_phys;
78099 -};
78100 +} __do_const;
78101
78102 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78103
78104 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78105 index 72cb0dd..7fe9a4b 100644
78106 --- a/include/linux/dmaengine.h
78107 +++ b/include/linux/dmaengine.h
78108 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78109 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78110 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78111
78112 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78113 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78114 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78115 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78116 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78117 struct dma_pinned_list *pinned_list, struct page *page,
78118 unsigned int offset, size_t len);
78119
78120 diff --git a/include/linux/efi.h b/include/linux/efi.h
78121 index 6c100ff..e3289b4 100644
78122 --- a/include/linux/efi.h
78123 +++ b/include/linux/efi.h
78124 @@ -1009,6 +1009,7 @@ struct efivar_operations {
78125 efi_set_variable_t *set_variable;
78126 efi_query_variable_store_t *query_variable_store;
78127 };
78128 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78129
78130 struct efivars {
78131 /*
78132 diff --git a/include/linux/elf.h b/include/linux/elf.h
78133 index 67a5fa7..b817372 100644
78134 --- a/include/linux/elf.h
78135 +++ b/include/linux/elf.h
78136 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78137 #define elf_note elf32_note
78138 #define elf_addr_t Elf32_Off
78139 #define Elf_Half Elf32_Half
78140 +#define elf_dyn Elf32_Dyn
78141
78142 #else
78143
78144 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78145 #define elf_note elf64_note
78146 #define elf_addr_t Elf64_Off
78147 #define Elf_Half Elf64_Half
78148 +#define elf_dyn Elf64_Dyn
78149
78150 #endif
78151
78152 diff --git a/include/linux/err.h b/include/linux/err.h
78153 index a729120..6ede2c9 100644
78154 --- a/include/linux/err.h
78155 +++ b/include/linux/err.h
78156 @@ -20,12 +20,12 @@
78157
78158 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78159
78160 -static inline void * __must_check ERR_PTR(long error)
78161 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78162 {
78163 return (void *) error;
78164 }
78165
78166 -static inline long __must_check PTR_ERR(__force const void *ptr)
78167 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78168 {
78169 return (long) ptr;
78170 }
78171 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78172 index f488145..3b6b04e 100644
78173 --- a/include/linux/extcon.h
78174 +++ b/include/linux/extcon.h
78175 @@ -135,7 +135,7 @@ struct extcon_dev {
78176 /* /sys/class/extcon/.../mutually_exclusive/... */
78177 struct attribute_group attr_g_muex;
78178 struct attribute **attrs_muex;
78179 - struct device_attribute *d_attrs_muex;
78180 + device_attribute_no_const *d_attrs_muex;
78181 };
78182
78183 /**
78184 diff --git a/include/linux/fb.h b/include/linux/fb.h
78185 index fe6ac95..898d41d 100644
78186 --- a/include/linux/fb.h
78187 +++ b/include/linux/fb.h
78188 @@ -304,7 +304,7 @@ struct fb_ops {
78189 /* called at KDB enter and leave time to prepare the console */
78190 int (*fb_debug_enter)(struct fb_info *info);
78191 int (*fb_debug_leave)(struct fb_info *info);
78192 -};
78193 +} __do_const;
78194
78195 #ifdef CONFIG_FB_TILEBLITTING
78196 #define FB_TILE_CURSOR_NONE 0
78197 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78198 index 230f87b..1fd0485 100644
78199 --- a/include/linux/fdtable.h
78200 +++ b/include/linux/fdtable.h
78201 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78202 void put_files_struct(struct files_struct *fs);
78203 void reset_files_struct(struct files_struct *);
78204 int unshare_files(struct files_struct **);
78205 -struct files_struct *dup_fd(struct files_struct *, int *);
78206 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78207 void do_close_on_exec(struct files_struct *);
78208 int iterate_fd(struct files_struct *, unsigned,
78209 int (*)(const void *, struct file *, unsigned),
78210 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78211 index 8293262..2b3b8bd 100644
78212 --- a/include/linux/frontswap.h
78213 +++ b/include/linux/frontswap.h
78214 @@ -11,7 +11,7 @@ struct frontswap_ops {
78215 int (*load)(unsigned, pgoff_t, struct page *);
78216 void (*invalidate_page)(unsigned, pgoff_t);
78217 void (*invalidate_area)(unsigned);
78218 -};
78219 +} __no_const;
78220
78221 extern bool frontswap_enabled;
78222 extern struct frontswap_ops *
78223 diff --git a/include/linux/fs.h b/include/linux/fs.h
78224 index 8780312..425cc22 100644
78225 --- a/include/linux/fs.h
78226 +++ b/include/linux/fs.h
78227 @@ -398,7 +398,7 @@ struct address_space {
78228 spinlock_t private_lock; /* for use by the address_space */
78229 struct list_head private_list; /* ditto */
78230 void *private_data; /* ditto */
78231 -} __attribute__((aligned(sizeof(long))));
78232 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78233 /*
78234 * On most architectures that alignment is already the case; but
78235 * must be enforced here for CRIS, to let the least significant bit
78236 @@ -441,7 +441,7 @@ struct block_device {
78237 int bd_fsfreeze_count;
78238 /* Mutex for freeze */
78239 struct mutex bd_fsfreeze_mutex;
78240 -};
78241 +} __randomize_layout;
78242
78243 /*
78244 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78245 @@ -585,7 +585,7 @@ struct inode {
78246 #endif
78247
78248 void *i_private; /* fs or device private pointer */
78249 -};
78250 +} __randomize_layout;
78251
78252 static inline int inode_unhashed(struct inode *inode)
78253 {
78254 @@ -778,7 +778,7 @@ struct file {
78255 struct list_head f_tfile_llink;
78256 #endif /* #ifdef CONFIG_EPOLL */
78257 struct address_space *f_mapping;
78258 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78259 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78260
78261 struct file_handle {
78262 __u32 handle_bytes;
78263 @@ -906,7 +906,7 @@ struct file_lock {
78264 int state; /* state of grant or error if -ve */
78265 } afs;
78266 } fl_u;
78267 -};
78268 +} __randomize_layout;
78269
78270 /* The following constant reflects the upper bound of the file/locking space */
78271 #ifndef OFFSET_MAX
78272 @@ -1255,7 +1255,7 @@ struct super_block {
78273 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78274 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78275 struct rcu_head rcu;
78276 -};
78277 +} __randomize_layout;
78278
78279 extern struct timespec current_fs_time(struct super_block *sb);
78280
78281 @@ -1477,7 +1477,8 @@ struct file_operations {
78282 long (*fallocate)(struct file *file, int mode, loff_t offset,
78283 loff_t len);
78284 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78285 -};
78286 +} __do_const __randomize_layout;
78287 +typedef struct file_operations __no_const file_operations_no_const;
78288
78289 struct inode_operations {
78290 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78291 @@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78292 return !IS_DEADDIR(inode);
78293 }
78294
78295 +static inline bool is_sidechannel_device(const struct inode *inode)
78296 +{
78297 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78298 + umode_t mode = inode->i_mode;
78299 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78300 +#else
78301 + return false;
78302 +#endif
78303 +}
78304 +
78305 #endif /* _LINUX_FS_H */
78306 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78307 index 0efc3e6..fd23610 100644
78308 --- a/include/linux/fs_struct.h
78309 +++ b/include/linux/fs_struct.h
78310 @@ -6,13 +6,13 @@
78311 #include <linux/seqlock.h>
78312
78313 struct fs_struct {
78314 - int users;
78315 + atomic_t users;
78316 spinlock_t lock;
78317 seqcount_t seq;
78318 int umask;
78319 int in_exec;
78320 struct path root, pwd;
78321 -};
78322 +} __randomize_layout;
78323
78324 extern struct kmem_cache *fs_cachep;
78325
78326 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78327 index 7714849..a4a5c7a 100644
78328 --- a/include/linux/fscache-cache.h
78329 +++ b/include/linux/fscache-cache.h
78330 @@ -113,7 +113,7 @@ struct fscache_operation {
78331 fscache_operation_release_t release;
78332 };
78333
78334 -extern atomic_t fscache_op_debug_id;
78335 +extern atomic_unchecked_t fscache_op_debug_id;
78336 extern void fscache_op_work_func(struct work_struct *work);
78337
78338 extern void fscache_enqueue_operation(struct fscache_operation *);
78339 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78340 INIT_WORK(&op->work, fscache_op_work_func);
78341 atomic_set(&op->usage, 1);
78342 op->state = FSCACHE_OP_ST_INITIALISED;
78343 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78344 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78345 op->processor = processor;
78346 op->release = release;
78347 INIT_LIST_HEAD(&op->pend_link);
78348 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78349 index 115bb81..e7b812b 100644
78350 --- a/include/linux/fscache.h
78351 +++ b/include/linux/fscache.h
78352 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
78353 * - this is mandatory for any object that may have data
78354 */
78355 void (*now_uncached)(void *cookie_netfs_data);
78356 -};
78357 +} __do_const;
78358
78359 /*
78360 * fscache cached network filesystem type
78361 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78362 index 1c804b0..1432c2b 100644
78363 --- a/include/linux/fsnotify.h
78364 +++ b/include/linux/fsnotify.h
78365 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78366 struct inode *inode = file_inode(file);
78367 __u32 mask = FS_ACCESS;
78368
78369 + if (is_sidechannel_device(inode))
78370 + return;
78371 +
78372 if (S_ISDIR(inode->i_mode))
78373 mask |= FS_ISDIR;
78374
78375 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78376 struct inode *inode = file_inode(file);
78377 __u32 mask = FS_MODIFY;
78378
78379 + if (is_sidechannel_device(inode))
78380 + return;
78381 +
78382 if (S_ISDIR(inode->i_mode))
78383 mask |= FS_ISDIR;
78384
78385 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78386 */
78387 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78388 {
78389 - return kstrdup(name, GFP_KERNEL);
78390 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78391 }
78392
78393 /*
78394 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78395 index 9f3c275..8bdff5d 100644
78396 --- a/include/linux/genhd.h
78397 +++ b/include/linux/genhd.h
78398 @@ -194,7 +194,7 @@ struct gendisk {
78399 struct kobject *slave_dir;
78400
78401 struct timer_rand_state *random;
78402 - atomic_t sync_io; /* RAID */
78403 + atomic_unchecked_t sync_io; /* RAID */
78404 struct disk_events *ev;
78405 #ifdef CONFIG_BLK_DEV_INTEGRITY
78406 struct blk_integrity *integrity;
78407 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78408 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78409
78410 /* drivers/char/random.c */
78411 -extern void add_disk_randomness(struct gendisk *disk);
78412 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78413 extern void rand_initialize_disk(struct gendisk *disk);
78414
78415 static inline sector_t get_start_sect(struct block_device *bdev)
78416 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78417 index c0894dd..2fbf10c 100644
78418 --- a/include/linux/genl_magic_func.h
78419 +++ b/include/linux/genl_magic_func.h
78420 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78421 },
78422
78423 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78424 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78425 +static struct genl_ops ZZZ_genl_ops[] = {
78426 #include GENL_MAGIC_INCLUDE_FILE
78427 };
78428
78429 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78430 index 39b81dc..819dc51 100644
78431 --- a/include/linux/gfp.h
78432 +++ b/include/linux/gfp.h
78433 @@ -36,6 +36,13 @@ struct vm_area_struct;
78434 #define ___GFP_NO_KSWAPD 0x400000u
78435 #define ___GFP_OTHER_NODE 0x800000u
78436 #define ___GFP_WRITE 0x1000000u
78437 +
78438 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78439 +#define ___GFP_USERCOPY 0x2000000u
78440 +#else
78441 +#define ___GFP_USERCOPY 0
78442 +#endif
78443 +
78444 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78445
78446 /*
78447 @@ -93,6 +100,7 @@ struct vm_area_struct;
78448 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78449 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78450 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78451 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78452
78453 /*
78454 * This may seem redundant, but it's a way of annotating false positives vs.
78455 @@ -100,7 +108,7 @@ struct vm_area_struct;
78456 */
78457 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78458
78459 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78460 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78461 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78462
78463 /* This equals 0, but use constants in case they ever change */
78464 @@ -158,6 +166,8 @@ struct vm_area_struct;
78465 /* 4GB DMA on some platforms */
78466 #define GFP_DMA32 __GFP_DMA32
78467
78468 +#define GFP_USERCOPY __GFP_USERCOPY
78469 +
78470 /* Convert GFP flags to their corresponding migrate type */
78471 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78472 {
78473 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78474 new file mode 100644
78475 index 0000000..edb2cb6
78476 --- /dev/null
78477 +++ b/include/linux/gracl.h
78478 @@ -0,0 +1,340 @@
78479 +#ifndef GR_ACL_H
78480 +#define GR_ACL_H
78481 +
78482 +#include <linux/grdefs.h>
78483 +#include <linux/resource.h>
78484 +#include <linux/capability.h>
78485 +#include <linux/dcache.h>
78486 +#include <asm/resource.h>
78487 +
78488 +/* Major status information */
78489 +
78490 +#define GR_VERSION "grsecurity 3.0"
78491 +#define GRSECURITY_VERSION 0x3000
78492 +
78493 +enum {
78494 + GR_SHUTDOWN = 0,
78495 + GR_ENABLE = 1,
78496 + GR_SPROLE = 2,
78497 + GR_OLDRELOAD = 3,
78498 + GR_SEGVMOD = 4,
78499 + GR_STATUS = 5,
78500 + GR_UNSPROLE = 6,
78501 + GR_PASSSET = 7,
78502 + GR_SPROLEPAM = 8,
78503 + GR_RELOAD = 9,
78504 +};
78505 +
78506 +/* Password setup definitions
78507 + * kernel/grhash.c */
78508 +enum {
78509 + GR_PW_LEN = 128,
78510 + GR_SALT_LEN = 16,
78511 + GR_SHA_LEN = 32,
78512 +};
78513 +
78514 +enum {
78515 + GR_SPROLE_LEN = 64,
78516 +};
78517 +
78518 +enum {
78519 + GR_NO_GLOB = 0,
78520 + GR_REG_GLOB,
78521 + GR_CREATE_GLOB
78522 +};
78523 +
78524 +#define GR_NLIMITS 32
78525 +
78526 +/* Begin Data Structures */
78527 +
78528 +struct sprole_pw {
78529 + unsigned char *rolename;
78530 + unsigned char salt[GR_SALT_LEN];
78531 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78532 +};
78533 +
78534 +struct name_entry {
78535 + __u32 key;
78536 + ino_t inode;
78537 + dev_t device;
78538 + char *name;
78539 + __u16 len;
78540 + __u8 deleted;
78541 + struct name_entry *prev;
78542 + struct name_entry *next;
78543 +};
78544 +
78545 +struct inodev_entry {
78546 + struct name_entry *nentry;
78547 + struct inodev_entry *prev;
78548 + struct inodev_entry *next;
78549 +};
78550 +
78551 +struct acl_role_db {
78552 + struct acl_role_label **r_hash;
78553 + __u32 r_size;
78554 +};
78555 +
78556 +struct inodev_db {
78557 + struct inodev_entry **i_hash;
78558 + __u32 i_size;
78559 +};
78560 +
78561 +struct name_db {
78562 + struct name_entry **n_hash;
78563 + __u32 n_size;
78564 +};
78565 +
78566 +struct crash_uid {
78567 + uid_t uid;
78568 + unsigned long expires;
78569 +};
78570 +
78571 +struct gr_hash_struct {
78572 + void **table;
78573 + void **nametable;
78574 + void *first;
78575 + __u32 table_size;
78576 + __u32 used_size;
78577 + int type;
78578 +};
78579 +
78580 +/* Userspace Grsecurity ACL data structures */
78581 +
78582 +struct acl_subject_label {
78583 + char *filename;
78584 + ino_t inode;
78585 + dev_t device;
78586 + __u32 mode;
78587 + kernel_cap_t cap_mask;
78588 + kernel_cap_t cap_lower;
78589 + kernel_cap_t cap_invert_audit;
78590 +
78591 + struct rlimit res[GR_NLIMITS];
78592 + __u32 resmask;
78593 +
78594 + __u8 user_trans_type;
78595 + __u8 group_trans_type;
78596 + uid_t *user_transitions;
78597 + gid_t *group_transitions;
78598 + __u16 user_trans_num;
78599 + __u16 group_trans_num;
78600 +
78601 + __u32 sock_families[2];
78602 + __u32 ip_proto[8];
78603 + __u32 ip_type;
78604 + struct acl_ip_label **ips;
78605 + __u32 ip_num;
78606 + __u32 inaddr_any_override;
78607 +
78608 + __u32 crashes;
78609 + unsigned long expires;
78610 +
78611 + struct acl_subject_label *parent_subject;
78612 + struct gr_hash_struct *hash;
78613 + struct acl_subject_label *prev;
78614 + struct acl_subject_label *next;
78615 +
78616 + struct acl_object_label **obj_hash;
78617 + __u32 obj_hash_size;
78618 + __u16 pax_flags;
78619 +};
78620 +
78621 +struct role_allowed_ip {
78622 + __u32 addr;
78623 + __u32 netmask;
78624 +
78625 + struct role_allowed_ip *prev;
78626 + struct role_allowed_ip *next;
78627 +};
78628 +
78629 +struct role_transition {
78630 + char *rolename;
78631 +
78632 + struct role_transition *prev;
78633 + struct role_transition *next;
78634 +};
78635 +
78636 +struct acl_role_label {
78637 + char *rolename;
78638 + uid_t uidgid;
78639 + __u16 roletype;
78640 +
78641 + __u16 auth_attempts;
78642 + unsigned long expires;
78643 +
78644 + struct acl_subject_label *root_label;
78645 + struct gr_hash_struct *hash;
78646 +
78647 + struct acl_role_label *prev;
78648 + struct acl_role_label *next;
78649 +
78650 + struct role_transition *transitions;
78651 + struct role_allowed_ip *allowed_ips;
78652 + uid_t *domain_children;
78653 + __u16 domain_child_num;
78654 +
78655 + umode_t umask;
78656 +
78657 + struct acl_subject_label **subj_hash;
78658 + __u32 subj_hash_size;
78659 +};
78660 +
78661 +struct user_acl_role_db {
78662 + struct acl_role_label **r_table;
78663 + __u32 num_pointers; /* Number of allocations to track */
78664 + __u32 num_roles; /* Number of roles */
78665 + __u32 num_domain_children; /* Number of domain children */
78666 + __u32 num_subjects; /* Number of subjects */
78667 + __u32 num_objects; /* Number of objects */
78668 +};
78669 +
78670 +struct acl_object_label {
78671 + char *filename;
78672 + ino_t inode;
78673 + dev_t device;
78674 + __u32 mode;
78675 +
78676 + struct acl_subject_label *nested;
78677 + struct acl_object_label *globbed;
78678 +
78679 + /* next two structures not used */
78680 +
78681 + struct acl_object_label *prev;
78682 + struct acl_object_label *next;
78683 +};
78684 +
78685 +struct acl_ip_label {
78686 + char *iface;
78687 + __u32 addr;
78688 + __u32 netmask;
78689 + __u16 low, high;
78690 + __u8 mode;
78691 + __u32 type;
78692 + __u32 proto[8];
78693 +
78694 + /* next two structures not used */
78695 +
78696 + struct acl_ip_label *prev;
78697 + struct acl_ip_label *next;
78698 +};
78699 +
78700 +struct gr_arg {
78701 + struct user_acl_role_db role_db;
78702 + unsigned char pw[GR_PW_LEN];
78703 + unsigned char salt[GR_SALT_LEN];
78704 + unsigned char sum[GR_SHA_LEN];
78705 + unsigned char sp_role[GR_SPROLE_LEN];
78706 + struct sprole_pw *sprole_pws;
78707 + dev_t segv_device;
78708 + ino_t segv_inode;
78709 + uid_t segv_uid;
78710 + __u16 num_sprole_pws;
78711 + __u16 mode;
78712 +};
78713 +
78714 +struct gr_arg_wrapper {
78715 + struct gr_arg *arg;
78716 + __u32 version;
78717 + __u32 size;
78718 +};
78719 +
78720 +struct subject_map {
78721 + struct acl_subject_label *user;
78722 + struct acl_subject_label *kernel;
78723 + struct subject_map *prev;
78724 + struct subject_map *next;
78725 +};
78726 +
78727 +struct acl_subj_map_db {
78728 + struct subject_map **s_hash;
78729 + __u32 s_size;
78730 +};
78731 +
78732 +struct gr_policy_state {
78733 + struct sprole_pw **acl_special_roles;
78734 + __u16 num_sprole_pws;
78735 + struct acl_role_label *kernel_role;
78736 + struct acl_role_label *role_list;
78737 + struct acl_role_label *default_role;
78738 + struct acl_role_db acl_role_set;
78739 + struct acl_subj_map_db subj_map_set;
78740 + struct name_db name_set;
78741 + struct inodev_db inodev_set;
78742 +};
78743 +
78744 +struct gr_alloc_state {
78745 + unsigned long alloc_stack_next;
78746 + unsigned long alloc_stack_size;
78747 + void **alloc_stack;
78748 +};
78749 +
78750 +struct gr_reload_state {
78751 + struct gr_policy_state oldpolicy;
78752 + struct gr_alloc_state oldalloc;
78753 + struct gr_policy_state newpolicy;
78754 + struct gr_alloc_state newalloc;
78755 + struct gr_policy_state *oldpolicy_ptr;
78756 + struct gr_alloc_state *oldalloc_ptr;
78757 + unsigned char oldmode;
78758 +};
78759 +
78760 +/* End Data Structures Section */
78761 +
78762 +/* Hash functions generated by empirical testing by Brad Spengler
78763 + Makes good use of the low bits of the inode. Generally 0-1 times
78764 + in loop for successful match. 0-3 for unsuccessful match.
78765 + Shift/add algorithm with modulus of table size and an XOR*/
78766 +
78767 +static __inline__ unsigned int
78768 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78769 +{
78770 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78771 +}
78772 +
78773 + static __inline__ unsigned int
78774 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78775 +{
78776 + return ((const unsigned long)userp % sz);
78777 +}
78778 +
78779 +static __inline__ unsigned int
78780 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78781 +{
78782 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78783 +}
78784 +
78785 +static __inline__ unsigned int
78786 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78787 +{
78788 + return full_name_hash((const unsigned char *)name, len) % sz;
78789 +}
78790 +
78791 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78792 + subj = NULL; \
78793 + iter = 0; \
78794 + while (iter < role->subj_hash_size) { \
78795 + if (subj == NULL) \
78796 + subj = role->subj_hash[iter]; \
78797 + if (subj == NULL) { \
78798 + iter++; \
78799 + continue; \
78800 + }
78801 +
78802 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78803 + subj = subj->next; \
78804 + if (subj == NULL) \
78805 + iter++; \
78806 + }
78807 +
78808 +
78809 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78810 + subj = role->hash->first; \
78811 + while (subj != NULL) {
78812 +
78813 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78814 + subj = subj->next; \
78815 + }
78816 +
78817 +#endif
78818 +
78819 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78820 new file mode 100644
78821 index 0000000..33ebd1f
78822 --- /dev/null
78823 +++ b/include/linux/gracl_compat.h
78824 @@ -0,0 +1,156 @@
78825 +#ifndef GR_ACL_COMPAT_H
78826 +#define GR_ACL_COMPAT_H
78827 +
78828 +#include <linux/resource.h>
78829 +#include <asm/resource.h>
78830 +
78831 +struct sprole_pw_compat {
78832 + compat_uptr_t rolename;
78833 + unsigned char salt[GR_SALT_LEN];
78834 + unsigned char sum[GR_SHA_LEN];
78835 +};
78836 +
78837 +struct gr_hash_struct_compat {
78838 + compat_uptr_t table;
78839 + compat_uptr_t nametable;
78840 + compat_uptr_t first;
78841 + __u32 table_size;
78842 + __u32 used_size;
78843 + int type;
78844 +};
78845 +
78846 +struct acl_subject_label_compat {
78847 + compat_uptr_t filename;
78848 + compat_ino_t inode;
78849 + __u32 device;
78850 + __u32 mode;
78851 + kernel_cap_t cap_mask;
78852 + kernel_cap_t cap_lower;
78853 + kernel_cap_t cap_invert_audit;
78854 +
78855 + struct compat_rlimit res[GR_NLIMITS];
78856 + __u32 resmask;
78857 +
78858 + __u8 user_trans_type;
78859 + __u8 group_trans_type;
78860 + compat_uptr_t user_transitions;
78861 + compat_uptr_t group_transitions;
78862 + __u16 user_trans_num;
78863 + __u16 group_trans_num;
78864 +
78865 + __u32 sock_families[2];
78866 + __u32 ip_proto[8];
78867 + __u32 ip_type;
78868 + compat_uptr_t ips;
78869 + __u32 ip_num;
78870 + __u32 inaddr_any_override;
78871 +
78872 + __u32 crashes;
78873 + compat_ulong_t expires;
78874 +
78875 + compat_uptr_t parent_subject;
78876 + compat_uptr_t hash;
78877 + compat_uptr_t prev;
78878 + compat_uptr_t next;
78879 +
78880 + compat_uptr_t obj_hash;
78881 + __u32 obj_hash_size;
78882 + __u16 pax_flags;
78883 +};
78884 +
78885 +struct role_allowed_ip_compat {
78886 + __u32 addr;
78887 + __u32 netmask;
78888 +
78889 + compat_uptr_t prev;
78890 + compat_uptr_t next;
78891 +};
78892 +
78893 +struct role_transition_compat {
78894 + compat_uptr_t rolename;
78895 +
78896 + compat_uptr_t prev;
78897 + compat_uptr_t next;
78898 +};
78899 +
78900 +struct acl_role_label_compat {
78901 + compat_uptr_t rolename;
78902 + uid_t uidgid;
78903 + __u16 roletype;
78904 +
78905 + __u16 auth_attempts;
78906 + compat_ulong_t expires;
78907 +
78908 + compat_uptr_t root_label;
78909 + compat_uptr_t hash;
78910 +
78911 + compat_uptr_t prev;
78912 + compat_uptr_t next;
78913 +
78914 + compat_uptr_t transitions;
78915 + compat_uptr_t allowed_ips;
78916 + compat_uptr_t domain_children;
78917 + __u16 domain_child_num;
78918 +
78919 + umode_t umask;
78920 +
78921 + compat_uptr_t subj_hash;
78922 + __u32 subj_hash_size;
78923 +};
78924 +
78925 +struct user_acl_role_db_compat {
78926 + compat_uptr_t r_table;
78927 + __u32 num_pointers;
78928 + __u32 num_roles;
78929 + __u32 num_domain_children;
78930 + __u32 num_subjects;
78931 + __u32 num_objects;
78932 +};
78933 +
78934 +struct acl_object_label_compat {
78935 + compat_uptr_t filename;
78936 + compat_ino_t inode;
78937 + __u32 device;
78938 + __u32 mode;
78939 +
78940 + compat_uptr_t nested;
78941 + compat_uptr_t globbed;
78942 +
78943 + compat_uptr_t prev;
78944 + compat_uptr_t next;
78945 +};
78946 +
78947 +struct acl_ip_label_compat {
78948 + compat_uptr_t iface;
78949 + __u32 addr;
78950 + __u32 netmask;
78951 + __u16 low, high;
78952 + __u8 mode;
78953 + __u32 type;
78954 + __u32 proto[8];
78955 +
78956 + compat_uptr_t prev;
78957 + compat_uptr_t next;
78958 +};
78959 +
78960 +struct gr_arg_compat {
78961 + struct user_acl_role_db_compat role_db;
78962 + unsigned char pw[GR_PW_LEN];
78963 + unsigned char salt[GR_SALT_LEN];
78964 + unsigned char sum[GR_SHA_LEN];
78965 + unsigned char sp_role[GR_SPROLE_LEN];
78966 + compat_uptr_t sprole_pws;
78967 + __u32 segv_device;
78968 + compat_ino_t segv_inode;
78969 + uid_t segv_uid;
78970 + __u16 num_sprole_pws;
78971 + __u16 mode;
78972 +};
78973 +
78974 +struct gr_arg_wrapper_compat {
78975 + compat_uptr_t arg;
78976 + __u32 version;
78977 + __u32 size;
78978 +};
78979 +
78980 +#endif
78981 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78982 new file mode 100644
78983 index 0000000..323ecf2
78984 --- /dev/null
78985 +++ b/include/linux/gralloc.h
78986 @@ -0,0 +1,9 @@
78987 +#ifndef __GRALLOC_H
78988 +#define __GRALLOC_H
78989 +
78990 +void acl_free_all(void);
78991 +int acl_alloc_stack_init(unsigned long size);
78992 +void *acl_alloc(unsigned long len);
78993 +void *acl_alloc_num(unsigned long num, unsigned long len);
78994 +
78995 +#endif
78996 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78997 new file mode 100644
78998 index 0000000..be66033
78999 --- /dev/null
79000 +++ b/include/linux/grdefs.h
79001 @@ -0,0 +1,140 @@
79002 +#ifndef GRDEFS_H
79003 +#define GRDEFS_H
79004 +
79005 +/* Begin grsecurity status declarations */
79006 +
79007 +enum {
79008 + GR_READY = 0x01,
79009 + GR_STATUS_INIT = 0x00 // disabled state
79010 +};
79011 +
79012 +/* Begin ACL declarations */
79013 +
79014 +/* Role flags */
79015 +
79016 +enum {
79017 + GR_ROLE_USER = 0x0001,
79018 + GR_ROLE_GROUP = 0x0002,
79019 + GR_ROLE_DEFAULT = 0x0004,
79020 + GR_ROLE_SPECIAL = 0x0008,
79021 + GR_ROLE_AUTH = 0x0010,
79022 + GR_ROLE_NOPW = 0x0020,
79023 + GR_ROLE_GOD = 0x0040,
79024 + GR_ROLE_LEARN = 0x0080,
79025 + GR_ROLE_TPE = 0x0100,
79026 + GR_ROLE_DOMAIN = 0x0200,
79027 + GR_ROLE_PAM = 0x0400,
79028 + GR_ROLE_PERSIST = 0x0800
79029 +};
79030 +
79031 +/* ACL Subject and Object mode flags */
79032 +enum {
79033 + GR_DELETED = 0x80000000
79034 +};
79035 +
79036 +/* ACL Object-only mode flags */
79037 +enum {
79038 + GR_READ = 0x00000001,
79039 + GR_APPEND = 0x00000002,
79040 + GR_WRITE = 0x00000004,
79041 + GR_EXEC = 0x00000008,
79042 + GR_FIND = 0x00000010,
79043 + GR_INHERIT = 0x00000020,
79044 + GR_SETID = 0x00000040,
79045 + GR_CREATE = 0x00000080,
79046 + GR_DELETE = 0x00000100,
79047 + GR_LINK = 0x00000200,
79048 + GR_AUDIT_READ = 0x00000400,
79049 + GR_AUDIT_APPEND = 0x00000800,
79050 + GR_AUDIT_WRITE = 0x00001000,
79051 + GR_AUDIT_EXEC = 0x00002000,
79052 + GR_AUDIT_FIND = 0x00004000,
79053 + GR_AUDIT_INHERIT= 0x00008000,
79054 + GR_AUDIT_SETID = 0x00010000,
79055 + GR_AUDIT_CREATE = 0x00020000,
79056 + GR_AUDIT_DELETE = 0x00040000,
79057 + GR_AUDIT_LINK = 0x00080000,
79058 + GR_PTRACERD = 0x00100000,
79059 + GR_NOPTRACE = 0x00200000,
79060 + GR_SUPPRESS = 0x00400000,
79061 + GR_NOLEARN = 0x00800000,
79062 + GR_INIT_TRANSFER= 0x01000000
79063 +};
79064 +
79065 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79066 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79067 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79068 +
79069 +/* ACL subject-only mode flags */
79070 +enum {
79071 + GR_KILL = 0x00000001,
79072 + GR_VIEW = 0x00000002,
79073 + GR_PROTECTED = 0x00000004,
79074 + GR_LEARN = 0x00000008,
79075 + GR_OVERRIDE = 0x00000010,
79076 + /* just a placeholder, this mode is only used in userspace */
79077 + GR_DUMMY = 0x00000020,
79078 + GR_PROTSHM = 0x00000040,
79079 + GR_KILLPROC = 0x00000080,
79080 + GR_KILLIPPROC = 0x00000100,
79081 + /* just a placeholder, this mode is only used in userspace */
79082 + GR_NOTROJAN = 0x00000200,
79083 + GR_PROTPROCFD = 0x00000400,
79084 + GR_PROCACCT = 0x00000800,
79085 + GR_RELAXPTRACE = 0x00001000,
79086 + //GR_NESTED = 0x00002000,
79087 + GR_INHERITLEARN = 0x00004000,
79088 + GR_PROCFIND = 0x00008000,
79089 + GR_POVERRIDE = 0x00010000,
79090 + GR_KERNELAUTH = 0x00020000,
79091 + GR_ATSECURE = 0x00040000,
79092 + GR_SHMEXEC = 0x00080000
79093 +};
79094 +
79095 +enum {
79096 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79097 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79098 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79099 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79100 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79101 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79102 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79103 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79104 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79105 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79106 +};
79107 +
79108 +enum {
79109 + GR_ID_USER = 0x01,
79110 + GR_ID_GROUP = 0x02,
79111 +};
79112 +
79113 +enum {
79114 + GR_ID_ALLOW = 0x01,
79115 + GR_ID_DENY = 0x02,
79116 +};
79117 +
79118 +#define GR_CRASH_RES 31
79119 +#define GR_UIDTABLE_MAX 500
79120 +
79121 +/* begin resource learning section */
79122 +enum {
79123 + GR_RLIM_CPU_BUMP = 60,
79124 + GR_RLIM_FSIZE_BUMP = 50000,
79125 + GR_RLIM_DATA_BUMP = 10000,
79126 + GR_RLIM_STACK_BUMP = 1000,
79127 + GR_RLIM_CORE_BUMP = 10000,
79128 + GR_RLIM_RSS_BUMP = 500000,
79129 + GR_RLIM_NPROC_BUMP = 1,
79130 + GR_RLIM_NOFILE_BUMP = 5,
79131 + GR_RLIM_MEMLOCK_BUMP = 50000,
79132 + GR_RLIM_AS_BUMP = 500000,
79133 + GR_RLIM_LOCKS_BUMP = 2,
79134 + GR_RLIM_SIGPENDING_BUMP = 5,
79135 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79136 + GR_RLIM_NICE_BUMP = 1,
79137 + GR_RLIM_RTPRIO_BUMP = 1,
79138 + GR_RLIM_RTTIME_BUMP = 1000000
79139 +};
79140 +
79141 +#endif
79142 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79143 new file mode 100644
79144 index 0000000..d25522e
79145 --- /dev/null
79146 +++ b/include/linux/grinternal.h
79147 @@ -0,0 +1,229 @@
79148 +#ifndef __GRINTERNAL_H
79149 +#define __GRINTERNAL_H
79150 +
79151 +#ifdef CONFIG_GRKERNSEC
79152 +
79153 +#include <linux/fs.h>
79154 +#include <linux/mnt_namespace.h>
79155 +#include <linux/nsproxy.h>
79156 +#include <linux/gracl.h>
79157 +#include <linux/grdefs.h>
79158 +#include <linux/grmsg.h>
79159 +
79160 +void gr_add_learn_entry(const char *fmt, ...)
79161 + __attribute__ ((format (printf, 1, 2)));
79162 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79163 + const struct vfsmount *mnt);
79164 +__u32 gr_check_create(const struct dentry *new_dentry,
79165 + const struct dentry *parent,
79166 + const struct vfsmount *mnt, const __u32 mode);
79167 +int gr_check_protected_task(const struct task_struct *task);
79168 +__u32 to_gr_audit(const __u32 reqmode);
79169 +int gr_set_acls(const int type);
79170 +int gr_acl_is_enabled(void);
79171 +char gr_roletype_to_char(void);
79172 +
79173 +void gr_handle_alertkill(struct task_struct *task);
79174 +char *gr_to_filename(const struct dentry *dentry,
79175 + const struct vfsmount *mnt);
79176 +char *gr_to_filename1(const struct dentry *dentry,
79177 + const struct vfsmount *mnt);
79178 +char *gr_to_filename2(const struct dentry *dentry,
79179 + const struct vfsmount *mnt);
79180 +char *gr_to_filename3(const struct dentry *dentry,
79181 + const struct vfsmount *mnt);
79182 +
79183 +extern int grsec_enable_ptrace_readexec;
79184 +extern int grsec_enable_harden_ptrace;
79185 +extern int grsec_enable_link;
79186 +extern int grsec_enable_fifo;
79187 +extern int grsec_enable_execve;
79188 +extern int grsec_enable_shm;
79189 +extern int grsec_enable_execlog;
79190 +extern int grsec_enable_signal;
79191 +extern int grsec_enable_audit_ptrace;
79192 +extern int grsec_enable_forkfail;
79193 +extern int grsec_enable_time;
79194 +extern int grsec_enable_rofs;
79195 +extern int grsec_deny_new_usb;
79196 +extern int grsec_enable_chroot_shmat;
79197 +extern int grsec_enable_chroot_mount;
79198 +extern int grsec_enable_chroot_double;
79199 +extern int grsec_enable_chroot_pivot;
79200 +extern int grsec_enable_chroot_chdir;
79201 +extern int grsec_enable_chroot_chmod;
79202 +extern int grsec_enable_chroot_mknod;
79203 +extern int grsec_enable_chroot_fchdir;
79204 +extern int grsec_enable_chroot_nice;
79205 +extern int grsec_enable_chroot_execlog;
79206 +extern int grsec_enable_chroot_caps;
79207 +extern int grsec_enable_chroot_sysctl;
79208 +extern int grsec_enable_chroot_unix;
79209 +extern int grsec_enable_symlinkown;
79210 +extern kgid_t grsec_symlinkown_gid;
79211 +extern int grsec_enable_tpe;
79212 +extern kgid_t grsec_tpe_gid;
79213 +extern int grsec_enable_tpe_all;
79214 +extern int grsec_enable_tpe_invert;
79215 +extern int grsec_enable_socket_all;
79216 +extern kgid_t grsec_socket_all_gid;
79217 +extern int grsec_enable_socket_client;
79218 +extern kgid_t grsec_socket_client_gid;
79219 +extern int grsec_enable_socket_server;
79220 +extern kgid_t grsec_socket_server_gid;
79221 +extern kgid_t grsec_audit_gid;
79222 +extern int grsec_enable_group;
79223 +extern int grsec_enable_log_rwxmaps;
79224 +extern int grsec_enable_mount;
79225 +extern int grsec_enable_chdir;
79226 +extern int grsec_resource_logging;
79227 +extern int grsec_enable_blackhole;
79228 +extern int grsec_lastack_retries;
79229 +extern int grsec_enable_brute;
79230 +extern int grsec_enable_harden_ipc;
79231 +extern int grsec_lock;
79232 +
79233 +extern spinlock_t grsec_alert_lock;
79234 +extern unsigned long grsec_alert_wtime;
79235 +extern unsigned long grsec_alert_fyet;
79236 +
79237 +extern spinlock_t grsec_audit_lock;
79238 +
79239 +extern rwlock_t grsec_exec_file_lock;
79240 +
79241 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79242 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79243 + (tsk)->exec_file->f_path.mnt) : "/")
79244 +
79245 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79246 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79247 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79248 +
79249 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79250 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79251 + (tsk)->exec_file->f_path.mnt) : "/")
79252 +
79253 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79254 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79255 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79256 +
79257 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79258 +
79259 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79260 +
79261 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79262 +{
79263 + if (file1 && file2) {
79264 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79265 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79266 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79267 + return true;
79268 + }
79269 +
79270 + return false;
79271 +}
79272 +
79273 +#define GR_CHROOT_CAPS {{ \
79274 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79275 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79276 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79277 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79278 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79279 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79280 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79281 +
79282 +#define security_learn(normal_msg,args...) \
79283 +({ \
79284 + read_lock(&grsec_exec_file_lock); \
79285 + gr_add_learn_entry(normal_msg "\n", ## args); \
79286 + read_unlock(&grsec_exec_file_lock); \
79287 +})
79288 +
79289 +enum {
79290 + GR_DO_AUDIT,
79291 + GR_DONT_AUDIT,
79292 + /* used for non-audit messages that we shouldn't kill the task on */
79293 + GR_DONT_AUDIT_GOOD
79294 +};
79295 +
79296 +enum {
79297 + GR_TTYSNIFF,
79298 + GR_RBAC,
79299 + GR_RBAC_STR,
79300 + GR_STR_RBAC,
79301 + GR_RBAC_MODE2,
79302 + GR_RBAC_MODE3,
79303 + GR_FILENAME,
79304 + GR_SYSCTL_HIDDEN,
79305 + GR_NOARGS,
79306 + GR_ONE_INT,
79307 + GR_ONE_INT_TWO_STR,
79308 + GR_ONE_STR,
79309 + GR_STR_INT,
79310 + GR_TWO_STR_INT,
79311 + GR_TWO_INT,
79312 + GR_TWO_U64,
79313 + GR_THREE_INT,
79314 + GR_FIVE_INT_TWO_STR,
79315 + GR_TWO_STR,
79316 + GR_THREE_STR,
79317 + GR_FOUR_STR,
79318 + GR_STR_FILENAME,
79319 + GR_FILENAME_STR,
79320 + GR_FILENAME_TWO_INT,
79321 + GR_FILENAME_TWO_INT_STR,
79322 + GR_TEXTREL,
79323 + GR_PTRACE,
79324 + GR_RESOURCE,
79325 + GR_CAP,
79326 + GR_SIG,
79327 + GR_SIG2,
79328 + GR_CRASH1,
79329 + GR_CRASH2,
79330 + GR_PSACCT,
79331 + GR_RWXMAP,
79332 + GR_RWXMAPVMA
79333 +};
79334 +
79335 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79336 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79337 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79338 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79339 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79340 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79341 +#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)
79342 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79343 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79344 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79345 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79346 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79347 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79348 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79349 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79350 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79351 +#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)
79352 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79353 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79354 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79355 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79356 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79357 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79358 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79359 +#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)
79360 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79361 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79362 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79363 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79364 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79365 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79366 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79367 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79368 +#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)
79369 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79370 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79371 +
79372 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79373 +
79374 +#endif
79375 +
79376 +#endif
79377 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79378 new file mode 100644
79379 index 0000000..b02ba9d
79380 --- /dev/null
79381 +++ b/include/linux/grmsg.h
79382 @@ -0,0 +1,117 @@
79383 +#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"
79384 +#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"
79385 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79386 +#define GR_STOPMOD_MSG "denied modification of module state by "
79387 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79388 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79389 +#define GR_IOPERM_MSG "denied use of ioperm() by "
79390 +#define GR_IOPL_MSG "denied use of iopl() by "
79391 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79392 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79393 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79394 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79395 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79396 +#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"
79397 +#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"
79398 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79399 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79400 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79401 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79402 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79403 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79404 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79405 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79406 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79407 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79408 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79409 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79410 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79411 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79412 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79413 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79414 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79415 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79416 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79417 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79418 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79419 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79420 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79421 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79422 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79423 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79424 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79425 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79426 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79427 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79428 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79429 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79430 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79431 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79432 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79433 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79434 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79435 +#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"
79436 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79437 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79438 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79439 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79440 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79441 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79442 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79443 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79444 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79445 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79446 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79447 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79448 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79449 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79450 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79451 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79452 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79453 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79454 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79455 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79456 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79457 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79458 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79459 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79460 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79461 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79462 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79463 +#define GR_TIME_MSG "time set by "
79464 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79465 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79466 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79467 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79468 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79469 +#define GR_BIND_MSG "denied bind() by "
79470 +#define GR_CONNECT_MSG "denied connect() by "
79471 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79472 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79473 +#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"
79474 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79475 +#define GR_CAP_ACL_MSG "use of %s denied for "
79476 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79477 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79478 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79479 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79480 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79481 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79482 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79483 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79484 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79485 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79486 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79487 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79488 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79489 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79490 +#define GR_VM86_MSG "denied use of vm86 by "
79491 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79492 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79493 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79494 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79495 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79496 +#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 "
79497 +#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 "
79498 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79499 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79500 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79501 new file mode 100644
79502 index 0000000..13ac2e2
79503 --- /dev/null
79504 +++ b/include/linux/grsecurity.h
79505 @@ -0,0 +1,249 @@
79506 +#ifndef GR_SECURITY_H
79507 +#define GR_SECURITY_H
79508 +#include <linux/fs.h>
79509 +#include <linux/fs_struct.h>
79510 +#include <linux/binfmts.h>
79511 +#include <linux/gracl.h>
79512 +
79513 +/* notify of brain-dead configs */
79514 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79515 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79516 +#endif
79517 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79518 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79519 +#endif
79520 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79521 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79522 +#endif
79523 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79524 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79525 +#endif
79526 +
79527 +int gr_handle_new_usb(void);
79528 +
79529 +void gr_handle_brute_attach(int dumpable);
79530 +void gr_handle_brute_check(void);
79531 +void gr_handle_kernel_exploit(void);
79532 +
79533 +char gr_roletype_to_char(void);
79534 +
79535 +int gr_proc_is_restricted(void);
79536 +
79537 +int gr_acl_enable_at_secure(void);
79538 +
79539 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79540 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79541 +
79542 +void gr_del_task_from_ip_table(struct task_struct *p);
79543 +
79544 +int gr_pid_is_chrooted(struct task_struct *p);
79545 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79546 +int gr_handle_chroot_nice(void);
79547 +int gr_handle_chroot_sysctl(const int op);
79548 +int gr_handle_chroot_setpriority(struct task_struct *p,
79549 + const int niceval);
79550 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79551 +int gr_chroot_fhandle(void);
79552 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79553 + const struct vfsmount *mnt);
79554 +void gr_handle_chroot_chdir(const struct path *path);
79555 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79556 + const struct vfsmount *mnt, const int mode);
79557 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79558 + const struct vfsmount *mnt, const int mode);
79559 +int gr_handle_chroot_mount(const struct dentry *dentry,
79560 + const struct vfsmount *mnt,
79561 + const char *dev_name);
79562 +int gr_handle_chroot_pivot(void);
79563 +int gr_handle_chroot_unix(const pid_t pid);
79564 +
79565 +int gr_handle_rawio(const struct inode *inode);
79566 +
79567 +void gr_handle_ioperm(void);
79568 +void gr_handle_iopl(void);
79569 +void gr_handle_msr_write(void);
79570 +
79571 +umode_t gr_acl_umask(void);
79572 +
79573 +int gr_tpe_allow(const struct file *file);
79574 +
79575 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79576 +void gr_clear_chroot_entries(struct task_struct *task);
79577 +
79578 +void gr_log_forkfail(const int retval);
79579 +void gr_log_timechange(void);
79580 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79581 +void gr_log_chdir(const struct dentry *dentry,
79582 + const struct vfsmount *mnt);
79583 +void gr_log_chroot_exec(const struct dentry *dentry,
79584 + const struct vfsmount *mnt);
79585 +void gr_log_remount(const char *devname, const int retval);
79586 +void gr_log_unmount(const char *devname, const int retval);
79587 +void gr_log_mount(const char *from, const char *to, const int retval);
79588 +void gr_log_textrel(struct vm_area_struct *vma);
79589 +void gr_log_ptgnustack(struct file *file);
79590 +void gr_log_rwxmmap(struct file *file);
79591 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79592 +
79593 +int gr_handle_follow_link(const struct inode *parent,
79594 + const struct inode *inode,
79595 + const struct dentry *dentry,
79596 + const struct vfsmount *mnt);
79597 +int gr_handle_fifo(const struct dentry *dentry,
79598 + const struct vfsmount *mnt,
79599 + const struct dentry *dir, const int flag,
79600 + const int acc_mode);
79601 +int gr_handle_hardlink(const struct dentry *dentry,
79602 + const struct vfsmount *mnt,
79603 + struct inode *inode,
79604 + const int mode, const struct filename *to);
79605 +
79606 +int gr_is_capable(const int cap);
79607 +int gr_is_capable_nolog(const int cap);
79608 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79609 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79610 +
79611 +void gr_copy_label(struct task_struct *tsk);
79612 +void gr_handle_crash(struct task_struct *task, const int sig);
79613 +int gr_handle_signal(const struct task_struct *p, const int sig);
79614 +int gr_check_crash_uid(const kuid_t uid);
79615 +int gr_check_protected_task(const struct task_struct *task);
79616 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79617 +int gr_acl_handle_mmap(const struct file *file,
79618 + const unsigned long prot);
79619 +int gr_acl_handle_mprotect(const struct file *file,
79620 + const unsigned long prot);
79621 +int gr_check_hidden_task(const struct task_struct *tsk);
79622 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79623 + const struct vfsmount *mnt);
79624 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79625 + const struct vfsmount *mnt);
79626 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79627 + const struct vfsmount *mnt, const int fmode);
79628 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79629 + const struct vfsmount *mnt, umode_t *mode);
79630 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79631 + const struct vfsmount *mnt);
79632 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79633 + const struct vfsmount *mnt);
79634 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79635 + const struct vfsmount *mnt);
79636 +int gr_handle_ptrace(struct task_struct *task, const long request);
79637 +int gr_handle_proc_ptrace(struct task_struct *task);
79638 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79639 + const struct vfsmount *mnt);
79640 +int gr_check_crash_exec(const struct file *filp);
79641 +int gr_acl_is_enabled(void);
79642 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79643 + const kgid_t gid);
79644 +int gr_set_proc_label(const struct dentry *dentry,
79645 + const struct vfsmount *mnt,
79646 + const int unsafe_flags);
79647 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79648 + const struct vfsmount *mnt);
79649 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79650 + const struct vfsmount *mnt, int acc_mode);
79651 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79652 + const struct dentry *p_dentry,
79653 + const struct vfsmount *p_mnt,
79654 + int open_flags, int acc_mode, const int imode);
79655 +void gr_handle_create(const struct dentry *dentry,
79656 + const struct vfsmount *mnt);
79657 +void gr_handle_proc_create(const struct dentry *dentry,
79658 + const struct inode *inode);
79659 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79660 + const struct dentry *parent_dentry,
79661 + const struct vfsmount *parent_mnt,
79662 + const int mode);
79663 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79664 + const struct dentry *parent_dentry,
79665 + const struct vfsmount *parent_mnt);
79666 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79667 + const struct vfsmount *mnt);
79668 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79669 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79670 + const struct vfsmount *mnt);
79671 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79672 + const struct dentry *parent_dentry,
79673 + const struct vfsmount *parent_mnt,
79674 + const struct filename *from);
79675 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79676 + const struct dentry *parent_dentry,
79677 + const struct vfsmount *parent_mnt,
79678 + const struct dentry *old_dentry,
79679 + const struct vfsmount *old_mnt, const struct filename *to);
79680 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79681 +int gr_acl_handle_rename(struct dentry *new_dentry,
79682 + struct dentry *parent_dentry,
79683 + const struct vfsmount *parent_mnt,
79684 + struct dentry *old_dentry,
79685 + struct inode *old_parent_inode,
79686 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
79687 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79688 + struct dentry *old_dentry,
79689 + struct dentry *new_dentry,
79690 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
79691 +__u32 gr_check_link(const struct dentry *new_dentry,
79692 + const struct dentry *parent_dentry,
79693 + const struct vfsmount *parent_mnt,
79694 + const struct dentry *old_dentry,
79695 + const struct vfsmount *old_mnt);
79696 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79697 + const unsigned int namelen, const ino_t ino);
79698 +
79699 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79700 + const struct vfsmount *mnt);
79701 +void gr_acl_handle_exit(void);
79702 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79703 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79704 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79705 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79706 +void gr_audit_ptrace(struct task_struct *task);
79707 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79708 +void gr_put_exec_file(struct task_struct *task);
79709 +
79710 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79711 +
79712 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79713 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79714 + const unsigned long wanted, const int gt);
79715 +#else
79716 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79717 + const unsigned long wanted, const int gt)
79718 +{
79719 +}
79720 +#endif
79721 +
79722 +#ifdef CONFIG_GRKERNSEC_RESLOG
79723 +extern void gr_log_resource(const struct task_struct *task, const int res,
79724 + const unsigned long wanted, const int gt);
79725 +#else
79726 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79727 + const unsigned long wanted, const int gt)
79728 +{
79729 +}
79730 +#endif
79731 +
79732 +#ifdef CONFIG_GRKERNSEC
79733 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79734 +void gr_handle_vm86(void);
79735 +void gr_handle_mem_readwrite(u64 from, u64 to);
79736 +
79737 +void gr_log_badprocpid(const char *entry);
79738 +
79739 +extern int grsec_enable_dmesg;
79740 +extern int grsec_disable_privio;
79741 +
79742 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79743 +extern kgid_t grsec_proc_gid;
79744 +#endif
79745 +
79746 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79747 +extern int grsec_enable_chroot_findtask;
79748 +#endif
79749 +#ifdef CONFIG_GRKERNSEC_SETXID
79750 +extern int grsec_enable_setxid;
79751 +#endif
79752 +#endif
79753 +
79754 +#endif
79755 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79756 new file mode 100644
79757 index 0000000..e7ffaaf
79758 --- /dev/null
79759 +++ b/include/linux/grsock.h
79760 @@ -0,0 +1,19 @@
79761 +#ifndef __GRSOCK_H
79762 +#define __GRSOCK_H
79763 +
79764 +extern void gr_attach_curr_ip(const struct sock *sk);
79765 +extern int gr_handle_sock_all(const int family, const int type,
79766 + const int protocol);
79767 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79768 +extern int gr_handle_sock_server_other(const struct sock *sck);
79769 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79770 +extern int gr_search_connect(struct socket * sock,
79771 + struct sockaddr_in * addr);
79772 +extern int gr_search_bind(struct socket * sock,
79773 + struct sockaddr_in * addr);
79774 +extern int gr_search_listen(struct socket * sock);
79775 +extern int gr_search_accept(struct socket * sock);
79776 +extern int gr_search_socket(const int domain, const int type,
79777 + const int protocol);
79778 +
79779 +#endif
79780 diff --git a/include/linux/hash.h b/include/linux/hash.h
79781 index bd1754c..8240892 100644
79782 --- a/include/linux/hash.h
79783 +++ b/include/linux/hash.h
79784 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79785 struct fast_hash_ops {
79786 u32 (*hash)(const void *data, u32 len, u32 seed);
79787 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79788 -};
79789 +} __no_const;
79790
79791 /**
79792 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79793 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79794 index 7fb31da..08b5114 100644
79795 --- a/include/linux/highmem.h
79796 +++ b/include/linux/highmem.h
79797 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79798 kunmap_atomic(kaddr);
79799 }
79800
79801 +static inline void sanitize_highpage(struct page *page)
79802 +{
79803 + void *kaddr;
79804 + unsigned long flags;
79805 +
79806 + local_irq_save(flags);
79807 + kaddr = kmap_atomic(page);
79808 + clear_page(kaddr);
79809 + kunmap_atomic(kaddr);
79810 + local_irq_restore(flags);
79811 +}
79812 +
79813 static inline void zero_user_segments(struct page *page,
79814 unsigned start1, unsigned end1,
79815 unsigned start2, unsigned end2)
79816 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79817 index 1c7b89a..7dda400 100644
79818 --- a/include/linux/hwmon-sysfs.h
79819 +++ b/include/linux/hwmon-sysfs.h
79820 @@ -25,7 +25,8 @@
79821 struct sensor_device_attribute{
79822 struct device_attribute dev_attr;
79823 int index;
79824 -};
79825 +} __do_const;
79826 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79827 #define to_sensor_dev_attr(_dev_attr) \
79828 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79829
79830 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79831 struct device_attribute dev_attr;
79832 u8 index;
79833 u8 nr;
79834 -};
79835 +} __do_const;
79836 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79837 #define to_sensor_dev_attr_2(_dev_attr) \
79838 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79839
79840 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79841 index b556e0a..c10a515 100644
79842 --- a/include/linux/i2c.h
79843 +++ b/include/linux/i2c.h
79844 @@ -378,6 +378,7 @@ struct i2c_algorithm {
79845 /* To determine what the adapter supports */
79846 u32 (*functionality) (struct i2c_adapter *);
79847 };
79848 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79849
79850 /**
79851 * struct i2c_bus_recovery_info - I2C bus recovery information
79852 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79853 index d23c3c2..eb63c81 100644
79854 --- a/include/linux/i2o.h
79855 +++ b/include/linux/i2o.h
79856 @@ -565,7 +565,7 @@ struct i2o_controller {
79857 struct i2o_device *exec; /* Executive */
79858 #if BITS_PER_LONG == 64
79859 spinlock_t context_list_lock; /* lock for context_list */
79860 - atomic_t context_list_counter; /* needed for unique contexts */
79861 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79862 struct list_head context_list; /* list of context id's
79863 and pointers */
79864 #endif
79865 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79866 index aff7ad8..3942bbd 100644
79867 --- a/include/linux/if_pppox.h
79868 +++ b/include/linux/if_pppox.h
79869 @@ -76,7 +76,7 @@ struct pppox_proto {
79870 int (*ioctl)(struct socket *sock, unsigned int cmd,
79871 unsigned long arg);
79872 struct module *owner;
79873 -};
79874 +} __do_const;
79875
79876 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79877 extern void unregister_pppox_proto(int proto_num);
79878 diff --git a/include/linux/init.h b/include/linux/init.h
79879 index a3ba270..a1b6604 100644
79880 --- a/include/linux/init.h
79881 +++ b/include/linux/init.h
79882 @@ -37,9 +37,17 @@
79883 * section.
79884 */
79885
79886 +#define add_init_latent_entropy __latent_entropy
79887 +
79888 +#ifdef CONFIG_MEMORY_HOTPLUG
79889 +#define add_meminit_latent_entropy
79890 +#else
79891 +#define add_meminit_latent_entropy __latent_entropy
79892 +#endif
79893 +
79894 /* These are for everybody (although not all archs will actually
79895 discard it in modules) */
79896 -#define __init __section(.init.text) __cold notrace
79897 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79898 #define __initdata __section(.init.data)
79899 #define __initconst __constsection(.init.rodata)
79900 #define __exitdata __section(.exit.data)
79901 @@ -100,7 +108,7 @@
79902 #define __cpuexitconst
79903
79904 /* Used for MEMORY_HOTPLUG */
79905 -#define __meminit __section(.meminit.text) __cold notrace
79906 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79907 #define __meminitdata __section(.meminit.data)
79908 #define __meminitconst __constsection(.meminit.rodata)
79909 #define __memexit __section(.memexit.text) __exitused __cold notrace
79910 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79911 index 6df7f9f..d0bf699 100644
79912 --- a/include/linux/init_task.h
79913 +++ b/include/linux/init_task.h
79914 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79915
79916 #define INIT_TASK_COMM "swapper"
79917
79918 +#ifdef CONFIG_X86
79919 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79920 +#else
79921 +#define INIT_TASK_THREAD_INFO
79922 +#endif
79923 +
79924 #ifdef CONFIG_RT_MUTEXES
79925 # define INIT_RT_MUTEXES(tsk) \
79926 .pi_waiters = RB_ROOT, \
79927 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79928 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79929 .comm = INIT_TASK_COMM, \
79930 .thread = INIT_THREAD, \
79931 + INIT_TASK_THREAD_INFO \
79932 .fs = &init_fs, \
79933 .files = &init_files, \
79934 .signal = &init_signals, \
79935 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79936 index 051c850..431f83a 100644
79937 --- a/include/linux/interrupt.h
79938 +++ b/include/linux/interrupt.h
79939 @@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79940
79941 struct softirq_action
79942 {
79943 - void (*action)(struct softirq_action *);
79944 -};
79945 + void (*action)(void);
79946 +} __no_const;
79947
79948 asmlinkage void do_softirq(void);
79949 asmlinkage void __do_softirq(void);
79950 @@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
79951 }
79952 #endif
79953
79954 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79955 +extern void open_softirq(int nr, void (*action)(void));
79956 extern void softirq_init(void);
79957 extern void __raise_softirq_irqoff(unsigned int nr);
79958
79959 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79960 index b96a5b2..2732d1c 100644
79961 --- a/include/linux/iommu.h
79962 +++ b/include/linux/iommu.h
79963 @@ -131,7 +131,7 @@ struct iommu_ops {
79964 u32 (*domain_get_windows)(struct iommu_domain *domain);
79965
79966 unsigned long pgsize_bitmap;
79967 -};
79968 +} __do_const;
79969
79970 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79971 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79972 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79973 index 5e3a906..3131d0f 100644
79974 --- a/include/linux/ioport.h
79975 +++ b/include/linux/ioport.h
79976 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79977 int adjust_resource(struct resource *res, resource_size_t start,
79978 resource_size_t size);
79979 resource_size_t resource_alignment(struct resource *res);
79980 -static inline resource_size_t resource_size(const struct resource *res)
79981 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79982 {
79983 return res->end - res->start + 1;
79984 }
79985 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79986 index 35e7eca..6afb7ad 100644
79987 --- a/include/linux/ipc_namespace.h
79988 +++ b/include/linux/ipc_namespace.h
79989 @@ -69,7 +69,7 @@ struct ipc_namespace {
79990 struct user_namespace *user_ns;
79991
79992 unsigned int proc_inum;
79993 -};
79994 +} __randomize_layout;
79995
79996 extern struct ipc_namespace init_ipc_ns;
79997 extern atomic_t nr_ipc_ns;
79998 diff --git a/include/linux/irq.h b/include/linux/irq.h
79999 index 5c57efb..965a62b 100644
80000 --- a/include/linux/irq.h
80001 +++ b/include/linux/irq.h
80002 @@ -344,7 +344,8 @@ struct irq_chip {
80003 void (*irq_release_resources)(struct irq_data *data);
80004
80005 unsigned long flags;
80006 -};
80007 +} __do_const;
80008 +typedef struct irq_chip __no_const irq_chip_no_const;
80009
80010 /*
80011 * irq_chip specific flags
80012 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80013 index 7ed92d0..589abf5 100644
80014 --- a/include/linux/irqchip/arm-gic.h
80015 +++ b/include/linux/irqchip/arm-gic.h
80016 @@ -73,9 +73,11 @@
80017
80018 #ifndef __ASSEMBLY__
80019
80020 +#include <linux/irq.h>
80021 +
80022 struct device_node;
80023
80024 -extern struct irq_chip gic_arch_extn;
80025 +extern irq_chip_no_const gic_arch_extn;
80026
80027 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80028 u32 offset, struct device_node *);
80029 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80030 index 1f44466..b481806 100644
80031 --- a/include/linux/jiffies.h
80032 +++ b/include/linux/jiffies.h
80033 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80034 /*
80035 * Convert various time units to each other:
80036 */
80037 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80038 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80039 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80040 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80041
80042 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80043 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80044 {
80045 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80046 }
80047
80048 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80049 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80050 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80051 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80052 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80053 extern void jiffies_to_timespec(const unsigned long jiffies,
80054 - struct timespec *value);
80055 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80056 + struct timespec *value) __intentional_overflow(-1);
80057 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80058 extern void jiffies_to_timeval(const unsigned long jiffies,
80059 struct timeval *value);
80060
80061 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80062 index 6883e19..e854fcb 100644
80063 --- a/include/linux/kallsyms.h
80064 +++ b/include/linux/kallsyms.h
80065 @@ -15,7 +15,8 @@
80066
80067 struct module;
80068
80069 -#ifdef CONFIG_KALLSYMS
80070 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80071 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80072 /* Lookup the address for a symbol. Returns 0 if not found. */
80073 unsigned long kallsyms_lookup_name(const char *name);
80074
80075 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80076 /* Stupid that this does nothing, but I didn't create this mess. */
80077 #define __print_symbol(fmt, addr)
80078 #endif /*CONFIG_KALLSYMS*/
80079 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80080 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80081 +extern unsigned long kallsyms_lookup_name(const char *name);
80082 +extern void __print_symbol(const char *fmt, unsigned long address);
80083 +extern int sprint_backtrace(char *buffer, unsigned long address);
80084 +extern int sprint_symbol(char *buffer, unsigned long address);
80085 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80086 +const char *kallsyms_lookup(unsigned long addr,
80087 + unsigned long *symbolsize,
80088 + unsigned long *offset,
80089 + char **modname, char *namebuf);
80090 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80091 + unsigned long *symbolsize,
80092 + unsigned long *offset);
80093 +#endif
80094
80095 /* This macro allows us to keep printk typechecking */
80096 static __printf(1, 2)
80097 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80098 index a74c3a8..28d3f21 100644
80099 --- a/include/linux/key-type.h
80100 +++ b/include/linux/key-type.h
80101 @@ -131,7 +131,7 @@ struct key_type {
80102 /* internal fields */
80103 struct list_head link; /* link in types list */
80104 struct lock_class_key lock_class; /* key->sem lock class */
80105 -};
80106 +} __do_const;
80107
80108 extern struct key_type key_type_keyring;
80109
80110 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80111 index 6b06d37..c134867 100644
80112 --- a/include/linux/kgdb.h
80113 +++ b/include/linux/kgdb.h
80114 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80115 extern int kgdb_io_module_registered;
80116
80117 extern atomic_t kgdb_setting_breakpoint;
80118 -extern atomic_t kgdb_cpu_doing_single_step;
80119 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80120
80121 extern struct task_struct *kgdb_usethread;
80122 extern struct task_struct *kgdb_contthread;
80123 @@ -254,7 +254,7 @@ struct kgdb_arch {
80124 void (*correct_hw_break)(void);
80125
80126 void (*enable_nmi)(bool on);
80127 -};
80128 +} __do_const;
80129
80130 /**
80131 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80132 @@ -279,7 +279,7 @@ struct kgdb_io {
80133 void (*pre_exception) (void);
80134 void (*post_exception) (void);
80135 int is_console;
80136 -};
80137 +} __do_const;
80138
80139 extern struct kgdb_arch arch_kgdb_ops;
80140
80141 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80142 index 0555cc6..40116ce 100644
80143 --- a/include/linux/kmod.h
80144 +++ b/include/linux/kmod.h
80145 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80146 * usually useless though. */
80147 extern __printf(2, 3)
80148 int __request_module(bool wait, const char *name, ...);
80149 +extern __printf(3, 4)
80150 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80151 #define request_module(mod...) __request_module(true, mod)
80152 #define request_module_nowait(mod...) __request_module(false, mod)
80153 #define try_then_request_module(x, mod...) \
80154 @@ -57,6 +59,9 @@ struct subprocess_info {
80155 struct work_struct work;
80156 struct completion *complete;
80157 char *path;
80158 +#ifdef CONFIG_GRKERNSEC
80159 + char *origpath;
80160 +#endif
80161 char **argv;
80162 char **envp;
80163 int wait;
80164 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80165 index f896a33..f2eb10f 100644
80166 --- a/include/linux/kobject.h
80167 +++ b/include/linux/kobject.h
80168 @@ -116,7 +116,7 @@ struct kobj_type {
80169 struct attribute **default_attrs;
80170 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80171 const void *(*namespace)(struct kobject *kobj);
80172 -};
80173 +} __do_const;
80174
80175 struct kobj_uevent_env {
80176 char *argv[3];
80177 @@ -140,6 +140,7 @@ struct kobj_attribute {
80178 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80179 const char *buf, size_t count);
80180 };
80181 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80182
80183 extern const struct sysfs_ops kobj_sysfs_ops;
80184
80185 @@ -167,7 +168,7 @@ struct kset {
80186 spinlock_t list_lock;
80187 struct kobject kobj;
80188 const struct kset_uevent_ops *uevent_ops;
80189 -};
80190 +} __randomize_layout;
80191
80192 extern void kset_init(struct kset *kset);
80193 extern int __must_check kset_register(struct kset *kset);
80194 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80195 index df32d25..fb52e27 100644
80196 --- a/include/linux/kobject_ns.h
80197 +++ b/include/linux/kobject_ns.h
80198 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80199 const void *(*netlink_ns)(struct sock *sk);
80200 const void *(*initial_ns)(void);
80201 void (*drop_ns)(void *);
80202 -};
80203 +} __do_const;
80204
80205 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80206 int kobj_ns_type_registered(enum kobj_ns_type type);
80207 diff --git a/include/linux/kref.h b/include/linux/kref.h
80208 index 484604d..0f6c5b6 100644
80209 --- a/include/linux/kref.h
80210 +++ b/include/linux/kref.h
80211 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80212 static inline int kref_sub(struct kref *kref, unsigned int count,
80213 void (*release)(struct kref *kref))
80214 {
80215 - WARN_ON(release == NULL);
80216 + BUG_ON(release == NULL);
80217
80218 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80219 release(kref);
80220 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80221 index 7d21cf9..bc0c81f 100644
80222 --- a/include/linux/kvm_host.h
80223 +++ b/include/linux/kvm_host.h
80224 @@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80225 {
80226 }
80227 #endif
80228 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80229 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80230 struct module *module);
80231 void kvm_exit(void);
80232
80233 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80234 struct kvm_guest_debug *dbg);
80235 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80236
80237 -int kvm_arch_init(void *opaque);
80238 +int kvm_arch_init(const void *opaque);
80239 void kvm_arch_exit(void);
80240
80241 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80242 diff --git a/include/linux/libata.h b/include/linux/libata.h
80243 index 5ab4e3a..2fe237b 100644
80244 --- a/include/linux/libata.h
80245 +++ b/include/linux/libata.h
80246 @@ -975,7 +975,7 @@ struct ata_port_operations {
80247 * fields must be pointers.
80248 */
80249 const struct ata_port_operations *inherits;
80250 -};
80251 +} __do_const;
80252
80253 struct ata_port_info {
80254 unsigned long flags;
80255 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80256 index a6a42dd..6c5ebce 100644
80257 --- a/include/linux/linkage.h
80258 +++ b/include/linux/linkage.h
80259 @@ -36,6 +36,7 @@
80260 #endif
80261
80262 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80263 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80264 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80265
80266 /*
80267 diff --git a/include/linux/list.h b/include/linux/list.h
80268 index ef95941..82db65a 100644
80269 --- a/include/linux/list.h
80270 +++ b/include/linux/list.h
80271 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80272 extern void list_del(struct list_head *entry);
80273 #endif
80274
80275 +extern void __pax_list_add(struct list_head *new,
80276 + struct list_head *prev,
80277 + struct list_head *next);
80278 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
80279 +{
80280 + __pax_list_add(new, head, head->next);
80281 +}
80282 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80283 +{
80284 + __pax_list_add(new, head->prev, head);
80285 +}
80286 +extern void pax_list_del(struct list_head *entry);
80287 +
80288 /**
80289 * list_replace - replace old entry by new one
80290 * @old : the element to be replaced
80291 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80292 INIT_LIST_HEAD(entry);
80293 }
80294
80295 +extern void pax_list_del_init(struct list_head *entry);
80296 +
80297 /**
80298 * list_move - delete from one list and add as another's head
80299 * @list: the entry to move
80300 diff --git a/include/linux/math64.h b/include/linux/math64.h
80301 index c45c089..298841c 100644
80302 --- a/include/linux/math64.h
80303 +++ b/include/linux/math64.h
80304 @@ -15,7 +15,7 @@
80305 * This is commonly provided by 32bit archs to provide an optimized 64bit
80306 * divide.
80307 */
80308 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80309 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80310 {
80311 *remainder = dividend % divisor;
80312 return dividend / divisor;
80313 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80314 /**
80315 * div64_u64 - unsigned 64bit divide with 64bit divisor
80316 */
80317 -static inline u64 div64_u64(u64 dividend, u64 divisor)
80318 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80319 {
80320 return dividend / divisor;
80321 }
80322 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80323 #define div64_ul(x, y) div_u64((x), (y))
80324
80325 #ifndef div_u64_rem
80326 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80327 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80328 {
80329 *remainder = do_div(dividend, divisor);
80330 return dividend;
80331 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80332 #endif
80333
80334 #ifndef div64_u64
80335 -extern u64 div64_u64(u64 dividend, u64 divisor);
80336 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80337 #endif
80338
80339 #ifndef div64_s64
80340 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80341 * divide.
80342 */
80343 #ifndef div_u64
80344 -static inline u64 div_u64(u64 dividend, u32 divisor)
80345 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80346 {
80347 u32 remainder;
80348 return div_u64_rem(dividend, divisor, &remainder);
80349 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80350 index f230a97..714c006 100644
80351 --- a/include/linux/mempolicy.h
80352 +++ b/include/linux/mempolicy.h
80353 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80354 }
80355
80356 #define vma_policy(vma) ((vma)->vm_policy)
80357 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80358 +{
80359 + vma->vm_policy = pol;
80360 +}
80361
80362 static inline void mpol_get(struct mempolicy *pol)
80363 {
80364 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80365 }
80366
80367 #define vma_policy(vma) NULL
80368 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80369 +{
80370 +}
80371
80372 static inline int
80373 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80374 diff --git a/include/linux/mm.h b/include/linux/mm.h
80375 index d677706..673408c 100644
80376 --- a/include/linux/mm.h
80377 +++ b/include/linux/mm.h
80378 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80379 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80380 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80381 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80382 +
80383 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80384 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80385 +#endif
80386 +
80387 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80388
80389 #ifdef CONFIG_MEM_SOFT_DIRTY
80390 @@ -237,8 +242,8 @@ struct vm_operations_struct {
80391 /* called by access_process_vm when get_user_pages() fails, typically
80392 * for use by special VMAs that can switch between memory and hardware
80393 */
80394 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
80395 - void *buf, int len, int write);
80396 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80397 + void *buf, size_t len, int write);
80398 #ifdef CONFIG_NUMA
80399 /*
80400 * set_policy() op must add a reference to any non-NULL @new mempolicy
80401 @@ -268,6 +273,7 @@ struct vm_operations_struct {
80402 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80403 unsigned long size, pgoff_t pgoff);
80404 };
80405 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80406
80407 struct mmu_gather;
80408 struct inode;
80409 @@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80410 unsigned long *pfn);
80411 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80412 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80413 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80414 - void *buf, int len, int write);
80415 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80416 + void *buf, size_t len, int write);
80417
80418 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80419 loff_t const holebegin, loff_t const holelen)
80420 @@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80421 }
80422 #endif
80423
80424 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80425 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80426 - void *buf, int len, int write);
80427 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80428 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80429 + void *buf, size_t len, int write);
80430
80431 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80432 unsigned long start, unsigned long nr_pages,
80433 @@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80434 int clear_page_dirty_for_io(struct page *page);
80435 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80436
80437 -/* Is the vma a continuation of the stack vma above it? */
80438 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80439 -{
80440 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80441 -}
80442 -
80443 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80444 - unsigned long addr)
80445 -{
80446 - return (vma->vm_flags & VM_GROWSDOWN) &&
80447 - (vma->vm_start == addr) &&
80448 - !vma_growsdown(vma->vm_prev, addr);
80449 -}
80450 -
80451 -/* Is the vma a continuation of the stack vma below it? */
80452 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80453 -{
80454 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80455 -}
80456 -
80457 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80458 - unsigned long addr)
80459 -{
80460 - return (vma->vm_flags & VM_GROWSUP) &&
80461 - (vma->vm_end == addr) &&
80462 - !vma_growsup(vma->vm_next, addr);
80463 -}
80464 -
80465 extern pid_t
80466 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80467
80468 @@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80469 }
80470 #endif
80471
80472 +#ifdef CONFIG_MMU
80473 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80474 +#else
80475 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80476 +{
80477 + return __pgprot(0);
80478 +}
80479 +#endif
80480 +
80481 int vma_wants_writenotify(struct vm_area_struct *vma);
80482
80483 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80484 @@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80485 {
80486 return 0;
80487 }
80488 +
80489 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80490 + unsigned long address)
80491 +{
80492 + return 0;
80493 +}
80494 #else
80495 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80496 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80497 #endif
80498
80499 #ifdef __PAGETABLE_PMD_FOLDED
80500 @@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80501 {
80502 return 0;
80503 }
80504 +
80505 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80506 + unsigned long address)
80507 +{
80508 + return 0;
80509 +}
80510 #else
80511 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80512 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80513 #endif
80514
80515 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80516 @@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80517 NULL: pud_offset(pgd, address);
80518 }
80519
80520 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80521 +{
80522 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80523 + NULL: pud_offset(pgd, address);
80524 +}
80525 +
80526 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80527 {
80528 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80529 NULL: pmd_offset(pud, address);
80530 }
80531 +
80532 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80533 +{
80534 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80535 + NULL: pmd_offset(pud, address);
80536 +}
80537 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80538
80539 #if USE_SPLIT_PTE_PTLOCKS
80540 @@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80541 unsigned long addr, unsigned long len,
80542 unsigned long flags, struct page **pages);
80543
80544 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80545 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80546
80547 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80548 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80549 @@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80550 unsigned long len, unsigned long prot, unsigned long flags,
80551 unsigned long pgoff, unsigned long *populate);
80552 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80553 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80554
80555 #ifdef CONFIG_MMU
80556 extern int __mm_populate(unsigned long addr, unsigned long len,
80557 @@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80558 unsigned long high_limit;
80559 unsigned long align_mask;
80560 unsigned long align_offset;
80561 + unsigned long threadstack_offset;
80562 };
80563
80564 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80565 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80566 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80567 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80568
80569 /*
80570 * Search for an unmapped address range.
80571 @@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80572 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80573 */
80574 static inline unsigned long
80575 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80576 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80577 {
80578 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80579 return unmapped_area(info);
80580 @@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80581 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80582 struct vm_area_struct **pprev);
80583
80584 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80585 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80586 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80587 +
80588 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80589 NULL if none. Assume start_addr < end_addr. */
80590 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80591 @@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80592 return vma;
80593 }
80594
80595 -#ifdef CONFIG_MMU
80596 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80597 -#else
80598 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80599 -{
80600 - return __pgprot(0);
80601 -}
80602 -#endif
80603 -
80604 #ifdef CONFIG_NUMA_BALANCING
80605 unsigned long change_prot_numa(struct vm_area_struct *vma,
80606 unsigned long start, unsigned long end);
80607 @@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80608 static inline void vm_stat_account(struct mm_struct *mm,
80609 unsigned long flags, struct file *file, long pages)
80610 {
80611 +
80612 +#ifdef CONFIG_PAX_RANDMMAP
80613 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80614 +#endif
80615 +
80616 mm->total_vm += pages;
80617 }
80618 #endif /* CONFIG_PROC_FS */
80619 @@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80620 extern int sysctl_memory_failure_early_kill;
80621 extern int sysctl_memory_failure_recovery;
80622 extern void shake_page(struct page *p, int access);
80623 -extern atomic_long_t num_poisoned_pages;
80624 +extern atomic_long_unchecked_t num_poisoned_pages;
80625 extern int soft_offline_page(struct page *page, int flags);
80626
80627 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80628 @@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80629 static inline void setup_nr_node_ids(void) {}
80630 #endif
80631
80632 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80633 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80634 +#else
80635 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80636 +#endif
80637 +
80638 #endif /* __KERNEL__ */
80639 #endif /* _LINUX_MM_H */
80640 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80641 index 8967e20..61f7900 100644
80642 --- a/include/linux/mm_types.h
80643 +++ b/include/linux/mm_types.h
80644 @@ -308,7 +308,9 @@ struct vm_area_struct {
80645 #ifdef CONFIG_NUMA
80646 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80647 #endif
80648 -};
80649 +
80650 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80651 +} __randomize_layout;
80652
80653 struct core_thread {
80654 struct task_struct *task;
80655 @@ -454,7 +456,25 @@ struct mm_struct {
80656 bool tlb_flush_pending;
80657 #endif
80658 struct uprobes_state uprobes_state;
80659 -};
80660 +
80661 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80662 + unsigned long pax_flags;
80663 +#endif
80664 +
80665 +#ifdef CONFIG_PAX_DLRESOLVE
80666 + unsigned long call_dl_resolve;
80667 +#endif
80668 +
80669 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80670 + unsigned long call_syscall;
80671 +#endif
80672 +
80673 +#ifdef CONFIG_PAX_ASLR
80674 + unsigned long delta_mmap; /* randomized offset */
80675 + unsigned long delta_stack; /* randomized offset */
80676 +#endif
80677 +
80678 +} __randomize_layout;
80679
80680 static inline void mm_init_cpumask(struct mm_struct *mm)
80681 {
80682 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80683 index c5d5278..f0b68c8 100644
80684 --- a/include/linux/mmiotrace.h
80685 +++ b/include/linux/mmiotrace.h
80686 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80687 /* Called from ioremap.c */
80688 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80689 void __iomem *addr);
80690 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80691 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80692
80693 /* For anyone to insert markers. Remember trailing newline. */
80694 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80695 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80696 {
80697 }
80698
80699 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80700 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80701 {
80702 }
80703
80704 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80705 index 835aa3d..676b387 100644
80706 --- a/include/linux/mmzone.h
80707 +++ b/include/linux/mmzone.h
80708 @@ -406,7 +406,7 @@ struct zone {
80709 unsigned long flags; /* zone flags, see below */
80710
80711 /* Zone statistics */
80712 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80713 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80714
80715 /*
80716 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80717 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80718 index 44eeef0..a92d3f9 100644
80719 --- a/include/linux/mod_devicetable.h
80720 +++ b/include/linux/mod_devicetable.h
80721 @@ -139,7 +139,7 @@ struct usb_device_id {
80722 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80723 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80724
80725 -#define HID_ANY_ID (~0)
80726 +#define HID_ANY_ID (~0U)
80727 #define HID_BUS_ANY 0xffff
80728 #define HID_GROUP_ANY 0x0000
80729
80730 @@ -475,7 +475,7 @@ struct dmi_system_id {
80731 const char *ident;
80732 struct dmi_strmatch matches[4];
80733 void *driver_data;
80734 -};
80735 +} __do_const;
80736 /*
80737 * struct dmi_device_id appears during expansion of
80738 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80739 diff --git a/include/linux/module.h b/include/linux/module.h
80740 index f520a76..5f898ef 100644
80741 --- a/include/linux/module.h
80742 +++ b/include/linux/module.h
80743 @@ -17,9 +17,11 @@
80744 #include <linux/moduleparam.h>
80745 #include <linux/jump_label.h>
80746 #include <linux/export.h>
80747 +#include <linux/fs.h>
80748
80749 #include <linux/percpu.h>
80750 #include <asm/module.h>
80751 +#include <asm/pgtable.h>
80752
80753 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80754 #define MODULE_SIG_STRING "~Module signature appended~\n"
80755 @@ -42,7 +44,7 @@ struct module_kobject {
80756 struct kobject *drivers_dir;
80757 struct module_param_attrs *mp;
80758 struct completion *kobj_completion;
80759 -};
80760 +} __randomize_layout;
80761
80762 struct module_attribute {
80763 struct attribute attr;
80764 @@ -54,12 +56,13 @@ struct module_attribute {
80765 int (*test)(struct module *);
80766 void (*free)(struct module *);
80767 };
80768 +typedef struct module_attribute __no_const module_attribute_no_const;
80769
80770 struct module_version_attribute {
80771 struct module_attribute mattr;
80772 const char *module_name;
80773 const char *version;
80774 -} __attribute__ ((__aligned__(sizeof(void *))));
80775 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80776
80777 extern ssize_t __modver_version_show(struct module_attribute *,
80778 struct module_kobject *, char *);
80779 @@ -235,7 +238,7 @@ struct module {
80780
80781 /* Sysfs stuff. */
80782 struct module_kobject mkobj;
80783 - struct module_attribute *modinfo_attrs;
80784 + module_attribute_no_const *modinfo_attrs;
80785 const char *version;
80786 const char *srcversion;
80787 struct kobject *holders_dir;
80788 @@ -284,19 +287,16 @@ struct module {
80789 int (*init)(void);
80790
80791 /* If this is non-NULL, vfree after init() returns */
80792 - void *module_init;
80793 + void *module_init_rx, *module_init_rw;
80794
80795 /* Here is the actual code + data, vfree'd on unload. */
80796 - void *module_core;
80797 + void *module_core_rx, *module_core_rw;
80798
80799 /* Here are the sizes of the init and core sections */
80800 - unsigned int init_size, core_size;
80801 + unsigned int init_size_rw, core_size_rw;
80802
80803 /* The size of the executable code in each section. */
80804 - unsigned int init_text_size, core_text_size;
80805 -
80806 - /* Size of RO sections of the module (text+rodata) */
80807 - unsigned int init_ro_size, core_ro_size;
80808 + unsigned int init_size_rx, core_size_rx;
80809
80810 /* Arch-specific module values */
80811 struct mod_arch_specific arch;
80812 @@ -352,6 +352,10 @@ struct module {
80813 #ifdef CONFIG_EVENT_TRACING
80814 struct ftrace_event_call **trace_events;
80815 unsigned int num_trace_events;
80816 + struct file_operations trace_id;
80817 + struct file_operations trace_enable;
80818 + struct file_operations trace_format;
80819 + struct file_operations trace_filter;
80820 #endif
80821 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80822 unsigned int num_ftrace_callsites;
80823 @@ -375,7 +379,7 @@ struct module {
80824 ctor_fn_t *ctors;
80825 unsigned int num_ctors;
80826 #endif
80827 -};
80828 +} __randomize_layout;
80829 #ifndef MODULE_ARCH_INIT
80830 #define MODULE_ARCH_INIT {}
80831 #endif
80832 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
80833 bool is_module_percpu_address(unsigned long addr);
80834 bool is_module_text_address(unsigned long addr);
80835
80836 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80837 +{
80838 +
80839 +#ifdef CONFIG_PAX_KERNEXEC
80840 + if (ktla_ktva(addr) >= (unsigned long)start &&
80841 + ktla_ktva(addr) < (unsigned long)start + size)
80842 + return 1;
80843 +#endif
80844 +
80845 + return ((void *)addr >= start && (void *)addr < start + size);
80846 +}
80847 +
80848 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80849 +{
80850 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80851 +}
80852 +
80853 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80854 +{
80855 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80856 +}
80857 +
80858 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80859 +{
80860 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80861 +}
80862 +
80863 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80864 +{
80865 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80866 +}
80867 +
80868 static inline int within_module_core(unsigned long addr, const struct module *mod)
80869 {
80870 - return (unsigned long)mod->module_core <= addr &&
80871 - addr < (unsigned long)mod->module_core + mod->core_size;
80872 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80873 }
80874
80875 static inline int within_module_init(unsigned long addr, const struct module *mod)
80876 {
80877 - return (unsigned long)mod->module_init <= addr &&
80878 - addr < (unsigned long)mod->module_init + mod->init_size;
80879 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80880 }
80881
80882 /* Search for module by name: must hold module_mutex. */
80883 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80884 index 560ca53..ef621ef 100644
80885 --- a/include/linux/moduleloader.h
80886 +++ b/include/linux/moduleloader.h
80887 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80888 sections. Returns NULL on failure. */
80889 void *module_alloc(unsigned long size);
80890
80891 +#ifdef CONFIG_PAX_KERNEXEC
80892 +void *module_alloc_exec(unsigned long size);
80893 +#else
80894 +#define module_alloc_exec(x) module_alloc(x)
80895 +#endif
80896 +
80897 /* Free memory returned from module_alloc. */
80898 void module_free(struct module *mod, void *module_region);
80899
80900 +#ifdef CONFIG_PAX_KERNEXEC
80901 +void module_free_exec(struct module *mod, void *module_region);
80902 +#else
80903 +#define module_free_exec(x, y) module_free((x), (y))
80904 +#endif
80905 +
80906 /*
80907 * Apply the given relocation to the (simplified) ELF. Return -error
80908 * or 0.
80909 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80910 unsigned int relsec,
80911 struct module *me)
80912 {
80913 +#ifdef CONFIG_MODULES
80914 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80915 +#endif
80916 return -ENOEXEC;
80917 }
80918 #endif
80919 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80920 unsigned int relsec,
80921 struct module *me)
80922 {
80923 +#ifdef CONFIG_MODULES
80924 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80925 +#endif
80926 return -ENOEXEC;
80927 }
80928 #endif
80929 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80930 index 204a677..e9b486a 100644
80931 --- a/include/linux/moduleparam.h
80932 +++ b/include/linux/moduleparam.h
80933 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
80934 * @len is usually just sizeof(string).
80935 */
80936 #define module_param_string(name, string, len, perm) \
80937 - static const struct kparam_string __param_string_##name \
80938 + static const struct kparam_string __param_string_##name __used \
80939 = { len, string }; \
80940 __module_param_call(MODULE_PARAM_PREFIX, name, \
80941 &param_ops_string, \
80942 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80943 */
80944 #define module_param_array_named(name, array, type, nump, perm) \
80945 param_check_##type(name, &(array)[0]); \
80946 - static const struct kparam_array __param_arr_##name \
80947 + static const struct kparam_array __param_arr_##name __used \
80948 = { .max = ARRAY_SIZE(array), .num = nump, \
80949 .ops = &param_ops_##type, \
80950 .elemsize = sizeof(array[0]), .elem = array }; \
80951 diff --git a/include/linux/mount.h b/include/linux/mount.h
80952 index 839bac2..a96b37c 100644
80953 --- a/include/linux/mount.h
80954 +++ b/include/linux/mount.h
80955 @@ -59,7 +59,7 @@ struct vfsmount {
80956 struct dentry *mnt_root; /* root of the mounted tree */
80957 struct super_block *mnt_sb; /* pointer to superblock */
80958 int mnt_flags;
80959 -};
80960 +} __randomize_layout;
80961
80962 struct file; /* forward dec */
80963
80964 diff --git a/include/linux/namei.h b/include/linux/namei.h
80965 index 492de72..1bddcd4 100644
80966 --- a/include/linux/namei.h
80967 +++ b/include/linux/namei.h
80968 @@ -19,7 +19,7 @@ struct nameidata {
80969 unsigned seq, m_seq;
80970 int last_type;
80971 unsigned depth;
80972 - char *saved_names[MAX_NESTED_LINKS + 1];
80973 + const char *saved_names[MAX_NESTED_LINKS + 1];
80974 };
80975
80976 /*
80977 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80978
80979 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80980
80981 -static inline void nd_set_link(struct nameidata *nd, char *path)
80982 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80983 {
80984 nd->saved_names[nd->depth] = path;
80985 }
80986
80987 -static inline char *nd_get_link(struct nameidata *nd)
80988 +static inline const char *nd_get_link(const struct nameidata *nd)
80989 {
80990 return nd->saved_names[nd->depth];
80991 }
80992 diff --git a/include/linux/net.h b/include/linux/net.h
80993 index 17d8339..81656c0 100644
80994 --- a/include/linux/net.h
80995 +++ b/include/linux/net.h
80996 @@ -192,7 +192,7 @@ struct net_proto_family {
80997 int (*create)(struct net *net, struct socket *sock,
80998 int protocol, int kern);
80999 struct module *owner;
81000 -};
81001 +} __do_const;
81002
81003 struct iovec;
81004 struct kvec;
81005 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81006 index b42d07b..7f45ae2 100644
81007 --- a/include/linux/netdevice.h
81008 +++ b/include/linux/netdevice.h
81009 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81010 void *priv);
81011 int (*ndo_get_lock_subclass)(struct net_device *dev);
81012 };
81013 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81014
81015 /**
81016 * enum net_device_priv_flags - &struct net_device priv_flags
81017 @@ -1313,11 +1314,11 @@ struct net_device {
81018 struct net_device_stats stats;
81019
81020 /* dropped packets by core network, Do not use this in drivers */
81021 - atomic_long_t rx_dropped;
81022 - atomic_long_t tx_dropped;
81023 + atomic_long_unchecked_t rx_dropped;
81024 + atomic_long_unchecked_t tx_dropped;
81025
81026 /* Stats to monitor carrier on<->off transitions */
81027 - atomic_t carrier_changes;
81028 + atomic_unchecked_t carrier_changes;
81029
81030 #ifdef CONFIG_WIRELESS_EXT
81031 /* List of functions to handle Wireless Extensions (instead of ioctl).
81032 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81033 index 2077489..a15e561 100644
81034 --- a/include/linux/netfilter.h
81035 +++ b/include/linux/netfilter.h
81036 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81037 #endif
81038 /* Use the module struct to lock set/get code in place */
81039 struct module *owner;
81040 -};
81041 +} __do_const;
81042
81043 /* Function to register/unregister hook points. */
81044 int nf_register_hook(struct nf_hook_ops *reg);
81045 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81046 index e955d47..04a5338 100644
81047 --- a/include/linux/netfilter/nfnetlink.h
81048 +++ b/include/linux/netfilter/nfnetlink.h
81049 @@ -19,7 +19,7 @@ struct nfnl_callback {
81050 const struct nlattr * const cda[]);
81051 const struct nla_policy *policy; /* netlink attribute policy */
81052 const u_int16_t attr_count; /* number of nlattr's */
81053 -};
81054 +} __do_const;
81055
81056 struct nfnetlink_subsystem {
81057 const char *name;
81058 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81059 new file mode 100644
81060 index 0000000..33f4af8
81061 --- /dev/null
81062 +++ b/include/linux/netfilter/xt_gradm.h
81063 @@ -0,0 +1,9 @@
81064 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81065 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81066 +
81067 +struct xt_gradm_mtinfo {
81068 + __u16 flags;
81069 + __u16 invflags;
81070 +};
81071 +
81072 +#endif
81073 diff --git a/include/linux/nls.h b/include/linux/nls.h
81074 index 520681b..1d67ed2 100644
81075 --- a/include/linux/nls.h
81076 +++ b/include/linux/nls.h
81077 @@ -31,7 +31,7 @@ struct nls_table {
81078 const unsigned char *charset2upper;
81079 struct module *owner;
81080 struct nls_table *next;
81081 -};
81082 +} __do_const;
81083
81084 /* this value hold the maximum octet of charset */
81085 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81086 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81087 index d14a4c3..a078786 100644
81088 --- a/include/linux/notifier.h
81089 +++ b/include/linux/notifier.h
81090 @@ -54,7 +54,8 @@ struct notifier_block {
81091 notifier_fn_t notifier_call;
81092 struct notifier_block __rcu *next;
81093 int priority;
81094 -};
81095 +} __do_const;
81096 +typedef struct notifier_block __no_const notifier_block_no_const;
81097
81098 struct atomic_notifier_head {
81099 spinlock_t lock;
81100 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81101 index b2a0f15..4d7da32 100644
81102 --- a/include/linux/oprofile.h
81103 +++ b/include/linux/oprofile.h
81104 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81105 int oprofilefs_create_ro_ulong(struct dentry * root,
81106 char const * name, ulong * val);
81107
81108 -/** Create a file for read-only access to an atomic_t. */
81109 +/** Create a file for read-only access to an atomic_unchecked_t. */
81110 int oprofilefs_create_ro_atomic(struct dentry * root,
81111 - char const * name, atomic_t * val);
81112 + char const * name, atomic_unchecked_t * val);
81113
81114 /** create a directory */
81115 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81116 diff --git a/include/linux/padata.h b/include/linux/padata.h
81117 index 4386946..f50c615 100644
81118 --- a/include/linux/padata.h
81119 +++ b/include/linux/padata.h
81120 @@ -129,7 +129,7 @@ struct parallel_data {
81121 struct padata_serial_queue __percpu *squeue;
81122 atomic_t reorder_objects;
81123 atomic_t refcnt;
81124 - atomic_t seq_nr;
81125 + atomic_unchecked_t seq_nr;
81126 struct padata_cpumask cpumask;
81127 spinlock_t lock ____cacheline_aligned;
81128 unsigned int processed;
81129 diff --git a/include/linux/path.h b/include/linux/path.h
81130 index d137218..be0c176 100644
81131 --- a/include/linux/path.h
81132 +++ b/include/linux/path.h
81133 @@ -1,13 +1,15 @@
81134 #ifndef _LINUX_PATH_H
81135 #define _LINUX_PATH_H
81136
81137 +#include <linux/compiler.h>
81138 +
81139 struct dentry;
81140 struct vfsmount;
81141
81142 struct path {
81143 struct vfsmount *mnt;
81144 struct dentry *dentry;
81145 -};
81146 +} __randomize_layout;
81147
81148 extern void path_get(const struct path *);
81149 extern void path_put(const struct path *);
81150 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81151 index 5f2e559..7d59314 100644
81152 --- a/include/linux/pci_hotplug.h
81153 +++ b/include/linux/pci_hotplug.h
81154 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81155 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81156 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81157 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81158 -};
81159 +} __do_const;
81160 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81161
81162 /**
81163 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81164 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81165 index 3ef6ea1..ed1a248 100644
81166 --- a/include/linux/perf_event.h
81167 +++ b/include/linux/perf_event.h
81168 @@ -328,8 +328,8 @@ struct perf_event {
81169
81170 enum perf_event_active_state state;
81171 unsigned int attach_state;
81172 - local64_t count;
81173 - atomic64_t child_count;
81174 + local64_t count; /* PaX: fix it one day */
81175 + atomic64_unchecked_t child_count;
81176
81177 /*
81178 * These are the total time in nanoseconds that the event
81179 @@ -380,8 +380,8 @@ struct perf_event {
81180 * These accumulate total time (in nanoseconds) that children
81181 * events have been enabled and running, respectively.
81182 */
81183 - atomic64_t child_total_time_enabled;
81184 - atomic64_t child_total_time_running;
81185 + atomic64_unchecked_t child_total_time_enabled;
81186 + atomic64_unchecked_t child_total_time_running;
81187
81188 /*
81189 * Protect attach/detach and child_list:
81190 @@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81191 entry->ip[entry->nr++] = ip;
81192 }
81193
81194 -extern int sysctl_perf_event_paranoid;
81195 +extern int sysctl_perf_event_legitimately_concerned;
81196 extern int sysctl_perf_event_mlock;
81197 extern int sysctl_perf_event_sample_rate;
81198 extern int sysctl_perf_cpu_time_max_percent;
81199 @@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81200 loff_t *ppos);
81201
81202
81203 +static inline bool perf_paranoid_any(void)
81204 +{
81205 + return sysctl_perf_event_legitimately_concerned > 2;
81206 +}
81207 +
81208 static inline bool perf_paranoid_tracepoint_raw(void)
81209 {
81210 - return sysctl_perf_event_paranoid > -1;
81211 + return sysctl_perf_event_legitimately_concerned > -1;
81212 }
81213
81214 static inline bool perf_paranoid_cpu(void)
81215 {
81216 - return sysctl_perf_event_paranoid > 0;
81217 + return sysctl_perf_event_legitimately_concerned > 0;
81218 }
81219
81220 static inline bool perf_paranoid_kernel(void)
81221 {
81222 - return sysctl_perf_event_paranoid > 1;
81223 + return sysctl_perf_event_legitimately_concerned > 1;
81224 }
81225
81226 extern void perf_event_init(void);
81227 @@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81228 struct device_attribute attr;
81229 u64 id;
81230 const char *event_str;
81231 -};
81232 +} __do_const;
81233
81234 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81235 static struct perf_pmu_events_attr _var = { \
81236 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81237 index 7246ef3..1539ea4 100644
81238 --- a/include/linux/pid_namespace.h
81239 +++ b/include/linux/pid_namespace.h
81240 @@ -43,7 +43,7 @@ struct pid_namespace {
81241 int hide_pid;
81242 int reboot; /* group exit code if this pidns was rebooted */
81243 unsigned int proc_inum;
81244 -};
81245 +} __randomize_layout;
81246
81247 extern struct pid_namespace init_pid_ns;
81248
81249 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81250 index eb8b8ac..62649e1 100644
81251 --- a/include/linux/pipe_fs_i.h
81252 +++ b/include/linux/pipe_fs_i.h
81253 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81254 struct mutex mutex;
81255 wait_queue_head_t wait;
81256 unsigned int nrbufs, curbuf, buffers;
81257 - unsigned int readers;
81258 - unsigned int writers;
81259 - unsigned int files;
81260 - unsigned int waiting_writers;
81261 + atomic_t readers;
81262 + atomic_t writers;
81263 + atomic_t files;
81264 + atomic_t waiting_writers;
81265 unsigned int r_counter;
81266 unsigned int w_counter;
81267 struct page *tmp_page;
81268 diff --git a/include/linux/pm.h b/include/linux/pm.h
81269 index d915d03..0531037 100644
81270 --- a/include/linux/pm.h
81271 +++ b/include/linux/pm.h
81272 @@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81273 struct dev_pm_domain {
81274 struct dev_pm_ops ops;
81275 };
81276 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81277
81278 /*
81279 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81280 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81281 index 7c1d252..0e7061d 100644
81282 --- a/include/linux/pm_domain.h
81283 +++ b/include/linux/pm_domain.h
81284 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
81285 int (*thaw_early)(struct device *dev);
81286 int (*thaw)(struct device *dev);
81287 bool (*active_wakeup)(struct device *dev);
81288 -};
81289 +} __no_const;
81290
81291 struct gpd_cpu_data {
81292 unsigned int saved_exit_latency;
81293 - struct cpuidle_state *idle_state;
81294 + cpuidle_state_no_const *idle_state;
81295 };
81296
81297 struct generic_pm_domain {
81298 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81299 index 2a5897a..4f9af63 100644
81300 --- a/include/linux/pm_runtime.h
81301 +++ b/include/linux/pm_runtime.h
81302 @@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81303
81304 static inline void pm_runtime_mark_last_busy(struct device *dev)
81305 {
81306 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
81307 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81308 }
81309
81310 #else /* !CONFIG_PM_RUNTIME */
81311 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81312 index 195aafc..49a7bc2 100644
81313 --- a/include/linux/pnp.h
81314 +++ b/include/linux/pnp.h
81315 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81316 struct pnp_fixup {
81317 char id[7];
81318 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81319 -};
81320 +} __do_const;
81321
81322 /* config parameters */
81323 #define PNP_CONFIG_NORMAL 0x0001
81324 diff --git a/include/linux/poison.h b/include/linux/poison.h
81325 index 2110a81..13a11bb 100644
81326 --- a/include/linux/poison.h
81327 +++ b/include/linux/poison.h
81328 @@ -19,8 +19,8 @@
81329 * under normal circumstances, used to verify that nobody uses
81330 * non-initialized list entries.
81331 */
81332 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81333 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81334 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81335 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81336
81337 /********** include/linux/timer.h **********/
81338 /*
81339 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81340 index d8b187c3..9a9257a 100644
81341 --- a/include/linux/power/smartreflex.h
81342 +++ b/include/linux/power/smartreflex.h
81343 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
81344 int (*notify)(struct omap_sr *sr, u32 status);
81345 u8 notify_flags;
81346 u8 class_type;
81347 -};
81348 +} __do_const;
81349
81350 /**
81351 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81352 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81353 index 4ea1d37..80f4b33 100644
81354 --- a/include/linux/ppp-comp.h
81355 +++ b/include/linux/ppp-comp.h
81356 @@ -84,7 +84,7 @@ struct compressor {
81357 struct module *owner;
81358 /* Extra skb space needed by the compressor algorithm */
81359 unsigned int comp_extra;
81360 -};
81361 +} __do_const;
81362
81363 /*
81364 * The return value from decompress routine is the length of the
81365 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81366 index de83b4e..c4b997d 100644
81367 --- a/include/linux/preempt.h
81368 +++ b/include/linux/preempt.h
81369 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81370 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81371 #endif
81372
81373 +#define raw_preempt_count_add(val) __preempt_count_add(val)
81374 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81375 +
81376 #define __preempt_count_inc() __preempt_count_add(1)
81377 #define __preempt_count_dec() __preempt_count_sub(1)
81378
81379 #define preempt_count_inc() preempt_count_add(1)
81380 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
81381 #define preempt_count_dec() preempt_count_sub(1)
81382 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81383
81384 #ifdef CONFIG_PREEMPT_COUNT
81385
81386 @@ -41,6 +46,12 @@ do { \
81387 barrier(); \
81388 } while (0)
81389
81390 +#define raw_preempt_disable() \
81391 +do { \
81392 + raw_preempt_count_inc(); \
81393 + barrier(); \
81394 +} while (0)
81395 +
81396 #define sched_preempt_enable_no_resched() \
81397 do { \
81398 barrier(); \
81399 @@ -49,6 +60,12 @@ do { \
81400
81401 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81402
81403 +#define raw_preempt_enable_no_resched() \
81404 +do { \
81405 + barrier(); \
81406 + raw_preempt_count_dec(); \
81407 +} while (0)
81408 +
81409 #ifdef CONFIG_PREEMPT
81410 #define preempt_enable() \
81411 do { \
81412 @@ -113,8 +130,10 @@ do { \
81413 * region.
81414 */
81415 #define preempt_disable() barrier()
81416 +#define raw_preempt_disable() barrier()
81417 #define sched_preempt_enable_no_resched() barrier()
81418 #define preempt_enable_no_resched() barrier()
81419 +#define raw_preempt_enable_no_resched() barrier()
81420 #define preempt_enable() barrier()
81421 #define preempt_check_resched() do { } while (0)
81422
81423 @@ -128,11 +147,13 @@ do { \
81424 /*
81425 * Modules have no business playing preemption tricks.
81426 */
81427 +#ifndef CONFIG_PAX_KERNEXEC
81428 #undef sched_preempt_enable_no_resched
81429 #undef preempt_enable_no_resched
81430 #undef preempt_enable_no_resched_notrace
81431 #undef preempt_check_resched
81432 #endif
81433 +#endif
81434
81435 #define preempt_set_need_resched() \
81436 do { \
81437 diff --git a/include/linux/printk.h b/include/linux/printk.h
81438 index 8752f75..2b80c0f 100644
81439 --- a/include/linux/printk.h
81440 +++ b/include/linux/printk.h
81441 @@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81442 void early_printk(const char *s, ...) { }
81443 #endif
81444
81445 +extern int kptr_restrict;
81446 +
81447 #ifdef CONFIG_PRINTK
81448 asmlinkage __printf(5, 0)
81449 int vprintk_emit(int facility, int level,
81450 @@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81451
81452 extern int printk_delay_msec;
81453 extern int dmesg_restrict;
81454 -extern int kptr_restrict;
81455
81456 extern void wake_up_klogd(void);
81457
81458 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81459 index 608e60a..79cfb18 100644
81460 --- a/include/linux/proc_fs.h
81461 +++ b/include/linux/proc_fs.h
81462 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81463 extern struct proc_dir_entry *proc_symlink(const char *,
81464 struct proc_dir_entry *, const char *);
81465 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81466 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81467 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81468 struct proc_dir_entry *, void *);
81469 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81470 + struct proc_dir_entry *, void *);
81471 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81472 struct proc_dir_entry *);
81473
81474 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81475 return proc_create_data(name, mode, parent, proc_fops, NULL);
81476 }
81477
81478 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81479 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81480 +{
81481 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81482 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81483 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81484 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81485 +#else
81486 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81487 +#endif
81488 +}
81489 +
81490 +
81491 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81492 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81493 extern void *PDE_DATA(const struct inode *);
81494 @@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81495 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81496 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81497 struct proc_dir_entry *parent) {return NULL;}
81498 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81499 + struct proc_dir_entry *parent) { return NULL; }
81500 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81501 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81502 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81503 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81504 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81505 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81506 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81507 @@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81508 static inline struct proc_dir_entry *proc_net_mkdir(
81509 struct net *net, const char *name, struct proc_dir_entry *parent)
81510 {
81511 - return proc_mkdir_data(name, 0, parent, net);
81512 + return proc_mkdir_data_restrict(name, 0, parent, net);
81513 }
81514
81515 #endif /* _LINUX_PROC_FS_H */
81516 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81517 index 34a1e10..70f6bde 100644
81518 --- a/include/linux/proc_ns.h
81519 +++ b/include/linux/proc_ns.h
81520 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81521 void (*put)(void *ns);
81522 int (*install)(struct nsproxy *nsproxy, void *ns);
81523 unsigned int (*inum)(void *ns);
81524 -};
81525 +} __do_const __randomize_layout;
81526
81527 struct proc_ns {
81528 void *ns;
81529 diff --git a/include/linux/quota.h b/include/linux/quota.h
81530 index cc7494a..1e27036 100644
81531 --- a/include/linux/quota.h
81532 +++ b/include/linux/quota.h
81533 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81534
81535 extern bool qid_eq(struct kqid left, struct kqid right);
81536 extern bool qid_lt(struct kqid left, struct kqid right);
81537 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81538 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81539 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81540 extern bool qid_valid(struct kqid qid);
81541
81542 diff --git a/include/linux/random.h b/include/linux/random.h
81543 index 57fbbff..2331f3f 100644
81544 --- a/include/linux/random.h
81545 +++ b/include/linux/random.h
81546 @@ -9,9 +9,19 @@
81547 #include <uapi/linux/random.h>
81548
81549 extern void add_device_randomness(const void *, unsigned int);
81550 +
81551 +static inline void add_latent_entropy(void)
81552 +{
81553 +
81554 +#ifdef LATENT_ENTROPY_PLUGIN
81555 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81556 +#endif
81557 +
81558 +}
81559 +
81560 extern void add_input_randomness(unsigned int type, unsigned int code,
81561 - unsigned int value);
81562 -extern void add_interrupt_randomness(int irq, int irq_flags);
81563 + unsigned int value) __latent_entropy;
81564 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81565
81566 extern void get_random_bytes(void *buf, int nbytes);
81567 extern void get_random_bytes_arch(void *buf, int nbytes);
81568 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81569 extern const struct file_operations random_fops, urandom_fops;
81570 #endif
81571
81572 -unsigned int get_random_int(void);
81573 +unsigned int __intentional_overflow(-1) get_random_int(void);
81574 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81575
81576 -u32 prandom_u32(void);
81577 +u32 prandom_u32(void) __intentional_overflow(-1);
81578 void prandom_bytes(void *buf, int nbytes);
81579 void prandom_seed(u32 seed);
81580 void prandom_reseed_late(void);
81581 @@ -37,6 +47,11 @@ struct rnd_state {
81582 u32 prandom_u32_state(struct rnd_state *state);
81583 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81584
81585 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81586 +{
81587 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81588 +}
81589 +
81590 /**
81591 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81592 * @ep_ro: right open interval endpoint
81593 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81594 index fea49b5..2ac22bb 100644
81595 --- a/include/linux/rbtree_augmented.h
81596 +++ b/include/linux/rbtree_augmented.h
81597 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81598 old->rbaugmented = rbcompute(old); \
81599 } \
81600 rbstatic const struct rb_augment_callbacks rbname = { \
81601 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81602 + .propagate = rbname ## _propagate, \
81603 + .copy = rbname ## _copy, \
81604 + .rotate = rbname ## _rotate \
81605 };
81606
81607
81608 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81609 index 8183b46..a388711 100644
81610 --- a/include/linux/rculist.h
81611 +++ b/include/linux/rculist.h
81612 @@ -29,8 +29,8 @@
81613 */
81614 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81615 {
81616 - ACCESS_ONCE(list->next) = list;
81617 - ACCESS_ONCE(list->prev) = list;
81618 + ACCESS_ONCE_RW(list->next) = list;
81619 + ACCESS_ONCE_RW(list->prev) = list;
81620 }
81621
81622 /*
81623 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81624 struct list_head *prev, struct list_head *next);
81625 #endif
81626
81627 +void __pax_list_add_rcu(struct list_head *new,
81628 + struct list_head *prev, struct list_head *next);
81629 +
81630 /**
81631 * list_add_rcu - add a new entry to rcu-protected list
81632 * @new: new entry to be added
81633 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81634 __list_add_rcu(new, head, head->next);
81635 }
81636
81637 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81638 +{
81639 + __pax_list_add_rcu(new, head, head->next);
81640 +}
81641 +
81642 /**
81643 * list_add_tail_rcu - add a new entry to rcu-protected list
81644 * @new: new entry to be added
81645 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81646 __list_add_rcu(new, head->prev, head);
81647 }
81648
81649 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81650 + struct list_head *head)
81651 +{
81652 + __pax_list_add_rcu(new, head->prev, head);
81653 +}
81654 +
81655 /**
81656 * list_del_rcu - deletes entry from list without re-initialization
81657 * @entry: the element to delete from the list.
81658 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81659 entry->prev = LIST_POISON2;
81660 }
81661
81662 +extern void pax_list_del_rcu(struct list_head *entry);
81663 +
81664 /**
81665 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81666 * @n: the element to delete from the hash list.
81667 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81668 index 48bf152..d38b785 100644
81669 --- a/include/linux/reboot.h
81670 +++ b/include/linux/reboot.h
81671 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81672 */
81673
81674 extern void migrate_to_reboot_cpu(void);
81675 -extern void machine_restart(char *cmd);
81676 -extern void machine_halt(void);
81677 -extern void machine_power_off(void);
81678 +extern void machine_restart(char *cmd) __noreturn;
81679 +extern void machine_halt(void) __noreturn;
81680 +extern void machine_power_off(void) __noreturn;
81681
81682 extern void machine_shutdown(void);
81683 struct pt_regs;
81684 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81685 */
81686
81687 extern void kernel_restart_prepare(char *cmd);
81688 -extern void kernel_restart(char *cmd);
81689 -extern void kernel_halt(void);
81690 -extern void kernel_power_off(void);
81691 +extern void kernel_restart(char *cmd) __noreturn;
81692 +extern void kernel_halt(void) __noreturn;
81693 +extern void kernel_power_off(void) __noreturn;
81694
81695 extern int C_A_D; /* for sysctl */
81696 void ctrl_alt_del(void);
81697 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81698 * Emergency restart, callable from an interrupt handler.
81699 */
81700
81701 -extern void emergency_restart(void);
81702 +extern void emergency_restart(void) __noreturn;
81703 #include <asm/emergency-restart.h>
81704
81705 #endif /* _LINUX_REBOOT_H */
81706 diff --git a/include/linux/regset.h b/include/linux/regset.h
81707 index 8e0c9fe..ac4d221 100644
81708 --- a/include/linux/regset.h
81709 +++ b/include/linux/regset.h
81710 @@ -161,7 +161,8 @@ struct user_regset {
81711 unsigned int align;
81712 unsigned int bias;
81713 unsigned int core_note_type;
81714 -};
81715 +} __do_const;
81716 +typedef struct user_regset __no_const user_regset_no_const;
81717
81718 /**
81719 * struct user_regset_view - available regsets
81720 diff --git a/include/linux/relay.h b/include/linux/relay.h
81721 index d7c8359..818daf5 100644
81722 --- a/include/linux/relay.h
81723 +++ b/include/linux/relay.h
81724 @@ -157,7 +157,7 @@ struct rchan_callbacks
81725 * The callback should return 0 if successful, negative if not.
81726 */
81727 int (*remove_buf_file)(struct dentry *dentry);
81728 -};
81729 +} __no_const;
81730
81731 /*
81732 * CONFIG_RELAY kernel API, kernel/relay.c
81733 diff --git a/include/linux/rio.h b/include/linux/rio.h
81734 index 6bda06f..bf39a9b 100644
81735 --- a/include/linux/rio.h
81736 +++ b/include/linux/rio.h
81737 @@ -358,7 +358,7 @@ struct rio_ops {
81738 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81739 u64 rstart, u32 size, u32 flags);
81740 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81741 -};
81742 +} __no_const;
81743
81744 #define RIO_RESOURCE_MEM 0x00000100
81745 #define RIO_RESOURCE_DOORBELL 0x00000200
81746 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81747 index b66c211..13d2915 100644
81748 --- a/include/linux/rmap.h
81749 +++ b/include/linux/rmap.h
81750 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81751 void anon_vma_init(void); /* create anon_vma_cachep */
81752 int anon_vma_prepare(struct vm_area_struct *);
81753 void unlink_anon_vmas(struct vm_area_struct *);
81754 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81755 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81756 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81757 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81758
81759 static inline void anon_vma_merge(struct vm_area_struct *vma,
81760 struct vm_area_struct *next)
81761 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
81762 index a964f72..b475afb 100644
81763 --- a/include/linux/scatterlist.h
81764 +++ b/include/linux/scatterlist.h
81765 @@ -1,6 +1,7 @@
81766 #ifndef _LINUX_SCATTERLIST_H
81767 #define _LINUX_SCATTERLIST_H
81768
81769 +#include <linux/sched.h>
81770 #include <linux/string.h>
81771 #include <linux/bug.h>
81772 #include <linux/mm.h>
81773 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81774 #ifdef CONFIG_DEBUG_SG
81775 BUG_ON(!virt_addr_valid(buf));
81776 #endif
81777 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81778 + if (object_starts_on_stack(buf)) {
81779 + void *adjbuf = buf - current->stack + current->lowmem_stack;
81780 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
81781 + } else
81782 +#endif
81783 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
81784 }
81785
81786 diff --git a/include/linux/sched.h b/include/linux/sched.h
81787 index 221b2bd..e2e5f82 100644
81788 --- a/include/linux/sched.h
81789 +++ b/include/linux/sched.h
81790 @@ -131,6 +131,7 @@ struct fs_struct;
81791 struct perf_event_context;
81792 struct blk_plug;
81793 struct filename;
81794 +struct linux_binprm;
81795
81796 #define VMACACHE_BITS 2
81797 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
81798 @@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
81799 extern int in_sched_functions(unsigned long addr);
81800
81801 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81802 -extern signed long schedule_timeout(signed long timeout);
81803 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81804 extern signed long schedule_timeout_interruptible(signed long timeout);
81805 extern signed long schedule_timeout_killable(signed long timeout);
81806 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81807 @@ -391,6 +392,19 @@ struct nsproxy;
81808 struct user_namespace;
81809
81810 #ifdef CONFIG_MMU
81811 +
81812 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81813 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81814 +#else
81815 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81816 +{
81817 + return 0;
81818 +}
81819 +#endif
81820 +
81821 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81822 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81823 +
81824 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81825 extern unsigned long
81826 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81827 @@ -688,6 +702,17 @@ struct signal_struct {
81828 #ifdef CONFIG_TASKSTATS
81829 struct taskstats *stats;
81830 #endif
81831 +
81832 +#ifdef CONFIG_GRKERNSEC
81833 + u32 curr_ip;
81834 + u32 saved_ip;
81835 + u32 gr_saddr;
81836 + u32 gr_daddr;
81837 + u16 gr_sport;
81838 + u16 gr_dport;
81839 + u8 used_accept:1;
81840 +#endif
81841 +
81842 #ifdef CONFIG_AUDIT
81843 unsigned audit_tty;
81844 unsigned audit_tty_log_passwd;
81845 @@ -714,7 +739,7 @@ struct signal_struct {
81846 struct mutex cred_guard_mutex; /* guard against foreign influences on
81847 * credential calculations
81848 * (notably. ptrace) */
81849 -};
81850 +} __randomize_layout;
81851
81852 /*
81853 * Bits in flags field of signal_struct.
81854 @@ -768,6 +793,14 @@ struct user_struct {
81855 struct key *session_keyring; /* UID's default session keyring */
81856 #endif
81857
81858 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81859 + unsigned char kernel_banned;
81860 +#endif
81861 +#ifdef CONFIG_GRKERNSEC_BRUTE
81862 + unsigned char suid_banned;
81863 + unsigned long suid_ban_expires;
81864 +#endif
81865 +
81866 /* Hash table maintenance information */
81867 struct hlist_node uidhash_node;
81868 kuid_t uid;
81869 @@ -775,7 +808,7 @@ struct user_struct {
81870 #ifdef CONFIG_PERF_EVENTS
81871 atomic_long_t locked_vm;
81872 #endif
81873 -};
81874 +} __randomize_layout;
81875
81876 extern int uids_sysfs_init(void);
81877
81878 @@ -1179,6 +1212,9 @@ enum perf_event_task_context {
81879 struct task_struct {
81880 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
81881 void *stack;
81882 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81883 + void *lowmem_stack;
81884 +#endif
81885 atomic_t usage;
81886 unsigned int flags; /* per process flags, defined below */
81887 unsigned int ptrace;
81888 @@ -1304,8 +1340,8 @@ struct task_struct {
81889 struct list_head thread_node;
81890
81891 struct completion *vfork_done; /* for vfork() */
81892 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81893 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81894 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81895 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81896
81897 cputime_t utime, stime, utimescaled, stimescaled;
81898 cputime_t gtime;
81899 @@ -1330,11 +1366,6 @@ struct task_struct {
81900 struct task_cputime cputime_expires;
81901 struct list_head cpu_timers[3];
81902
81903 -/* process credentials */
81904 - const struct cred __rcu *real_cred; /* objective and real subjective task
81905 - * credentials (COW) */
81906 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81907 - * credentials (COW) */
81908 char comm[TASK_COMM_LEN]; /* executable name excluding path
81909 - access with [gs]et_task_comm (which lock
81910 it with task_lock())
81911 @@ -1351,6 +1382,10 @@ struct task_struct {
81912 #endif
81913 /* CPU-specific state of this task */
81914 struct thread_struct thread;
81915 +/* thread_info moved to task_struct */
81916 +#ifdef CONFIG_X86
81917 + struct thread_info tinfo;
81918 +#endif
81919 /* filesystem information */
81920 struct fs_struct *fs;
81921 /* open file information */
81922 @@ -1427,6 +1462,10 @@ struct task_struct {
81923 gfp_t lockdep_reclaim_gfp;
81924 #endif
81925
81926 +/* process credentials */
81927 + const struct cred __rcu *real_cred; /* objective and real subjective task
81928 + * credentials (COW) */
81929 +
81930 /* journalling filesystem info */
81931 void *journal_info;
81932
81933 @@ -1465,6 +1504,10 @@ struct task_struct {
81934 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81935 struct list_head cg_list;
81936 #endif
81937 +
81938 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81939 + * credentials (COW) */
81940 +
81941 #ifdef CONFIG_FUTEX
81942 struct robust_list_head __user *robust_list;
81943 #ifdef CONFIG_COMPAT
81944 @@ -1610,7 +1653,78 @@ struct task_struct {
81945 unsigned int sequential_io;
81946 unsigned int sequential_io_avg;
81947 #endif
81948 -};
81949 +
81950 +#ifdef CONFIG_GRKERNSEC
81951 + /* grsecurity */
81952 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81953 + u64 exec_id;
81954 +#endif
81955 +#ifdef CONFIG_GRKERNSEC_SETXID
81956 + const struct cred *delayed_cred;
81957 +#endif
81958 + struct dentry *gr_chroot_dentry;
81959 + struct acl_subject_label *acl;
81960 + struct acl_subject_label *tmpacl;
81961 + struct acl_role_label *role;
81962 + struct file *exec_file;
81963 + unsigned long brute_expires;
81964 + u16 acl_role_id;
81965 + u8 inherited;
81966 + /* is this the task that authenticated to the special role */
81967 + u8 acl_sp_role;
81968 + u8 is_writable;
81969 + u8 brute;
81970 + u8 gr_is_chrooted;
81971 +#endif
81972 +
81973 +} __randomize_layout;
81974 +
81975 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81976 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81977 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81978 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81979 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81980 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81981 +
81982 +#ifdef CONFIG_PAX_SOFTMODE
81983 +extern int pax_softmode;
81984 +#endif
81985 +
81986 +extern int pax_check_flags(unsigned long *);
81987 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81988 +
81989 +/* if tsk != current then task_lock must be held on it */
81990 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81991 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81992 +{
81993 + if (likely(tsk->mm))
81994 + return tsk->mm->pax_flags;
81995 + else
81996 + return 0UL;
81997 +}
81998 +
81999 +/* if tsk != current then task_lock must be held on it */
82000 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82001 +{
82002 + if (likely(tsk->mm)) {
82003 + tsk->mm->pax_flags = flags;
82004 + return 0;
82005 + }
82006 + return -EINVAL;
82007 +}
82008 +#endif
82009 +
82010 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82011 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82012 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82013 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82014 +#endif
82015 +
82016 +struct path;
82017 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82018 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82019 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82020 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82021
82022 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82023 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82024 @@ -1692,7 +1806,7 @@ struct pid_namespace;
82025 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82026 struct pid_namespace *ns);
82027
82028 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82029 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82030 {
82031 return tsk->pid;
82032 }
82033 @@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82034
82035 extern void sched_clock_init(void);
82036
82037 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82038 +static inline void populate_stack(void)
82039 +{
82040 + struct task_struct *curtask = current;
82041 + int c;
82042 + int *ptr = curtask->stack;
82043 + int *end = curtask->stack + THREAD_SIZE;
82044 +
82045 + while (ptr < end) {
82046 + c = *(volatile int *)ptr;
82047 + ptr += PAGE_SIZE/sizeof(int);
82048 + }
82049 +}
82050 +#else
82051 +static inline void populate_stack(void)
82052 +{
82053 +}
82054 +#endif
82055 +
82056 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82057 static inline void sched_clock_tick(void)
82058 {
82059 @@ -2172,7 +2305,9 @@ void yield(void);
82060 extern struct exec_domain default_exec_domain;
82061
82062 union thread_union {
82063 +#ifndef CONFIG_X86
82064 struct thread_info thread_info;
82065 +#endif
82066 unsigned long stack[THREAD_SIZE/sizeof(long)];
82067 };
82068
82069 @@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82070 */
82071
82072 extern struct task_struct *find_task_by_vpid(pid_t nr);
82073 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82074 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82075 struct pid_namespace *ns);
82076
82077 @@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82078 extern void exit_itimers(struct signal_struct *);
82079 extern void flush_itimer_signals(void);
82080
82081 -extern void do_group_exit(int);
82082 +extern __noreturn void do_group_exit(int);
82083
82084 extern int allow_signal(int);
82085 extern int disallow_signal(int);
82086 @@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82087
82088 #endif
82089
82090 -static inline int object_is_on_stack(void *obj)
82091 +static inline int object_starts_on_stack(const void *obj)
82092 {
82093 - void *stack = task_stack_page(current);
82094 + const void *stack = task_stack_page(current);
82095
82096 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82097 }
82098 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82099 index 8045a55..c959cd5 100644
82100 --- a/include/linux/sched/sysctl.h
82101 +++ b/include/linux/sched/sysctl.h
82102 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82103 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82104
82105 extern int sysctl_max_map_count;
82106 +extern unsigned long sysctl_heap_stack_gap;
82107
82108 extern unsigned int sysctl_sched_latency;
82109 extern unsigned int sysctl_sched_min_granularity;
82110 diff --git a/include/linux/security.h b/include/linux/security.h
82111 index 6478ce3..5e6ad6e 100644
82112 --- a/include/linux/security.h
82113 +++ b/include/linux/security.h
82114 @@ -27,6 +27,7 @@
82115 #include <linux/slab.h>
82116 #include <linux/err.h>
82117 #include <linux/string.h>
82118 +#include <linux/grsecurity.h>
82119
82120 struct linux_binprm;
82121 struct cred;
82122 @@ -116,8 +117,6 @@ struct seq_file;
82123
82124 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82125
82126 -void reset_security_ops(void);
82127 -
82128 #ifdef CONFIG_MMU
82129 extern unsigned long mmap_min_addr;
82130 extern unsigned long dac_mmap_min_addr;
82131 @@ -1719,7 +1718,7 @@ struct security_operations {
82132 struct audit_context *actx);
82133 void (*audit_rule_free) (void *lsmrule);
82134 #endif /* CONFIG_AUDIT */
82135 -};
82136 +} __randomize_layout;
82137
82138 /* prototypes */
82139 extern int security_init(void);
82140 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82141 index dc368b8..e895209 100644
82142 --- a/include/linux/semaphore.h
82143 +++ b/include/linux/semaphore.h
82144 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82145 }
82146
82147 extern void down(struct semaphore *sem);
82148 -extern int __must_check down_interruptible(struct semaphore *sem);
82149 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82150 extern int __must_check down_killable(struct semaphore *sem);
82151 extern int __must_check down_trylock(struct semaphore *sem);
82152 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82153 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82154 index 52e0097..383f21d 100644
82155 --- a/include/linux/seq_file.h
82156 +++ b/include/linux/seq_file.h
82157 @@ -27,6 +27,9 @@ struct seq_file {
82158 struct mutex lock;
82159 const struct seq_operations *op;
82160 int poll_event;
82161 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82162 + u64 exec_id;
82163 +#endif
82164 #ifdef CONFIG_USER_NS
82165 struct user_namespace *user_ns;
82166 #endif
82167 @@ -39,6 +42,7 @@ struct seq_operations {
82168 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82169 int (*show) (struct seq_file *m, void *v);
82170 };
82171 +typedef struct seq_operations __no_const seq_operations_no_const;
82172
82173 #define SEQ_SKIP 1
82174
82175 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82176
82177 char *mangle_path(char *s, const char *p, const char *esc);
82178 int seq_open(struct file *, const struct seq_operations *);
82179 +int seq_open_restrict(struct file *, const struct seq_operations *);
82180 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82181 loff_t seq_lseek(struct file *, loff_t, int);
82182 int seq_release(struct inode *, struct file *);
82183 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82184 }
82185
82186 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82187 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82188 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82189 int single_release(struct inode *, struct file *);
82190 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82191 diff --git a/include/linux/shm.h b/include/linux/shm.h
82192 index 1e2cd2e..0288750 100644
82193 --- a/include/linux/shm.h
82194 +++ b/include/linux/shm.h
82195 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82196
82197 /* The task created the shm object. NULL if the task is dead. */
82198 struct task_struct *shm_creator;
82199 +#ifdef CONFIG_GRKERNSEC
82200 + time_t shm_createtime;
82201 + pid_t shm_lapid;
82202 +#endif
82203 };
82204
82205 /* shm_mode upper byte flags */
82206 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82207 index 08074a8..e2ae280 100644
82208 --- a/include/linux/skbuff.h
82209 +++ b/include/linux/skbuff.h
82210 @@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82211 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82212 int node);
82213 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82214 -static inline struct sk_buff *alloc_skb(unsigned int size,
82215 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82216 gfp_t priority)
82217 {
82218 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82219 @@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82220 return skb->inner_transport_header - skb->inner_network_header;
82221 }
82222
82223 -static inline int skb_network_offset(const struct sk_buff *skb)
82224 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82225 {
82226 return skb_network_header(skb) - skb->data;
82227 }
82228 @@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82229 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82230 */
82231 #ifndef NET_SKB_PAD
82232 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82233 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82234 #endif
82235
82236 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82237 @@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82238 int *err);
82239 unsigned int datagram_poll(struct file *file, struct socket *sock,
82240 struct poll_table_struct *wait);
82241 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82242 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82243 struct iovec *to, int size);
82244 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82245 struct iovec *iov);
82246 @@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82247 nf_bridge_put(skb->nf_bridge);
82248 skb->nf_bridge = NULL;
82249 #endif
82250 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82251 + skb->nf_trace = 0;
82252 +#endif
82253 }
82254
82255 static inline void nf_reset_trace(struct sk_buff *skb)
82256 diff --git a/include/linux/slab.h b/include/linux/slab.h
82257 index 307bfbe..a999cf3 100644
82258 --- a/include/linux/slab.h
82259 +++ b/include/linux/slab.h
82260 @@ -14,15 +14,29 @@
82261 #include <linux/gfp.h>
82262 #include <linux/types.h>
82263 #include <linux/workqueue.h>
82264 -
82265 +#include <linux/err.h>
82266
82267 /*
82268 * Flags to pass to kmem_cache_create().
82269 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82270 */
82271 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82272 +
82273 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82274 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82275 +#else
82276 +#define SLAB_USERCOPY 0x00000000UL
82277 +#endif
82278 +
82279 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82280 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82281 +
82282 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82283 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82284 +#else
82285 +#define SLAB_NO_SANITIZE 0x00000000UL
82286 +#endif
82287 +
82288 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82289 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82290 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82291 @@ -98,10 +112,13 @@
82292 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82293 * Both make kfree a no-op.
82294 */
82295 -#define ZERO_SIZE_PTR ((void *)16)
82296 +#define ZERO_SIZE_PTR \
82297 +({ \
82298 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82299 + (void *)(-MAX_ERRNO-1L); \
82300 +})
82301
82302 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82303 - (unsigned long)ZERO_SIZE_PTR)
82304 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82305
82306 #include <linux/kmemleak.h>
82307
82308 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82309 void kfree(const void *);
82310 void kzfree(const void *);
82311 size_t ksize(const void *);
82312 +const char *check_heap_object(const void *ptr, unsigned long n);
82313 +bool is_usercopy_object(const void *ptr);
82314
82315 /*
82316 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82317 @@ -174,7 +193,7 @@ struct kmem_cache {
82318 unsigned int align; /* Alignment as calculated */
82319 unsigned long flags; /* Active flags on the slab */
82320 const char *name; /* Slab name for sysfs */
82321 - int refcount; /* Use counter */
82322 + atomic_t refcount; /* Use counter */
82323 void (*ctor)(void *); /* Called on object slot creation */
82324 struct list_head list; /* List of all slab caches on the system */
82325 };
82326 @@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82327 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82328 #endif
82329
82330 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82331 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82332 +#endif
82333 +
82334 /*
82335 * Figure out which kmalloc slab an allocation of a certain size
82336 * belongs to.
82337 @@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82338 * 2 = 120 .. 192 bytes
82339 * n = 2^(n-1) .. 2^n -1
82340 */
82341 -static __always_inline int kmalloc_index(size_t size)
82342 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82343 {
82344 if (!size)
82345 return 0;
82346 @@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82347 }
82348 #endif /* !CONFIG_SLOB */
82349
82350 -void *__kmalloc(size_t size, gfp_t flags);
82351 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82352 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82353
82354 #ifdef CONFIG_NUMA
82355 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
82356 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82357 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82358 #else
82359 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82360 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82361 index 8235dfb..47ce586 100644
82362 --- a/include/linux/slab_def.h
82363 +++ b/include/linux/slab_def.h
82364 @@ -38,7 +38,7 @@ struct kmem_cache {
82365 /* 4) cache creation/removal */
82366 const char *name;
82367 struct list_head list;
82368 - int refcount;
82369 + atomic_t refcount;
82370 int object_size;
82371 int align;
82372
82373 @@ -54,10 +54,14 @@ struct kmem_cache {
82374 unsigned long node_allocs;
82375 unsigned long node_frees;
82376 unsigned long node_overflow;
82377 - atomic_t allochit;
82378 - atomic_t allocmiss;
82379 - atomic_t freehit;
82380 - atomic_t freemiss;
82381 + atomic_unchecked_t allochit;
82382 + atomic_unchecked_t allocmiss;
82383 + atomic_unchecked_t freehit;
82384 + atomic_unchecked_t freemiss;
82385 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82386 + atomic_unchecked_t sanitized;
82387 + atomic_unchecked_t not_sanitized;
82388 +#endif
82389
82390 /*
82391 * If debugging is enabled, then the allocator can add additional
82392 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82393 index d82abd4..408c3a0 100644
82394 --- a/include/linux/slub_def.h
82395 +++ b/include/linux/slub_def.h
82396 @@ -74,7 +74,7 @@ struct kmem_cache {
82397 struct kmem_cache_order_objects max;
82398 struct kmem_cache_order_objects min;
82399 gfp_t allocflags; /* gfp flags to use on each alloc */
82400 - int refcount; /* Refcount for slab cache destroy */
82401 + atomic_t refcount; /* Refcount for slab cache destroy */
82402 void (*ctor)(void *);
82403 int inuse; /* Offset to metadata */
82404 int align; /* Alignment */
82405 diff --git a/include/linux/smp.h b/include/linux/smp.h
82406 index 633f5ed..6c3dc3f 100644
82407 --- a/include/linux/smp.h
82408 +++ b/include/linux/smp.h
82409 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82410 #endif
82411
82412 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82413 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82414 #define put_cpu() preempt_enable()
82415 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82416
82417 /*
82418 * Callback to arch code if there's nosmp or maxcpus=0 on the
82419 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82420 index 46cca4c..3323536 100644
82421 --- a/include/linux/sock_diag.h
82422 +++ b/include/linux/sock_diag.h
82423 @@ -11,7 +11,7 @@ struct sock;
82424 struct sock_diag_handler {
82425 __u8 family;
82426 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82427 -};
82428 +} __do_const;
82429
82430 int sock_diag_register(const struct sock_diag_handler *h);
82431 void sock_diag_unregister(const struct sock_diag_handler *h);
82432 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82433 index 680f9a3..f13aeb0 100644
82434 --- a/include/linux/sonet.h
82435 +++ b/include/linux/sonet.h
82436 @@ -7,7 +7,7 @@
82437 #include <uapi/linux/sonet.h>
82438
82439 struct k_sonet_stats {
82440 -#define __HANDLE_ITEM(i) atomic_t i
82441 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
82442 __SONET_ITEMS
82443 #undef __HANDLE_ITEM
82444 };
82445 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82446 index 07d8e53..dc934c9 100644
82447 --- a/include/linux/sunrpc/addr.h
82448 +++ b/include/linux/sunrpc/addr.h
82449 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82450 {
82451 switch (sap->sa_family) {
82452 case AF_INET:
82453 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
82454 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82455 case AF_INET6:
82456 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82457 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82458 }
82459 return 0;
82460 }
82461 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82462 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82463 const struct sockaddr *src)
82464 {
82465 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82466 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82467 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82468
82469 dsin->sin_family = ssin->sin_family;
82470 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82471 if (sa->sa_family != AF_INET6)
82472 return 0;
82473
82474 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82475 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82476 }
82477
82478 #endif /* _LINUX_SUNRPC_ADDR_H */
82479 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82480 index 70736b9..37f33db 100644
82481 --- a/include/linux/sunrpc/clnt.h
82482 +++ b/include/linux/sunrpc/clnt.h
82483 @@ -97,7 +97,7 @@ struct rpc_procinfo {
82484 unsigned int p_timer; /* Which RTT timer to use */
82485 u32 p_statidx; /* Which procedure to account */
82486 const char * p_name; /* name of procedure */
82487 -};
82488 +} __do_const;
82489
82490 #ifdef __KERNEL__
82491
82492 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82493 index 04e7632..2e2a8a3 100644
82494 --- a/include/linux/sunrpc/svc.h
82495 +++ b/include/linux/sunrpc/svc.h
82496 @@ -412,7 +412,7 @@ struct svc_procedure {
82497 unsigned int pc_count; /* call count */
82498 unsigned int pc_cachetype; /* cache info (NFS) */
82499 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82500 -};
82501 +} __do_const;
82502
82503 /*
82504 * Function prototypes.
82505 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82506 index 0b8e3e6..33e0a01 100644
82507 --- a/include/linux/sunrpc/svc_rdma.h
82508 +++ b/include/linux/sunrpc/svc_rdma.h
82509 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82510 extern unsigned int svcrdma_max_requests;
82511 extern unsigned int svcrdma_max_req_size;
82512
82513 -extern atomic_t rdma_stat_recv;
82514 -extern atomic_t rdma_stat_read;
82515 -extern atomic_t rdma_stat_write;
82516 -extern atomic_t rdma_stat_sq_starve;
82517 -extern atomic_t rdma_stat_rq_starve;
82518 -extern atomic_t rdma_stat_rq_poll;
82519 -extern atomic_t rdma_stat_rq_prod;
82520 -extern atomic_t rdma_stat_sq_poll;
82521 -extern atomic_t rdma_stat_sq_prod;
82522 +extern atomic_unchecked_t rdma_stat_recv;
82523 +extern atomic_unchecked_t rdma_stat_read;
82524 +extern atomic_unchecked_t rdma_stat_write;
82525 +extern atomic_unchecked_t rdma_stat_sq_starve;
82526 +extern atomic_unchecked_t rdma_stat_rq_starve;
82527 +extern atomic_unchecked_t rdma_stat_rq_poll;
82528 +extern atomic_unchecked_t rdma_stat_rq_prod;
82529 +extern atomic_unchecked_t rdma_stat_sq_poll;
82530 +extern atomic_unchecked_t rdma_stat_sq_prod;
82531
82532 #define RPCRDMA_VERSION 1
82533
82534 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82535 index 8d71d65..f79586e 100644
82536 --- a/include/linux/sunrpc/svcauth.h
82537 +++ b/include/linux/sunrpc/svcauth.h
82538 @@ -120,7 +120,7 @@ struct auth_ops {
82539 int (*release)(struct svc_rqst *rq);
82540 void (*domain_release)(struct auth_domain *);
82541 int (*set_client)(struct svc_rqst *rq);
82542 -};
82543 +} __do_const;
82544
82545 #define SVC_GARBAGE 1
82546 #define SVC_SYSERR 2
82547 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82548 index a5ffd32..0935dea 100644
82549 --- a/include/linux/swiotlb.h
82550 +++ b/include/linux/swiotlb.h
82551 @@ -60,7 +60,8 @@ extern void
82552
82553 extern void
82554 swiotlb_free_coherent(struct device *hwdev, size_t size,
82555 - void *vaddr, dma_addr_t dma_handle);
82556 + void *vaddr, dma_addr_t dma_handle,
82557 + struct dma_attrs *attrs);
82558
82559 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82560 unsigned long offset, size_t size,
82561 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82562 index a4a0588..752870e 100644
82563 --- a/include/linux/syscalls.h
82564 +++ b/include/linux/syscalls.h
82565 @@ -98,10 +98,16 @@ struct sigaltstack;
82566 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82567
82568 #define __SC_DECL(t, a) t a
82569 +#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))
82570 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82571 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82572 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82573 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82574 +#define __SC_LONG(t, a) __typeof( \
82575 + __builtin_choose_expr( \
82576 + sizeof(t) > sizeof(int), \
82577 + (t) 0, \
82578 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82579 + )) a
82580 #define __SC_CAST(t, a) (t) a
82581 #define __SC_ARGS(t, a) a
82582 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82583 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82584 asmlinkage long sys_fsync(unsigned int fd);
82585 asmlinkage long sys_fdatasync(unsigned int fd);
82586 asmlinkage long sys_bdflush(int func, long data);
82587 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82588 - char __user *type, unsigned long flags,
82589 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82590 + const char __user *type, unsigned long flags,
82591 void __user *data);
82592 -asmlinkage long sys_umount(char __user *name, int flags);
82593 -asmlinkage long sys_oldumount(char __user *name);
82594 +asmlinkage long sys_umount(const char __user *name, int flags);
82595 +asmlinkage long sys_oldumount(const char __user *name);
82596 asmlinkage long sys_truncate(const char __user *path, long length);
82597 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82598 asmlinkage long sys_stat(const char __user *filename,
82599 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82600 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82601 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82602 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82603 - struct sockaddr __user *, int);
82604 + struct sockaddr __user *, int) __intentional_overflow(0);
82605 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82606 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82607 unsigned int vlen, unsigned flags);
82608 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82609 index 27b3b0b..e093dd9 100644
82610 --- a/include/linux/syscore_ops.h
82611 +++ b/include/linux/syscore_ops.h
82612 @@ -16,7 +16,7 @@ struct syscore_ops {
82613 int (*suspend)(void);
82614 void (*resume)(void);
82615 void (*shutdown)(void);
82616 -};
82617 +} __do_const;
82618
82619 extern void register_syscore_ops(struct syscore_ops *ops);
82620 extern void unregister_syscore_ops(struct syscore_ops *ops);
82621 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82622 index 14a8ff2..fa95f3a 100644
82623 --- a/include/linux/sysctl.h
82624 +++ b/include/linux/sysctl.h
82625 @@ -34,13 +34,13 @@ struct ctl_table_root;
82626 struct ctl_table_header;
82627 struct ctl_dir;
82628
82629 -typedef struct ctl_table ctl_table;
82630 -
82631 typedef int proc_handler (struct ctl_table *ctl, int write,
82632 void __user *buffer, size_t *lenp, loff_t *ppos);
82633
82634 extern int proc_dostring(struct ctl_table *, int,
82635 void __user *, size_t *, loff_t *);
82636 +extern int proc_dostring_modpriv(struct ctl_table *, int,
82637 + void __user *, size_t *, loff_t *);
82638 extern int proc_dointvec(struct ctl_table *, int,
82639 void __user *, size_t *, loff_t *);
82640 extern int proc_dointvec_minmax(struct ctl_table *, int,
82641 @@ -115,7 +115,9 @@ struct ctl_table
82642 struct ctl_table_poll *poll;
82643 void *extra1;
82644 void *extra2;
82645 -};
82646 +} __do_const __randomize_layout;
82647 +typedef struct ctl_table __no_const ctl_table_no_const;
82648 +typedef struct ctl_table ctl_table;
82649
82650 struct ctl_node {
82651 struct rb_node node;
82652 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82653 index 5ffaa34..fe3e31c 100644
82654 --- a/include/linux/sysfs.h
82655 +++ b/include/linux/sysfs.h
82656 @@ -34,7 +34,8 @@ struct attribute {
82657 struct lock_class_key *key;
82658 struct lock_class_key skey;
82659 #endif
82660 -};
82661 +} __do_const;
82662 +typedef struct attribute __no_const attribute_no_const;
82663
82664 /**
82665 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82666 @@ -63,7 +64,8 @@ struct attribute_group {
82667 struct attribute *, int);
82668 struct attribute **attrs;
82669 struct bin_attribute **bin_attrs;
82670 -};
82671 +} __do_const;
82672 +typedef struct attribute_group __no_const attribute_group_no_const;
82673
82674 /**
82675 * Use these macros to make defining attributes easier. See include/linux/device.h
82676 @@ -128,7 +130,8 @@ struct bin_attribute {
82677 char *, loff_t, size_t);
82678 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82679 struct vm_area_struct *vma);
82680 -};
82681 +} __do_const;
82682 +typedef struct bin_attribute __no_const bin_attribute_no_const;
82683
82684 /**
82685 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82686 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82687 index 387fa7d..3fcde6b 100644
82688 --- a/include/linux/sysrq.h
82689 +++ b/include/linux/sysrq.h
82690 @@ -16,6 +16,7 @@
82691
82692 #include <linux/errno.h>
82693 #include <linux/types.h>
82694 +#include <linux/compiler.h>
82695
82696 /* Possible values of bitmask for enabling sysrq functions */
82697 /* 0x0001 is reserved for enable everything */
82698 @@ -33,7 +34,7 @@ struct sysrq_key_op {
82699 char *help_msg;
82700 char *action_msg;
82701 int enable_mask;
82702 -};
82703 +} __do_const;
82704
82705 #ifdef CONFIG_MAGIC_SYSRQ
82706
82707 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82708 index fddbe20..a0e76ab 100644
82709 --- a/include/linux/thread_info.h
82710 +++ b/include/linux/thread_info.h
82711 @@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
82712 #error "no set_restore_sigmask() provided and default one won't work"
82713 #endif
82714
82715 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
82716 +
82717 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82718 +{
82719 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
82720 +}
82721 +
82722 #endif /* __KERNEL__ */
82723
82724 #endif /* _LINUX_THREAD_INFO_H */
82725 diff --git a/include/linux/tty.h b/include/linux/tty.h
82726 index 1c3316a..ae83b9f 100644
82727 --- a/include/linux/tty.h
82728 +++ b/include/linux/tty.h
82729 @@ -202,7 +202,7 @@ struct tty_port {
82730 const struct tty_port_operations *ops; /* Port operations */
82731 spinlock_t lock; /* Lock protecting tty field */
82732 int blocked_open; /* Waiting to open */
82733 - int count; /* Usage count */
82734 + atomic_t count; /* Usage count */
82735 wait_queue_head_t open_wait; /* Open waiters */
82736 wait_queue_head_t close_wait; /* Close waiters */
82737 wait_queue_head_t delta_msr_wait; /* Modem status change */
82738 @@ -284,7 +284,7 @@ struct tty_struct {
82739 /* If the tty has a pending do_SAK, queue it here - akpm */
82740 struct work_struct SAK_work;
82741 struct tty_port *port;
82742 -};
82743 +} __randomize_layout;
82744
82745 /* Each of a tty's open files has private_data pointing to tty_file_private */
82746 struct tty_file_private {
82747 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82748 struct tty_struct *tty, struct file *filp);
82749 static inline int tty_port_users(struct tty_port *port)
82750 {
82751 - return port->count + port->blocked_open;
82752 + return atomic_read(&port->count) + port->blocked_open;
82753 }
82754
82755 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82756 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82757 index 756a609..89db85e 100644
82758 --- a/include/linux/tty_driver.h
82759 +++ b/include/linux/tty_driver.h
82760 @@ -285,7 +285,7 @@ struct tty_operations {
82761 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82762 #endif
82763 const struct file_operations *proc_fops;
82764 -};
82765 +} __do_const __randomize_layout;
82766
82767 struct tty_driver {
82768 int magic; /* magic number for this structure */
82769 @@ -319,7 +319,7 @@ struct tty_driver {
82770
82771 const struct tty_operations *ops;
82772 struct list_head tty_drivers;
82773 -};
82774 +} __randomize_layout;
82775
82776 extern struct list_head tty_drivers;
82777
82778 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82779 index add26da..22c00bef 100644
82780 --- a/include/linux/tty_ldisc.h
82781 +++ b/include/linux/tty_ldisc.h
82782 @@ -212,7 +212,7 @@ struct tty_ldisc_ops {
82783
82784 struct module *owner;
82785
82786 - int refcount;
82787 + atomic_t refcount;
82788 };
82789
82790 struct tty_ldisc {
82791 diff --git a/include/linux/types.h b/include/linux/types.h
82792 index 4d118ba..c3ee9bf 100644
82793 --- a/include/linux/types.h
82794 +++ b/include/linux/types.h
82795 @@ -176,10 +176,26 @@ typedef struct {
82796 int counter;
82797 } atomic_t;
82798
82799 +#ifdef CONFIG_PAX_REFCOUNT
82800 +typedef struct {
82801 + int counter;
82802 +} atomic_unchecked_t;
82803 +#else
82804 +typedef atomic_t atomic_unchecked_t;
82805 +#endif
82806 +
82807 #ifdef CONFIG_64BIT
82808 typedef struct {
82809 long counter;
82810 } atomic64_t;
82811 +
82812 +#ifdef CONFIG_PAX_REFCOUNT
82813 +typedef struct {
82814 + long counter;
82815 +} atomic64_unchecked_t;
82816 +#else
82817 +typedef atomic64_t atomic64_unchecked_t;
82818 +#endif
82819 #endif
82820
82821 struct list_head {
82822 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82823 index ecd3319..8a36ded 100644
82824 --- a/include/linux/uaccess.h
82825 +++ b/include/linux/uaccess.h
82826 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82827 long ret; \
82828 mm_segment_t old_fs = get_fs(); \
82829 \
82830 - set_fs(KERNEL_DS); \
82831 pagefault_disable(); \
82832 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82833 - pagefault_enable(); \
82834 + set_fs(KERNEL_DS); \
82835 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82836 set_fs(old_fs); \
82837 + pagefault_enable(); \
82838 ret; \
82839 })
82840
82841 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82842 index 2d1f9b6..d7a9fce 100644
82843 --- a/include/linux/uidgid.h
82844 +++ b/include/linux/uidgid.h
82845 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82846
82847 #endif /* CONFIG_USER_NS */
82848
82849 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82850 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82851 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82852 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82853 +
82854 #endif /* _LINUX_UIDGID_H */
82855 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82856 index 99c1b4d..562e6f3 100644
82857 --- a/include/linux/unaligned/access_ok.h
82858 +++ b/include/linux/unaligned/access_ok.h
82859 @@ -4,34 +4,34 @@
82860 #include <linux/kernel.h>
82861 #include <asm/byteorder.h>
82862
82863 -static inline u16 get_unaligned_le16(const void *p)
82864 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82865 {
82866 - return le16_to_cpup((__le16 *)p);
82867 + return le16_to_cpup((const __le16 *)p);
82868 }
82869
82870 -static inline u32 get_unaligned_le32(const void *p)
82871 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82872 {
82873 - return le32_to_cpup((__le32 *)p);
82874 + return le32_to_cpup((const __le32 *)p);
82875 }
82876
82877 -static inline u64 get_unaligned_le64(const void *p)
82878 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82879 {
82880 - return le64_to_cpup((__le64 *)p);
82881 + return le64_to_cpup((const __le64 *)p);
82882 }
82883
82884 -static inline u16 get_unaligned_be16(const void *p)
82885 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82886 {
82887 - return be16_to_cpup((__be16 *)p);
82888 + return be16_to_cpup((const __be16 *)p);
82889 }
82890
82891 -static inline u32 get_unaligned_be32(const void *p)
82892 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82893 {
82894 - return be32_to_cpup((__be32 *)p);
82895 + return be32_to_cpup((const __be32 *)p);
82896 }
82897
82898 -static inline u64 get_unaligned_be64(const void *p)
82899 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82900 {
82901 - return be64_to_cpup((__be64 *)p);
82902 + return be64_to_cpup((const __be64 *)p);
82903 }
82904
82905 static inline void put_unaligned_le16(u16 val, void *p)
82906 diff --git a/include/linux/usb.h b/include/linux/usb.h
82907 index 6b7ec37..4428419 100644
82908 --- a/include/linux/usb.h
82909 +++ b/include/linux/usb.h
82910 @@ -569,7 +569,7 @@ struct usb_device {
82911 int maxchild;
82912
82913 u32 quirks;
82914 - atomic_t urbnum;
82915 + atomic_unchecked_t urbnum;
82916
82917 unsigned long active_duration;
82918
82919 @@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82920
82921 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82922 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82923 - void *data, __u16 size, int timeout);
82924 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82925 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82926 void *data, int len, int *actual_length, int timeout);
82927 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82928 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82929 index e452ba6..78f8e80 100644
82930 --- a/include/linux/usb/renesas_usbhs.h
82931 +++ b/include/linux/usb/renesas_usbhs.h
82932 @@ -39,7 +39,7 @@ enum {
82933 */
82934 struct renesas_usbhs_driver_callback {
82935 int (*notify_hotplug)(struct platform_device *pdev);
82936 -};
82937 +} __no_const;
82938
82939 /*
82940 * callback functions for platform
82941 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82942 index 4836ba3..603f6ee 100644
82943 --- a/include/linux/user_namespace.h
82944 +++ b/include/linux/user_namespace.h
82945 @@ -33,7 +33,7 @@ struct user_namespace {
82946 struct key *persistent_keyring_register;
82947 struct rw_semaphore persistent_keyring_register_sem;
82948 #endif
82949 -};
82950 +} __randomize_layout;
82951
82952 extern struct user_namespace init_user_ns;
82953
82954 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82955 index 239e277..22a5cf5 100644
82956 --- a/include/linux/utsname.h
82957 +++ b/include/linux/utsname.h
82958 @@ -24,7 +24,7 @@ struct uts_namespace {
82959 struct new_utsname name;
82960 struct user_namespace *user_ns;
82961 unsigned int proc_inum;
82962 -};
82963 +} __randomize_layout;
82964 extern struct uts_namespace init_uts_ns;
82965
82966 #ifdef CONFIG_UTS_NS
82967 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82968 index 6f8fbcf..4efc177 100644
82969 --- a/include/linux/vermagic.h
82970 +++ b/include/linux/vermagic.h
82971 @@ -25,9 +25,42 @@
82972 #define MODULE_ARCH_VERMAGIC ""
82973 #endif
82974
82975 +#ifdef CONFIG_PAX_REFCOUNT
82976 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82977 +#else
82978 +#define MODULE_PAX_REFCOUNT ""
82979 +#endif
82980 +
82981 +#ifdef CONSTIFY_PLUGIN
82982 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82983 +#else
82984 +#define MODULE_CONSTIFY_PLUGIN ""
82985 +#endif
82986 +
82987 +#ifdef STACKLEAK_PLUGIN
82988 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82989 +#else
82990 +#define MODULE_STACKLEAK_PLUGIN ""
82991 +#endif
82992 +
82993 +#ifdef RANDSTRUCT_PLUGIN
82994 +#include <generated/randomize_layout_hash.h>
82995 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82996 +#else
82997 +#define MODULE_RANDSTRUCT_PLUGIN
82998 +#endif
82999 +
83000 +#ifdef CONFIG_GRKERNSEC
83001 +#define MODULE_GRSEC "GRSEC "
83002 +#else
83003 +#define MODULE_GRSEC ""
83004 +#endif
83005 +
83006 #define VERMAGIC_STRING \
83007 UTS_RELEASE " " \
83008 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83009 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83010 - MODULE_ARCH_VERMAGIC
83011 + MODULE_ARCH_VERMAGIC \
83012 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83013 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83014
83015 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83016 index 502073a..a7de024 100644
83017 --- a/include/linux/vga_switcheroo.h
83018 +++ b/include/linux/vga_switcheroo.h
83019 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83020
83021 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83022
83023 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83024 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83025 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83026 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83027 #else
83028
83029 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83030 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83031
83032 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83033
83034 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83035 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83036 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83037 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83038
83039 #endif
83040 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83041 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83042 index 4b8a891..e9a2863 100644
83043 --- a/include/linux/vmalloc.h
83044 +++ b/include/linux/vmalloc.h
83045 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83046 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83047 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83048 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83049 +
83050 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83051 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83052 +#endif
83053 +
83054 /* bits [20..32] reserved for arch specific ioremap internals */
83055
83056 /*
83057 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83058 unsigned long flags, pgprot_t prot);
83059 extern void vunmap(const void *addr);
83060
83061 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83062 +extern void unmap_process_stacks(struct task_struct *task);
83063 +#endif
83064 +
83065 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83066 unsigned long uaddr, void *kaddr,
83067 unsigned long size);
83068 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83069
83070 /* for /dev/kmem */
83071 extern long vread(char *buf, char *addr, unsigned long count);
83072 -extern long vwrite(char *buf, char *addr, unsigned long count);
83073 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83074
83075 /*
83076 * Internals. Dont't use..
83077 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83078 index 45c9cd1..20bd0bf 100644
83079 --- a/include/linux/vmstat.h
83080 +++ b/include/linux/vmstat.h
83081 @@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83082 /*
83083 * Zone based page accounting with per cpu differentials.
83084 */
83085 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83086 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83087
83088 static inline void zone_page_state_add(long x, struct zone *zone,
83089 enum zone_stat_item item)
83090 {
83091 - atomic_long_add(x, &zone->vm_stat[item]);
83092 - atomic_long_add(x, &vm_stat[item]);
83093 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83094 + atomic_long_add_unchecked(x, &vm_stat[item]);
83095 }
83096
83097 -static inline unsigned long global_page_state(enum zone_stat_item item)
83098 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83099 {
83100 - long x = atomic_long_read(&vm_stat[item]);
83101 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83102 #ifdef CONFIG_SMP
83103 if (x < 0)
83104 x = 0;
83105 @@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83106 return x;
83107 }
83108
83109 -static inline unsigned long zone_page_state(struct zone *zone,
83110 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83111 enum zone_stat_item item)
83112 {
83113 - long x = atomic_long_read(&zone->vm_stat[item]);
83114 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83115 #ifdef CONFIG_SMP
83116 if (x < 0)
83117 x = 0;
83118 @@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83119 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83120 enum zone_stat_item item)
83121 {
83122 - long x = atomic_long_read(&zone->vm_stat[item]);
83123 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83124
83125 #ifdef CONFIG_SMP
83126 int cpu;
83127 @@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83128
83129 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83130 {
83131 - atomic_long_inc(&zone->vm_stat[item]);
83132 - atomic_long_inc(&vm_stat[item]);
83133 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83134 + atomic_long_inc_unchecked(&vm_stat[item]);
83135 }
83136
83137 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83138 {
83139 - atomic_long_dec(&zone->vm_stat[item]);
83140 - atomic_long_dec(&vm_stat[item]);
83141 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83142 + atomic_long_dec_unchecked(&vm_stat[item]);
83143 }
83144
83145 static inline void __inc_zone_page_state(struct page *page,
83146 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83147 index 91b0a68..0e9adf6 100644
83148 --- a/include/linux/xattr.h
83149 +++ b/include/linux/xattr.h
83150 @@ -28,7 +28,7 @@ struct xattr_handler {
83151 size_t size, int handler_flags);
83152 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83153 size_t size, int flags, int handler_flags);
83154 -};
83155 +} __do_const;
83156
83157 struct xattr {
83158 const char *name;
83159 @@ -37,6 +37,9 @@ struct xattr {
83160 };
83161
83162 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83163 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83164 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83165 +#endif
83166 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83167 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83168 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83169 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83170 index 9c5a6b4..09c9438 100644
83171 --- a/include/linux/zlib.h
83172 +++ b/include/linux/zlib.h
83173 @@ -31,6 +31,7 @@
83174 #define _ZLIB_H
83175
83176 #include <linux/zconf.h>
83177 +#include <linux/compiler.h>
83178
83179 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83180 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83181 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83182
83183 /* basic functions */
83184
83185 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83186 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83187 /*
83188 Returns the number of bytes that needs to be allocated for a per-
83189 stream workspace with the specified parameters. A pointer to this
83190 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83191 index eec6e46..82d5641 100644
83192 --- a/include/media/v4l2-dev.h
83193 +++ b/include/media/v4l2-dev.h
83194 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
83195 int (*mmap) (struct file *, struct vm_area_struct *);
83196 int (*open) (struct file *);
83197 int (*release) (struct file *);
83198 -};
83199 +} __do_const;
83200
83201 /*
83202 * Newer version of video_device, handled by videodev2.c
83203 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83204 index c9b1593..a572459 100644
83205 --- a/include/media/v4l2-device.h
83206 +++ b/include/media/v4l2-device.h
83207 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83208 this function returns 0. If the name ends with a digit (e.g. cx18),
83209 then the name will be set to cx18-0 since cx180 looks really odd. */
83210 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83211 - atomic_t *instance);
83212 + atomic_unchecked_t *instance);
83213
83214 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83215 Since the parent disappears this ensures that v4l2_dev doesn't have an
83216 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83217 index d9fa68f..45c88d1 100644
83218 --- a/include/net/9p/transport.h
83219 +++ b/include/net/9p/transport.h
83220 @@ -63,7 +63,7 @@ struct p9_trans_module {
83221 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83222 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83223 char *, char *, int , int, int, int);
83224 -};
83225 +} __do_const;
83226
83227 void v9fs_register_trans(struct p9_trans_module *m);
83228 void v9fs_unregister_trans(struct p9_trans_module *m);
83229 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83230 index a175ba4..196eb82 100644
83231 --- a/include/net/af_unix.h
83232 +++ b/include/net/af_unix.h
83233 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83234 u32 secid; /* Security ID */
83235 #endif
83236 u32 consumed;
83237 -};
83238 +} __randomize_layout;
83239
83240 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83241 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83242 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83243 index 4abdcb2..945c5cc 100644
83244 --- a/include/net/bluetooth/l2cap.h
83245 +++ b/include/net/bluetooth/l2cap.h
83246 @@ -601,7 +601,7 @@ struct l2cap_ops {
83247 long (*get_sndtimeo) (struct l2cap_chan *chan);
83248 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83249 unsigned long len, int nb);
83250 -};
83251 +} __do_const;
83252
83253 struct l2cap_conn {
83254 struct hci_conn *hcon;
83255 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83256 index f2ae33d..c457cf0 100644
83257 --- a/include/net/caif/cfctrl.h
83258 +++ b/include/net/caif/cfctrl.h
83259 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83260 void (*radioset_rsp)(void);
83261 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83262 struct cflayer *client_layer);
83263 -};
83264 +} __no_const;
83265
83266 /* Link Setup Parameters for CAIF-Links. */
83267 struct cfctrl_link_param {
83268 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
83269 struct cfctrl {
83270 struct cfsrvl serv;
83271 struct cfctrl_rsp res;
83272 - atomic_t req_seq_no;
83273 - atomic_t rsp_seq_no;
83274 + atomic_unchecked_t req_seq_no;
83275 + atomic_unchecked_t rsp_seq_no;
83276 struct list_head list;
83277 /* Protects from simultaneous access to first_req list */
83278 spinlock_t info_list_lock;
83279 diff --git a/include/net/flow.h b/include/net/flow.h
83280 index 8109a15..504466d 100644
83281 --- a/include/net/flow.h
83282 +++ b/include/net/flow.h
83283 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83284
83285 void flow_cache_flush(struct net *net);
83286 void flow_cache_flush_deferred(struct net *net);
83287 -extern atomic_t flow_cache_genid;
83288 +extern atomic_unchecked_t flow_cache_genid;
83289
83290 #endif
83291 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83292 index 93695f0..766d71c 100644
83293 --- a/include/net/genetlink.h
83294 +++ b/include/net/genetlink.h
83295 @@ -120,7 +120,7 @@ struct genl_ops {
83296 u8 cmd;
83297 u8 internal_flags;
83298 u8 flags;
83299 -};
83300 +} __do_const;
83301
83302 int __genl_register_family(struct genl_family *family);
83303
83304 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83305 index 734d9b5..48a9a4b 100644
83306 --- a/include/net/gro_cells.h
83307 +++ b/include/net/gro_cells.h
83308 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83309 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83310
83311 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83312 - atomic_long_inc(&dev->rx_dropped);
83313 + atomic_long_inc_unchecked(&dev->rx_dropped);
83314 kfree_skb(skb);
83315 return;
83316 }
83317 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83318 index 7a43138..bc76865 100644
83319 --- a/include/net/inet_connection_sock.h
83320 +++ b/include/net/inet_connection_sock.h
83321 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83322 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83323 int (*bind_conflict)(const struct sock *sk,
83324 const struct inet_bind_bucket *tb, bool relax);
83325 -};
83326 +} __do_const;
83327
83328 /** inet_connection_sock - INET connection oriented sock
83329 *
83330 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83331 index 058271b..1a44af7 100644
83332 --- a/include/net/inetpeer.h
83333 +++ b/include/net/inetpeer.h
83334 @@ -47,8 +47,8 @@ struct inet_peer {
83335 */
83336 union {
83337 struct {
83338 - atomic_t rid; /* Frag reception counter */
83339 - atomic_t ip_id_count; /* IP ID for the next packet */
83340 + atomic_unchecked_t rid; /* Frag reception counter */
83341 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83342 };
83343 struct rcu_head rcu;
83344 struct inet_peer *gc_next;
83345 @@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83346 {
83347 more++;
83348 inet_peer_refcheck(p);
83349 - return atomic_add_return(more, &p->ip_id_count) - more;
83350 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83351 }
83352
83353 #endif /* _NET_INETPEER_H */
83354 diff --git a/include/net/ip.h b/include/net/ip.h
83355 index 3ec2b0f..72435b6 100644
83356 --- a/include/net/ip.h
83357 +++ b/include/net/ip.h
83358 @@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83359
83360 void inet_get_local_port_range(struct net *net, int *low, int *high);
83361
83362 -extern unsigned long *sysctl_local_reserved_ports;
83363 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83364 static inline int inet_is_reserved_local_port(int port)
83365 {
83366 return test_bit(port, sysctl_local_reserved_ports);
83367 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83368 index 9922093..a1755d6 100644
83369 --- a/include/net/ip_fib.h
83370 +++ b/include/net/ip_fib.h
83371 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83372
83373 #define FIB_RES_SADDR(net, res) \
83374 ((FIB_RES_NH(res).nh_saddr_genid == \
83375 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83376 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83377 FIB_RES_NH(res).nh_saddr : \
83378 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83379 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83380 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83381 index 5679d92..2e7a690 100644
83382 --- a/include/net/ip_vs.h
83383 +++ b/include/net/ip_vs.h
83384 @@ -558,7 +558,7 @@ struct ip_vs_conn {
83385 struct ip_vs_conn *control; /* Master control connection */
83386 atomic_t n_control; /* Number of controlled ones */
83387 struct ip_vs_dest *dest; /* real server */
83388 - atomic_t in_pkts; /* incoming packet counter */
83389 + atomic_unchecked_t in_pkts; /* incoming packet counter */
83390
83391 /* packet transmitter for different forwarding methods. If it
83392 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83393 @@ -705,7 +705,7 @@ struct ip_vs_dest {
83394 __be16 port; /* port number of the server */
83395 union nf_inet_addr addr; /* IP address of the server */
83396 volatile unsigned int flags; /* dest status flags */
83397 - atomic_t conn_flags; /* flags to copy to conn */
83398 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
83399 atomic_t weight; /* server weight */
83400
83401 atomic_t refcnt; /* reference counter */
83402 @@ -960,11 +960,11 @@ struct netns_ipvs {
83403 /* ip_vs_lblc */
83404 int sysctl_lblc_expiration;
83405 struct ctl_table_header *lblc_ctl_header;
83406 - struct ctl_table *lblc_ctl_table;
83407 + ctl_table_no_const *lblc_ctl_table;
83408 /* ip_vs_lblcr */
83409 int sysctl_lblcr_expiration;
83410 struct ctl_table_header *lblcr_ctl_header;
83411 - struct ctl_table *lblcr_ctl_table;
83412 + ctl_table_no_const *lblcr_ctl_table;
83413 /* ip_vs_est */
83414 struct list_head est_list; /* estimator list */
83415 spinlock_t est_lock;
83416 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83417 index 8d4f588..2e37ad2 100644
83418 --- a/include/net/irda/ircomm_tty.h
83419 +++ b/include/net/irda/ircomm_tty.h
83420 @@ -33,6 +33,7 @@
83421 #include <linux/termios.h>
83422 #include <linux/timer.h>
83423 #include <linux/tty.h> /* struct tty_struct */
83424 +#include <asm/local.h>
83425
83426 #include <net/irda/irias_object.h>
83427 #include <net/irda/ircomm_core.h>
83428 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83429 index 714cc9a..ea05f3e 100644
83430 --- a/include/net/iucv/af_iucv.h
83431 +++ b/include/net/iucv/af_iucv.h
83432 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
83433 struct iucv_sock_list {
83434 struct hlist_head head;
83435 rwlock_t lock;
83436 - atomic_t autobind_name;
83437 + atomic_unchecked_t autobind_name;
83438 };
83439
83440 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83441 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83442 index f3be818..bf46196 100644
83443 --- a/include/net/llc_c_ac.h
83444 +++ b/include/net/llc_c_ac.h
83445 @@ -87,7 +87,7 @@
83446 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83447 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83448
83449 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83450 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83451
83452 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83453 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83454 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83455 index 3948cf1..83b28c4 100644
83456 --- a/include/net/llc_c_ev.h
83457 +++ b/include/net/llc_c_ev.h
83458 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83459 return (struct llc_conn_state_ev *)skb->cb;
83460 }
83461
83462 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83463 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83464 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83465 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83466
83467 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83468 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83469 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83470 index 0e79cfb..f46db31 100644
83471 --- a/include/net/llc_c_st.h
83472 +++ b/include/net/llc_c_st.h
83473 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83474 u8 next_state;
83475 llc_conn_ev_qfyr_t *ev_qualifiers;
83476 llc_conn_action_t *ev_actions;
83477 -};
83478 +} __do_const;
83479
83480 struct llc_conn_state {
83481 u8 current_state;
83482 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83483 index a61b98c..aade1eb 100644
83484 --- a/include/net/llc_s_ac.h
83485 +++ b/include/net/llc_s_ac.h
83486 @@ -23,7 +23,7 @@
83487 #define SAP_ACT_TEST_IND 9
83488
83489 /* All action functions must look like this */
83490 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83491 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83492
83493 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83494 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83495 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83496 index 567c681..cd73ac02 100644
83497 --- a/include/net/llc_s_st.h
83498 +++ b/include/net/llc_s_st.h
83499 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83500 llc_sap_ev_t ev;
83501 u8 next_state;
83502 llc_sap_action_t *ev_actions;
83503 -};
83504 +} __do_const;
83505
83506 struct llc_sap_state {
83507 u8 curr_state;
83508 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83509 index 8248e39..7610eec 100644
83510 --- a/include/net/mac80211.h
83511 +++ b/include/net/mac80211.h
83512 @@ -4467,7 +4467,7 @@ struct rate_control_ops {
83513 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83514 struct dentry *dir);
83515 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83516 -};
83517 +} __do_const;
83518
83519 static inline int rate_supported(struct ieee80211_sta *sta,
83520 enum ieee80211_band band,
83521 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83522 index 7277caf..fd095bc 100644
83523 --- a/include/net/neighbour.h
83524 +++ b/include/net/neighbour.h
83525 @@ -163,7 +163,7 @@ struct neigh_ops {
83526 void (*error_report)(struct neighbour *, struct sk_buff *);
83527 int (*output)(struct neighbour *, struct sk_buff *);
83528 int (*connected_output)(struct neighbour *, struct sk_buff *);
83529 -};
83530 +} __do_const;
83531
83532 struct pneigh_entry {
83533 struct pneigh_entry *next;
83534 @@ -203,7 +203,6 @@ struct neigh_table {
83535 void (*proxy_redo)(struct sk_buff *skb);
83536 char *id;
83537 struct neigh_parms parms;
83538 - /* HACK. gc_* should follow parms without a gap! */
83539 int gc_interval;
83540 int gc_thresh1;
83541 int gc_thresh2;
83542 @@ -218,7 +217,7 @@ struct neigh_table {
83543 struct neigh_statistics __percpu *stats;
83544 struct neigh_hash_table __rcu *nht;
83545 struct pneigh_entry **phash_buckets;
83546 -};
83547 +} __randomize_layout;
83548
83549 static inline int neigh_parms_family(struct neigh_parms *p)
83550 {
83551 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83552 index 5f9eb26..85699c4 100644
83553 --- a/include/net/net_namespace.h
83554 +++ b/include/net/net_namespace.h
83555 @@ -129,8 +129,8 @@ struct net {
83556 struct netns_ipvs *ipvs;
83557 #endif
83558 struct sock *diag_nlsk;
83559 - atomic_t fnhe_genid;
83560 -};
83561 + atomic_unchecked_t fnhe_genid;
83562 +} __randomize_layout;
83563
83564 #include <linux/seq_file_net.h>
83565
83566 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83567 #define __net_init __init
83568 #define __net_exit __exit_refok
83569 #define __net_initdata __initdata
83570 +#ifdef CONSTIFY_PLUGIN
83571 #define __net_initconst __initconst
83572 +#else
83573 +#define __net_initconst __initdata
83574 +#endif
83575 #endif
83576
83577 struct pernet_operations {
83578 @@ -296,7 +300,7 @@ struct pernet_operations {
83579 void (*exit_batch)(struct list_head *net_exit_list);
83580 int *id;
83581 size_t size;
83582 -};
83583 +} __do_const;
83584
83585 /*
83586 * Use these carefully. If you implement a network device and it
83587 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83588
83589 static inline int rt_genid_ipv4(struct net *net)
83590 {
83591 - return atomic_read(&net->ipv4.rt_genid);
83592 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83593 }
83594
83595 static inline void rt_genid_bump_ipv4(struct net *net)
83596 {
83597 - atomic_inc(&net->ipv4.rt_genid);
83598 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83599 }
83600
83601 #if IS_ENABLED(CONFIG_IPV6)
83602 static inline int rt_genid_ipv6(struct net *net)
83603 {
83604 - return atomic_read(&net->ipv6.rt_genid);
83605 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83606 }
83607
83608 static inline void rt_genid_bump_ipv6(struct net *net)
83609 {
83610 - atomic_inc(&net->ipv6.rt_genid);
83611 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83612 }
83613 #else
83614 static inline int rt_genid_ipv6(struct net *net)
83615 @@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83616
83617 static inline int fnhe_genid(struct net *net)
83618 {
83619 - return atomic_read(&net->fnhe_genid);
83620 + return atomic_read_unchecked(&net->fnhe_genid);
83621 }
83622
83623 static inline void fnhe_genid_bump(struct net *net)
83624 {
83625 - atomic_inc(&net->fnhe_genid);
83626 + atomic_inc_unchecked(&net->fnhe_genid);
83627 }
83628
83629 #endif /* __NET_NET_NAMESPACE_H */
83630 diff --git a/include/net/netdma.h b/include/net/netdma.h
83631 index 8ba8ce2..99b7fff 100644
83632 --- a/include/net/netdma.h
83633 +++ b/include/net/netdma.h
83634 @@ -24,7 +24,7 @@
83635 #include <linux/dmaengine.h>
83636 #include <linux/skbuff.h>
83637
83638 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83639 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83640 struct sk_buff *skb, int offset, struct iovec *to,
83641 size_t len, struct dma_pinned_list *pinned_list);
83642
83643 diff --git a/include/net/netlink.h b/include/net/netlink.h
83644 index 2b47eaa..6d5bcc2 100644
83645 --- a/include/net/netlink.h
83646 +++ b/include/net/netlink.h
83647 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83648 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83649 {
83650 if (mark)
83651 - skb_trim(skb, (unsigned char *) mark - skb->data);
83652 + skb_trim(skb, (const unsigned char *) mark - skb->data);
83653 }
83654
83655 /**
83656 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83657 index 773cce3..6a11852 100644
83658 --- a/include/net/netns/conntrack.h
83659 +++ b/include/net/netns/conntrack.h
83660 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
83661 struct nf_proto_net {
83662 #ifdef CONFIG_SYSCTL
83663 struct ctl_table_header *ctl_table_header;
83664 - struct ctl_table *ctl_table;
83665 + ctl_table_no_const *ctl_table;
83666 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83667 struct ctl_table_header *ctl_compat_header;
83668 - struct ctl_table *ctl_compat_table;
83669 + ctl_table_no_const *ctl_compat_table;
83670 #endif
83671 #endif
83672 unsigned int users;
83673 @@ -59,7 +59,7 @@ struct nf_ip_net {
83674 struct nf_icmp_net icmpv6;
83675 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83676 struct ctl_table_header *ctl_table_header;
83677 - struct ctl_table *ctl_table;
83678 + ctl_table_no_const *ctl_table;
83679 #endif
83680 };
83681
83682 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83683 index b2704fd0..421d717 100644
83684 --- a/include/net/netns/ipv4.h
83685 +++ b/include/net/netns/ipv4.h
83686 @@ -79,7 +79,7 @@ struct netns_ipv4 {
83687
83688 struct ping_group_range ping_group_range;
83689
83690 - atomic_t dev_addr_genid;
83691 + atomic_unchecked_t dev_addr_genid;
83692
83693 #ifdef CONFIG_IP_MROUTE
83694 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83695 @@ -89,6 +89,6 @@ struct netns_ipv4 {
83696 struct fib_rules_ops *mr_rules_ops;
83697 #endif
83698 #endif
83699 - atomic_t rt_genid;
83700 + atomic_unchecked_t rt_genid;
83701 };
83702 #endif
83703 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83704 index 21edaf1..4c5faae 100644
83705 --- a/include/net/netns/ipv6.h
83706 +++ b/include/net/netns/ipv6.h
83707 @@ -73,8 +73,8 @@ struct netns_ipv6 {
83708 struct fib_rules_ops *mr6_rules_ops;
83709 #endif
83710 #endif
83711 - atomic_t dev_addr_genid;
83712 - atomic_t rt_genid;
83713 + atomic_unchecked_t dev_addr_genid;
83714 + atomic_unchecked_t rt_genid;
83715 };
83716
83717 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83718 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
83719 index 3492434..209f58c 100644
83720 --- a/include/net/netns/xfrm.h
83721 +++ b/include/net/netns/xfrm.h
83722 @@ -64,7 +64,7 @@ struct netns_xfrm {
83723
83724 /* flow cache part */
83725 struct flow_cache flow_cache_global;
83726 - atomic_t flow_cache_genid;
83727 + atomic_unchecked_t flow_cache_genid;
83728 struct list_head flow_cache_gc_list;
83729 spinlock_t flow_cache_gc_lock;
83730 struct work_struct flow_cache_gc_work;
83731 diff --git a/include/net/ping.h b/include/net/ping.h
83732 index 026479b..d9b2829 100644
83733 --- a/include/net/ping.h
83734 +++ b/include/net/ping.h
83735 @@ -54,7 +54,7 @@ struct ping_iter_state {
83736
83737 extern struct proto ping_prot;
83738 #if IS_ENABLED(CONFIG_IPV6)
83739 -extern struct pingv6_ops pingv6_ops;
83740 +extern struct pingv6_ops *pingv6_ops;
83741 #endif
83742
83743 struct pingfakehdr {
83744 diff --git a/include/net/protocol.h b/include/net/protocol.h
83745 index a7e986b..dc67bce 100644
83746 --- a/include/net/protocol.h
83747 +++ b/include/net/protocol.h
83748 @@ -49,7 +49,7 @@ struct net_protocol {
83749 * socket lookup?
83750 */
83751 icmp_strict_tag_validation:1;
83752 -};
83753 +} __do_const;
83754
83755 #if IS_ENABLED(CONFIG_IPV6)
83756 struct inet6_protocol {
83757 @@ -62,7 +62,7 @@ struct inet6_protocol {
83758 u8 type, u8 code, int offset,
83759 __be32 info);
83760 unsigned int flags; /* INET6_PROTO_xxx */
83761 -};
83762 +} __do_const;
83763
83764 #define INET6_PROTO_NOPOLICY 0x1
83765 #define INET6_PROTO_FINAL 0x2
83766 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83767 index 72240e5..8c14bef 100644
83768 --- a/include/net/rtnetlink.h
83769 +++ b/include/net/rtnetlink.h
83770 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
83771 int (*fill_slave_info)(struct sk_buff *skb,
83772 const struct net_device *dev,
83773 const struct net_device *slave_dev);
83774 -};
83775 +} __do_const;
83776
83777 int __rtnl_link_register(struct rtnl_link_ops *ops);
83778 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83779 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83780 index 4a5b9a3..ca27d73 100644
83781 --- a/include/net/sctp/checksum.h
83782 +++ b/include/net/sctp/checksum.h
83783 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83784 unsigned int offset)
83785 {
83786 struct sctphdr *sh = sctp_hdr(skb);
83787 - __le32 ret, old = sh->checksum;
83788 - const struct skb_checksum_ops ops = {
83789 + __le32 ret, old = sh->checksum;
83790 + static const struct skb_checksum_ops ops = {
83791 .update = sctp_csum_update,
83792 .combine = sctp_csum_combine,
83793 };
83794 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83795 index 7f4eeb3..37e8fe1 100644
83796 --- a/include/net/sctp/sm.h
83797 +++ b/include/net/sctp/sm.h
83798 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83799 typedef struct {
83800 sctp_state_fn_t *fn;
83801 const char *name;
83802 -} sctp_sm_table_entry_t;
83803 +} __do_const sctp_sm_table_entry_t;
83804
83805 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83806 * currently in use.
83807 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83808 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83809
83810 /* Extern declarations for major data structures. */
83811 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83812 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83813
83814
83815 /* Get the size of a DATA chunk payload. */
83816 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83817 index 0dfcc92..7967849 100644
83818 --- a/include/net/sctp/structs.h
83819 +++ b/include/net/sctp/structs.h
83820 @@ -507,7 +507,7 @@ struct sctp_pf {
83821 struct sctp_association *asoc);
83822 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83823 struct sctp_af *af;
83824 -};
83825 +} __do_const;
83826
83827
83828 /* Structure to track chunk fragments that have been acked, but peer
83829 diff --git a/include/net/sock.h b/include/net/sock.h
83830 index 21569cf..dd60300 100644
83831 --- a/include/net/sock.h
83832 +++ b/include/net/sock.h
83833 @@ -348,7 +348,7 @@ struct sock {
83834 unsigned int sk_napi_id;
83835 unsigned int sk_ll_usec;
83836 #endif
83837 - atomic_t sk_drops;
83838 + atomic_unchecked_t sk_drops;
83839 int sk_rcvbuf;
83840
83841 struct sk_filter __rcu *sk_filter;
83842 @@ -1036,7 +1036,7 @@ struct proto {
83843 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83844 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83845 #endif
83846 -};
83847 +} __randomize_layout;
83848
83849 /*
83850 * Bits in struct cg_proto.flags
83851 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83852 return ret >> PAGE_SHIFT;
83853 }
83854
83855 -static inline long
83856 +static inline long __intentional_overflow(-1)
83857 sk_memory_allocated(const struct sock *sk)
83858 {
83859 struct proto *prot = sk->sk_prot;
83860 @@ -1368,7 +1368,7 @@ struct sock_iocb {
83861 struct scm_cookie *scm;
83862 struct msghdr *msg, async_msg;
83863 struct kiocb *kiocb;
83864 -};
83865 +} __randomize_layout;
83866
83867 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83868 {
83869 @@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
83870
83871 rcu_read_lock();
83872 dst = rcu_dereference(sk->sk_dst_cache);
83873 - if (dst)
83874 - dst_hold(dst);
83875 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
83876 + dst = NULL;
83877 rcu_read_unlock();
83878 return dst;
83879 }
83880 @@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83881 }
83882
83883 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83884 - char __user *from, char *to,
83885 + char __user *from, unsigned char *to,
83886 int copy, int offset)
83887 {
83888 if (skb->ip_summed == CHECKSUM_NONE) {
83889 @@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83890 }
83891 }
83892
83893 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83894 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83895
83896 /**
83897 * sk_page_frag - return an appropriate page_frag
83898 diff --git a/include/net/tcp.h b/include/net/tcp.h
83899 index 87d8774..cf214f8 100644
83900 --- a/include/net/tcp.h
83901 +++ b/include/net/tcp.h
83902 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83903 void tcp_xmit_retransmit_queue(struct sock *);
83904 void tcp_simple_retransmit(struct sock *);
83905 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83906 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83907 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83908
83909 void tcp_send_probe0(struct sock *);
83910 void tcp_send_partial(struct sock *);
83911 @@ -715,8 +715,8 @@ struct tcp_skb_cb {
83912 struct inet6_skb_parm h6;
83913 #endif
83914 } header; /* For incoming frames */
83915 - __u32 seq; /* Starting sequence number */
83916 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83917 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83918 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83919 __u32 when; /* used to compute rtt's */
83920 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83921
83922 @@ -730,7 +730,7 @@ struct tcp_skb_cb {
83923
83924 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83925 /* 1 byte hole */
83926 - __u32 ack_seq; /* Sequence number ACK'd */
83927 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83928 };
83929
83930 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83931 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83932 index 116e9c7..3070537 100644
83933 --- a/include/net/xfrm.h
83934 +++ b/include/net/xfrm.h
83935 @@ -285,7 +285,6 @@ struct xfrm_dst;
83936 struct xfrm_policy_afinfo {
83937 unsigned short family;
83938 struct dst_ops *dst_ops;
83939 - void (*garbage_collect)(struct net *net);
83940 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83941 const xfrm_address_t *saddr,
83942 const xfrm_address_t *daddr);
83943 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
83944 struct net_device *dev,
83945 const struct flowi *fl);
83946 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83947 -};
83948 +} __do_const;
83949
83950 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83951 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83952 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
83953 int (*transport_finish)(struct sk_buff *skb,
83954 int async);
83955 void (*local_error)(struct sk_buff *skb, u32 mtu);
83956 -};
83957 +} __do_const;
83958
83959 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83960 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83961 @@ -437,7 +436,7 @@ struct xfrm_mode {
83962 struct module *owner;
83963 unsigned int encap;
83964 int flags;
83965 -};
83966 +} __do_const;
83967
83968 /* Flags for xfrm_mode. */
83969 enum {
83970 @@ -534,7 +533,7 @@ struct xfrm_policy {
83971 struct timer_list timer;
83972
83973 struct flow_cache_object flo;
83974 - atomic_t genid;
83975 + atomic_unchecked_t genid;
83976 u32 priority;
83977 u32 index;
83978 struct xfrm_mark mark;
83979 @@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83980 }
83981
83982 void xfrm_garbage_collect(struct net *net);
83983 +void xfrm_garbage_collect_deferred(struct net *net);
83984
83985 #else
83986
83987 @@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83988 static inline void xfrm_garbage_collect(struct net *net)
83989 {
83990 }
83991 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83992 +{
83993 +}
83994 #endif
83995
83996 static __inline__
83997 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83998 index 1017e0b..227aa4d 100644
83999 --- a/include/rdma/iw_cm.h
84000 +++ b/include/rdma/iw_cm.h
84001 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84002 int backlog);
84003
84004 int (*destroy_listen)(struct iw_cm_id *cm_id);
84005 -};
84006 +} __no_const;
84007
84008 /**
84009 * iw_create_cm_id - Create an IW CM identifier.
84010 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84011 index 52beadf..598734c 100644
84012 --- a/include/scsi/libfc.h
84013 +++ b/include/scsi/libfc.h
84014 @@ -771,6 +771,7 @@ struct libfc_function_template {
84015 */
84016 void (*disc_stop_final) (struct fc_lport *);
84017 };
84018 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84019
84020 /**
84021 * struct fc_disc - Discovery context
84022 @@ -875,7 +876,7 @@ struct fc_lport {
84023 struct fc_vport *vport;
84024
84025 /* Operational Information */
84026 - struct libfc_function_template tt;
84027 + libfc_function_template_no_const tt;
84028 u8 link_up;
84029 u8 qfull;
84030 enum fc_lport_state state;
84031 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84032 index 5853c91..1e355a8 100644
84033 --- a/include/scsi/scsi_device.h
84034 +++ b/include/scsi/scsi_device.h
84035 @@ -186,9 +186,9 @@ struct scsi_device {
84036 unsigned int max_device_blocked; /* what device_blocked counts down from */
84037 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84038
84039 - atomic_t iorequest_cnt;
84040 - atomic_t iodone_cnt;
84041 - atomic_t ioerr_cnt;
84042 + atomic_unchecked_t iorequest_cnt;
84043 + atomic_unchecked_t iodone_cnt;
84044 + atomic_unchecked_t ioerr_cnt;
84045
84046 struct device sdev_gendev,
84047 sdev_dev;
84048 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84049 index 8c79980..723f6f9 100644
84050 --- a/include/scsi/scsi_transport_fc.h
84051 +++ b/include/scsi/scsi_transport_fc.h
84052 @@ -752,7 +752,8 @@ struct fc_function_template {
84053 unsigned long show_host_system_hostname:1;
84054
84055 unsigned long disable_target_scan:1;
84056 -};
84057 +} __do_const;
84058 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84059
84060
84061 /**
84062 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84063 index ae6c3b8..fd748ac 100644
84064 --- a/include/sound/compress_driver.h
84065 +++ b/include/sound/compress_driver.h
84066 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84067 struct snd_compr_caps *caps);
84068 int (*get_codec_caps) (struct snd_compr_stream *stream,
84069 struct snd_compr_codec_caps *codec);
84070 -};
84071 +} __no_const;
84072
84073 /**
84074 * struct snd_compr: Compressed device
84075 diff --git a/include/sound/soc.h b/include/sound/soc.h
84076 index 0b83168..d67280a 100644
84077 --- a/include/sound/soc.h
84078 +++ b/include/sound/soc.h
84079 @@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84080 /* probe ordering - for components with runtime dependencies */
84081 int probe_order;
84082 int remove_order;
84083 -};
84084 +} __do_const;
84085
84086 /* SoC platform interface */
84087 struct snd_soc_platform_driver {
84088 @@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84089 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84090 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84091 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84092 -};
84093 +} __do_const;
84094
84095 struct snd_soc_platform {
84096 const char *name;
84097 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84098 index 9ec9864..e2ee1ee 100644
84099 --- a/include/target/target_core_base.h
84100 +++ b/include/target/target_core_base.h
84101 @@ -761,7 +761,7 @@ struct se_device {
84102 atomic_long_t write_bytes;
84103 /* Active commands on this virtual SE device */
84104 atomic_t simple_cmds;
84105 - atomic_t dev_ordered_id;
84106 + atomic_unchecked_t dev_ordered_id;
84107 atomic_t dev_ordered_sync;
84108 atomic_t dev_qf_count;
84109 int export_count;
84110 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84111 new file mode 100644
84112 index 0000000..fb634b7
84113 --- /dev/null
84114 +++ b/include/trace/events/fs.h
84115 @@ -0,0 +1,53 @@
84116 +#undef TRACE_SYSTEM
84117 +#define TRACE_SYSTEM fs
84118 +
84119 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84120 +#define _TRACE_FS_H
84121 +
84122 +#include <linux/fs.h>
84123 +#include <linux/tracepoint.h>
84124 +
84125 +TRACE_EVENT(do_sys_open,
84126 +
84127 + TP_PROTO(const char *filename, int flags, int mode),
84128 +
84129 + TP_ARGS(filename, flags, mode),
84130 +
84131 + TP_STRUCT__entry(
84132 + __string( filename, filename )
84133 + __field( int, flags )
84134 + __field( int, mode )
84135 + ),
84136 +
84137 + TP_fast_assign(
84138 + __assign_str(filename, filename);
84139 + __entry->flags = flags;
84140 + __entry->mode = mode;
84141 + ),
84142 +
84143 + TP_printk("\"%s\" %x %o",
84144 + __get_str(filename), __entry->flags, __entry->mode)
84145 +);
84146 +
84147 +TRACE_EVENT(open_exec,
84148 +
84149 + TP_PROTO(const char *filename),
84150 +
84151 + TP_ARGS(filename),
84152 +
84153 + TP_STRUCT__entry(
84154 + __string( filename, filename )
84155 + ),
84156 +
84157 + TP_fast_assign(
84158 + __assign_str(filename, filename);
84159 + ),
84160 +
84161 + TP_printk("\"%s\"",
84162 + __get_str(filename))
84163 +);
84164 +
84165 +#endif /* _TRACE_FS_H */
84166 +
84167 +/* This part must be outside protection */
84168 +#include <trace/define_trace.h>
84169 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84170 index 1c09820..7f5ec79 100644
84171 --- a/include/trace/events/irq.h
84172 +++ b/include/trace/events/irq.h
84173 @@ -36,7 +36,7 @@ struct softirq_action;
84174 */
84175 TRACE_EVENT(irq_handler_entry,
84176
84177 - TP_PROTO(int irq, struct irqaction *action),
84178 + TP_PROTO(int irq, const struct irqaction *action),
84179
84180 TP_ARGS(irq, action),
84181
84182 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84183 */
84184 TRACE_EVENT(irq_handler_exit,
84185
84186 - TP_PROTO(int irq, struct irqaction *action, int ret),
84187 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84188
84189 TP_ARGS(irq, action, ret),
84190
84191 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84192 index 7caf44c..23c6f27 100644
84193 --- a/include/uapi/linux/a.out.h
84194 +++ b/include/uapi/linux/a.out.h
84195 @@ -39,6 +39,14 @@ enum machine_type {
84196 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84197 };
84198
84199 +/* Constants for the N_FLAGS field */
84200 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84201 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84202 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84203 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84204 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84205 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84206 +
84207 #if !defined (N_MAGIC)
84208 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84209 #endif
84210 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84211 index 22b6ad3..aeba37e 100644
84212 --- a/include/uapi/linux/bcache.h
84213 +++ b/include/uapi/linux/bcache.h
84214 @@ -5,6 +5,7 @@
84215 * Bcache on disk data structures
84216 */
84217
84218 +#include <linux/compiler.h>
84219 #include <asm/types.h>
84220
84221 #define BITMASK(name, type, field, offset, size) \
84222 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84223 /* Btree keys - all units are in sectors */
84224
84225 struct bkey {
84226 - __u64 high;
84227 - __u64 low;
84228 + __u64 high __intentional_overflow(-1);
84229 + __u64 low __intentional_overflow(-1);
84230 __u64 ptr[];
84231 };
84232
84233 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84234 index d876736..ccce5c0 100644
84235 --- a/include/uapi/linux/byteorder/little_endian.h
84236 +++ b/include/uapi/linux/byteorder/little_endian.h
84237 @@ -42,51 +42,51 @@
84238
84239 static inline __le64 __cpu_to_le64p(const __u64 *p)
84240 {
84241 - return (__force __le64)*p;
84242 + return (__force const __le64)*p;
84243 }
84244 -static inline __u64 __le64_to_cpup(const __le64 *p)
84245 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84246 {
84247 - return (__force __u64)*p;
84248 + return (__force const __u64)*p;
84249 }
84250 static inline __le32 __cpu_to_le32p(const __u32 *p)
84251 {
84252 - return (__force __le32)*p;
84253 + return (__force const __le32)*p;
84254 }
84255 static inline __u32 __le32_to_cpup(const __le32 *p)
84256 {
84257 - return (__force __u32)*p;
84258 + return (__force const __u32)*p;
84259 }
84260 static inline __le16 __cpu_to_le16p(const __u16 *p)
84261 {
84262 - return (__force __le16)*p;
84263 + return (__force const __le16)*p;
84264 }
84265 static inline __u16 __le16_to_cpup(const __le16 *p)
84266 {
84267 - return (__force __u16)*p;
84268 + return (__force const __u16)*p;
84269 }
84270 static inline __be64 __cpu_to_be64p(const __u64 *p)
84271 {
84272 - return (__force __be64)__swab64p(p);
84273 + return (__force const __be64)__swab64p(p);
84274 }
84275 static inline __u64 __be64_to_cpup(const __be64 *p)
84276 {
84277 - return __swab64p((__u64 *)p);
84278 + return __swab64p((const __u64 *)p);
84279 }
84280 static inline __be32 __cpu_to_be32p(const __u32 *p)
84281 {
84282 - return (__force __be32)__swab32p(p);
84283 + return (__force const __be32)__swab32p(p);
84284 }
84285 -static inline __u32 __be32_to_cpup(const __be32 *p)
84286 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84287 {
84288 - return __swab32p((__u32 *)p);
84289 + return __swab32p((const __u32 *)p);
84290 }
84291 static inline __be16 __cpu_to_be16p(const __u16 *p)
84292 {
84293 - return (__force __be16)__swab16p(p);
84294 + return (__force const __be16)__swab16p(p);
84295 }
84296 static inline __u16 __be16_to_cpup(const __be16 *p)
84297 {
84298 - return __swab16p((__u16 *)p);
84299 + return __swab16p((const __u16 *)p);
84300 }
84301 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84302 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84303 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84304 index ef6103b..d4e65dd 100644
84305 --- a/include/uapi/linux/elf.h
84306 +++ b/include/uapi/linux/elf.h
84307 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84308 #define PT_GNU_EH_FRAME 0x6474e550
84309
84310 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84311 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84312 +
84313 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84314 +
84315 +/* Constants for the e_flags field */
84316 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84317 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84318 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84319 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84320 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84321 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84322
84323 /*
84324 * Extended Numbering
84325 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84326 #define DT_DEBUG 21
84327 #define DT_TEXTREL 22
84328 #define DT_JMPREL 23
84329 +#define DT_FLAGS 30
84330 + #define DF_TEXTREL 0x00000004
84331 #define DT_ENCODING 32
84332 #define OLD_DT_LOOS 0x60000000
84333 #define DT_LOOS 0x6000000d
84334 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84335 #define PF_W 0x2
84336 #define PF_X 0x1
84337
84338 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84339 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84340 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84341 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84342 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84343 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84344 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84345 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84346 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84347 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84348 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84349 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84350 +
84351 typedef struct elf32_phdr{
84352 Elf32_Word p_type;
84353 Elf32_Off p_offset;
84354 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84355 #define EI_OSABI 7
84356 #define EI_PAD 8
84357
84358 +#define EI_PAX 14
84359 +
84360 #define ELFMAG0 0x7f /* EI_MAG */
84361 #define ELFMAG1 'E'
84362 #define ELFMAG2 'L'
84363 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84364 index aa169c4..6a2771d 100644
84365 --- a/include/uapi/linux/personality.h
84366 +++ b/include/uapi/linux/personality.h
84367 @@ -30,6 +30,7 @@ enum {
84368 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84369 ADDR_NO_RANDOMIZE | \
84370 ADDR_COMPAT_LAYOUT | \
84371 + ADDR_LIMIT_3GB | \
84372 MMAP_PAGE_ZERO)
84373
84374 /*
84375 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84376 index 7530e74..e714828 100644
84377 --- a/include/uapi/linux/screen_info.h
84378 +++ b/include/uapi/linux/screen_info.h
84379 @@ -43,7 +43,8 @@ struct screen_info {
84380 __u16 pages; /* 0x32 */
84381 __u16 vesa_attributes; /* 0x34 */
84382 __u32 capabilities; /* 0x36 */
84383 - __u8 _reserved[6]; /* 0x3a */
84384 + __u16 vesapm_size; /* 0x3a */
84385 + __u8 _reserved[4]; /* 0x3c */
84386 } __attribute__((packed));
84387
84388 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84389 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84390 index 0e011eb..82681b1 100644
84391 --- a/include/uapi/linux/swab.h
84392 +++ b/include/uapi/linux/swab.h
84393 @@ -43,7 +43,7 @@
84394 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84395 */
84396
84397 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
84398 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84399 {
84400 #ifdef __HAVE_BUILTIN_BSWAP16__
84401 return __builtin_bswap16(val);
84402 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84403 #endif
84404 }
84405
84406 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
84407 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84408 {
84409 #ifdef __HAVE_BUILTIN_BSWAP32__
84410 return __builtin_bswap32(val);
84411 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84412 #endif
84413 }
84414
84415 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
84416 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84417 {
84418 #ifdef __HAVE_BUILTIN_BSWAP64__
84419 return __builtin_bswap64(val);
84420 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84421 index 6d67213..552fdd9 100644
84422 --- a/include/uapi/linux/sysctl.h
84423 +++ b/include/uapi/linux/sysctl.h
84424 @@ -155,8 +155,6 @@ enum
84425 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84426 };
84427
84428 -
84429 -
84430 /* CTL_VM names: */
84431 enum
84432 {
84433 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84434 index ea468ee..4d367a5 100644
84435 --- a/include/uapi/linux/videodev2.h
84436 +++ b/include/uapi/linux/videodev2.h
84437 @@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84438 union {
84439 __s32 value;
84440 __s64 value64;
84441 - char *string;
84442 + char __user *string;
84443 };
84444 } __attribute__ ((packed));
84445
84446 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84447 index c38355c..17a57bc 100644
84448 --- a/include/uapi/linux/xattr.h
84449 +++ b/include/uapi/linux/xattr.h
84450 @@ -73,5 +73,9 @@
84451 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84452 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84453
84454 +/* User namespace */
84455 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84456 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
84457 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84458
84459 #endif /* _UAPI_LINUX_XATTR_H */
84460 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84461 index f9466fa..f4e2b81 100644
84462 --- a/include/video/udlfb.h
84463 +++ b/include/video/udlfb.h
84464 @@ -53,10 +53,10 @@ struct dlfb_data {
84465 u32 pseudo_palette[256];
84466 int blank_mode; /*one of FB_BLANK_ */
84467 /* blit-only rendering path metrics, exposed through sysfs */
84468 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84469 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84470 - atomic_t bytes_sent; /* to usb, after compression including overhead */
84471 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84472 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84473 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84474 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84475 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84476 };
84477
84478 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84479 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84480 index 30f5362..8ed8ac9 100644
84481 --- a/include/video/uvesafb.h
84482 +++ b/include/video/uvesafb.h
84483 @@ -122,6 +122,7 @@ struct uvesafb_par {
84484 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84485 u8 pmi_setpal; /* PMI for palette changes */
84486 u16 *pmi_base; /* protected mode interface location */
84487 + u8 *pmi_code; /* protected mode code location */
84488 void *pmi_start;
84489 void *pmi_pal;
84490 u8 *vbe_state_orig; /*
84491 diff --git a/init/Kconfig b/init/Kconfig
84492 index 9d3585b..ad45d34 100644
84493 --- a/init/Kconfig
84494 +++ b/init/Kconfig
84495 @@ -1093,6 +1093,7 @@ endif # CGROUPS
84496
84497 config CHECKPOINT_RESTORE
84498 bool "Checkpoint/restore support" if EXPERT
84499 + depends on !GRKERNSEC
84500 default n
84501 help
84502 Enables additional kernel features in a sake of checkpoint/restore.
84503 @@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84504
84505 config COMPAT_BRK
84506 bool "Disable heap randomization"
84507 - default y
84508 + default n
84509 help
84510 Randomizing heap placement makes heap exploits harder, but it
84511 also breaks ancient binaries (including anything libc5 based).
84512 @@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84513 config STOP_MACHINE
84514 bool
84515 default y
84516 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84517 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84518 help
84519 Need stop_machine() primitive.
84520
84521 diff --git a/init/Makefile b/init/Makefile
84522 index 7bc47ee..6da2dc7 100644
84523 --- a/init/Makefile
84524 +++ b/init/Makefile
84525 @@ -2,6 +2,9 @@
84526 # Makefile for the linux kernel.
84527 #
84528
84529 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84530 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84531 +
84532 obj-y := main.o version.o mounts.o
84533 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84534 obj-y += noinitramfs.o
84535 diff --git a/init/do_mounts.c b/init/do_mounts.c
84536 index 82f2288..ea1430a 100644
84537 --- a/init/do_mounts.c
84538 +++ b/init/do_mounts.c
84539 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84540 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84541 {
84542 struct super_block *s;
84543 - int err = sys_mount(name, "/root", fs, flags, data);
84544 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84545 if (err)
84546 return err;
84547
84548 - sys_chdir("/root");
84549 + sys_chdir((const char __force_user *)"/root");
84550 s = current->fs->pwd.dentry->d_sb;
84551 ROOT_DEV = s->s_dev;
84552 printk(KERN_INFO
84553 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84554 va_start(args, fmt);
84555 vsprintf(buf, fmt, args);
84556 va_end(args);
84557 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84558 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84559 if (fd >= 0) {
84560 sys_ioctl(fd, FDEJECT, 0);
84561 sys_close(fd);
84562 }
84563 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84564 - fd = sys_open("/dev/console", O_RDWR, 0);
84565 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84566 if (fd >= 0) {
84567 sys_ioctl(fd, TCGETS, (long)&termios);
84568 termios.c_lflag &= ~ICANON;
84569 sys_ioctl(fd, TCSETSF, (long)&termios);
84570 - sys_read(fd, &c, 1);
84571 + sys_read(fd, (char __user *)&c, 1);
84572 termios.c_lflag |= ICANON;
84573 sys_ioctl(fd, TCSETSF, (long)&termios);
84574 sys_close(fd);
84575 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84576 mount_root();
84577 out:
84578 devtmpfs_mount("dev");
84579 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84580 - sys_chroot(".");
84581 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84582 + sys_chroot((const char __force_user *)".");
84583 }
84584
84585 static bool is_tmpfs;
84586 diff --git a/init/do_mounts.h b/init/do_mounts.h
84587 index f5b978a..69dbfe8 100644
84588 --- a/init/do_mounts.h
84589 +++ b/init/do_mounts.h
84590 @@ -15,15 +15,15 @@ extern int root_mountflags;
84591
84592 static inline int create_dev(char *name, dev_t dev)
84593 {
84594 - sys_unlink(name);
84595 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84596 + sys_unlink((char __force_user *)name);
84597 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84598 }
84599
84600 #if BITS_PER_LONG == 32
84601 static inline u32 bstat(char *name)
84602 {
84603 struct stat64 stat;
84604 - if (sys_stat64(name, &stat) != 0)
84605 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84606 return 0;
84607 if (!S_ISBLK(stat.st_mode))
84608 return 0;
84609 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84610 static inline u32 bstat(char *name)
84611 {
84612 struct stat stat;
84613 - if (sys_newstat(name, &stat) != 0)
84614 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84615 return 0;
84616 if (!S_ISBLK(stat.st_mode))
84617 return 0;
84618 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84619 index 3e0878e..8a9d7a0 100644
84620 --- a/init/do_mounts_initrd.c
84621 +++ b/init/do_mounts_initrd.c
84622 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84623 {
84624 sys_unshare(CLONE_FS | CLONE_FILES);
84625 /* stdin/stdout/stderr for /linuxrc */
84626 - sys_open("/dev/console", O_RDWR, 0);
84627 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84628 sys_dup(0);
84629 sys_dup(0);
84630 /* move initrd over / and chdir/chroot in initrd root */
84631 - sys_chdir("/root");
84632 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84633 - sys_chroot(".");
84634 + sys_chdir((const char __force_user *)"/root");
84635 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84636 + sys_chroot((const char __force_user *)".");
84637 sys_setsid();
84638 return 0;
84639 }
84640 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84641 create_dev("/dev/root.old", Root_RAM0);
84642 /* mount initrd on rootfs' /root */
84643 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84644 - sys_mkdir("/old", 0700);
84645 - sys_chdir("/old");
84646 + sys_mkdir((const char __force_user *)"/old", 0700);
84647 + sys_chdir((const char __force_user *)"/old");
84648
84649 /* try loading default modules from initrd */
84650 load_default_modules();
84651 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84652 current->flags &= ~PF_FREEZER_SKIP;
84653
84654 /* move initrd to rootfs' /old */
84655 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
84656 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84657 /* switch root and cwd back to / of rootfs */
84658 - sys_chroot("..");
84659 + sys_chroot((const char __force_user *)"..");
84660
84661 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84662 - sys_chdir("/old");
84663 + sys_chdir((const char __force_user *)"/old");
84664 return;
84665 }
84666
84667 - sys_chdir("/");
84668 + sys_chdir((const char __force_user *)"/");
84669 ROOT_DEV = new_decode_dev(real_root_dev);
84670 mount_root();
84671
84672 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84673 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84674 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84675 if (!error)
84676 printk("okay\n");
84677 else {
84678 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
84679 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84680 if (error == -ENOENT)
84681 printk("/initrd does not exist. Ignored.\n");
84682 else
84683 printk("failed\n");
84684 printk(KERN_NOTICE "Unmounting old root\n");
84685 - sys_umount("/old", MNT_DETACH);
84686 + sys_umount((char __force_user *)"/old", MNT_DETACH);
84687 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84688 if (fd < 0) {
84689 error = fd;
84690 @@ -127,11 +127,11 @@ int __init initrd_load(void)
84691 * mounted in the normal path.
84692 */
84693 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84694 - sys_unlink("/initrd.image");
84695 + sys_unlink((const char __force_user *)"/initrd.image");
84696 handle_initrd();
84697 return 1;
84698 }
84699 }
84700 - sys_unlink("/initrd.image");
84701 + sys_unlink((const char __force_user *)"/initrd.image");
84702 return 0;
84703 }
84704 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84705 index 8cb6db5..d729f50 100644
84706 --- a/init/do_mounts_md.c
84707 +++ b/init/do_mounts_md.c
84708 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84709 partitioned ? "_d" : "", minor,
84710 md_setup_args[ent].device_names);
84711
84712 - fd = sys_open(name, 0, 0);
84713 + fd = sys_open((char __force_user *)name, 0, 0);
84714 if (fd < 0) {
84715 printk(KERN_ERR "md: open failed - cannot start "
84716 "array %s\n", name);
84717 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84718 * array without it
84719 */
84720 sys_close(fd);
84721 - fd = sys_open(name, 0, 0);
84722 + fd = sys_open((char __force_user *)name, 0, 0);
84723 sys_ioctl(fd, BLKRRPART, 0);
84724 }
84725 sys_close(fd);
84726 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84727
84728 wait_for_device_probe();
84729
84730 - fd = sys_open("/dev/md0", 0, 0);
84731 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84732 if (fd >= 0) {
84733 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84734 sys_close(fd);
84735 diff --git a/init/init_task.c b/init/init_task.c
84736 index ba0a7f36..2bcf1d5 100644
84737 --- a/init/init_task.c
84738 +++ b/init/init_task.c
84739 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84740 * Initial thread structure. Alignment of this is handled by a special
84741 * linker map entry.
84742 */
84743 +#ifdef CONFIG_X86
84744 +union thread_union init_thread_union __init_task_data;
84745 +#else
84746 union thread_union init_thread_union __init_task_data =
84747 { INIT_THREAD_INFO(init_task) };
84748 +#endif
84749 diff --git a/init/initramfs.c b/init/initramfs.c
84750 index a8497fa..35b3c90 100644
84751 --- a/init/initramfs.c
84752 +++ b/init/initramfs.c
84753 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84754 }
84755 }
84756
84757 -static long __init do_utime(char *filename, time_t mtime)
84758 +static long __init do_utime(char __force_user *filename, time_t mtime)
84759 {
84760 struct timespec t[2];
84761
84762 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84763 struct dir_entry *de, *tmp;
84764 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84765 list_del(&de->list);
84766 - do_utime(de->name, de->mtime);
84767 + do_utime((char __force_user *)de->name, de->mtime);
84768 kfree(de->name);
84769 kfree(de);
84770 }
84771 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84772 if (nlink >= 2) {
84773 char *old = find_link(major, minor, ino, mode, collected);
84774 if (old)
84775 - return (sys_link(old, collected) < 0) ? -1 : 1;
84776 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84777 }
84778 return 0;
84779 }
84780 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84781 {
84782 struct stat st;
84783
84784 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84785 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84786 if (S_ISDIR(st.st_mode))
84787 - sys_rmdir(path);
84788 + sys_rmdir((char __force_user *)path);
84789 else
84790 - sys_unlink(path);
84791 + sys_unlink((char __force_user *)path);
84792 }
84793 }
84794
84795 @@ -315,7 +315,7 @@ static int __init do_name(void)
84796 int openflags = O_WRONLY|O_CREAT;
84797 if (ml != 1)
84798 openflags |= O_TRUNC;
84799 - wfd = sys_open(collected, openflags, mode);
84800 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84801
84802 if (wfd >= 0) {
84803 sys_fchown(wfd, uid, gid);
84804 @@ -327,17 +327,17 @@ static int __init do_name(void)
84805 }
84806 }
84807 } else if (S_ISDIR(mode)) {
84808 - sys_mkdir(collected, mode);
84809 - sys_chown(collected, uid, gid);
84810 - sys_chmod(collected, mode);
84811 + sys_mkdir((char __force_user *)collected, mode);
84812 + sys_chown((char __force_user *)collected, uid, gid);
84813 + sys_chmod((char __force_user *)collected, mode);
84814 dir_add(collected, mtime);
84815 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84816 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84817 if (maybe_link() == 0) {
84818 - sys_mknod(collected, mode, rdev);
84819 - sys_chown(collected, uid, gid);
84820 - sys_chmod(collected, mode);
84821 - do_utime(collected, mtime);
84822 + sys_mknod((char __force_user *)collected, mode, rdev);
84823 + sys_chown((char __force_user *)collected, uid, gid);
84824 + sys_chmod((char __force_user *)collected, mode);
84825 + do_utime((char __force_user *)collected, mtime);
84826 }
84827 }
84828 return 0;
84829 @@ -346,15 +346,15 @@ static int __init do_name(void)
84830 static int __init do_copy(void)
84831 {
84832 if (count >= body_len) {
84833 - sys_write(wfd, victim, body_len);
84834 + sys_write(wfd, (char __force_user *)victim, body_len);
84835 sys_close(wfd);
84836 - do_utime(vcollected, mtime);
84837 + do_utime((char __force_user *)vcollected, mtime);
84838 kfree(vcollected);
84839 eat(body_len);
84840 state = SkipIt;
84841 return 0;
84842 } else {
84843 - sys_write(wfd, victim, count);
84844 + sys_write(wfd, (char __force_user *)victim, count);
84845 body_len -= count;
84846 eat(count);
84847 return 1;
84848 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84849 {
84850 collected[N_ALIGN(name_len) + body_len] = '\0';
84851 clean_path(collected, 0);
84852 - sys_symlink(collected + N_ALIGN(name_len), collected);
84853 - sys_lchown(collected, uid, gid);
84854 - do_utime(collected, mtime);
84855 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84856 + sys_lchown((char __force_user *)collected, uid, gid);
84857 + do_utime((char __force_user *)collected, mtime);
84858 state = SkipIt;
84859 next_state = Reset;
84860 return 0;
84861 diff --git a/init/main.c b/init/main.c
84862 index 48655ce..d0113e4 100644
84863 --- a/init/main.c
84864 +++ b/init/main.c
84865 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84866 static inline void mark_rodata_ro(void) { }
84867 #endif
84868
84869 +extern void grsecurity_init(void);
84870 +
84871 /*
84872 * Debug helper: via this flag we know that we are in 'early bootup code'
84873 * where only the boot processor is running with IRQ disabled. This means
84874 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84875
84876 __setup("reset_devices", set_reset_devices);
84877
84878 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84879 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84880 +static int __init setup_grsec_proc_gid(char *str)
84881 +{
84882 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84883 + return 1;
84884 +}
84885 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84886 +#endif
84887 +
84888 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84889 +unsigned long pax_user_shadow_base __read_only;
84890 +EXPORT_SYMBOL(pax_user_shadow_base);
84891 +extern char pax_enter_kernel_user[];
84892 +extern char pax_exit_kernel_user[];
84893 +#endif
84894 +
84895 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84896 +static int __init setup_pax_nouderef(char *str)
84897 +{
84898 +#ifdef CONFIG_X86_32
84899 + unsigned int cpu;
84900 + struct desc_struct *gdt;
84901 +
84902 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84903 + gdt = get_cpu_gdt_table(cpu);
84904 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84905 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84906 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84907 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84908 + }
84909 + loadsegment(ds, __KERNEL_DS);
84910 + loadsegment(es, __KERNEL_DS);
84911 + loadsegment(ss, __KERNEL_DS);
84912 +#else
84913 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84914 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84915 + clone_pgd_mask = ~(pgdval_t)0UL;
84916 + pax_user_shadow_base = 0UL;
84917 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84918 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84919 +#endif
84920 +
84921 + return 0;
84922 +}
84923 +early_param("pax_nouderef", setup_pax_nouderef);
84924 +
84925 +#ifdef CONFIG_X86_64
84926 +static int __init setup_pax_weakuderef(char *str)
84927 +{
84928 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84929 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84930 + return 1;
84931 +}
84932 +__setup("pax_weakuderef", setup_pax_weakuderef);
84933 +#endif
84934 +#endif
84935 +
84936 +#ifdef CONFIG_PAX_SOFTMODE
84937 +int pax_softmode;
84938 +
84939 +static int __init setup_pax_softmode(char *str)
84940 +{
84941 + get_option(&str, &pax_softmode);
84942 + return 1;
84943 +}
84944 +__setup("pax_softmode=", setup_pax_softmode);
84945 +#endif
84946 +
84947 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84948 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84949 static const char *panic_later, *panic_param;
84950 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84951 {
84952 int count = preempt_count();
84953 int ret;
84954 - char msgbuf[64];
84955 + const char *msg1 = "", *msg2 = "";
84956
84957 if (initcall_debug)
84958 ret = do_one_initcall_debug(fn);
84959 else
84960 ret = fn();
84961
84962 - msgbuf[0] = 0;
84963 -
84964 if (preempt_count() != count) {
84965 - sprintf(msgbuf, "preemption imbalance ");
84966 + msg1 = " preemption imbalance";
84967 preempt_count_set(count);
84968 }
84969 if (irqs_disabled()) {
84970 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84971 + msg2 = " disabled interrupts";
84972 local_irq_enable();
84973 }
84974 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84975 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84976
84977 + add_latent_entropy();
84978 return ret;
84979 }
84980
84981 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84982 {
84983 argv_init[0] = init_filename;
84984 return do_execve(getname_kernel(init_filename),
84985 - (const char __user *const __user *)argv_init,
84986 - (const char __user *const __user *)envp_init);
84987 + (const char __user *const __force_user *)argv_init,
84988 + (const char __user *const __force_user *)envp_init);
84989 }
84990
84991 static int try_to_run_init_process(const char *init_filename)
84992 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84993 return ret;
84994 }
84995
84996 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84997 +extern int gr_init_ran;
84998 +#endif
84999 +
85000 static noinline void __init kernel_init_freeable(void);
85001
85002 static int __ref kernel_init(void *unused)
85003 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85004 ramdisk_execute_command, ret);
85005 }
85006
85007 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85008 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85009 + gr_init_ran = 1;
85010 +#endif
85011 +
85012 /*
85013 * We try each of these until one succeeds.
85014 *
85015 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85016 do_basic_setup();
85017
85018 /* Open the /dev/console on the rootfs, this should never fail */
85019 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85020 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85021 pr_err("Warning: unable to open an initial console.\n");
85022
85023 (void) sys_dup(0);
85024 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85025 if (!ramdisk_execute_command)
85026 ramdisk_execute_command = "/init";
85027
85028 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85029 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85030 ramdisk_execute_command = NULL;
85031 prepare_namespace();
85032 }
85033
85034 + grsecurity_init();
85035 +
85036 /*
85037 * Ok, we have completed the initial bootup, and
85038 * we're essentially up and running. Get rid of the
85039 diff --git a/ipc/compat.c b/ipc/compat.c
85040 index 45d035d..e4a7f99 100644
85041 --- a/ipc/compat.c
85042 +++ b/ipc/compat.c
85043 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85044 COMPAT_SHMLBA);
85045 if (err < 0)
85046 return err;
85047 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85048 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85049 }
85050 case SHMDT:
85051 return sys_shmdt(compat_ptr(ptr));
85052 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85053 index 998d31b..30c24df 100644
85054 --- a/ipc/ipc_sysctl.c
85055 +++ b/ipc/ipc_sysctl.c
85056 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85057 static int proc_ipc_dointvec(ctl_table *table, int write,
85058 void __user *buffer, size_t *lenp, loff_t *ppos)
85059 {
85060 - struct ctl_table ipc_table;
85061 + ctl_table_no_const ipc_table;
85062
85063 memcpy(&ipc_table, table, sizeof(ipc_table));
85064 ipc_table.data = get_ipc(table);
85065 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85066 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85067 void __user *buffer, size_t *lenp, loff_t *ppos)
85068 {
85069 - struct ctl_table ipc_table;
85070 + ctl_table_no_const ipc_table;
85071
85072 memcpy(&ipc_table, table, sizeof(ipc_table));
85073 ipc_table.data = get_ipc(table);
85074 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85075 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85076 void __user *buffer, size_t *lenp, loff_t *ppos)
85077 {
85078 - struct ctl_table ipc_table;
85079 + ctl_table_no_const ipc_table;
85080 size_t lenp_bef = *lenp;
85081 int rc;
85082
85083 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85084 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85085 void __user *buffer, size_t *lenp, loff_t *ppos)
85086 {
85087 - struct ctl_table ipc_table;
85088 + ctl_table_no_const ipc_table;
85089 memcpy(&ipc_table, table, sizeof(ipc_table));
85090 ipc_table.data = get_ipc(table);
85091
85092 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85093 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85094 void __user *buffer, size_t *lenp, loff_t *ppos)
85095 {
85096 - struct ctl_table ipc_table;
85097 + ctl_table_no_const ipc_table;
85098 size_t lenp_bef = *lenp;
85099 int oldval;
85100 int rc;
85101 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85102 index 5bb8bfe..a38ec05 100644
85103 --- a/ipc/mq_sysctl.c
85104 +++ b/ipc/mq_sysctl.c
85105 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85106 static int proc_mq_dointvec(ctl_table *table, int write,
85107 void __user *buffer, size_t *lenp, loff_t *ppos)
85108 {
85109 - struct ctl_table mq_table;
85110 + ctl_table_no_const mq_table;
85111 memcpy(&mq_table, table, sizeof(mq_table));
85112 mq_table.data = get_mq(table);
85113
85114 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85115 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85116 void __user *buffer, size_t *lenp, loff_t *ppos)
85117 {
85118 - struct ctl_table mq_table;
85119 + ctl_table_no_const mq_table;
85120 memcpy(&mq_table, table, sizeof(mq_table));
85121 mq_table.data = get_mq(table);
85122
85123 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85124 index 4fcf39a..d3cc2ec 100644
85125 --- a/ipc/mqueue.c
85126 +++ b/ipc/mqueue.c
85127 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85128 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85129 info->attr.mq_msgsize);
85130
85131 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85132 spin_lock(&mq_lock);
85133 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85134 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85135 diff --git a/ipc/msg.c b/ipc/msg.c
85136 index 6498531..b0ff3c8 100644
85137 --- a/ipc/msg.c
85138 +++ b/ipc/msg.c
85139 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85140 return security_msg_queue_associate(msq, msgflg);
85141 }
85142
85143 +static struct ipc_ops msg_ops = {
85144 + .getnew = newque,
85145 + .associate = msg_security,
85146 + .more_checks = NULL
85147 +};
85148 +
85149 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85150 {
85151 struct ipc_namespace *ns;
85152 - struct ipc_ops msg_ops;
85153 struct ipc_params msg_params;
85154
85155 ns = current->nsproxy->ipc_ns;
85156
85157 - msg_ops.getnew = newque;
85158 - msg_ops.associate = msg_security;
85159 - msg_ops.more_checks = NULL;
85160 -
85161 msg_params.key = key;
85162 msg_params.flg = msgflg;
85163
85164 diff --git a/ipc/sem.c b/ipc/sem.c
85165 index bee5554..e9af81dd 100644
85166 --- a/ipc/sem.c
85167 +++ b/ipc/sem.c
85168 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85169 return 0;
85170 }
85171
85172 +static struct ipc_ops sem_ops = {
85173 + .getnew = newary,
85174 + .associate = sem_security,
85175 + .more_checks = sem_more_checks
85176 +};
85177 +
85178 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85179 {
85180 struct ipc_namespace *ns;
85181 - struct ipc_ops sem_ops;
85182 struct ipc_params sem_params;
85183
85184 ns = current->nsproxy->ipc_ns;
85185 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85186 if (nsems < 0 || nsems > ns->sc_semmsl)
85187 return -EINVAL;
85188
85189 - sem_ops.getnew = newary;
85190 - sem_ops.associate = sem_security;
85191 - sem_ops.more_checks = sem_more_checks;
85192 -
85193 sem_params.key = key;
85194 sem_params.flg = semflg;
85195 sem_params.u.nsems = nsems;
85196 diff --git a/ipc/shm.c b/ipc/shm.c
85197 index 7645961..afc7f02 100644
85198 --- a/ipc/shm.c
85199 +++ b/ipc/shm.c
85200 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85201 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85202 #endif
85203
85204 +#ifdef CONFIG_GRKERNSEC
85205 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85206 + const time_t shm_createtime, const kuid_t cuid,
85207 + const int shmid);
85208 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85209 + const time_t shm_createtime);
85210 +#endif
85211 +
85212 void shm_init_ns(struct ipc_namespace *ns)
85213 {
85214 ns->shm_ctlmax = SHMMAX;
85215 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85216 shp->shm_lprid = 0;
85217 shp->shm_atim = shp->shm_dtim = 0;
85218 shp->shm_ctim = get_seconds();
85219 +#ifdef CONFIG_GRKERNSEC
85220 + {
85221 + struct timespec timeval;
85222 + do_posix_clock_monotonic_gettime(&timeval);
85223 +
85224 + shp->shm_createtime = timeval.tv_sec;
85225 + }
85226 +#endif
85227 shp->shm_segsz = size;
85228 shp->shm_nattch = 0;
85229 shp->shm_file = file;
85230 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85231 return 0;
85232 }
85233
85234 +static struct ipc_ops shm_ops = {
85235 + .getnew = newseg,
85236 + .associate = shm_security,
85237 + .more_checks = shm_more_checks
85238 +};
85239 +
85240 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85241 {
85242 struct ipc_namespace *ns;
85243 - struct ipc_ops shm_ops;
85244 struct ipc_params shm_params;
85245
85246 ns = current->nsproxy->ipc_ns;
85247
85248 - shm_ops.getnew = newseg;
85249 - shm_ops.associate = shm_security;
85250 - shm_ops.more_checks = shm_more_checks;
85251 -
85252 shm_params.key = key;
85253 shm_params.flg = shmflg;
85254 shm_params.u.size = size;
85255 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85256 f_mode = FMODE_READ | FMODE_WRITE;
85257 }
85258 if (shmflg & SHM_EXEC) {
85259 +
85260 +#ifdef CONFIG_PAX_MPROTECT
85261 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85262 + goto out;
85263 +#endif
85264 +
85265 prot |= PROT_EXEC;
85266 acc_mode |= S_IXUGO;
85267 }
85268 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85269 if (err)
85270 goto out_unlock;
85271
85272 +#ifdef CONFIG_GRKERNSEC
85273 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85274 + shp->shm_perm.cuid, shmid) ||
85275 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85276 + err = -EACCES;
85277 + goto out_unlock;
85278 + }
85279 +#endif
85280 +
85281 ipc_lock_object(&shp->shm_perm);
85282
85283 /* check if shm_destroy() is tearing down shp */
85284 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85285 path = shp->shm_file->f_path;
85286 path_get(&path);
85287 shp->shm_nattch++;
85288 +#ifdef CONFIG_GRKERNSEC
85289 + shp->shm_lapid = current->pid;
85290 +#endif
85291 size = i_size_read(path.dentry->d_inode);
85292 ipc_unlock_object(&shp->shm_perm);
85293 rcu_read_unlock();
85294 diff --git a/ipc/util.c b/ipc/util.c
85295 index 2eb0d1e..0308564 100644
85296 --- a/ipc/util.c
85297 +++ b/ipc/util.c
85298 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
85299 int (*show)(struct seq_file *, void *);
85300 };
85301
85302 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85303 +
85304 static void ipc_memory_notifier(struct work_struct *work)
85305 {
85306 ipcns_notify(IPCNS_MEMCHANGED);
85307 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85308 granted_mode >>= 6;
85309 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85310 granted_mode >>= 3;
85311 +
85312 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85313 + return -1;
85314 +
85315 /* is there some bit set in requested_mode but not in granted_mode? */
85316 if ((requested_mode & ~granted_mode & 0007) &&
85317 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85318 diff --git a/kernel/acct.c b/kernel/acct.c
85319 index 8d6e145..33e0b1e 100644
85320 --- a/kernel/acct.c
85321 +++ b/kernel/acct.c
85322 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85323 */
85324 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85325 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85326 - file->f_op->write(file, (char *)&ac,
85327 + file->f_op->write(file, (char __force_user *)&ac,
85328 sizeof(acct_t), &file->f_pos);
85329 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85330 set_fs(fs);
85331 diff --git a/kernel/audit.c b/kernel/audit.c
85332 index 47845c5..bd9dd5b 100644
85333 --- a/kernel/audit.c
85334 +++ b/kernel/audit.c
85335 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85336 3) suppressed due to audit_rate_limit
85337 4) suppressed due to audit_backlog_limit
85338 */
85339 -static atomic_t audit_lost = ATOMIC_INIT(0);
85340 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85341
85342 /* The netlink socket. */
85343 static struct sock *audit_sock;
85344 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85345 unsigned long now;
85346 int print;
85347
85348 - atomic_inc(&audit_lost);
85349 + atomic_inc_unchecked(&audit_lost);
85350
85351 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85352
85353 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85354 if (print) {
85355 if (printk_ratelimit())
85356 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85357 - atomic_read(&audit_lost),
85358 + atomic_read_unchecked(&audit_lost),
85359 audit_rate_limit,
85360 audit_backlog_limit);
85361 audit_panic(message);
85362 @@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85363 s.pid = audit_pid;
85364 s.rate_limit = audit_rate_limit;
85365 s.backlog_limit = audit_backlog_limit;
85366 - s.lost = atomic_read(&audit_lost);
85367 + s.lost = atomic_read_unchecked(&audit_lost);
85368 s.backlog = skb_queue_len(&audit_skb_queue);
85369 s.version = AUDIT_VERSION_LATEST;
85370 s.backlog_wait_time = audit_backlog_wait_time;
85371 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85372 index 21eae3c..66db239 100644
85373 --- a/kernel/auditsc.c
85374 +++ b/kernel/auditsc.c
85375 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85376 }
85377
85378 /* global counter which is incremented every time something logs in */
85379 -static atomic_t session_id = ATOMIC_INIT(0);
85380 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85381
85382 static int audit_set_loginuid_perm(kuid_t loginuid)
85383 {
85384 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85385
85386 /* are we setting or clearing? */
85387 if (uid_valid(loginuid))
85388 - sessionid = (unsigned int)atomic_inc_return(&session_id);
85389 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85390
85391 task->sessionid = sessionid;
85392 task->loginuid = loginuid;
85393 diff --git a/kernel/capability.c b/kernel/capability.c
85394 index 24663b3..b926ae1 100644
85395 --- a/kernel/capability.c
85396 +++ b/kernel/capability.c
85397 @@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85398 * before modification is attempted and the application
85399 * fails.
85400 */
85401 + if (tocopy > ARRAY_SIZE(kdata))
85402 + return -EFAULT;
85403 +
85404 if (copy_to_user(dataptr, kdata, tocopy
85405 * sizeof(struct __user_cap_data_struct))) {
85406 return -EFAULT;
85407 @@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85408 int ret;
85409
85410 rcu_read_lock();
85411 - ret = security_capable(__task_cred(t), ns, cap);
85412 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85413 + gr_task_is_capable(t, __task_cred(t), cap);
85414 rcu_read_unlock();
85415
85416 - return (ret == 0);
85417 + return ret;
85418 }
85419
85420 /**
85421 @@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85422 int ret;
85423
85424 rcu_read_lock();
85425 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
85426 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85427 rcu_read_unlock();
85428
85429 - return (ret == 0);
85430 + return ret;
85431 }
85432
85433 /**
85434 @@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85435 BUG();
85436 }
85437
85438 - if (security_capable(current_cred(), ns, cap) == 0) {
85439 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85440 current->flags |= PF_SUPERPRIV;
85441 return true;
85442 }
85443 @@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85444 }
85445 EXPORT_SYMBOL(ns_capable);
85446
85447 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
85448 +{
85449 + if (unlikely(!cap_valid(cap))) {
85450 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85451 + BUG();
85452 + }
85453 +
85454 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85455 + current->flags |= PF_SUPERPRIV;
85456 + return true;
85457 + }
85458 + return false;
85459 +}
85460 +EXPORT_SYMBOL(ns_capable_nolog);
85461 +
85462 /**
85463 * file_ns_capable - Determine if the file's opener had a capability in effect
85464 * @file: The file we want to check
85465 @@ -423,6 +442,12 @@ bool capable(int cap)
85466 }
85467 EXPORT_SYMBOL(capable);
85468
85469 +bool capable_nolog(int cap)
85470 +{
85471 + return ns_capable_nolog(&init_user_ns, cap);
85472 +}
85473 +EXPORT_SYMBOL(capable_nolog);
85474 +
85475 /**
85476 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85477 * @inode: The inode in question
85478 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85479 kgid_has_mapping(ns, inode->i_gid);
85480 }
85481 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85482 +
85483 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85484 +{
85485 + struct user_namespace *ns = current_user_ns();
85486 +
85487 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85488 + kgid_has_mapping(ns, inode->i_gid);
85489 +}
85490 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85491 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85492 index ceee0c5..d6f81dd 100644
85493 --- a/kernel/cgroup.c
85494 +++ b/kernel/cgroup.c
85495 @@ -4757,7 +4757,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85496 struct task_struct *task;
85497 int count = 0;
85498
85499 - seq_printf(seq, "css_set %p\n", cset);
85500 + seq_printf(seq, "css_set %pK\n", cset);
85501
85502 list_for_each_entry(task, &cset->tasks, cg_list) {
85503 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85504 diff --git a/kernel/compat.c b/kernel/compat.c
85505 index e40b043..3da8f51 100644
85506 --- a/kernel/compat.c
85507 +++ b/kernel/compat.c
85508 @@ -13,6 +13,7 @@
85509
85510 #include <linux/linkage.h>
85511 #include <linux/compat.h>
85512 +#include <linux/module.h>
85513 #include <linux/errno.h>
85514 #include <linux/time.h>
85515 #include <linux/signal.h>
85516 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85517 mm_segment_t oldfs;
85518 long ret;
85519
85520 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85521 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85522 oldfs = get_fs();
85523 set_fs(KERNEL_DS);
85524 ret = hrtimer_nanosleep_restart(restart);
85525 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85526 oldfs = get_fs();
85527 set_fs(KERNEL_DS);
85528 ret = hrtimer_nanosleep(&tu,
85529 - rmtp ? (struct timespec __user *)&rmt : NULL,
85530 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85531 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85532 set_fs(oldfs);
85533
85534 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85535 mm_segment_t old_fs = get_fs();
85536
85537 set_fs(KERNEL_DS);
85538 - ret = sys_sigpending((old_sigset_t __user *) &s);
85539 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85540 set_fs(old_fs);
85541 if (ret == 0)
85542 ret = put_user(s, set);
85543 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85544 mm_segment_t old_fs = get_fs();
85545
85546 set_fs(KERNEL_DS);
85547 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85548 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85549 set_fs(old_fs);
85550
85551 if (!ret) {
85552 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85553 set_fs (KERNEL_DS);
85554 ret = sys_wait4(pid,
85555 (stat_addr ?
85556 - (unsigned int __user *) &status : NULL),
85557 - options, (struct rusage __user *) &r);
85558 + (unsigned int __force_user *) &status : NULL),
85559 + options, (struct rusage __force_user *) &r);
85560 set_fs (old_fs);
85561
85562 if (ret > 0) {
85563 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85564 memset(&info, 0, sizeof(info));
85565
85566 set_fs(KERNEL_DS);
85567 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85568 - uru ? (struct rusage __user *)&ru : NULL);
85569 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85570 + uru ? (struct rusage __force_user *)&ru : NULL);
85571 set_fs(old_fs);
85572
85573 if ((ret < 0) || (info.si_signo == 0))
85574 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85575 oldfs = get_fs();
85576 set_fs(KERNEL_DS);
85577 err = sys_timer_settime(timer_id, flags,
85578 - (struct itimerspec __user *) &newts,
85579 - (struct itimerspec __user *) &oldts);
85580 + (struct itimerspec __force_user *) &newts,
85581 + (struct itimerspec __force_user *) &oldts);
85582 set_fs(oldfs);
85583 if (!err && old && put_compat_itimerspec(old, &oldts))
85584 return -EFAULT;
85585 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85586 oldfs = get_fs();
85587 set_fs(KERNEL_DS);
85588 err = sys_timer_gettime(timer_id,
85589 - (struct itimerspec __user *) &ts);
85590 + (struct itimerspec __force_user *) &ts);
85591 set_fs(oldfs);
85592 if (!err && put_compat_itimerspec(setting, &ts))
85593 return -EFAULT;
85594 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85595 oldfs = get_fs();
85596 set_fs(KERNEL_DS);
85597 err = sys_clock_settime(which_clock,
85598 - (struct timespec __user *) &ts);
85599 + (struct timespec __force_user *) &ts);
85600 set_fs(oldfs);
85601 return err;
85602 }
85603 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85604 oldfs = get_fs();
85605 set_fs(KERNEL_DS);
85606 err = sys_clock_gettime(which_clock,
85607 - (struct timespec __user *) &ts);
85608 + (struct timespec __force_user *) &ts);
85609 set_fs(oldfs);
85610 if (!err && compat_put_timespec(&ts, tp))
85611 return -EFAULT;
85612 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85613
85614 oldfs = get_fs();
85615 set_fs(KERNEL_DS);
85616 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85617 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85618 set_fs(oldfs);
85619
85620 err = compat_put_timex(utp, &txc);
85621 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85622 oldfs = get_fs();
85623 set_fs(KERNEL_DS);
85624 err = sys_clock_getres(which_clock,
85625 - (struct timespec __user *) &ts);
85626 + (struct timespec __force_user *) &ts);
85627 set_fs(oldfs);
85628 if (!err && tp && compat_put_timespec(&ts, tp))
85629 return -EFAULT;
85630 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85631 struct timespec tu;
85632 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85633
85634 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85635 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85636 oldfs = get_fs();
85637 set_fs(KERNEL_DS);
85638 err = clock_nanosleep_restart(restart);
85639 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
85640 oldfs = get_fs();
85641 set_fs(KERNEL_DS);
85642 err = sys_clock_nanosleep(which_clock, flags,
85643 - (struct timespec __user *) &in,
85644 - (struct timespec __user *) &out);
85645 + (struct timespec __force_user *) &in,
85646 + (struct timespec __force_user *) &out);
85647 set_fs(oldfs);
85648
85649 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85650 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85651 mm_segment_t old_fs = get_fs();
85652
85653 set_fs(KERNEL_DS);
85654 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85655 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85656 set_fs(old_fs);
85657 if (compat_put_timespec(&t, interval))
85658 return -EFAULT;
85659 diff --git a/kernel/configs.c b/kernel/configs.c
85660 index c18b1f1..b9a0132 100644
85661 --- a/kernel/configs.c
85662 +++ b/kernel/configs.c
85663 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85664 struct proc_dir_entry *entry;
85665
85666 /* create the current config file */
85667 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85668 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85669 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85670 + &ikconfig_file_ops);
85671 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85672 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85673 + &ikconfig_file_ops);
85674 +#endif
85675 +#else
85676 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85677 &ikconfig_file_ops);
85678 +#endif
85679 +
85680 if (!entry)
85681 return -ENOMEM;
85682
85683 diff --git a/kernel/cred.c b/kernel/cred.c
85684 index e0573a4..26c0fd3 100644
85685 --- a/kernel/cred.c
85686 +++ b/kernel/cred.c
85687 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85688 validate_creds(cred);
85689 alter_cred_subscribers(cred, -1);
85690 put_cred(cred);
85691 +
85692 +#ifdef CONFIG_GRKERNSEC_SETXID
85693 + cred = (struct cred *) tsk->delayed_cred;
85694 + if (cred != NULL) {
85695 + tsk->delayed_cred = NULL;
85696 + validate_creds(cred);
85697 + alter_cred_subscribers(cred, -1);
85698 + put_cred(cred);
85699 + }
85700 +#endif
85701 }
85702
85703 /**
85704 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85705 * Always returns 0 thus allowing this function to be tail-called at the end
85706 * of, say, sys_setgid().
85707 */
85708 -int commit_creds(struct cred *new)
85709 +static int __commit_creds(struct cred *new)
85710 {
85711 struct task_struct *task = current;
85712 const struct cred *old = task->real_cred;
85713 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85714
85715 get_cred(new); /* we will require a ref for the subj creds too */
85716
85717 + gr_set_role_label(task, new->uid, new->gid);
85718 +
85719 /* dumpability changes */
85720 if (!uid_eq(old->euid, new->euid) ||
85721 !gid_eq(old->egid, new->egid) ||
85722 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
85723 put_cred(old);
85724 return 0;
85725 }
85726 +#ifdef CONFIG_GRKERNSEC_SETXID
85727 +extern int set_user(struct cred *new);
85728 +
85729 +void gr_delayed_cred_worker(void)
85730 +{
85731 + const struct cred *new = current->delayed_cred;
85732 + struct cred *ncred;
85733 +
85734 + current->delayed_cred = NULL;
85735 +
85736 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85737 + // from doing get_cred on it when queueing this
85738 + put_cred(new);
85739 + return;
85740 + } else if (new == NULL)
85741 + return;
85742 +
85743 + ncred = prepare_creds();
85744 + if (!ncred)
85745 + goto die;
85746 + // uids
85747 + ncred->uid = new->uid;
85748 + ncred->euid = new->euid;
85749 + ncred->suid = new->suid;
85750 + ncred->fsuid = new->fsuid;
85751 + // gids
85752 + ncred->gid = new->gid;
85753 + ncred->egid = new->egid;
85754 + ncred->sgid = new->sgid;
85755 + ncred->fsgid = new->fsgid;
85756 + // groups
85757 + set_groups(ncred, new->group_info);
85758 + // caps
85759 + ncred->securebits = new->securebits;
85760 + ncred->cap_inheritable = new->cap_inheritable;
85761 + ncred->cap_permitted = new->cap_permitted;
85762 + ncred->cap_effective = new->cap_effective;
85763 + ncred->cap_bset = new->cap_bset;
85764 +
85765 + if (set_user(ncred)) {
85766 + abort_creds(ncred);
85767 + goto die;
85768 + }
85769 +
85770 + // from doing get_cred on it when queueing this
85771 + put_cred(new);
85772 +
85773 + __commit_creds(ncred);
85774 + return;
85775 +die:
85776 + // from doing get_cred on it when queueing this
85777 + put_cred(new);
85778 + do_group_exit(SIGKILL);
85779 +}
85780 +#endif
85781 +
85782 +int commit_creds(struct cred *new)
85783 +{
85784 +#ifdef CONFIG_GRKERNSEC_SETXID
85785 + int ret;
85786 + int schedule_it = 0;
85787 + struct task_struct *t;
85788 + unsigned oldsecurebits = current_cred()->securebits;
85789 +
85790 + /* we won't get called with tasklist_lock held for writing
85791 + and interrupts disabled as the cred struct in that case is
85792 + init_cred
85793 + */
85794 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85795 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85796 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85797 + schedule_it = 1;
85798 + }
85799 + ret = __commit_creds(new);
85800 + if (schedule_it) {
85801 + rcu_read_lock();
85802 + read_lock(&tasklist_lock);
85803 + for (t = next_thread(current); t != current;
85804 + t = next_thread(t)) {
85805 + /* we'll check if the thread has uid 0 in
85806 + * the delayed worker routine
85807 + */
85808 + if (task_securebits(t) == oldsecurebits &&
85809 + t->delayed_cred == NULL) {
85810 + t->delayed_cred = get_cred(new);
85811 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85812 + set_tsk_need_resched(t);
85813 + }
85814 + }
85815 + read_unlock(&tasklist_lock);
85816 + rcu_read_unlock();
85817 + }
85818 +
85819 + return ret;
85820 +#else
85821 + return __commit_creds(new);
85822 +#endif
85823 +}
85824 +
85825 EXPORT_SYMBOL(commit_creds);
85826
85827 /**
85828 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85829 index 2956c8d..cfe1e2e 100644
85830 --- a/kernel/debug/debug_core.c
85831 +++ b/kernel/debug/debug_core.c
85832 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85833 */
85834 static atomic_t masters_in_kgdb;
85835 static atomic_t slaves_in_kgdb;
85836 -static atomic_t kgdb_break_tasklet_var;
85837 +static atomic_unchecked_t kgdb_break_tasklet_var;
85838 atomic_t kgdb_setting_breakpoint;
85839
85840 struct task_struct *kgdb_usethread;
85841 @@ -134,7 +134,7 @@ int kgdb_single_step;
85842 static pid_t kgdb_sstep_pid;
85843
85844 /* to keep track of the CPU which is doing the single stepping*/
85845 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85846 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85847
85848 /*
85849 * If you are debugging a problem where roundup (the collection of
85850 @@ -549,7 +549,7 @@ return_normal:
85851 * kernel will only try for the value of sstep_tries before
85852 * giving up and continuing on.
85853 */
85854 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85855 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85856 (kgdb_info[cpu].task &&
85857 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85858 atomic_set(&kgdb_active, -1);
85859 @@ -647,8 +647,8 @@ cpu_master_loop:
85860 }
85861
85862 kgdb_restore:
85863 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85864 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85865 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85866 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85867 if (kgdb_info[sstep_cpu].task)
85868 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85869 else
85870 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
85871 static void kgdb_tasklet_bpt(unsigned long ing)
85872 {
85873 kgdb_breakpoint();
85874 - atomic_set(&kgdb_break_tasklet_var, 0);
85875 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85876 }
85877
85878 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85879
85880 void kgdb_schedule_breakpoint(void)
85881 {
85882 - if (atomic_read(&kgdb_break_tasklet_var) ||
85883 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85884 atomic_read(&kgdb_active) != -1 ||
85885 atomic_read(&kgdb_setting_breakpoint))
85886 return;
85887 - atomic_inc(&kgdb_break_tasklet_var);
85888 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85889 tasklet_schedule(&kgdb_tasklet_breakpoint);
85890 }
85891 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85892 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85893 index 0b097c8..11dd5c5 100644
85894 --- a/kernel/debug/kdb/kdb_main.c
85895 +++ b/kernel/debug/kdb/kdb_main.c
85896 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85897 continue;
85898
85899 kdb_printf("%-20s%8u 0x%p ", mod->name,
85900 - mod->core_size, (void *)mod);
85901 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85902 #ifdef CONFIG_MODULE_UNLOAD
85903 kdb_printf("%4ld ", module_refcount(mod));
85904 #endif
85905 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85906 kdb_printf(" (Loading)");
85907 else
85908 kdb_printf(" (Live)");
85909 - kdb_printf(" 0x%p", mod->module_core);
85910 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85911
85912 #ifdef CONFIG_MODULE_UNLOAD
85913 {
85914 diff --git a/kernel/events/core.c b/kernel/events/core.c
85915 index 440eefc..0909f02 100644
85916 --- a/kernel/events/core.c
85917 +++ b/kernel/events/core.c
85918 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85919 * 0 - disallow raw tracepoint access for unpriv
85920 * 1 - disallow cpu events for unpriv
85921 * 2 - disallow kernel profiling for unpriv
85922 + * 3 - disallow all unpriv perf event use
85923 */
85924 -int sysctl_perf_event_paranoid __read_mostly = 1;
85925 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85926 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85927 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85928 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85929 +#else
85930 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85931 +#endif
85932
85933 /* Minimum for 512 kiB + 1 user control page */
85934 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85935 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85936
85937 tmp *= sysctl_perf_cpu_time_max_percent;
85938 do_div(tmp, 100);
85939 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85940 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85941 }
85942
85943 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85944 @@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85945 }
85946 }
85947
85948 -static atomic64_t perf_event_id;
85949 +static atomic64_unchecked_t perf_event_id;
85950
85951 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85952 enum event_type_t event_type);
85953 @@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
85954
85955 static inline u64 perf_event_count(struct perf_event *event)
85956 {
85957 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85958 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85959 }
85960
85961 static u64 perf_event_read(struct perf_event *event)
85962 @@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85963 mutex_lock(&event->child_mutex);
85964 total += perf_event_read(event);
85965 *enabled += event->total_time_enabled +
85966 - atomic64_read(&event->child_total_time_enabled);
85967 + atomic64_read_unchecked(&event->child_total_time_enabled);
85968 *running += event->total_time_running +
85969 - atomic64_read(&event->child_total_time_running);
85970 + atomic64_read_unchecked(&event->child_total_time_running);
85971
85972 list_for_each_entry(child, &event->child_list, child_list) {
85973 total += perf_event_read(child);
85974 @@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
85975 userpg->offset -= local64_read(&event->hw.prev_count);
85976
85977 userpg->time_enabled = enabled +
85978 - atomic64_read(&event->child_total_time_enabled);
85979 + atomic64_read_unchecked(&event->child_total_time_enabled);
85980
85981 userpg->time_running = running +
85982 - atomic64_read(&event->child_total_time_running);
85983 + atomic64_read_unchecked(&event->child_total_time_running);
85984
85985 arch_perf_update_userpage(userpg, now);
85986
85987 @@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85988
85989 /* Data. */
85990 sp = perf_user_stack_pointer(regs);
85991 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85992 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85993 dyn_size = dump_size - rem;
85994
85995 perf_output_skip(handle, rem);
85996 @@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85997 values[n++] = perf_event_count(event);
85998 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85999 values[n++] = enabled +
86000 - atomic64_read(&event->child_total_time_enabled);
86001 + atomic64_read_unchecked(&event->child_total_time_enabled);
86002 }
86003 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86004 values[n++] = running +
86005 - atomic64_read(&event->child_total_time_running);
86006 + atomic64_read_unchecked(&event->child_total_time_running);
86007 }
86008 if (read_format & PERF_FORMAT_ID)
86009 values[n++] = primary_event_id(event);
86010 @@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86011 event->parent = parent_event;
86012
86013 event->ns = get_pid_ns(task_active_pid_ns(current));
86014 - event->id = atomic64_inc_return(&perf_event_id);
86015 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86016
86017 event->state = PERF_EVENT_STATE_INACTIVE;
86018
86019 @@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86020 if (flags & ~PERF_FLAG_ALL)
86021 return -EINVAL;
86022
86023 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86024 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86025 + return -EACCES;
86026 +#endif
86027 +
86028 err = perf_copy_attr(attr_uptr, &attr);
86029 if (err)
86030 return err;
86031 @@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86032 /*
86033 * Add back the child's count to the parent's count:
86034 */
86035 - atomic64_add(child_val, &parent_event->child_count);
86036 - atomic64_add(child_event->total_time_enabled,
86037 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86038 + atomic64_add_unchecked(child_event->total_time_enabled,
86039 &parent_event->child_total_time_enabled);
86040 - atomic64_add(child_event->total_time_running,
86041 + atomic64_add_unchecked(child_event->total_time_running,
86042 &parent_event->child_total_time_running);
86043
86044 /*
86045 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86046 index 569b2187..19940d9 100644
86047 --- a/kernel/events/internal.h
86048 +++ b/kernel/events/internal.h
86049 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86050 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86051 }
86052
86053 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86054 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86055 static inline unsigned long \
86056 func_name(struct perf_output_handle *handle, \
86057 - const void *buf, unsigned long len) \
86058 + const void user *buf, unsigned long len) \
86059 { \
86060 unsigned long size, written; \
86061 \
86062 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86063 return 0;
86064 }
86065
86066 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86067 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86068
86069 static inline unsigned long
86070 memcpy_skip(void *dst, const void *src, unsigned long n)
86071 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86072 return 0;
86073 }
86074
86075 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86076 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86077
86078 #ifndef arch_perf_out_copy_user
86079 #define arch_perf_out_copy_user arch_perf_out_copy_user
86080 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86081 }
86082 #endif
86083
86084 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86085 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86086
86087 /* Callchain handling */
86088 extern struct perf_callchain_entry *
86089 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86090 index 04709b6..d330828 100644
86091 --- a/kernel/events/uprobes.c
86092 +++ b/kernel/events/uprobes.c
86093 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86094 {
86095 struct page *page;
86096 uprobe_opcode_t opcode;
86097 - int result;
86098 + long result;
86099
86100 pagefault_disable();
86101 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86102 diff --git a/kernel/exit.c b/kernel/exit.c
86103 index 6ed6a1d..edecb0e 100644
86104 --- a/kernel/exit.c
86105 +++ b/kernel/exit.c
86106 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86107 struct task_struct *leader;
86108 int zap_leader;
86109 repeat:
86110 +#ifdef CONFIG_NET
86111 + gr_del_task_from_ip_table(p);
86112 +#endif
86113 +
86114 /* don't need to get the RCU readlock here - the process is dead and
86115 * can't be modifying its own credentials. But shut RCU-lockdep up */
86116 rcu_read_lock();
86117 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86118 * know it'll be handled, so that they don't get converted to
86119 * SIGKILL or just silently dropped.
86120 */
86121 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86122 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86123 recalc_sigpending();
86124 spin_unlock_irq(&current->sighand->siglock);
86125 return 0;
86126 @@ -699,6 +703,8 @@ void do_exit(long code)
86127 struct task_struct *tsk = current;
86128 int group_dead;
86129
86130 + set_fs(USER_DS);
86131 +
86132 profile_task_exit(tsk);
86133
86134 WARN_ON(blk_needs_flush_plug(tsk));
86135 @@ -715,7 +721,6 @@ void do_exit(long code)
86136 * mm_release()->clear_child_tid() from writing to a user-controlled
86137 * kernel address.
86138 */
86139 - set_fs(USER_DS);
86140
86141 ptrace_event(PTRACE_EVENT_EXIT, code);
86142
86143 @@ -774,6 +779,9 @@ void do_exit(long code)
86144 tsk->exit_code = code;
86145 taskstats_exit(tsk, group_dead);
86146
86147 + gr_acl_handle_psacct(tsk, code);
86148 + gr_acl_handle_exit();
86149 +
86150 exit_mm(tsk);
86151
86152 if (group_dead)
86153 @@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86154 * Take down every thread in the group. This is called by fatal signals
86155 * as well as by sys_exit_group (below).
86156 */
86157 -void
86158 +__noreturn void
86159 do_group_exit(int exit_code)
86160 {
86161 struct signal_struct *sig = current->signal;
86162 diff --git a/kernel/fork.c b/kernel/fork.c
86163 index 1429043..9d95f16 100644
86164 --- a/kernel/fork.c
86165 +++ b/kernel/fork.c
86166 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86167 # endif
86168 #endif
86169
86170 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86171 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86172 + int node, void **lowmem_stack)
86173 +{
86174 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
86175 + void *ret = NULL;
86176 + unsigned int i;
86177 +
86178 + *lowmem_stack = alloc_thread_info_node(tsk, node);
86179 + if (*lowmem_stack == NULL)
86180 + goto out;
86181 +
86182 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86183 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86184 +
86185 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86186 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86187 + if (ret == NULL) {
86188 + free_thread_info(*lowmem_stack);
86189 + *lowmem_stack = NULL;
86190 + }
86191 +
86192 +out:
86193 + return ret;
86194 +}
86195 +
86196 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86197 +{
86198 + unmap_process_stacks(tsk);
86199 +}
86200 +#else
86201 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86202 + int node, void **lowmem_stack)
86203 +{
86204 + return alloc_thread_info_node(tsk, node);
86205 +}
86206 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86207 +{
86208 + free_thread_info(ti);
86209 +}
86210 +#endif
86211 +
86212 /* SLAB cache for signal_struct structures (tsk->signal) */
86213 static struct kmem_cache *signal_cachep;
86214
86215 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86216 /* SLAB cache for mm_struct structures (tsk->mm) */
86217 static struct kmem_cache *mm_cachep;
86218
86219 -static void account_kernel_stack(struct thread_info *ti, int account)
86220 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86221 {
86222 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86223 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86224 +#else
86225 struct zone *zone = page_zone(virt_to_page(ti));
86226 +#endif
86227
86228 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86229 }
86230
86231 void free_task(struct task_struct *tsk)
86232 {
86233 - account_kernel_stack(tsk->stack, -1);
86234 + account_kernel_stack(tsk, tsk->stack, -1);
86235 arch_release_thread_info(tsk->stack);
86236 - free_thread_info(tsk->stack);
86237 + gr_free_thread_info(tsk, tsk->stack);
86238 rt_mutex_debug_task_free(tsk);
86239 ftrace_graph_exit_task(tsk);
86240 put_seccomp_filter(tsk);
86241 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86242 struct task_struct *tsk;
86243 struct thread_info *ti;
86244 unsigned long *stackend;
86245 + void *lowmem_stack;
86246 int node = tsk_fork_get_node(orig);
86247 int err;
86248
86249 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86250 if (!tsk)
86251 return NULL;
86252
86253 - ti = alloc_thread_info_node(tsk, node);
86254 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86255 if (!ti)
86256 goto free_tsk;
86257
86258 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86259 goto free_ti;
86260
86261 tsk->stack = ti;
86262 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86263 + tsk->lowmem_stack = lowmem_stack;
86264 +#endif
86265
86266 setup_thread_stack(tsk, orig);
86267 clear_user_return_notifier(tsk);
86268 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86269 *stackend = STACK_END_MAGIC; /* for overflow detection */
86270
86271 #ifdef CONFIG_CC_STACKPROTECTOR
86272 - tsk->stack_canary = get_random_int();
86273 + tsk->stack_canary = pax_get_random_long();
86274 #endif
86275
86276 /*
86277 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86278 tsk->splice_pipe = NULL;
86279 tsk->task_frag.page = NULL;
86280
86281 - account_kernel_stack(ti, 1);
86282 + account_kernel_stack(tsk, ti, 1);
86283
86284 return tsk;
86285
86286 free_ti:
86287 - free_thread_info(ti);
86288 + gr_free_thread_info(tsk, ti);
86289 free_tsk:
86290 free_task_struct(tsk);
86291 return NULL;
86292 }
86293
86294 #ifdef CONFIG_MMU
86295 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86296 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86297 +{
86298 + struct vm_area_struct *tmp;
86299 + unsigned long charge;
86300 + struct file *file;
86301 + int retval;
86302 +
86303 + charge = 0;
86304 + if (mpnt->vm_flags & VM_ACCOUNT) {
86305 + unsigned long len = vma_pages(mpnt);
86306 +
86307 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86308 + goto fail_nomem;
86309 + charge = len;
86310 + }
86311 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86312 + if (!tmp)
86313 + goto fail_nomem;
86314 + *tmp = *mpnt;
86315 + tmp->vm_mm = mm;
86316 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
86317 + retval = vma_dup_policy(mpnt, tmp);
86318 + if (retval)
86319 + goto fail_nomem_policy;
86320 + if (anon_vma_fork(tmp, mpnt))
86321 + goto fail_nomem_anon_vma_fork;
86322 + tmp->vm_flags &= ~VM_LOCKED;
86323 + tmp->vm_next = tmp->vm_prev = NULL;
86324 + tmp->vm_mirror = NULL;
86325 + file = tmp->vm_file;
86326 + if (file) {
86327 + struct inode *inode = file_inode(file);
86328 + struct address_space *mapping = file->f_mapping;
86329 +
86330 + get_file(file);
86331 + if (tmp->vm_flags & VM_DENYWRITE)
86332 + atomic_dec(&inode->i_writecount);
86333 + mutex_lock(&mapping->i_mmap_mutex);
86334 + if (tmp->vm_flags & VM_SHARED)
86335 + mapping->i_mmap_writable++;
86336 + flush_dcache_mmap_lock(mapping);
86337 + /* insert tmp into the share list, just after mpnt */
86338 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86339 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86340 + else
86341 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86342 + flush_dcache_mmap_unlock(mapping);
86343 + mutex_unlock(&mapping->i_mmap_mutex);
86344 + }
86345 +
86346 + /*
86347 + * Clear hugetlb-related page reserves for children. This only
86348 + * affects MAP_PRIVATE mappings. Faults generated by the child
86349 + * are not guaranteed to succeed, even if read-only
86350 + */
86351 + if (is_vm_hugetlb_page(tmp))
86352 + reset_vma_resv_huge_pages(tmp);
86353 +
86354 + return tmp;
86355 +
86356 +fail_nomem_anon_vma_fork:
86357 + mpol_put(vma_policy(tmp));
86358 +fail_nomem_policy:
86359 + kmem_cache_free(vm_area_cachep, tmp);
86360 +fail_nomem:
86361 + vm_unacct_memory(charge);
86362 + return NULL;
86363 +}
86364 +
86365 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86366 {
86367 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86368 struct rb_node **rb_link, *rb_parent;
86369 int retval;
86370 - unsigned long charge;
86371
86372 uprobe_start_dup_mmap();
86373 down_write(&oldmm->mmap_sem);
86374 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86375
86376 prev = NULL;
86377 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86378 - struct file *file;
86379 -
86380 if (mpnt->vm_flags & VM_DONTCOPY) {
86381 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86382 -vma_pages(mpnt));
86383 continue;
86384 }
86385 - charge = 0;
86386 - if (mpnt->vm_flags & VM_ACCOUNT) {
86387 - unsigned long len = vma_pages(mpnt);
86388 -
86389 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86390 - goto fail_nomem;
86391 - charge = len;
86392 - }
86393 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86394 - if (!tmp)
86395 - goto fail_nomem;
86396 - *tmp = *mpnt;
86397 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
86398 - retval = vma_dup_policy(mpnt, tmp);
86399 - if (retval)
86400 - goto fail_nomem_policy;
86401 - tmp->vm_mm = mm;
86402 - if (anon_vma_fork(tmp, mpnt))
86403 - goto fail_nomem_anon_vma_fork;
86404 - tmp->vm_flags &= ~VM_LOCKED;
86405 - tmp->vm_next = tmp->vm_prev = NULL;
86406 - file = tmp->vm_file;
86407 - if (file) {
86408 - struct inode *inode = file_inode(file);
86409 - struct address_space *mapping = file->f_mapping;
86410 -
86411 - get_file(file);
86412 - if (tmp->vm_flags & VM_DENYWRITE)
86413 - atomic_dec(&inode->i_writecount);
86414 - mutex_lock(&mapping->i_mmap_mutex);
86415 - if (tmp->vm_flags & VM_SHARED)
86416 - mapping->i_mmap_writable++;
86417 - flush_dcache_mmap_lock(mapping);
86418 - /* insert tmp into the share list, just after mpnt */
86419 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86420 - vma_nonlinear_insert(tmp,
86421 - &mapping->i_mmap_nonlinear);
86422 - else
86423 - vma_interval_tree_insert_after(tmp, mpnt,
86424 - &mapping->i_mmap);
86425 - flush_dcache_mmap_unlock(mapping);
86426 - mutex_unlock(&mapping->i_mmap_mutex);
86427 + tmp = dup_vma(mm, oldmm, mpnt);
86428 + if (!tmp) {
86429 + retval = -ENOMEM;
86430 + goto out;
86431 }
86432
86433 /*
86434 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86435 if (retval)
86436 goto out;
86437 }
86438 +
86439 +#ifdef CONFIG_PAX_SEGMEXEC
86440 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86441 + struct vm_area_struct *mpnt_m;
86442 +
86443 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86444 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86445 +
86446 + if (!mpnt->vm_mirror)
86447 + continue;
86448 +
86449 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86450 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86451 + mpnt->vm_mirror = mpnt_m;
86452 + } else {
86453 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86454 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86455 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86456 + mpnt->vm_mirror->vm_mirror = mpnt;
86457 + }
86458 + }
86459 + BUG_ON(mpnt_m);
86460 + }
86461 +#endif
86462 +
86463 /* a new mm has just been created */
86464 arch_dup_mmap(oldmm, mm);
86465 retval = 0;
86466 @@ -472,14 +575,6 @@ out:
86467 up_write(&oldmm->mmap_sem);
86468 uprobe_end_dup_mmap();
86469 return retval;
86470 -fail_nomem_anon_vma_fork:
86471 - mpol_put(vma_policy(tmp));
86472 -fail_nomem_policy:
86473 - kmem_cache_free(vm_area_cachep, tmp);
86474 -fail_nomem:
86475 - retval = -ENOMEM;
86476 - vm_unacct_memory(charge);
86477 - goto out;
86478 }
86479
86480 static inline int mm_alloc_pgd(struct mm_struct *mm)
86481 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86482 return ERR_PTR(err);
86483
86484 mm = get_task_mm(task);
86485 - if (mm && mm != current->mm &&
86486 - !ptrace_may_access(task, mode)) {
86487 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86488 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86489 mmput(mm);
86490 mm = ERR_PTR(-EACCES);
86491 }
86492 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86493 spin_unlock(&fs->lock);
86494 return -EAGAIN;
86495 }
86496 - fs->users++;
86497 + atomic_inc(&fs->users);
86498 spin_unlock(&fs->lock);
86499 return 0;
86500 }
86501 tsk->fs = copy_fs_struct(fs);
86502 if (!tsk->fs)
86503 return -ENOMEM;
86504 + /* Carry through gr_chroot_dentry and is_chrooted instead
86505 + of recomputing it here. Already copied when the task struct
86506 + is duplicated. This allows pivot_root to not be treated as
86507 + a chroot
86508 + */
86509 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
86510 +
86511 return 0;
86512 }
86513
86514 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86515 * parts of the process environment (as per the clone
86516 * flags). The actual kick-off is left to the caller.
86517 */
86518 -static struct task_struct *copy_process(unsigned long clone_flags,
86519 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86520 unsigned long stack_start,
86521 unsigned long stack_size,
86522 int __user *child_tidptr,
86523 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86524 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86525 #endif
86526 retval = -EAGAIN;
86527 +
86528 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86529 +
86530 if (atomic_read(&p->real_cred->user->processes) >=
86531 task_rlimit(p, RLIMIT_NPROC)) {
86532 if (p->real_cred->user != INIT_USER &&
86533 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86534 goto bad_fork_free_pid;
86535 }
86536
86537 + /* synchronizes with gr_set_acls()
86538 + we need to call this past the point of no return for fork()
86539 + */
86540 + gr_copy_label(p);
86541 +
86542 if (likely(p->pid)) {
86543 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86544
86545 @@ -1539,6 +1649,8 @@ bad_fork_cleanup_count:
86546 bad_fork_free:
86547 free_task(p);
86548 fork_out:
86549 + gr_log_forkfail(retval);
86550 +
86551 return ERR_PTR(retval);
86552 }
86553
86554 @@ -1600,6 +1712,7 @@ long do_fork(unsigned long clone_flags,
86555
86556 p = copy_process(clone_flags, stack_start, stack_size,
86557 child_tidptr, NULL, trace);
86558 + add_latent_entropy();
86559 /*
86560 * Do this prior waking up the new thread - the thread pointer
86561 * might get invalid after that point, if the thread exits quickly.
86562 @@ -1616,6 +1729,8 @@ long do_fork(unsigned long clone_flags,
86563 if (clone_flags & CLONE_PARENT_SETTID)
86564 put_user(nr, parent_tidptr);
86565
86566 + gr_handle_brute_check();
86567 +
86568 if (clone_flags & CLONE_VFORK) {
86569 p->vfork_done = &vfork;
86570 init_completion(&vfork);
86571 @@ -1734,7 +1849,7 @@ void __init proc_caches_init(void)
86572 mm_cachep = kmem_cache_create("mm_struct",
86573 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86574 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86575 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86576 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86577 mmap_init();
86578 nsproxy_cache_init();
86579 }
86580 @@ -1774,7 +1889,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86581 return 0;
86582
86583 /* don't need lock here; in the worst case we'll do useless copy */
86584 - if (fs->users == 1)
86585 + if (atomic_read(&fs->users) == 1)
86586 return 0;
86587
86588 *new_fsp = copy_fs_struct(fs);
86589 @@ -1881,7 +1996,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86590 fs = current->fs;
86591 spin_lock(&fs->lock);
86592 current->fs = new_fs;
86593 - if (--fs->users)
86594 + gr_set_chroot_entries(current, &current->fs->root);
86595 + if (atomic_dec_return(&fs->users))
86596 new_fs = NULL;
86597 else
86598 new_fs = fs;
86599 diff --git a/kernel/futex.c b/kernel/futex.c
86600 index de938d2..c566038 100644
86601 --- a/kernel/futex.c
86602 +++ b/kernel/futex.c
86603 @@ -202,7 +202,7 @@ struct futex_pi_state {
86604 atomic_t refcount;
86605
86606 union futex_key key;
86607 -};
86608 +} __randomize_layout;
86609
86610 /**
86611 * struct futex_q - The hashed futex queue entry, one per waiting task
86612 @@ -236,7 +236,7 @@ struct futex_q {
86613 struct rt_mutex_waiter *rt_waiter;
86614 union futex_key *requeue_pi_key;
86615 u32 bitset;
86616 -};
86617 +} __randomize_layout;
86618
86619 static const struct futex_q futex_q_init = {
86620 /* list gets initialized in queue_me()*/
86621 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86622 struct page *page, *page_head;
86623 int err, ro = 0;
86624
86625 +#ifdef CONFIG_PAX_SEGMEXEC
86626 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86627 + return -EFAULT;
86628 +#endif
86629 +
86630 /*
86631 * The futex address must be "naturally" aligned.
86632 */
86633 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86634
86635 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86636 {
86637 - int ret;
86638 + unsigned long ret;
86639
86640 pagefault_disable();
86641 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86642 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
86643 {
86644 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86645 u32 curval;
86646 + mm_segment_t oldfs;
86647
86648 /*
86649 * This will fail and we want it. Some arch implementations do
86650 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
86651 * implementation, the non-functional ones will return
86652 * -ENOSYS.
86653 */
86654 + oldfs = get_fs();
86655 + set_fs(USER_DS);
86656 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86657 futex_cmpxchg_enabled = 1;
86658 + set_fs(oldfs);
86659 #endif
86660 }
86661
86662 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86663 index 55c8c93..9ba7ad6 100644
86664 --- a/kernel/futex_compat.c
86665 +++ b/kernel/futex_compat.c
86666 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86667 return 0;
86668 }
86669
86670 -static void __user *futex_uaddr(struct robust_list __user *entry,
86671 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86672 compat_long_t futex_offset)
86673 {
86674 compat_uptr_t base = ptr_to_compat(entry);
86675 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86676 index f45b75b..bfac6d5 100644
86677 --- a/kernel/gcov/base.c
86678 +++ b/kernel/gcov/base.c
86679 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
86680 }
86681
86682 #ifdef CONFIG_MODULES
86683 -static inline int within(void *addr, void *start, unsigned long size)
86684 -{
86685 - return ((addr >= start) && (addr < start + size));
86686 -}
86687 -
86688 /* Update list and generate events when modules are unloaded. */
86689 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86690 void *data)
86691 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86692
86693 /* Remove entries located in module from linked list. */
86694 while ((info = gcov_info_next(info))) {
86695 - if (within(info, mod->module_core, mod->core_size)) {
86696 + if (within_module_core_rw((unsigned long)info, mod)) {
86697 gcov_info_unlink(prev, info);
86698 if (gcov_events_enabled)
86699 gcov_event(GCOV_REMOVE, info);
86700 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86701 index e0501fe..312edd6 100644
86702 --- a/kernel/hrtimer.c
86703 +++ b/kernel/hrtimer.c
86704 @@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
86705 local_irq_restore(flags);
86706 }
86707
86708 -static void run_hrtimer_softirq(struct softirq_action *h)
86709 +static __latent_entropy void run_hrtimer_softirq(void)
86710 {
86711 hrtimer_peek_ahead_timers();
86712 }
86713 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86714 index a82170e..5b01e7f 100644
86715 --- a/kernel/irq_work.c
86716 +++ b/kernel/irq_work.c
86717 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86718 return NOTIFY_OK;
86719 }
86720
86721 -static struct notifier_block cpu_notify;
86722 +static struct notifier_block cpu_notify = {
86723 + .notifier_call = irq_work_cpu_notify,
86724 + .priority = 0,
86725 +};
86726
86727 static __init int irq_work_init_cpu_notifier(void)
86728 {
86729 - cpu_notify.notifier_call = irq_work_cpu_notify;
86730 - cpu_notify.priority = 0;
86731 register_cpu_notifier(&cpu_notify);
86732 return 0;
86733 }
86734 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86735 index 9019f15..9a3c42e 100644
86736 --- a/kernel/jump_label.c
86737 +++ b/kernel/jump_label.c
86738 @@ -14,6 +14,7 @@
86739 #include <linux/err.h>
86740 #include <linux/static_key.h>
86741 #include <linux/jump_label_ratelimit.h>
86742 +#include <linux/mm.h>
86743
86744 #ifdef HAVE_JUMP_LABEL
86745
86746 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86747
86748 size = (((unsigned long)stop - (unsigned long)start)
86749 / sizeof(struct jump_entry));
86750 + pax_open_kernel();
86751 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86752 + pax_close_kernel();
86753 }
86754
86755 static void jump_label_update(struct static_key *key, int enable);
86756 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86757 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86758 struct jump_entry *iter;
86759
86760 + pax_open_kernel();
86761 for (iter = iter_start; iter < iter_stop; iter++) {
86762 if (within_module_init(iter->code, mod))
86763 iter->code = 0;
86764 }
86765 + pax_close_kernel();
86766 }
86767
86768 static int
86769 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86770 index cb0cf37..b69e161 100644
86771 --- a/kernel/kallsyms.c
86772 +++ b/kernel/kallsyms.c
86773 @@ -11,6 +11,9 @@
86774 * Changed the compression method from stem compression to "table lookup"
86775 * compression (see scripts/kallsyms.c for a more complete description)
86776 */
86777 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86778 +#define __INCLUDED_BY_HIDESYM 1
86779 +#endif
86780 #include <linux/kallsyms.h>
86781 #include <linux/module.h>
86782 #include <linux/init.h>
86783 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
86784
86785 static inline int is_kernel_inittext(unsigned long addr)
86786 {
86787 + if (system_state != SYSTEM_BOOTING)
86788 + return 0;
86789 +
86790 if (addr >= (unsigned long)_sinittext
86791 && addr <= (unsigned long)_einittext)
86792 return 1;
86793 return 0;
86794 }
86795
86796 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86797 +#ifdef CONFIG_MODULES
86798 +static inline int is_module_text(unsigned long addr)
86799 +{
86800 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86801 + return 1;
86802 +
86803 + addr = ktla_ktva(addr);
86804 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86805 +}
86806 +#else
86807 +static inline int is_module_text(unsigned long addr)
86808 +{
86809 + return 0;
86810 +}
86811 +#endif
86812 +#endif
86813 +
86814 static inline int is_kernel_text(unsigned long addr)
86815 {
86816 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86817 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
86818
86819 static inline int is_kernel(unsigned long addr)
86820 {
86821 +
86822 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86823 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
86824 + return 1;
86825 +
86826 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86827 +#else
86828 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86829 +#endif
86830 +
86831 return 1;
86832 return in_gate_area_no_mm(addr);
86833 }
86834
86835 static int is_ksym_addr(unsigned long addr)
86836 {
86837 +
86838 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86839 + if (is_module_text(addr))
86840 + return 0;
86841 +#endif
86842 +
86843 if (all_var)
86844 return is_kernel(addr);
86845
86846 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86847
86848 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86849 {
86850 - iter->name[0] = '\0';
86851 iter->nameoff = get_symbol_offset(new_pos);
86852 iter->pos = new_pos;
86853 }
86854 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
86855 {
86856 struct kallsym_iter *iter = m->private;
86857
86858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86859 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86860 + return 0;
86861 +#endif
86862 +
86863 /* Some debugging symbols have no name. Ignore them. */
86864 if (!iter->name[0])
86865 return 0;
86866 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
86867 */
86868 type = iter->exported ? toupper(iter->type) :
86869 tolower(iter->type);
86870 +
86871 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86872 type, iter->name, iter->module_name);
86873 } else
86874 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86875 struct kallsym_iter *iter;
86876 int ret;
86877
86878 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86879 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86880 if (!iter)
86881 return -ENOMEM;
86882 reset_iter(iter, 0);
86883 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86884 index e30ac0f..3528cac 100644
86885 --- a/kernel/kcmp.c
86886 +++ b/kernel/kcmp.c
86887 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86888 struct task_struct *task1, *task2;
86889 int ret;
86890
86891 +#ifdef CONFIG_GRKERNSEC
86892 + return -ENOSYS;
86893 +#endif
86894 +
86895 rcu_read_lock();
86896
86897 /*
86898 diff --git a/kernel/kexec.c b/kernel/kexec.c
86899 index 28c5706..bfc8388 100644
86900 --- a/kernel/kexec.c
86901 +++ b/kernel/kexec.c
86902 @@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
86903 compat_ulong_t, flags)
86904 {
86905 struct compat_kexec_segment in;
86906 - struct kexec_segment out, __user *ksegments;
86907 + struct kexec_segment out;
86908 + struct kexec_segment __user *ksegments;
86909 unsigned long i, result;
86910
86911 /* Don't allow clients that don't understand the native
86912 diff --git a/kernel/kmod.c b/kernel/kmod.c
86913 index 6b375af..eaff670 100644
86914 --- a/kernel/kmod.c
86915 +++ b/kernel/kmod.c
86916 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86917 kfree(info->argv);
86918 }
86919
86920 -static int call_modprobe(char *module_name, int wait)
86921 +static int call_modprobe(char *module_name, char *module_param, int wait)
86922 {
86923 struct subprocess_info *info;
86924 static char *envp[] = {
86925 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86926 NULL
86927 };
86928
86929 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86930 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86931 if (!argv)
86932 goto out;
86933
86934 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86935 argv[1] = "-q";
86936 argv[2] = "--";
86937 argv[3] = module_name; /* check free_modprobe_argv() */
86938 - argv[4] = NULL;
86939 + argv[4] = module_param;
86940 + argv[5] = NULL;
86941
86942 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86943 NULL, free_modprobe_argv, NULL);
86944 @@ -129,9 +130,8 @@ out:
86945 * If module auto-loading support is disabled then this function
86946 * becomes a no-operation.
86947 */
86948 -int __request_module(bool wait, const char *fmt, ...)
86949 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86950 {
86951 - va_list args;
86952 char module_name[MODULE_NAME_LEN];
86953 unsigned int max_modprobes;
86954 int ret;
86955 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86956 if (!modprobe_path[0])
86957 return 0;
86958
86959 - va_start(args, fmt);
86960 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86961 - va_end(args);
86962 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86963 if (ret >= MODULE_NAME_LEN)
86964 return -ENAMETOOLONG;
86965
86966 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86967 if (ret)
86968 return ret;
86969
86970 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86971 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86972 + /* hack to workaround consolekit/udisks stupidity */
86973 + read_lock(&tasklist_lock);
86974 + if (!strcmp(current->comm, "mount") &&
86975 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86976 + read_unlock(&tasklist_lock);
86977 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86978 + return -EPERM;
86979 + }
86980 + read_unlock(&tasklist_lock);
86981 + }
86982 +#endif
86983 +
86984 /* If modprobe needs a service that is in a module, we get a recursive
86985 * loop. Limit the number of running kmod threads to max_threads/2 or
86986 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86987 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86988
86989 trace_module_request(module_name, wait, _RET_IP_);
86990
86991 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86992 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86993
86994 atomic_dec(&kmod_concurrent);
86995 return ret;
86996 }
86997 +
86998 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86999 +{
87000 + va_list args;
87001 + int ret;
87002 +
87003 + va_start(args, fmt);
87004 + ret = ____request_module(wait, module_param, fmt, args);
87005 + va_end(args);
87006 +
87007 + return ret;
87008 +}
87009 +
87010 +int __request_module(bool wait, const char *fmt, ...)
87011 +{
87012 + va_list args;
87013 + int ret;
87014 +
87015 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87016 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87017 + char module_param[MODULE_NAME_LEN];
87018 +
87019 + memset(module_param, 0, sizeof(module_param));
87020 +
87021 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87022 +
87023 + va_start(args, fmt);
87024 + ret = ____request_module(wait, module_param, fmt, args);
87025 + va_end(args);
87026 +
87027 + return ret;
87028 + }
87029 +#endif
87030 +
87031 + va_start(args, fmt);
87032 + ret = ____request_module(wait, NULL, fmt, args);
87033 + va_end(args);
87034 +
87035 + return ret;
87036 +}
87037 +
87038 EXPORT_SYMBOL(__request_module);
87039 #endif /* CONFIG_MODULES */
87040
87041 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87042 */
87043 set_user_nice(current, 0);
87044
87045 +#ifdef CONFIG_GRKERNSEC
87046 + /* this is race-free as far as userland is concerned as we copied
87047 + out the path to be used prior to this point and are now operating
87048 + on that copy
87049 + */
87050 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87051 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87052 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87053 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87054 + retval = -EPERM;
87055 + goto fail;
87056 + }
87057 +#endif
87058 +
87059 retval = -ENOMEM;
87060 new = prepare_kernel_cred(current);
87061 if (!new)
87062 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87063 commit_creds(new);
87064
87065 retval = do_execve(getname_kernel(sub_info->path),
87066 - (const char __user *const __user *)sub_info->argv,
87067 - (const char __user *const __user *)sub_info->envp);
87068 + (const char __user *const __force_user *)sub_info->argv,
87069 + (const char __user *const __force_user *)sub_info->envp);
87070 if (!retval)
87071 return 0;
87072
87073 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87074
87075 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87076 {
87077 +#ifdef CONFIG_GRKERNSEC
87078 + kfree(info->path);
87079 + info->path = info->origpath;
87080 +#endif
87081 if (info->cleanup)
87082 (*info->cleanup)(info);
87083 kfree(info);
87084 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87085 *
87086 * Thus the __user pointer cast is valid here.
87087 */
87088 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87089 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87090
87091 /*
87092 * If ret is 0, either ____call_usermodehelper failed and the
87093 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87094 goto out;
87095
87096 INIT_WORK(&sub_info->work, __call_usermodehelper);
87097 +#ifdef CONFIG_GRKERNSEC
87098 + sub_info->origpath = path;
87099 + sub_info->path = kstrdup(path, gfp_mask);
87100 +#else
87101 sub_info->path = path;
87102 +#endif
87103 sub_info->argv = argv;
87104 sub_info->envp = envp;
87105
87106 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87107 static int proc_cap_handler(struct ctl_table *table, int write,
87108 void __user *buffer, size_t *lenp, loff_t *ppos)
87109 {
87110 - struct ctl_table t;
87111 + ctl_table_no_const t;
87112 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87113 kernel_cap_t new_cap;
87114 int err, i;
87115 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87116 index ceeadfc..11c18b6 100644
87117 --- a/kernel/kprobes.c
87118 +++ b/kernel/kprobes.c
87119 @@ -31,6 +31,9 @@
87120 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87121 * <prasanna@in.ibm.com> added function-return probes.
87122 */
87123 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87124 +#define __INCLUDED_BY_HIDESYM 1
87125 +#endif
87126 #include <linux/kprobes.h>
87127 #include <linux/hash.h>
87128 #include <linux/init.h>
87129 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87130
87131 static void *alloc_insn_page(void)
87132 {
87133 - return module_alloc(PAGE_SIZE);
87134 + return module_alloc_exec(PAGE_SIZE);
87135 }
87136
87137 static void free_insn_page(void *page)
87138 {
87139 - module_free(NULL, page);
87140 + module_free_exec(NULL, page);
87141 }
87142
87143 struct kprobe_insn_cache kprobe_insn_slots = {
87144 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87145 kprobe_type = "k";
87146
87147 if (sym)
87148 - seq_printf(pi, "%p %s %s+0x%x %s ",
87149 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87150 p->addr, kprobe_type, sym, offset,
87151 (modname ? modname : " "));
87152 else
87153 - seq_printf(pi, "%p %s %p ",
87154 + seq_printf(pi, "%pK %s %pK ",
87155 p->addr, kprobe_type, p->addr);
87156
87157 if (!pp)
87158 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87159 index 2495a9b..071b906 100644
87160 --- a/kernel/ksysfs.c
87161 +++ b/kernel/ksysfs.c
87162 @@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87163 {
87164 if (count+1 > UEVENT_HELPER_PATH_LEN)
87165 return -ENOENT;
87166 + if (!capable(CAP_SYS_ADMIN))
87167 + return -EPERM;
87168 memcpy(uevent_helper, buf, count);
87169 uevent_helper[count] = '\0';
87170 if (count && uevent_helper[count-1] == '\n')
87171 @@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87172 return count;
87173 }
87174
87175 -static struct bin_attribute notes_attr = {
87176 +static bin_attribute_no_const notes_attr __read_only = {
87177 .attr = {
87178 .name = "notes",
87179 .mode = S_IRUGO,
87180 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87181 index d24e433..fa04fb8 100644
87182 --- a/kernel/locking/lockdep.c
87183 +++ b/kernel/locking/lockdep.c
87184 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87185 end = (unsigned long) &_end,
87186 addr = (unsigned long) obj;
87187
87188 +#ifdef CONFIG_PAX_KERNEXEC
87189 + start = ktla_ktva(start);
87190 +#endif
87191 +
87192 /*
87193 * static variable?
87194 */
87195 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87196 if (!static_obj(lock->key)) {
87197 debug_locks_off();
87198 printk("INFO: trying to register non-static key.\n");
87199 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87200 printk("the code is fine but needs lockdep annotation.\n");
87201 printk("turning off the locking correctness validator.\n");
87202 dump_stack();
87203 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87204 if (!class)
87205 return 0;
87206 }
87207 - atomic_inc((atomic_t *)&class->ops);
87208 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87209 if (very_verbose(class)) {
87210 printk("\nacquire class [%p] %s", class->key, class->name);
87211 if (class->name_version > 1)
87212 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87213 index ef43ac4..2720dfa 100644
87214 --- a/kernel/locking/lockdep_proc.c
87215 +++ b/kernel/locking/lockdep_proc.c
87216 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87217 return 0;
87218 }
87219
87220 - seq_printf(m, "%p", class->key);
87221 + seq_printf(m, "%pK", class->key);
87222 #ifdef CONFIG_DEBUG_LOCKDEP
87223 seq_printf(m, " OPS:%8ld", class->ops);
87224 #endif
87225 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87226
87227 list_for_each_entry(entry, &class->locks_after, entry) {
87228 if (entry->distance == 1) {
87229 - seq_printf(m, " -> [%p] ", entry->class->key);
87230 + seq_printf(m, " -> [%pK] ", entry->class->key);
87231 print_name(m, entry->class);
87232 seq_puts(m, "\n");
87233 }
87234 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87235 if (!class->key)
87236 continue;
87237
87238 - seq_printf(m, "[%p] ", class->key);
87239 + seq_printf(m, "[%pK] ", class->key);
87240 print_name(m, class);
87241 seq_puts(m, "\n");
87242 }
87243 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87244 if (!i)
87245 seq_line(m, '-', 40-namelen, namelen);
87246
87247 - snprintf(ip, sizeof(ip), "[<%p>]",
87248 + snprintf(ip, sizeof(ip), "[<%pK>]",
87249 (void *)class->contention_point[i]);
87250 seq_printf(m, "%40s %14lu %29s %pS\n",
87251 name, stats->contention_point[i],
87252 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87253 if (!i)
87254 seq_line(m, '-', 40-namelen, namelen);
87255
87256 - snprintf(ip, sizeof(ip), "[<%p>]",
87257 + snprintf(ip, sizeof(ip), "[<%pK>]",
87258 (void *)class->contending_point[i]);
87259 seq_printf(m, "%40s %14lu %29s %pS\n",
87260 name, stats->contending_point[i],
87261 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87262 index 838dc9e..760e158 100644
87263 --- a/kernel/locking/mcs_spinlock.c
87264 +++ b/kernel/locking/mcs_spinlock.c
87265 @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87266 if (likely(prev == NULL))
87267 return true;
87268
87269 - ACCESS_ONCE(prev->next) = node;
87270 + ACCESS_ONCE_RW(prev->next) = node;
87271
87272 /*
87273 * Normally @prev is untouchable after the above store; because at that
87274 @@ -143,8 +143,8 @@ unqueue:
87275 * it will wait in Step-A.
87276 */
87277
87278 - ACCESS_ONCE(next->prev) = prev;
87279 - ACCESS_ONCE(prev->next) = next;
87280 + ACCESS_ONCE_RW(next->prev) = prev;
87281 + ACCESS_ONCE_RW(prev->next) = next;
87282
87283 return false;
87284 }
87285 @@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87286 */
87287 next = xchg(&node->next, NULL);
87288 if (next) {
87289 - ACCESS_ONCE(next->locked) = 1;
87290 + ACCESS_ONCE_RW(next->locked) = 1;
87291 return;
87292 }
87293
87294 next = osq_wait_next(lock, node, NULL);
87295 if (next)
87296 - ACCESS_ONCE(next->locked) = 1;
87297 + ACCESS_ONCE_RW(next->locked) = 1;
87298 }
87299
87300 #endif
87301 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87302 index a2dbac4..e02a34a 100644
87303 --- a/kernel/locking/mcs_spinlock.h
87304 +++ b/kernel/locking/mcs_spinlock.h
87305 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87306 */
87307 return;
87308 }
87309 - ACCESS_ONCE(prev->next) = node;
87310 + ACCESS_ONCE_RW(prev->next) = node;
87311
87312 /* Wait until the lock holder passes the lock down. */
87313 arch_mcs_spin_lock_contended(&node->locked);
87314 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87315 index 5cf6731..ce3bc5a 100644
87316 --- a/kernel/locking/mutex-debug.c
87317 +++ b/kernel/locking/mutex-debug.c
87318 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87319 }
87320
87321 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87322 - struct thread_info *ti)
87323 + struct task_struct *task)
87324 {
87325 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87326
87327 /* Mark the current thread as blocked on the lock: */
87328 - ti->task->blocked_on = waiter;
87329 + task->blocked_on = waiter;
87330 }
87331
87332 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87333 - struct thread_info *ti)
87334 + struct task_struct *task)
87335 {
87336 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87337 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87338 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87339 - ti->task->blocked_on = NULL;
87340 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
87341 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87342 + task->blocked_on = NULL;
87343
87344 list_del_init(&waiter->list);
87345 waiter->task = NULL;
87346 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87347 index 0799fd3..d06ae3b 100644
87348 --- a/kernel/locking/mutex-debug.h
87349 +++ b/kernel/locking/mutex-debug.h
87350 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87351 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87352 extern void debug_mutex_add_waiter(struct mutex *lock,
87353 struct mutex_waiter *waiter,
87354 - struct thread_info *ti);
87355 + struct task_struct *task);
87356 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87357 - struct thread_info *ti);
87358 + struct task_struct *task);
87359 extern void debug_mutex_unlock(struct mutex *lock);
87360 extern void debug_mutex_init(struct mutex *lock, const char *name,
87361 struct lock_class_key *key);
87362 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87363 index bc73d33..6f308aa 100644
87364 --- a/kernel/locking/mutex.c
87365 +++ b/kernel/locking/mutex.c
87366 @@ -490,7 +490,7 @@ slowpath:
87367 goto skip_wait;
87368
87369 debug_mutex_lock_common(lock, &waiter);
87370 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87371 + debug_mutex_add_waiter(lock, &waiter, task);
87372
87373 /* add waiting tasks to the end of the waitqueue (FIFO): */
87374 list_add_tail(&waiter.list, &lock->wait_list);
87375 @@ -534,7 +534,7 @@ slowpath:
87376 schedule_preempt_disabled();
87377 spin_lock_mutex(&lock->wait_lock, flags);
87378 }
87379 - mutex_remove_waiter(lock, &waiter, current_thread_info());
87380 + mutex_remove_waiter(lock, &waiter, task);
87381 /* set it to 0 if there are no waiters left: */
87382 if (likely(list_empty(&lock->wait_list)))
87383 atomic_set(&lock->count, 0);
87384 @@ -571,7 +571,7 @@ skip_wait:
87385 return 0;
87386
87387 err:
87388 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87389 + mutex_remove_waiter(lock, &waiter, task);
87390 spin_unlock_mutex(&lock->wait_lock, flags);
87391 debug_mutex_free_waiter(&waiter);
87392 mutex_release(&lock->dep_map, 1, ip);
87393 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87394 index 1d96dd0..994ff19 100644
87395 --- a/kernel/locking/rtmutex-tester.c
87396 +++ b/kernel/locking/rtmutex-tester.c
87397 @@ -22,7 +22,7 @@
87398 #define MAX_RT_TEST_MUTEXES 8
87399
87400 static spinlock_t rttest_lock;
87401 -static atomic_t rttest_event;
87402 +static atomic_unchecked_t rttest_event;
87403
87404 struct test_thread_data {
87405 int opcode;
87406 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87407
87408 case RTTEST_LOCKCONT:
87409 td->mutexes[td->opdata] = 1;
87410 - td->event = atomic_add_return(1, &rttest_event);
87411 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87412 return 0;
87413
87414 case RTTEST_RESET:
87415 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87416 return 0;
87417
87418 case RTTEST_RESETEVENT:
87419 - atomic_set(&rttest_event, 0);
87420 + atomic_set_unchecked(&rttest_event, 0);
87421 return 0;
87422
87423 default:
87424 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87425 return ret;
87426
87427 td->mutexes[id] = 1;
87428 - td->event = atomic_add_return(1, &rttest_event);
87429 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87430 rt_mutex_lock(&mutexes[id]);
87431 - td->event = atomic_add_return(1, &rttest_event);
87432 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87433 td->mutexes[id] = 4;
87434 return 0;
87435
87436 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87437 return ret;
87438
87439 td->mutexes[id] = 1;
87440 - td->event = atomic_add_return(1, &rttest_event);
87441 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87442 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87443 - td->event = atomic_add_return(1, &rttest_event);
87444 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87445 td->mutexes[id] = ret ? 0 : 4;
87446 return ret ? -EINTR : 0;
87447
87448 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87449 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87450 return ret;
87451
87452 - td->event = atomic_add_return(1, &rttest_event);
87453 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87454 rt_mutex_unlock(&mutexes[id]);
87455 - td->event = atomic_add_return(1, &rttest_event);
87456 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87457 td->mutexes[id] = 0;
87458 return 0;
87459
87460 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87461 break;
87462
87463 td->mutexes[dat] = 2;
87464 - td->event = atomic_add_return(1, &rttest_event);
87465 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87466 break;
87467
87468 default:
87469 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87470 return;
87471
87472 td->mutexes[dat] = 3;
87473 - td->event = atomic_add_return(1, &rttest_event);
87474 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87475 break;
87476
87477 case RTTEST_LOCKNOWAIT:
87478 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87479 return;
87480
87481 td->mutexes[dat] = 1;
87482 - td->event = atomic_add_return(1, &rttest_event);
87483 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87484 return;
87485
87486 default:
87487 diff --git a/kernel/module.c b/kernel/module.c
87488 index 079c461..741f79c 100644
87489 --- a/kernel/module.c
87490 +++ b/kernel/module.c
87491 @@ -61,6 +61,7 @@
87492 #include <linux/pfn.h>
87493 #include <linux/bsearch.h>
87494 #include <linux/fips.h>
87495 +#include <linux/grsecurity.h>
87496 #include <uapi/linux/module.h>
87497 #include "module-internal.h"
87498
87499 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87500
87501 /* Bounds of module allocation, for speeding __module_address.
87502 * Protected by module_mutex. */
87503 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87504 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87505 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87506
87507 int register_module_notifier(struct notifier_block * nb)
87508 {
87509 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87510 return true;
87511
87512 list_for_each_entry_rcu(mod, &modules, list) {
87513 - struct symsearch arr[] = {
87514 + struct symsearch modarr[] = {
87515 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87516 NOT_GPL_ONLY, false },
87517 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87518 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87519 if (mod->state == MODULE_STATE_UNFORMED)
87520 continue;
87521
87522 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87523 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87524 return true;
87525 }
87526 return false;
87527 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87528 if (!pcpusec->sh_size)
87529 return 0;
87530
87531 - if (align > PAGE_SIZE) {
87532 + if (align-1 >= PAGE_SIZE) {
87533 pr_warn("%s: per-cpu alignment %li > %li\n",
87534 mod->name, align, PAGE_SIZE);
87535 align = PAGE_SIZE;
87536 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87537 static ssize_t show_coresize(struct module_attribute *mattr,
87538 struct module_kobject *mk, char *buffer)
87539 {
87540 - return sprintf(buffer, "%u\n", mk->mod->core_size);
87541 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87542 }
87543
87544 static struct module_attribute modinfo_coresize =
87545 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87546 static ssize_t show_initsize(struct module_attribute *mattr,
87547 struct module_kobject *mk, char *buffer)
87548 {
87549 - return sprintf(buffer, "%u\n", mk->mod->init_size);
87550 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87551 }
87552
87553 static struct module_attribute modinfo_initsize =
87554 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87555 goto bad_version;
87556 }
87557
87558 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87559 + /*
87560 + * avoid potentially printing jibberish on attempted load
87561 + * of a module randomized with a different seed
87562 + */
87563 + pr_warn("no symbol version for %s\n", symname);
87564 +#else
87565 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87566 +#endif
87567 return 0;
87568
87569 bad_version:
87570 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87571 + /*
87572 + * avoid potentially printing jibberish on attempted load
87573 + * of a module randomized with a different seed
87574 + */
87575 + printk("attempted module disagrees about version of symbol %s\n",
87576 + symname);
87577 +#else
87578 printk("%s: disagrees about version of symbol %s\n",
87579 mod->name, symname);
87580 +#endif
87581 return 0;
87582 }
87583
87584 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87585 */
87586 #ifdef CONFIG_SYSFS
87587
87588 -#ifdef CONFIG_KALLSYMS
87589 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87590 static inline bool sect_empty(const Elf_Shdr *sect)
87591 {
87592 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87593 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87594 {
87595 unsigned int notes, loaded, i;
87596 struct module_notes_attrs *notes_attrs;
87597 - struct bin_attribute *nattr;
87598 + bin_attribute_no_const *nattr;
87599
87600 /* failed to create section attributes, so can't create notes */
87601 if (!mod->sect_attrs)
87602 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87603 static int module_add_modinfo_attrs(struct module *mod)
87604 {
87605 struct module_attribute *attr;
87606 - struct module_attribute *temp_attr;
87607 + module_attribute_no_const *temp_attr;
87608 int error = 0;
87609 int i;
87610
87611 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87612
87613 static void unset_module_core_ro_nx(struct module *mod)
87614 {
87615 - set_page_attributes(mod->module_core + mod->core_text_size,
87616 - mod->module_core + mod->core_size,
87617 + set_page_attributes(mod->module_core_rw,
87618 + mod->module_core_rw + mod->core_size_rw,
87619 set_memory_x);
87620 - set_page_attributes(mod->module_core,
87621 - mod->module_core + mod->core_ro_size,
87622 + set_page_attributes(mod->module_core_rx,
87623 + mod->module_core_rx + mod->core_size_rx,
87624 set_memory_rw);
87625 }
87626
87627 static void unset_module_init_ro_nx(struct module *mod)
87628 {
87629 - set_page_attributes(mod->module_init + mod->init_text_size,
87630 - mod->module_init + mod->init_size,
87631 + set_page_attributes(mod->module_init_rw,
87632 + mod->module_init_rw + mod->init_size_rw,
87633 set_memory_x);
87634 - set_page_attributes(mod->module_init,
87635 - mod->module_init + mod->init_ro_size,
87636 + set_page_attributes(mod->module_init_rx,
87637 + mod->module_init_rx + mod->init_size_rx,
87638 set_memory_rw);
87639 }
87640
87641 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
87642 list_for_each_entry_rcu(mod, &modules, list) {
87643 if (mod->state == MODULE_STATE_UNFORMED)
87644 continue;
87645 - if ((mod->module_core) && (mod->core_text_size)) {
87646 - set_page_attributes(mod->module_core,
87647 - mod->module_core + mod->core_text_size,
87648 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87649 + set_page_attributes(mod->module_core_rx,
87650 + mod->module_core_rx + mod->core_size_rx,
87651 set_memory_rw);
87652 }
87653 - if ((mod->module_init) && (mod->init_text_size)) {
87654 - set_page_attributes(mod->module_init,
87655 - mod->module_init + mod->init_text_size,
87656 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87657 + set_page_attributes(mod->module_init_rx,
87658 + mod->module_init_rx + mod->init_size_rx,
87659 set_memory_rw);
87660 }
87661 }
87662 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
87663 list_for_each_entry_rcu(mod, &modules, list) {
87664 if (mod->state == MODULE_STATE_UNFORMED)
87665 continue;
87666 - if ((mod->module_core) && (mod->core_text_size)) {
87667 - set_page_attributes(mod->module_core,
87668 - mod->module_core + mod->core_text_size,
87669 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87670 + set_page_attributes(mod->module_core_rx,
87671 + mod->module_core_rx + mod->core_size_rx,
87672 set_memory_ro);
87673 }
87674 - if ((mod->module_init) && (mod->init_text_size)) {
87675 - set_page_attributes(mod->module_init,
87676 - mod->module_init + mod->init_text_size,
87677 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87678 + set_page_attributes(mod->module_init_rx,
87679 + mod->module_init_rx + mod->init_size_rx,
87680 set_memory_ro);
87681 }
87682 }
87683 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
87684
87685 /* This may be NULL, but that's OK */
87686 unset_module_init_ro_nx(mod);
87687 - module_free(mod, mod->module_init);
87688 + module_free(mod, mod->module_init_rw);
87689 + module_free_exec(mod, mod->module_init_rx);
87690 kfree(mod->args);
87691 percpu_modfree(mod);
87692
87693 /* Free lock-classes: */
87694 - lockdep_free_key_range(mod->module_core, mod->core_size);
87695 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87696 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87697
87698 /* Finally, free the core (containing the module structure) */
87699 unset_module_core_ro_nx(mod);
87700 - module_free(mod, mod->module_core);
87701 + module_free_exec(mod, mod->module_core_rx);
87702 + module_free(mod, mod->module_core_rw);
87703
87704 #ifdef CONFIG_MPU
87705 update_protections(current->mm);
87706 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87707 int ret = 0;
87708 const struct kernel_symbol *ksym;
87709
87710 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87711 + int is_fs_load = 0;
87712 + int register_filesystem_found = 0;
87713 + char *p;
87714 +
87715 + p = strstr(mod->args, "grsec_modharden_fs");
87716 + if (p) {
87717 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87718 + /* copy \0 as well */
87719 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87720 + is_fs_load = 1;
87721 + }
87722 +#endif
87723 +
87724 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87725 const char *name = info->strtab + sym[i].st_name;
87726
87727 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87728 + /* it's a real shame this will never get ripped and copied
87729 + upstream! ;(
87730 + */
87731 + if (is_fs_load && !strcmp(name, "register_filesystem"))
87732 + register_filesystem_found = 1;
87733 +#endif
87734 +
87735 switch (sym[i].st_shndx) {
87736 case SHN_COMMON:
87737 /* Ignore common symbols */
87738 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87739 ksym = resolve_symbol_wait(mod, info, name);
87740 /* Ok if resolved. */
87741 if (ksym && !IS_ERR(ksym)) {
87742 + pax_open_kernel();
87743 sym[i].st_value = ksym->value;
87744 + pax_close_kernel();
87745 break;
87746 }
87747
87748 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87749 secbase = (unsigned long)mod_percpu(mod);
87750 else
87751 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87752 + pax_open_kernel();
87753 sym[i].st_value += secbase;
87754 + pax_close_kernel();
87755 break;
87756 }
87757 }
87758
87759 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87760 + if (is_fs_load && !register_filesystem_found) {
87761 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87762 + ret = -EPERM;
87763 + }
87764 +#endif
87765 +
87766 return ret;
87767 }
87768
87769 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87770 || s->sh_entsize != ~0UL
87771 || strstarts(sname, ".init"))
87772 continue;
87773 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87774 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87775 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87776 + else
87777 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87778 pr_debug("\t%s\n", sname);
87779 }
87780 - switch (m) {
87781 - case 0: /* executable */
87782 - mod->core_size = debug_align(mod->core_size);
87783 - mod->core_text_size = mod->core_size;
87784 - break;
87785 - case 1: /* RO: text and ro-data */
87786 - mod->core_size = debug_align(mod->core_size);
87787 - mod->core_ro_size = mod->core_size;
87788 - break;
87789 - case 3: /* whole core */
87790 - mod->core_size = debug_align(mod->core_size);
87791 - break;
87792 - }
87793 }
87794
87795 pr_debug("Init section allocation order:\n");
87796 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87797 || s->sh_entsize != ~0UL
87798 || !strstarts(sname, ".init"))
87799 continue;
87800 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87801 - | INIT_OFFSET_MASK);
87802 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87803 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87804 + else
87805 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87806 + s->sh_entsize |= INIT_OFFSET_MASK;
87807 pr_debug("\t%s\n", sname);
87808 }
87809 - switch (m) {
87810 - case 0: /* executable */
87811 - mod->init_size = debug_align(mod->init_size);
87812 - mod->init_text_size = mod->init_size;
87813 - break;
87814 - case 1: /* RO: text and ro-data */
87815 - mod->init_size = debug_align(mod->init_size);
87816 - mod->init_ro_size = mod->init_size;
87817 - break;
87818 - case 3: /* whole init */
87819 - mod->init_size = debug_align(mod->init_size);
87820 - break;
87821 - }
87822 }
87823 }
87824
87825 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87826
87827 /* Put symbol section at end of init part of module. */
87828 symsect->sh_flags |= SHF_ALLOC;
87829 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87830 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87831 info->index.sym) | INIT_OFFSET_MASK;
87832 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87833
87834 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87835 }
87836
87837 /* Append room for core symbols at end of core part. */
87838 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87839 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87840 - mod->core_size += strtab_size;
87841 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87842 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87843 + mod->core_size_rx += strtab_size;
87844
87845 /* Put string table section at end of init part of module. */
87846 strsect->sh_flags |= SHF_ALLOC;
87847 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87848 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87849 info->index.str) | INIT_OFFSET_MASK;
87850 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87851 }
87852 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87853 /* Make sure we get permanent strtab: don't use info->strtab. */
87854 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87855
87856 + pax_open_kernel();
87857 +
87858 /* Set types up while we still have access to sections. */
87859 for (i = 0; i < mod->num_symtab; i++)
87860 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87861
87862 - mod->core_symtab = dst = mod->module_core + info->symoffs;
87863 - mod->core_strtab = s = mod->module_core + info->stroffs;
87864 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87865 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87866 src = mod->symtab;
87867 for (ndst = i = 0; i < mod->num_symtab; i++) {
87868 if (i == 0 ||
87869 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87870 }
87871 }
87872 mod->core_num_syms = ndst;
87873 +
87874 + pax_close_kernel();
87875 }
87876 #else
87877 static inline void layout_symtab(struct module *mod, struct load_info *info)
87878 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
87879 return vmalloc_exec(size);
87880 }
87881
87882 -static void *module_alloc_update_bounds(unsigned long size)
87883 +static void *module_alloc_update_bounds_rw(unsigned long size)
87884 {
87885 void *ret = module_alloc(size);
87886
87887 if (ret) {
87888 mutex_lock(&module_mutex);
87889 /* Update module bounds. */
87890 - if ((unsigned long)ret < module_addr_min)
87891 - module_addr_min = (unsigned long)ret;
87892 - if ((unsigned long)ret + size > module_addr_max)
87893 - module_addr_max = (unsigned long)ret + size;
87894 + if ((unsigned long)ret < module_addr_min_rw)
87895 + module_addr_min_rw = (unsigned long)ret;
87896 + if ((unsigned long)ret + size > module_addr_max_rw)
87897 + module_addr_max_rw = (unsigned long)ret + size;
87898 + mutex_unlock(&module_mutex);
87899 + }
87900 + return ret;
87901 +}
87902 +
87903 +static void *module_alloc_update_bounds_rx(unsigned long size)
87904 +{
87905 + void *ret = module_alloc_exec(size);
87906 +
87907 + if (ret) {
87908 + mutex_lock(&module_mutex);
87909 + /* Update module bounds. */
87910 + if ((unsigned long)ret < module_addr_min_rx)
87911 + module_addr_min_rx = (unsigned long)ret;
87912 + if ((unsigned long)ret + size > module_addr_max_rx)
87913 + module_addr_max_rx = (unsigned long)ret + size;
87914 mutex_unlock(&module_mutex);
87915 }
87916 return ret;
87917 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87918 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87919
87920 if (info->index.sym == 0) {
87921 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87922 + /*
87923 + * avoid potentially printing jibberish on attempted load
87924 + * of a module randomized with a different seed
87925 + */
87926 + pr_warn("module has no symbols (stripped?)\n");
87927 +#else
87928 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87929 +#endif
87930 return ERR_PTR(-ENOEXEC);
87931 }
87932
87933 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87934 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87935 {
87936 const char *modmagic = get_modinfo(info, "vermagic");
87937 + const char *license = get_modinfo(info, "license");
87938 int err;
87939
87940 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87941 + if (!license || !license_is_gpl_compatible(license))
87942 + return -ENOEXEC;
87943 +#endif
87944 +
87945 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87946 modmagic = NULL;
87947
87948 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87949 }
87950
87951 /* Set up license info based on the info section */
87952 - set_license(mod, get_modinfo(info, "license"));
87953 + set_license(mod, license);
87954
87955 return 0;
87956 }
87957 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
87958 void *ptr;
87959
87960 /* Do the allocs. */
87961 - ptr = module_alloc_update_bounds(mod->core_size);
87962 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87963 /*
87964 * The pointer to this block is stored in the module structure
87965 * which is inside the block. Just mark it as not being a
87966 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
87967 if (!ptr)
87968 return -ENOMEM;
87969
87970 - memset(ptr, 0, mod->core_size);
87971 - mod->module_core = ptr;
87972 + memset(ptr, 0, mod->core_size_rw);
87973 + mod->module_core_rw = ptr;
87974
87975 - if (mod->init_size) {
87976 - ptr = module_alloc_update_bounds(mod->init_size);
87977 + if (mod->init_size_rw) {
87978 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87979 /*
87980 * The pointer to this block is stored in the module structure
87981 * which is inside the block. This block doesn't need to be
87982 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
87983 */
87984 kmemleak_ignore(ptr);
87985 if (!ptr) {
87986 - module_free(mod, mod->module_core);
87987 + module_free(mod, mod->module_core_rw);
87988 return -ENOMEM;
87989 }
87990 - memset(ptr, 0, mod->init_size);
87991 - mod->module_init = ptr;
87992 + memset(ptr, 0, mod->init_size_rw);
87993 + mod->module_init_rw = ptr;
87994 } else
87995 - mod->module_init = NULL;
87996 + mod->module_init_rw = NULL;
87997 +
87998 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87999 + kmemleak_not_leak(ptr);
88000 + if (!ptr) {
88001 + if (mod->module_init_rw)
88002 + module_free(mod, mod->module_init_rw);
88003 + module_free(mod, mod->module_core_rw);
88004 + return -ENOMEM;
88005 + }
88006 +
88007 + pax_open_kernel();
88008 + memset(ptr, 0, mod->core_size_rx);
88009 + pax_close_kernel();
88010 + mod->module_core_rx = ptr;
88011 +
88012 + if (mod->init_size_rx) {
88013 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88014 + kmemleak_ignore(ptr);
88015 + if (!ptr && mod->init_size_rx) {
88016 + module_free_exec(mod, mod->module_core_rx);
88017 + if (mod->module_init_rw)
88018 + module_free(mod, mod->module_init_rw);
88019 + module_free(mod, mod->module_core_rw);
88020 + return -ENOMEM;
88021 + }
88022 +
88023 + pax_open_kernel();
88024 + memset(ptr, 0, mod->init_size_rx);
88025 + pax_close_kernel();
88026 + mod->module_init_rx = ptr;
88027 + } else
88028 + mod->module_init_rx = NULL;
88029
88030 /* Transfer each section which specifies SHF_ALLOC */
88031 pr_debug("final section addresses:\n");
88032 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88033 if (!(shdr->sh_flags & SHF_ALLOC))
88034 continue;
88035
88036 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88037 - dest = mod->module_init
88038 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88039 - else
88040 - dest = mod->module_core + shdr->sh_entsize;
88041 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88042 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88043 + dest = mod->module_init_rw
88044 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88045 + else
88046 + dest = mod->module_init_rx
88047 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88048 + } else {
88049 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88050 + dest = mod->module_core_rw + shdr->sh_entsize;
88051 + else
88052 + dest = mod->module_core_rx + shdr->sh_entsize;
88053 + }
88054 +
88055 + if (shdr->sh_type != SHT_NOBITS) {
88056 +
88057 +#ifdef CONFIG_PAX_KERNEXEC
88058 +#ifdef CONFIG_X86_64
88059 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88060 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88061 +#endif
88062 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88063 + pax_open_kernel();
88064 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88065 + pax_close_kernel();
88066 + } else
88067 +#endif
88068
88069 - if (shdr->sh_type != SHT_NOBITS)
88070 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88071 + }
88072 /* Update sh_addr to point to copy in image. */
88073 - shdr->sh_addr = (unsigned long)dest;
88074 +
88075 +#ifdef CONFIG_PAX_KERNEXEC
88076 + if (shdr->sh_flags & SHF_EXECINSTR)
88077 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88078 + else
88079 +#endif
88080 +
88081 + shdr->sh_addr = (unsigned long)dest;
88082 pr_debug("\t0x%lx %s\n",
88083 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88084 }
88085 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88086 * Do it before processing of module parameters, so the module
88087 * can provide parameter accessor functions of its own.
88088 */
88089 - if (mod->module_init)
88090 - flush_icache_range((unsigned long)mod->module_init,
88091 - (unsigned long)mod->module_init
88092 - + mod->init_size);
88093 - flush_icache_range((unsigned long)mod->module_core,
88094 - (unsigned long)mod->module_core + mod->core_size);
88095 + if (mod->module_init_rx)
88096 + flush_icache_range((unsigned long)mod->module_init_rx,
88097 + (unsigned long)mod->module_init_rx
88098 + + mod->init_size_rx);
88099 + flush_icache_range((unsigned long)mod->module_core_rx,
88100 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88101
88102 set_fs(old_fs);
88103 }
88104 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88105 static void module_deallocate(struct module *mod, struct load_info *info)
88106 {
88107 percpu_modfree(mod);
88108 - module_free(mod, mod->module_init);
88109 - module_free(mod, mod->module_core);
88110 + module_free_exec(mod, mod->module_init_rx);
88111 + module_free_exec(mod, mod->module_core_rx);
88112 + module_free(mod, mod->module_init_rw);
88113 + module_free(mod, mod->module_core_rw);
88114 }
88115
88116 int __weak module_finalize(const Elf_Ehdr *hdr,
88117 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88118 static int post_relocation(struct module *mod, const struct load_info *info)
88119 {
88120 /* Sort exception table now relocations are done. */
88121 + pax_open_kernel();
88122 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88123 + pax_close_kernel();
88124
88125 /* Copy relocated percpu area over. */
88126 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88127 @@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88128 MODULE_STATE_COMING, mod);
88129
88130 /* Set RO and NX regions for core */
88131 - set_section_ro_nx(mod->module_core,
88132 - mod->core_text_size,
88133 - mod->core_ro_size,
88134 - mod->core_size);
88135 + set_section_ro_nx(mod->module_core_rx,
88136 + mod->core_size_rx,
88137 + mod->core_size_rx,
88138 + mod->core_size_rx);
88139
88140 /* Set RO and NX regions for init */
88141 - set_section_ro_nx(mod->module_init,
88142 - mod->init_text_size,
88143 - mod->init_ro_size,
88144 - mod->init_size);
88145 + set_section_ro_nx(mod->module_init_rx,
88146 + mod->init_size_rx,
88147 + mod->init_size_rx,
88148 + mod->init_size_rx);
88149
88150 do_mod_ctors(mod);
88151 /* Start the module */
88152 @@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88153 mod->strtab = mod->core_strtab;
88154 #endif
88155 unset_module_init_ro_nx(mod);
88156 - module_free(mod, mod->module_init);
88157 - mod->module_init = NULL;
88158 - mod->init_size = 0;
88159 - mod->init_ro_size = 0;
88160 - mod->init_text_size = 0;
88161 + module_free(mod, mod->module_init_rw);
88162 + module_free_exec(mod, mod->module_init_rx);
88163 + mod->module_init_rw = NULL;
88164 + mod->module_init_rx = NULL;
88165 + mod->init_size_rw = 0;
88166 + mod->init_size_rx = 0;
88167 mutex_unlock(&module_mutex);
88168 wake_up_all(&module_wq);
88169
88170 @@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88171 if (err)
88172 goto free_unload;
88173
88174 + /* Now copy in args */
88175 + mod->args = strndup_user(uargs, ~0UL >> 1);
88176 + if (IS_ERR(mod->args)) {
88177 + err = PTR_ERR(mod->args);
88178 + goto free_unload;
88179 + }
88180 +
88181 /* Set up MODINFO_ATTR fields */
88182 setup_modinfo(mod, info);
88183
88184 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88185 + {
88186 + char *p, *p2;
88187 +
88188 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88189 + 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);
88190 + err = -EPERM;
88191 + goto free_modinfo;
88192 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88193 + p += sizeof("grsec_modharden_normal") - 1;
88194 + p2 = strstr(p, "_");
88195 + if (p2) {
88196 + *p2 = '\0';
88197 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88198 + *p2 = '_';
88199 + }
88200 + err = -EPERM;
88201 + goto free_modinfo;
88202 + }
88203 + }
88204 +#endif
88205 +
88206 /* Fix up syms, so that st_value is a pointer to location. */
88207 err = simplify_symbols(mod, info);
88208 if (err < 0)
88209 @@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88210
88211 flush_module_icache(mod);
88212
88213 - /* Now copy in args */
88214 - mod->args = strndup_user(uargs, ~0UL >> 1);
88215 - if (IS_ERR(mod->args)) {
88216 - err = PTR_ERR(mod->args);
88217 - goto free_arch_cleanup;
88218 - }
88219 -
88220 dynamic_debug_setup(info->debug, info->num_debug);
88221
88222 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88223 @@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88224 ddebug_cleanup:
88225 dynamic_debug_remove(info->debug);
88226 synchronize_sched();
88227 - kfree(mod->args);
88228 - free_arch_cleanup:
88229 module_arch_cleanup(mod);
88230 free_modinfo:
88231 free_modinfo(mod);
88232 + kfree(mod->args);
88233 free_unload:
88234 module_unload_free(mod);
88235 unlink_mod:
88236 @@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88237 unsigned long nextval;
88238
88239 /* At worse, next value is at end of module */
88240 - if (within_module_init(addr, mod))
88241 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88242 + if (within_module_init_rx(addr, mod))
88243 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88244 + else if (within_module_init_rw(addr, mod))
88245 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88246 + else if (within_module_core_rx(addr, mod))
88247 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88248 + else if (within_module_core_rw(addr, mod))
88249 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88250 else
88251 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88252 + return NULL;
88253
88254 /* Scan for closest preceding symbol, and next symbol. (ELF
88255 starts real symbols at 1). */
88256 @@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88257 return 0;
88258
88259 seq_printf(m, "%s %u",
88260 - mod->name, mod->init_size + mod->core_size);
88261 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88262 print_unload_info(m, mod);
88263
88264 /* Informative for users. */
88265 @@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88266 mod->state == MODULE_STATE_COMING ? "Loading":
88267 "Live");
88268 /* Used by oprofile and other similar tools. */
88269 - seq_printf(m, " 0x%pK", mod->module_core);
88270 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88271
88272 /* Taints info */
88273 if (mod->taints)
88274 @@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88275
88276 static int __init proc_modules_init(void)
88277 {
88278 +#ifndef CONFIG_GRKERNSEC_HIDESYM
88279 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88280 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88281 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88282 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88283 +#else
88284 proc_create("modules", 0, NULL, &proc_modules_operations);
88285 +#endif
88286 +#else
88287 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88288 +#endif
88289 return 0;
88290 }
88291 module_init(proc_modules_init);
88292 @@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88293 {
88294 struct module *mod;
88295
88296 - if (addr < module_addr_min || addr > module_addr_max)
88297 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88298 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
88299 return NULL;
88300
88301 list_for_each_entry_rcu(mod, &modules, list) {
88302 if (mod->state == MODULE_STATE_UNFORMED)
88303 continue;
88304 - if (within_module_core(addr, mod)
88305 - || within_module_init(addr, mod))
88306 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
88307 return mod;
88308 }
88309 return NULL;
88310 @@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88311 */
88312 struct module *__module_text_address(unsigned long addr)
88313 {
88314 - struct module *mod = __module_address(addr);
88315 + struct module *mod;
88316 +
88317 +#ifdef CONFIG_X86_32
88318 + addr = ktla_ktva(addr);
88319 +#endif
88320 +
88321 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88322 + return NULL;
88323 +
88324 + mod = __module_address(addr);
88325 +
88326 if (mod) {
88327 /* Make sure it's within the text section. */
88328 - if (!within(addr, mod->module_init, mod->init_text_size)
88329 - && !within(addr, mod->module_core, mod->core_text_size))
88330 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88331 mod = NULL;
88332 }
88333 return mod;
88334 diff --git a/kernel/notifier.c b/kernel/notifier.c
88335 index db4c8b0..ad011c5 100644
88336 --- a/kernel/notifier.c
88337 +++ b/kernel/notifier.c
88338 @@ -5,6 +5,7 @@
88339 #include <linux/rcupdate.h>
88340 #include <linux/vmalloc.h>
88341 #include <linux/reboot.h>
88342 +#include <linux/mm.h>
88343
88344 /*
88345 * Notifier list for kernel code which wants to be called
88346 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88347 while ((*nl) != NULL) {
88348 if (n->priority > (*nl)->priority)
88349 break;
88350 - nl = &((*nl)->next);
88351 + nl = (struct notifier_block **)&((*nl)->next);
88352 }
88353 - n->next = *nl;
88354 + pax_open_kernel();
88355 + *(const void **)&n->next = *nl;
88356 rcu_assign_pointer(*nl, n);
88357 + pax_close_kernel();
88358 return 0;
88359 }
88360
88361 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88362 return 0;
88363 if (n->priority > (*nl)->priority)
88364 break;
88365 - nl = &((*nl)->next);
88366 + nl = (struct notifier_block **)&((*nl)->next);
88367 }
88368 - n->next = *nl;
88369 + pax_open_kernel();
88370 + *(const void **)&n->next = *nl;
88371 rcu_assign_pointer(*nl, n);
88372 + pax_close_kernel();
88373 return 0;
88374 }
88375
88376 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88377 {
88378 while ((*nl) != NULL) {
88379 if ((*nl) == n) {
88380 + pax_open_kernel();
88381 rcu_assign_pointer(*nl, n->next);
88382 + pax_close_kernel();
88383 return 0;
88384 }
88385 - nl = &((*nl)->next);
88386 + nl = (struct notifier_block **)&((*nl)->next);
88387 }
88388 return -ENOENT;
88389 }
88390 diff --git a/kernel/padata.c b/kernel/padata.c
88391 index 161402f..598814c 100644
88392 --- a/kernel/padata.c
88393 +++ b/kernel/padata.c
88394 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88395 * seq_nr mod. number of cpus in use.
88396 */
88397
88398 - seq_nr = atomic_inc_return(&pd->seq_nr);
88399 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88400 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88401
88402 return padata_index_to_cpu(pd, cpu_index);
88403 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88404 padata_init_pqueues(pd);
88405 padata_init_squeues(pd);
88406 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88407 - atomic_set(&pd->seq_nr, -1);
88408 + atomic_set_unchecked(&pd->seq_nr, -1);
88409 atomic_set(&pd->reorder_objects, 0);
88410 atomic_set(&pd->refcnt, 0);
88411 pd->pinst = pinst;
88412 diff --git a/kernel/panic.c b/kernel/panic.c
88413 index d02fa9f..9faec0a 100644
88414 --- a/kernel/panic.c
88415 +++ b/kernel/panic.c
88416 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88417 /*
88418 * Stop ourself in panic -- architecture code may override this
88419 */
88420 -void __weak panic_smp_self_stop(void)
88421 +void __weak __noreturn panic_smp_self_stop(void)
88422 {
88423 while (1)
88424 cpu_relax();
88425 @@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88426 disable_trace_on_warning();
88427
88428 pr_warn("------------[ cut here ]------------\n");
88429 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88430 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88431 raw_smp_processor_id(), current->pid, file, line, caller);
88432
88433 if (args)
88434 @@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88435 */
88436 __visible void __stack_chk_fail(void)
88437 {
88438 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
88439 + dump_stack();
88440 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88441 __builtin_return_address(0));
88442 }
88443 EXPORT_SYMBOL(__stack_chk_fail);
88444 diff --git a/kernel/pid.c b/kernel/pid.c
88445 index 9b9a266..c20ef80 100644
88446 --- a/kernel/pid.c
88447 +++ b/kernel/pid.c
88448 @@ -33,6 +33,7 @@
88449 #include <linux/rculist.h>
88450 #include <linux/bootmem.h>
88451 #include <linux/hash.h>
88452 +#include <linux/security.h>
88453 #include <linux/pid_namespace.h>
88454 #include <linux/init_task.h>
88455 #include <linux/syscalls.h>
88456 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88457
88458 int pid_max = PID_MAX_DEFAULT;
88459
88460 -#define RESERVED_PIDS 300
88461 +#define RESERVED_PIDS 500
88462
88463 int pid_max_min = RESERVED_PIDS + 1;
88464 int pid_max_max = PID_MAX_LIMIT;
88465 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88466 */
88467 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88468 {
88469 + struct task_struct *task;
88470 +
88471 rcu_lockdep_assert(rcu_read_lock_held(),
88472 "find_task_by_pid_ns() needs rcu_read_lock()"
88473 " protection");
88474 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88475 +
88476 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88477 +
88478 + if (gr_pid_is_chrooted(task))
88479 + return NULL;
88480 +
88481 + return task;
88482 }
88483
88484 struct task_struct *find_task_by_vpid(pid_t vnr)
88485 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88486 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88487 }
88488
88489 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88490 +{
88491 + rcu_lockdep_assert(rcu_read_lock_held(),
88492 + "find_task_by_pid_ns() needs rcu_read_lock()"
88493 + " protection");
88494 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88495 +}
88496 +
88497 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88498 {
88499 struct pid *pid;
88500 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88501 index db95d8e..a0ca23f 100644
88502 --- a/kernel/pid_namespace.c
88503 +++ b/kernel/pid_namespace.c
88504 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88505 void __user *buffer, size_t *lenp, loff_t *ppos)
88506 {
88507 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88508 - struct ctl_table tmp = *table;
88509 + ctl_table_no_const tmp = *table;
88510
88511 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88512 return -EPERM;
88513 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88514 index 3b89464..5e38379 100644
88515 --- a/kernel/posix-cpu-timers.c
88516 +++ b/kernel/posix-cpu-timers.c
88517 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88518
88519 static __init int init_posix_cpu_timers(void)
88520 {
88521 - struct k_clock process = {
88522 + static struct k_clock process = {
88523 .clock_getres = process_cpu_clock_getres,
88524 .clock_get = process_cpu_clock_get,
88525 .timer_create = process_cpu_timer_create,
88526 .nsleep = process_cpu_nsleep,
88527 .nsleep_restart = process_cpu_nsleep_restart,
88528 };
88529 - struct k_clock thread = {
88530 + static struct k_clock thread = {
88531 .clock_getres = thread_cpu_clock_getres,
88532 .clock_get = thread_cpu_clock_get,
88533 .timer_create = thread_cpu_timer_create,
88534 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88535 index 424c2d4..679242f 100644
88536 --- a/kernel/posix-timers.c
88537 +++ b/kernel/posix-timers.c
88538 @@ -43,6 +43,7 @@
88539 #include <linux/hash.h>
88540 #include <linux/posix-clock.h>
88541 #include <linux/posix-timers.h>
88542 +#include <linux/grsecurity.h>
88543 #include <linux/syscalls.h>
88544 #include <linux/wait.h>
88545 #include <linux/workqueue.h>
88546 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88547 * which we beg off on and pass to do_sys_settimeofday().
88548 */
88549
88550 -static struct k_clock posix_clocks[MAX_CLOCKS];
88551 +static struct k_clock *posix_clocks[MAX_CLOCKS];
88552
88553 /*
88554 * These ones are defined below.
88555 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88556 */
88557 static __init int init_posix_timers(void)
88558 {
88559 - struct k_clock clock_realtime = {
88560 + static struct k_clock clock_realtime = {
88561 .clock_getres = hrtimer_get_res,
88562 .clock_get = posix_clock_realtime_get,
88563 .clock_set = posix_clock_realtime_set,
88564 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88565 .timer_get = common_timer_get,
88566 .timer_del = common_timer_del,
88567 };
88568 - struct k_clock clock_monotonic = {
88569 + static struct k_clock clock_monotonic = {
88570 .clock_getres = hrtimer_get_res,
88571 .clock_get = posix_ktime_get_ts,
88572 .nsleep = common_nsleep,
88573 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88574 .timer_get = common_timer_get,
88575 .timer_del = common_timer_del,
88576 };
88577 - struct k_clock clock_monotonic_raw = {
88578 + static struct k_clock clock_monotonic_raw = {
88579 .clock_getres = hrtimer_get_res,
88580 .clock_get = posix_get_monotonic_raw,
88581 };
88582 - struct k_clock clock_realtime_coarse = {
88583 + static struct k_clock clock_realtime_coarse = {
88584 .clock_getres = posix_get_coarse_res,
88585 .clock_get = posix_get_realtime_coarse,
88586 };
88587 - struct k_clock clock_monotonic_coarse = {
88588 + static struct k_clock clock_monotonic_coarse = {
88589 .clock_getres = posix_get_coarse_res,
88590 .clock_get = posix_get_monotonic_coarse,
88591 };
88592 - struct k_clock clock_tai = {
88593 + static struct k_clock clock_tai = {
88594 .clock_getres = hrtimer_get_res,
88595 .clock_get = posix_get_tai,
88596 .nsleep = common_nsleep,
88597 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88598 .timer_get = common_timer_get,
88599 .timer_del = common_timer_del,
88600 };
88601 - struct k_clock clock_boottime = {
88602 + static struct k_clock clock_boottime = {
88603 .clock_getres = hrtimer_get_res,
88604 .clock_get = posix_get_boottime,
88605 .nsleep = common_nsleep,
88606 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88607 return;
88608 }
88609
88610 - posix_clocks[clock_id] = *new_clock;
88611 + posix_clocks[clock_id] = new_clock;
88612 }
88613 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88614
88615 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88616 return (id & CLOCKFD_MASK) == CLOCKFD ?
88617 &clock_posix_dynamic : &clock_posix_cpu;
88618
88619 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88620 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88621 return NULL;
88622 - return &posix_clocks[id];
88623 + return posix_clocks[id];
88624 }
88625
88626 static int common_timer_create(struct k_itimer *new_timer)
88627 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88628 struct k_clock *kc = clockid_to_kclock(which_clock);
88629 struct k_itimer *new_timer;
88630 int error, new_timer_id;
88631 - sigevent_t event;
88632 + sigevent_t event = { };
88633 int it_id_set = IT_ID_NOT_SET;
88634
88635 if (!kc)
88636 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88637 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88638 return -EFAULT;
88639
88640 + /* only the CLOCK_REALTIME clock can be set, all other clocks
88641 + have their clock_set fptr set to a nosettime dummy function
88642 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88643 + call common_clock_set, which calls do_sys_settimeofday, which
88644 + we hook
88645 + */
88646 +
88647 return kc->clock_set(which_clock, &new_tp);
88648 }
88649
88650 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88651 index 2fac9cc..56fef29 100644
88652 --- a/kernel/power/Kconfig
88653 +++ b/kernel/power/Kconfig
88654 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88655 config HIBERNATION
88656 bool "Hibernation (aka 'suspend to disk')"
88657 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88658 + depends on !GRKERNSEC_KMEM
88659 + depends on !PAX_MEMORY_SANITIZE
88660 select HIBERNATE_CALLBACKS
88661 select LZO_COMPRESS
88662 select LZO_DECOMPRESS
88663 diff --git a/kernel/power/process.c b/kernel/power/process.c
88664 index 06ec886..9dba35e 100644
88665 --- a/kernel/power/process.c
88666 +++ b/kernel/power/process.c
88667 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88668 unsigned int elapsed_msecs;
88669 bool wakeup = false;
88670 int sleep_usecs = USEC_PER_MSEC;
88671 + bool timedout = false;
88672
88673 do_gettimeofday(&start);
88674
88675 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88676
88677 while (true) {
88678 todo = 0;
88679 + if (time_after(jiffies, end_time))
88680 + timedout = true;
88681 read_lock(&tasklist_lock);
88682 do_each_thread(g, p) {
88683 if (p == current || !freeze_task(p))
88684 continue;
88685
88686 - if (!freezer_should_skip(p))
88687 + if (!freezer_should_skip(p)) {
88688 todo++;
88689 + if (timedout) {
88690 + printk(KERN_ERR "Task refusing to freeze:\n");
88691 + sched_show_task(p);
88692 + }
88693 + }
88694 } while_each_thread(g, p);
88695 read_unlock(&tasklist_lock);
88696
88697 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88698 todo += wq_busy;
88699 }
88700
88701 - if (!todo || time_after(jiffies, end_time))
88702 + if (!todo || timedout)
88703 break;
88704
88705 if (pm_wakeup_pending()) {
88706 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88707 index 221229c..c76ca0a 100644
88708 --- a/kernel/printk/printk.c
88709 +++ b/kernel/printk/printk.c
88710 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88711 if (from_file && type != SYSLOG_ACTION_OPEN)
88712 return 0;
88713
88714 +#ifdef CONFIG_GRKERNSEC_DMESG
88715 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88716 + return -EPERM;
88717 +#endif
88718 +
88719 if (syslog_action_restricted(type)) {
88720 if (capable(CAP_SYSLOG))
88721 return 0;
88722 diff --git a/kernel/profile.c b/kernel/profile.c
88723 index cb980f0..ccd8782 100644
88724 --- a/kernel/profile.c
88725 +++ b/kernel/profile.c
88726 @@ -37,7 +37,7 @@ struct profile_hit {
88727 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88728 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88729
88730 -static atomic_t *prof_buffer;
88731 +static atomic_unchecked_t *prof_buffer;
88732 static unsigned long prof_len, prof_shift;
88733
88734 int prof_on __read_mostly;
88735 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88736 hits[i].pc = 0;
88737 continue;
88738 }
88739 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88740 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88741 hits[i].hits = hits[i].pc = 0;
88742 }
88743 }
88744 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88745 * Add the current hit(s) and flush the write-queue out
88746 * to the global buffer:
88747 */
88748 - atomic_add(nr_hits, &prof_buffer[pc]);
88749 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88750 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88751 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88752 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88753 hits[i].pc = hits[i].hits = 0;
88754 }
88755 out:
88756 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88757 {
88758 unsigned long pc;
88759 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88760 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88761 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88762 }
88763 #endif /* !CONFIG_SMP */
88764
88765 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88766 return -EFAULT;
88767 buf++; p++; count--; read++;
88768 }
88769 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88770 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88771 if (copy_to_user(buf, (void *)pnt, count))
88772 return -EFAULT;
88773 read += count;
88774 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88775 }
88776 #endif
88777 profile_discard_flip_buffers();
88778 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88779 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88780 return count;
88781 }
88782
88783 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88784 index adf9862..9d86345 100644
88785 --- a/kernel/ptrace.c
88786 +++ b/kernel/ptrace.c
88787 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88788 if (seize)
88789 flags |= PT_SEIZED;
88790 rcu_read_lock();
88791 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88792 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88793 flags |= PT_PTRACE_CAP;
88794 rcu_read_unlock();
88795 task->ptrace = flags;
88796 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88797 break;
88798 return -EIO;
88799 }
88800 - if (copy_to_user(dst, buf, retval))
88801 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88802 return -EFAULT;
88803 copied += retval;
88804 src += retval;
88805 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88806 bool seized = child->ptrace & PT_SEIZED;
88807 int ret = -EIO;
88808 siginfo_t siginfo, *si;
88809 - void __user *datavp = (void __user *) data;
88810 + void __user *datavp = (__force void __user *) data;
88811 unsigned long __user *datalp = datavp;
88812 unsigned long flags;
88813
88814 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88815 goto out;
88816 }
88817
88818 + if (gr_handle_ptrace(child, request)) {
88819 + ret = -EPERM;
88820 + goto out_put_task_struct;
88821 + }
88822 +
88823 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88824 ret = ptrace_attach(child, request, addr, data);
88825 /*
88826 * Some architectures need to do book-keeping after
88827 * a ptrace attach.
88828 */
88829 - if (!ret)
88830 + if (!ret) {
88831 arch_ptrace_attach(child);
88832 + gr_audit_ptrace(child);
88833 + }
88834 goto out_put_task_struct;
88835 }
88836
88837 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88838 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88839 if (copied != sizeof(tmp))
88840 return -EIO;
88841 - return put_user(tmp, (unsigned long __user *)data);
88842 + return put_user(tmp, (__force unsigned long __user *)data);
88843 }
88844
88845 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88846 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88847 }
88848
88849 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88850 - compat_long_t, addr, compat_long_t, data)
88851 + compat_ulong_t, addr, compat_ulong_t, data)
88852 {
88853 struct task_struct *child;
88854 long ret;
88855 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88856 goto out;
88857 }
88858
88859 + if (gr_handle_ptrace(child, request)) {
88860 + ret = -EPERM;
88861 + goto out_put_task_struct;
88862 + }
88863 +
88864 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88865 ret = ptrace_attach(child, request, addr, data);
88866 /*
88867 * Some architectures need to do book-keeping after
88868 * a ptrace attach.
88869 */
88870 - if (!ret)
88871 + if (!ret) {
88872 arch_ptrace_attach(child);
88873 + gr_audit_ptrace(child);
88874 + }
88875 goto out_put_task_struct;
88876 }
88877
88878 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
88879 index bd30bc6..dce23da 100644
88880 --- a/kernel/rcu/rcutorture.c
88881 +++ b/kernel/rcu/rcutorture.c
88882 @@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88883 rcu_torture_count) = { 0 };
88884 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88885 rcu_torture_batch) = { 0 };
88886 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88887 -static atomic_t n_rcu_torture_alloc;
88888 -static atomic_t n_rcu_torture_alloc_fail;
88889 -static atomic_t n_rcu_torture_free;
88890 -static atomic_t n_rcu_torture_mberror;
88891 -static atomic_t n_rcu_torture_error;
88892 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88893 +static atomic_unchecked_t n_rcu_torture_alloc;
88894 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
88895 +static atomic_unchecked_t n_rcu_torture_free;
88896 +static atomic_unchecked_t n_rcu_torture_mberror;
88897 +static atomic_unchecked_t n_rcu_torture_error;
88898 static long n_rcu_torture_barrier_error;
88899 static long n_rcu_torture_boost_ktrerror;
88900 static long n_rcu_torture_boost_rterror;
88901 @@ -186,11 +186,11 @@ rcu_torture_alloc(void)
88902
88903 spin_lock_bh(&rcu_torture_lock);
88904 if (list_empty(&rcu_torture_freelist)) {
88905 - atomic_inc(&n_rcu_torture_alloc_fail);
88906 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88907 spin_unlock_bh(&rcu_torture_lock);
88908 return NULL;
88909 }
88910 - atomic_inc(&n_rcu_torture_alloc);
88911 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88912 p = rcu_torture_freelist.next;
88913 list_del_init(p);
88914 spin_unlock_bh(&rcu_torture_lock);
88915 @@ -203,7 +203,7 @@ rcu_torture_alloc(void)
88916 static void
88917 rcu_torture_free(struct rcu_torture *p)
88918 {
88919 - atomic_inc(&n_rcu_torture_free);
88920 + atomic_inc_unchecked(&n_rcu_torture_free);
88921 spin_lock_bh(&rcu_torture_lock);
88922 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88923 spin_unlock_bh(&rcu_torture_lock);
88924 @@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
88925 i = rp->rtort_pipe_count;
88926 if (i > RCU_TORTURE_PIPE_LEN)
88927 i = RCU_TORTURE_PIPE_LEN;
88928 - atomic_inc(&rcu_torture_wcount[i]);
88929 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88930 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88931 rp->rtort_mbtest = 0;
88932 rcu_torture_free(rp);
88933 @@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
88934 i = old_rp->rtort_pipe_count;
88935 if (i > RCU_TORTURE_PIPE_LEN)
88936 i = RCU_TORTURE_PIPE_LEN;
88937 - atomic_inc(&rcu_torture_wcount[i]);
88938 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88939 old_rp->rtort_pipe_count++;
88940 if (gp_normal == gp_exp)
88941 exp = !!(torture_random(&rand) & 0x80);
88942 @@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
88943 i = rp->rtort_pipe_count;
88944 if (i > RCU_TORTURE_PIPE_LEN)
88945 i = RCU_TORTURE_PIPE_LEN;
88946 - atomic_inc(&rcu_torture_wcount[i]);
88947 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88948 if (++rp->rtort_pipe_count >=
88949 RCU_TORTURE_PIPE_LEN) {
88950 rp->rtort_mbtest = 0;
88951 @@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
88952 return;
88953 }
88954 if (p->rtort_mbtest == 0)
88955 - atomic_inc(&n_rcu_torture_mberror);
88956 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88957 spin_lock(&rand_lock);
88958 cur_ops->read_delay(&rand);
88959 n_rcu_torture_timers++;
88960 @@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
88961 continue;
88962 }
88963 if (p->rtort_mbtest == 0)
88964 - atomic_inc(&n_rcu_torture_mberror);
88965 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88966 cur_ops->read_delay(&rand);
88967 preempt_disable();
88968 pipe_count = p->rtort_pipe_count;
88969 @@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
88970 }
88971 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88972 page += sprintf(page,
88973 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88974 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88975 rcu_torture_current,
88976 rcu_torture_current_version,
88977 list_empty(&rcu_torture_freelist),
88978 - atomic_read(&n_rcu_torture_alloc),
88979 - atomic_read(&n_rcu_torture_alloc_fail),
88980 - atomic_read(&n_rcu_torture_free));
88981 + atomic_read_unchecked(&n_rcu_torture_alloc),
88982 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88983 + atomic_read_unchecked(&n_rcu_torture_free));
88984 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88985 - atomic_read(&n_rcu_torture_mberror),
88986 + atomic_read_unchecked(&n_rcu_torture_mberror),
88987 n_rcu_torture_boost_ktrerror,
88988 n_rcu_torture_boost_rterror);
88989 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88990 @@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
88991 n_barrier_attempts,
88992 n_rcu_torture_barrier_error);
88993 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88994 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88995 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88996 n_rcu_torture_barrier_error != 0 ||
88997 n_rcu_torture_boost_ktrerror != 0 ||
88998 n_rcu_torture_boost_rterror != 0 ||
88999 n_rcu_torture_boost_failure != 0 ||
89000 i > 1) {
89001 page += sprintf(page, "!!! ");
89002 - atomic_inc(&n_rcu_torture_error);
89003 + atomic_inc_unchecked(&n_rcu_torture_error);
89004 WARN_ON_ONCE(1);
89005 }
89006 page += sprintf(page, "Reader Pipe: ");
89007 @@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89008 page += sprintf(page, "Free-Block Circulation: ");
89009 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89010 page += sprintf(page, " %d",
89011 - atomic_read(&rcu_torture_wcount[i]));
89012 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89013 }
89014 page += sprintf(page, "\n");
89015 if (cur_ops->stats)
89016 @@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89017
89018 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89019
89020 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89021 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89022 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89023 else if (torture_onoff_failures())
89024 rcu_torture_print_module_parms(cur_ops,
89025 @@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89026
89027 rcu_torture_current = NULL;
89028 rcu_torture_current_version = 0;
89029 - atomic_set(&n_rcu_torture_alloc, 0);
89030 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89031 - atomic_set(&n_rcu_torture_free, 0);
89032 - atomic_set(&n_rcu_torture_mberror, 0);
89033 - atomic_set(&n_rcu_torture_error, 0);
89034 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89035 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89036 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89037 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89038 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89039 n_rcu_torture_barrier_error = 0;
89040 n_rcu_torture_boost_ktrerror = 0;
89041 n_rcu_torture_boost_rterror = 0;
89042 n_rcu_torture_boost_failure = 0;
89043 n_rcu_torture_boosts = 0;
89044 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89045 - atomic_set(&rcu_torture_wcount[i], 0);
89046 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89047 for_each_possible_cpu(cpu) {
89048 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89049 per_cpu(rcu_torture_count, cpu)[i] = 0;
89050 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89051 index c639556..cf0a0d5 100644
89052 --- a/kernel/rcu/srcu.c
89053 +++ b/kernel/rcu/srcu.c
89054 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89055
89056 idx = ACCESS_ONCE(sp->completed) & 0x1;
89057 preempt_disable();
89058 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89059 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89060 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89061 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89062 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89063 preempt_enable();
89064 return idx;
89065 }
89066 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89067 index d9efcc1..ea543e9 100644
89068 --- a/kernel/rcu/tiny.c
89069 +++ b/kernel/rcu/tiny.c
89070 @@ -42,7 +42,7 @@
89071 /* Forward declarations for tiny_plugin.h. */
89072 struct rcu_ctrlblk;
89073 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89074 -static void rcu_process_callbacks(struct softirq_action *unused);
89075 +static void rcu_process_callbacks(void);
89076 static void __call_rcu(struct rcu_head *head,
89077 void (*func)(struct rcu_head *rcu),
89078 struct rcu_ctrlblk *rcp);
89079 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89080 false));
89081 }
89082
89083 -static void rcu_process_callbacks(struct softirq_action *unused)
89084 +static __latent_entropy void rcu_process_callbacks(void)
89085 {
89086 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89087 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89088 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89089 index 0c47e30..a084591 100644
89090 --- a/kernel/rcu/tree.c
89091 +++ b/kernel/rcu/tree.c
89092 @@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89093 rcu_prepare_for_idle(smp_processor_id());
89094 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89095 smp_mb__before_atomic_inc(); /* See above. */
89096 - atomic_inc(&rdtp->dynticks);
89097 + atomic_inc_unchecked(&rdtp->dynticks);
89098 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89099 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89100 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89101
89102 /*
89103 * It is illegal to enter an extended quiescent state while
89104 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89105 int user)
89106 {
89107 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89108 - atomic_inc(&rdtp->dynticks);
89109 + atomic_inc_unchecked(&rdtp->dynticks);
89110 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89111 smp_mb__after_atomic_inc(); /* See above. */
89112 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89113 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89114 rcu_cleanup_after_idle(smp_processor_id());
89115 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89116 if (!user && !is_idle_task(current)) {
89117 @@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89118 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89119
89120 if (rdtp->dynticks_nmi_nesting == 0 &&
89121 - (atomic_read(&rdtp->dynticks) & 0x1))
89122 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89123 return;
89124 rdtp->dynticks_nmi_nesting++;
89125 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89126 - atomic_inc(&rdtp->dynticks);
89127 + atomic_inc_unchecked(&rdtp->dynticks);
89128 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89129 smp_mb__after_atomic_inc(); /* See above. */
89130 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89131 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89132 }
89133
89134 /**
89135 @@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89136 return;
89137 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89138 smp_mb__before_atomic_inc(); /* See above. */
89139 - atomic_inc(&rdtp->dynticks);
89140 + atomic_inc_unchecked(&rdtp->dynticks);
89141 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89142 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89143 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89144 }
89145
89146 /**
89147 @@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89148 */
89149 bool notrace __rcu_is_watching(void)
89150 {
89151 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89152 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89153 }
89154
89155 /**
89156 @@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89157 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89158 bool *isidle, unsigned long *maxj)
89159 {
89160 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89161 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89162 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89163 return (rdp->dynticks_snap & 0x1) == 0;
89164 }
89165 @@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89166 unsigned int curr;
89167 unsigned int snap;
89168
89169 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89170 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89171 snap = (unsigned int)rdp->dynticks_snap;
89172
89173 /*
89174 @@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89175 rdp = this_cpu_ptr(rsp->rda);
89176 rcu_preempt_check_blocked_tasks(rnp);
89177 rnp->qsmask = rnp->qsmaskinit;
89178 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89179 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89180 WARN_ON_ONCE(rnp->completed != rsp->completed);
89181 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89182 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89183 if (rnp == rdp->mynode)
89184 __note_gp_changes(rsp, rnp, rdp);
89185 rcu_preempt_boost_start_gp(rnp);
89186 @@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89187 rcu_for_each_node_breadth_first(rsp, rnp) {
89188 raw_spin_lock_irq(&rnp->lock);
89189 smp_mb__after_unlock_lock();
89190 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89191 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89192 rdp = this_cpu_ptr(rsp->rda);
89193 if (rnp == rdp->mynode)
89194 __note_gp_changes(rsp, rnp, rdp);
89195 @@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89196 rcu_nocb_gp_set(rnp, nocb);
89197
89198 /* Declare grace period done. */
89199 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89200 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89201 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89202 rsp->fqs_state = RCU_GP_IDLE;
89203 rdp = this_cpu_ptr(rsp->rda);
89204 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89205 rsp->qlen += rdp->qlen;
89206 rdp->n_cbs_orphaned += rdp->qlen;
89207 rdp->qlen_lazy = 0;
89208 - ACCESS_ONCE(rdp->qlen) = 0;
89209 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89210 }
89211
89212 /*
89213 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89214 }
89215 smp_mb(); /* List handling before counting for rcu_barrier(). */
89216 rdp->qlen_lazy -= count_lazy;
89217 - ACCESS_ONCE(rdp->qlen) -= count;
89218 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89219 rdp->n_cbs_invoked += count;
89220
89221 /* Reinstate batch limit if we have worked down the excess. */
89222 @@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89223 if (rnp_old != NULL)
89224 raw_spin_unlock(&rnp_old->fqslock);
89225 if (ret) {
89226 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89227 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89228 return;
89229 }
89230 rnp_old = rnp;
89231 @@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89232 smp_mb__after_unlock_lock();
89233 raw_spin_unlock(&rnp_old->fqslock);
89234 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89235 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89236 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89237 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89238 return; /* Someone beat us to it. */
89239 }
89240 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89241 /*
89242 * Do RCU core processing for the current CPU.
89243 */
89244 -static void rcu_process_callbacks(struct softirq_action *unused)
89245 +static void rcu_process_callbacks(void)
89246 {
89247 struct rcu_state *rsp;
89248
89249 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89250 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89251 if (debug_rcu_head_queue(head)) {
89252 /* Probable double call_rcu(), so leak the callback. */
89253 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89254 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89255 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89256 return;
89257 }
89258 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89259 local_irq_restore(flags);
89260 return;
89261 }
89262 - ACCESS_ONCE(rdp->qlen)++;
89263 + ACCESS_ONCE_RW(rdp->qlen)++;
89264 if (lazy)
89265 rdp->qlen_lazy++;
89266 else
89267 @@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89268 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89269 * course be required on a 64-bit system.
89270 */
89271 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89272 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89273 (ulong)atomic_long_read(&rsp->expedited_done) +
89274 ULONG_MAX / 8)) {
89275 synchronize_sched();
89276 - atomic_long_inc(&rsp->expedited_wrap);
89277 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
89278 return;
89279 }
89280
89281 @@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89282 * Take a ticket. Note that atomic_inc_return() implies a
89283 * full memory barrier.
89284 */
89285 - snap = atomic_long_inc_return(&rsp->expedited_start);
89286 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89287 firstsnap = snap;
89288 get_online_cpus();
89289 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89290 @@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89291 synchronize_sched_expedited_cpu_stop,
89292 NULL) == -EAGAIN) {
89293 put_online_cpus();
89294 - atomic_long_inc(&rsp->expedited_tryfail);
89295 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89296
89297 /* Check to see if someone else did our work for us. */
89298 s = atomic_long_read(&rsp->expedited_done);
89299 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89300 /* ensure test happens before caller kfree */
89301 smp_mb__before_atomic_inc(); /* ^^^ */
89302 - atomic_long_inc(&rsp->expedited_workdone1);
89303 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89304 return;
89305 }
89306
89307 @@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89308 udelay(trycount * num_online_cpus());
89309 } else {
89310 wait_rcu_gp(call_rcu_sched);
89311 - atomic_long_inc(&rsp->expedited_normal);
89312 + atomic_long_inc_unchecked(&rsp->expedited_normal);
89313 return;
89314 }
89315
89316 @@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89317 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89318 /* ensure test happens before caller kfree */
89319 smp_mb__before_atomic_inc(); /* ^^^ */
89320 - atomic_long_inc(&rsp->expedited_workdone2);
89321 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89322 return;
89323 }
89324
89325 @@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89326 * period works for us.
89327 */
89328 get_online_cpus();
89329 - snap = atomic_long_read(&rsp->expedited_start);
89330 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
89331 smp_mb(); /* ensure read is before try_stop_cpus(). */
89332 }
89333 - atomic_long_inc(&rsp->expedited_stoppedcpus);
89334 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89335
89336 /*
89337 * Everyone up to our most recent fetch is covered by our grace
89338 @@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89339 * than we did already did their update.
89340 */
89341 do {
89342 - atomic_long_inc(&rsp->expedited_done_tries);
89343 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89344 s = atomic_long_read(&rsp->expedited_done);
89345 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89346 /* ensure test happens before caller kfree */
89347 smp_mb__before_atomic_inc(); /* ^^^ */
89348 - atomic_long_inc(&rsp->expedited_done_lost);
89349 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89350 break;
89351 }
89352 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89353 - atomic_long_inc(&rsp->expedited_done_exit);
89354 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89355
89356 put_online_cpus();
89357 }
89358 @@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89359 * ACCESS_ONCE() to prevent the compiler from speculating
89360 * the increment to precede the early-exit check.
89361 */
89362 - ACCESS_ONCE(rsp->n_barrier_done)++;
89363 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89364 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89365 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89366 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89367 @@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89368
89369 /* Increment ->n_barrier_done to prevent duplicate work. */
89370 smp_mb(); /* Keep increment after above mechanism. */
89371 - ACCESS_ONCE(rsp->n_barrier_done)++;
89372 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89373 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89374 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89375 smp_mb(); /* Keep increment before caller's subsequent code. */
89376 @@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89377 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89378 init_callback_list(rdp);
89379 rdp->qlen_lazy = 0;
89380 - ACCESS_ONCE(rdp->qlen) = 0;
89381 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89382 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89383 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89384 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89385 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89386 rdp->cpu = cpu;
89387 rdp->rsp = rsp;
89388 rcu_boot_init_nocb_percpu_data(rdp);
89389 @@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89390 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89391 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89392 rcu_sysidle_init_percpu_data(rdp->dynticks);
89393 - atomic_set(&rdp->dynticks->dynticks,
89394 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89395 + atomic_set_unchecked(&rdp->dynticks->dynticks,
89396 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89397 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89398
89399 /* Add CPU to rcu_node bitmasks. */
89400 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89401 index 75dc3c3..b95d624 100644
89402 --- a/kernel/rcu/tree.h
89403 +++ b/kernel/rcu/tree.h
89404 @@ -87,11 +87,11 @@ struct rcu_dynticks {
89405 long long dynticks_nesting; /* Track irq/process nesting level. */
89406 /* Process level is worth LLONG_MAX/2. */
89407 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89408 - atomic_t dynticks; /* Even value for idle, else odd. */
89409 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89410 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89411 long long dynticks_idle_nesting;
89412 /* irq/process nesting level from idle. */
89413 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
89414 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89415 /* "Idle" excludes userspace execution. */
89416 unsigned long dynticks_idle_jiffies;
89417 /* End of last non-NMI non-idle period. */
89418 @@ -431,17 +431,17 @@ struct rcu_state {
89419 /* _rcu_barrier(). */
89420 /* End of fields guarded by barrier_mutex. */
89421
89422 - atomic_long_t expedited_start; /* Starting ticket. */
89423 - atomic_long_t expedited_done; /* Done ticket. */
89424 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89425 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
89426 - atomic_long_t expedited_workdone1; /* # done by others #1. */
89427 - atomic_long_t expedited_workdone2; /* # done by others #2. */
89428 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
89429 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89430 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
89431 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89432 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89433 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89434 + atomic_long_t expedited_done; /* Done ticket. */
89435 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89436 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89437 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89438 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89439 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89440 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89441 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89442 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89443 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89444
89445 unsigned long jiffies_force_qs; /* Time at which to invoke */
89446 /* force_quiescent_state(). */
89447 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89448 index 962d1d5..c6c62d12d 100644
89449 --- a/kernel/rcu/tree_plugin.h
89450 +++ b/kernel/rcu/tree_plugin.h
89451 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89452 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89453 {
89454 return !rcu_preempted_readers_exp(rnp) &&
89455 - ACCESS_ONCE(rnp->expmask) == 0;
89456 + ACCESS_ONCE_RW(rnp->expmask) == 0;
89457 }
89458
89459 /*
89460 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89461
89462 /* Clean up and exit. */
89463 smp_mb(); /* ensure expedited GP seen before counter increment. */
89464 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89465 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89466 unlock_mb_ret:
89467 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89468 mb_ret:
89469 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89470 free_cpumask_var(cm);
89471 }
89472
89473 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89474 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89475 .store = &rcu_cpu_kthread_task,
89476 .thread_should_run = rcu_cpu_kthread_should_run,
89477 .thread_fn = rcu_cpu_kthread,
89478 @@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89479 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89480 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89481 cpu, ticks_value, ticks_title,
89482 - atomic_read(&rdtp->dynticks) & 0xfff,
89483 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89484 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89485 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89486 fast_no_hz);
89487 @@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89488
89489 /* Enqueue the callback on the nocb list and update counts. */
89490 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89491 - ACCESS_ONCE(*old_rhpp) = rhp;
89492 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
89493 atomic_long_add(rhcount, &rdp->nocb_q_count);
89494 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89495
89496 @@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89497 * Extract queued callbacks, update counts, and wait
89498 * for a grace period to elapse.
89499 */
89500 - ACCESS_ONCE(rdp->nocb_head) = NULL;
89501 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89502 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89503 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89504 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89505 - ACCESS_ONCE(rdp->nocb_p_count) += c;
89506 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89507 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89508 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89509 rcu_nocb_wait_gp(rdp);
89510
89511 /* Each pass through the following loop invokes a callback. */
89512 @@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89513 list = next;
89514 }
89515 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89516 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
89517 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89518 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89519 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89520 rdp->n_nocbs_invoked += c;
89521 }
89522 return 0;
89523 @@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89524 {
89525 if (!rcu_nocb_need_deferred_wakeup(rdp))
89526 return;
89527 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89528 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89529 wake_up(&rdp->nocb_wq);
89530 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89531 }
89532 @@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89533 t = kthread_run(rcu_nocb_kthread, rdp,
89534 "rcuo%c/%d", rsp->abbr, cpu);
89535 BUG_ON(IS_ERR(t));
89536 - ACCESS_ONCE(rdp->nocb_kthread) = t;
89537 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89538 }
89539 }
89540
89541 @@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89542
89543 /* Record start of fully idle period. */
89544 j = jiffies;
89545 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89546 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89547 smp_mb__before_atomic_inc();
89548 - atomic_inc(&rdtp->dynticks_idle);
89549 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89550 smp_mb__after_atomic_inc();
89551 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89552 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89553 }
89554
89555 /*
89556 @@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89557
89558 /* Record end of idle period. */
89559 smp_mb__before_atomic_inc();
89560 - atomic_inc(&rdtp->dynticks_idle);
89561 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89562 smp_mb__after_atomic_inc();
89563 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89564 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89565
89566 /*
89567 * If we are the timekeeping CPU, we are permitted to be non-idle
89568 @@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89569 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89570
89571 /* Pick up current idle and NMI-nesting counter and check. */
89572 - cur = atomic_read(&rdtp->dynticks_idle);
89573 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89574 if (cur & 0x1) {
89575 *isidle = false; /* We are not idle! */
89576 return;
89577 @@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89578 case RCU_SYSIDLE_NOT:
89579
89580 /* First time all are idle, so note a short idle period. */
89581 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89582 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89583 break;
89584
89585 case RCU_SYSIDLE_SHORT:
89586 @@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89587 static void rcu_sysidle_cancel(void)
89588 {
89589 smp_mb();
89590 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89591 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89592 }
89593
89594 /*
89595 @@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89596 smp_mb(); /* grace period precedes setting inuse. */
89597
89598 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89599 - ACCESS_ONCE(rshp->inuse) = 0;
89600 + ACCESS_ONCE_RW(rshp->inuse) = 0;
89601 }
89602
89603 /*
89604 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89605 index 5cdc62e..cc52e88 100644
89606 --- a/kernel/rcu/tree_trace.c
89607 +++ b/kernel/rcu/tree_trace.c
89608 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89609 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89610 rdp->passed_quiesce, rdp->qs_pending);
89611 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89612 - atomic_read(&rdp->dynticks->dynticks),
89613 + atomic_read_unchecked(&rdp->dynticks->dynticks),
89614 rdp->dynticks->dynticks_nesting,
89615 rdp->dynticks->dynticks_nmi_nesting,
89616 rdp->dynticks_fqs);
89617 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89618 struct rcu_state *rsp = (struct rcu_state *)m->private;
89619
89620 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",
89621 - atomic_long_read(&rsp->expedited_start),
89622 + atomic_long_read_unchecked(&rsp->expedited_start),
89623 atomic_long_read(&rsp->expedited_done),
89624 - atomic_long_read(&rsp->expedited_wrap),
89625 - atomic_long_read(&rsp->expedited_tryfail),
89626 - atomic_long_read(&rsp->expedited_workdone1),
89627 - atomic_long_read(&rsp->expedited_workdone2),
89628 - atomic_long_read(&rsp->expedited_normal),
89629 - atomic_long_read(&rsp->expedited_stoppedcpus),
89630 - atomic_long_read(&rsp->expedited_done_tries),
89631 - atomic_long_read(&rsp->expedited_done_lost),
89632 - atomic_long_read(&rsp->expedited_done_exit));
89633 + atomic_long_read_unchecked(&rsp->expedited_wrap),
89634 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
89635 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
89636 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
89637 + atomic_long_read_unchecked(&rsp->expedited_normal),
89638 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89639 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
89640 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
89641 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
89642 return 0;
89643 }
89644
89645 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89646 index 4c0a9b0..7e81362 100644
89647 --- a/kernel/rcu/update.c
89648 +++ b/kernel/rcu/update.c
89649 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
89650 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89651 */
89652 if (till_stall_check < 3) {
89653 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89654 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89655 till_stall_check = 3;
89656 } else if (till_stall_check > 300) {
89657 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89658 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89659 till_stall_check = 300;
89660 }
89661 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89662 diff --git a/kernel/resource.c b/kernel/resource.c
89663 index 8957d68..770cbe4 100644
89664 --- a/kernel/resource.c
89665 +++ b/kernel/resource.c
89666 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89667
89668 static int __init ioresources_init(void)
89669 {
89670 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89671 +#ifdef CONFIG_GRKERNSEC_PROC_USER
89672 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89673 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89674 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89675 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89676 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89677 +#endif
89678 +#else
89679 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89680 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89681 +#endif
89682 return 0;
89683 }
89684 __initcall(ioresources_init);
89685 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89686 index e73efba..c9bfbd4 100644
89687 --- a/kernel/sched/auto_group.c
89688 +++ b/kernel/sched/auto_group.c
89689 @@ -11,7 +11,7 @@
89690
89691 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89692 static struct autogroup autogroup_default;
89693 -static atomic_t autogroup_seq_nr;
89694 +static atomic_unchecked_t autogroup_seq_nr;
89695
89696 void __init autogroup_init(struct task_struct *init_task)
89697 {
89698 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89699
89700 kref_init(&ag->kref);
89701 init_rwsem(&ag->lock);
89702 - ag->id = atomic_inc_return(&autogroup_seq_nr);
89703 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89704 ag->tg = tg;
89705 #ifdef CONFIG_RT_GROUP_SCHED
89706 /*
89707 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89708 index a63f4dc..349bbb0 100644
89709 --- a/kernel/sched/completion.c
89710 +++ b/kernel/sched/completion.c
89711 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89712 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89713 * or number of jiffies left till timeout) if completed.
89714 */
89715 -long __sched
89716 +long __sched __intentional_overflow(-1)
89717 wait_for_completion_interruptible_timeout(struct completion *x,
89718 unsigned long timeout)
89719 {
89720 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89721 *
89722 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89723 */
89724 -int __sched wait_for_completion_killable(struct completion *x)
89725 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89726 {
89727 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89728 if (t == -ERESTARTSYS)
89729 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89730 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89731 * or number of jiffies left till timeout) if completed.
89732 */
89733 -long __sched
89734 +long __sched __intentional_overflow(-1)
89735 wait_for_completion_killable_timeout(struct completion *x,
89736 unsigned long timeout)
89737 {
89738 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89739 index 084d17f..e416b9f 100644
89740 --- a/kernel/sched/core.c
89741 +++ b/kernel/sched/core.c
89742 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89743 int sysctl_numa_balancing(struct ctl_table *table, int write,
89744 void __user *buffer, size_t *lenp, loff_t *ppos)
89745 {
89746 - struct ctl_table t;
89747 + ctl_table_no_const t;
89748 int err;
89749 int state = numabalancing_enabled;
89750
89751 @@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89752 next->active_mm = oldmm;
89753 atomic_inc(&oldmm->mm_count);
89754 enter_lazy_tlb(oldmm, next);
89755 - } else
89756 + } else {
89757 switch_mm(oldmm, mm, next);
89758 + populate_stack();
89759 + }
89760
89761 if (!prev->mm) {
89762 prev->active_mm = NULL;
89763 @@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
89764 /* convert nice value [19,-20] to rlimit style value [1,40] */
89765 int nice_rlim = 20 - nice;
89766
89767 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89768 +
89769 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89770 capable(CAP_SYS_NICE));
89771 }
89772 @@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89773 if (nice > MAX_NICE)
89774 nice = MAX_NICE;
89775
89776 - if (increment < 0 && !can_nice(current, nice))
89777 + if (increment < 0 && (!can_nice(current, nice) ||
89778 + gr_handle_chroot_nice()))
89779 return -EPERM;
89780
89781 retval = security_task_setnice(current, nice);
89782 @@ -3310,6 +3315,7 @@ recheck:
89783 if (policy != p->policy && !rlim_rtprio)
89784 return -EPERM;
89785
89786 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89787 /* can't increase priority */
89788 if (attr->sched_priority > p->rt_priority &&
89789 attr->sched_priority > rlim_rtprio)
89790 @@ -4708,6 +4714,7 @@ void idle_task_exit(void)
89791
89792 if (mm != &init_mm) {
89793 switch_mm(mm, &init_mm, current);
89794 + populate_stack();
89795 finish_arch_post_lock_switch();
89796 }
89797 mmdrop(mm);
89798 @@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89799
89800 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89801
89802 -static struct ctl_table sd_ctl_dir[] = {
89803 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
89804 {
89805 .procname = "sched_domain",
89806 .mode = 0555,
89807 @@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
89808 {}
89809 };
89810
89811 -static struct ctl_table *sd_alloc_ctl_entry(int n)
89812 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89813 {
89814 - struct ctl_table *entry =
89815 + ctl_table_no_const *entry =
89816 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89817
89818 return entry;
89819 }
89820
89821 -static void sd_free_ctl_entry(struct ctl_table **tablep)
89822 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89823 {
89824 - struct ctl_table *entry;
89825 + ctl_table_no_const *entry;
89826
89827 /*
89828 * In the intermediate directories, both the child directory and
89829 @@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89830 * will always be set. In the lowest directory the names are
89831 * static strings and all have proc handlers.
89832 */
89833 - for (entry = *tablep; entry->mode; entry++) {
89834 - if (entry->child)
89835 - sd_free_ctl_entry(&entry->child);
89836 + for (entry = tablep; entry->mode; entry++) {
89837 + if (entry->child) {
89838 + sd_free_ctl_entry(entry->child);
89839 + pax_open_kernel();
89840 + entry->child = NULL;
89841 + pax_close_kernel();
89842 + }
89843 if (entry->proc_handler == NULL)
89844 kfree(entry->procname);
89845 }
89846
89847 - kfree(*tablep);
89848 - *tablep = NULL;
89849 + kfree(tablep);
89850 }
89851
89852 static int min_load_idx = 0;
89853 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89854
89855 static void
89856 -set_table_entry(struct ctl_table *entry,
89857 +set_table_entry(ctl_table_no_const *entry,
89858 const char *procname, void *data, int maxlen,
89859 umode_t mode, proc_handler *proc_handler,
89860 bool load_idx)
89861 @@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
89862 static struct ctl_table *
89863 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89864 {
89865 - struct ctl_table *table = sd_alloc_ctl_entry(14);
89866 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
89867
89868 if (table == NULL)
89869 return NULL;
89870 @@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89871 return table;
89872 }
89873
89874 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89875 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89876 {
89877 - struct ctl_table *entry, *table;
89878 + ctl_table_no_const *entry, *table;
89879 struct sched_domain *sd;
89880 int domain_num = 0, i;
89881 char buf[32];
89882 @@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
89883 static void register_sched_domain_sysctl(void)
89884 {
89885 int i, cpu_num = num_possible_cpus();
89886 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89887 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89888 char buf[32];
89889
89890 WARN_ON(sd_ctl_dir[0].child);
89891 + pax_open_kernel();
89892 sd_ctl_dir[0].child = entry;
89893 + pax_close_kernel();
89894
89895 if (entry == NULL)
89896 return;
89897 @@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
89898 if (sd_sysctl_header)
89899 unregister_sysctl_table(sd_sysctl_header);
89900 sd_sysctl_header = NULL;
89901 - if (sd_ctl_dir[0].child)
89902 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
89903 + if (sd_ctl_dir[0].child) {
89904 + sd_free_ctl_entry(sd_ctl_dir[0].child);
89905 + pax_open_kernel();
89906 + sd_ctl_dir[0].child = NULL;
89907 + pax_close_kernel();
89908 + }
89909 }
89910 #else
89911 static void register_sched_domain_sysctl(void)
89912 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89913 index 8cbe2d2..61f20a1 100644
89914 --- a/kernel/sched/fair.c
89915 +++ b/kernel/sched/fair.c
89916 @@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
89917
89918 static void reset_ptenuma_scan(struct task_struct *p)
89919 {
89920 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
89921 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89922 p->mm->numa_scan_offset = 0;
89923 }
89924
89925 @@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89926 * run_rebalance_domains is triggered when needed from the scheduler tick.
89927 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89928 */
89929 -static void run_rebalance_domains(struct softirq_action *h)
89930 +static __latent_entropy void run_rebalance_domains(void)
89931 {
89932 struct rq *this_rq = this_rq();
89933 enum cpu_idle_type idle = this_rq->idle_balance ?
89934 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89935 index 369b4d6..fa4eb3b 100644
89936 --- a/kernel/sched/sched.h
89937 +++ b/kernel/sched/sched.h
89938 @@ -1157,7 +1157,7 @@ struct sched_class {
89939 #ifdef CONFIG_FAIR_GROUP_SCHED
89940 void (*task_move_group) (struct task_struct *p, int on_rq);
89941 #endif
89942 -};
89943 +} __do_const;
89944
89945 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
89946 {
89947 diff --git a/kernel/signal.c b/kernel/signal.c
89948 index 6ea13c0..31e3b25 100644
89949 --- a/kernel/signal.c
89950 +++ b/kernel/signal.c
89951 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
89952
89953 int print_fatal_signals __read_mostly;
89954
89955 -static void __user *sig_handler(struct task_struct *t, int sig)
89956 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
89957 {
89958 return t->sighand->action[sig - 1].sa.sa_handler;
89959 }
89960
89961 -static int sig_handler_ignored(void __user *handler, int sig)
89962 +static int sig_handler_ignored(__sighandler_t handler, int sig)
89963 {
89964 /* Is it explicitly or implicitly ignored? */
89965 return handler == SIG_IGN ||
89966 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89967
89968 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89969 {
89970 - void __user *handler;
89971 + __sighandler_t handler;
89972
89973 handler = sig_handler(t, sig);
89974
89975 @@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89976 atomic_inc(&user->sigpending);
89977 rcu_read_unlock();
89978
89979 + if (!override_rlimit)
89980 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89981 +
89982 if (override_rlimit ||
89983 atomic_read(&user->sigpending) <=
89984 task_rlimit(t, RLIMIT_SIGPENDING)) {
89985 @@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89986
89987 int unhandled_signal(struct task_struct *tsk, int sig)
89988 {
89989 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89990 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89991 if (is_global_init(tsk))
89992 return 1;
89993 if (handler != SIG_IGN && handler != SIG_DFL)
89994 @@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89995 }
89996 }
89997
89998 + /* allow glibc communication via tgkill to other threads in our
89999 + thread group */
90000 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90001 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90002 + && gr_handle_signal(t, sig))
90003 + return -EPERM;
90004 +
90005 return security_task_kill(t, info, sig, 0);
90006 }
90007
90008 @@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90009 return send_signal(sig, info, p, 1);
90010 }
90011
90012 -static int
90013 +int
90014 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90015 {
90016 return send_signal(sig, info, t, 0);
90017 @@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90018 unsigned long int flags;
90019 int ret, blocked, ignored;
90020 struct k_sigaction *action;
90021 + int is_unhandled = 0;
90022
90023 spin_lock_irqsave(&t->sighand->siglock, flags);
90024 action = &t->sighand->action[sig-1];
90025 @@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90026 }
90027 if (action->sa.sa_handler == SIG_DFL)
90028 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90029 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90030 + is_unhandled = 1;
90031 ret = specific_send_sig_info(sig, info, t);
90032 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90033
90034 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90035 + normal operation */
90036 + if (is_unhandled) {
90037 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90038 + gr_handle_crash(t, sig);
90039 + }
90040 +
90041 return ret;
90042 }
90043
90044 @@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90045 ret = check_kill_permission(sig, info, p);
90046 rcu_read_unlock();
90047
90048 - if (!ret && sig)
90049 + if (!ret && sig) {
90050 ret = do_send_sig_info(sig, info, p, true);
90051 + if (!ret)
90052 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90053 + }
90054
90055 return ret;
90056 }
90057 @@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90058 int error = -ESRCH;
90059
90060 rcu_read_lock();
90061 - p = find_task_by_vpid(pid);
90062 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90063 + /* allow glibc communication via tgkill to other threads in our
90064 + thread group */
90065 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90066 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90067 + p = find_task_by_vpid_unrestricted(pid);
90068 + else
90069 +#endif
90070 + p = find_task_by_vpid(pid);
90071 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90072 error = check_kill_permission(sig, info, p);
90073 /*
90074 @@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90075 }
90076 seg = get_fs();
90077 set_fs(KERNEL_DS);
90078 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90079 - (stack_t __force __user *) &uoss,
90080 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90081 + (stack_t __force_user *) &uoss,
90082 compat_user_stack_pointer());
90083 set_fs(seg);
90084 if (ret >= 0 && uoss_ptr) {
90085 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90086 index eb89e18..a4e6792 100644
90087 --- a/kernel/smpboot.c
90088 +++ b/kernel/smpboot.c
90089 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90090 }
90091 smpboot_unpark_thread(plug_thread, cpu);
90092 }
90093 - list_add(&plug_thread->list, &hotplug_threads);
90094 + pax_list_add(&plug_thread->list, &hotplug_threads);
90095 out:
90096 mutex_unlock(&smpboot_threads_lock);
90097 return ret;
90098 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90099 {
90100 get_online_cpus();
90101 mutex_lock(&smpboot_threads_lock);
90102 - list_del(&plug_thread->list);
90103 + pax_list_del(&plug_thread->list);
90104 smpboot_destroy_threads(plug_thread);
90105 mutex_unlock(&smpboot_threads_lock);
90106 put_online_cpus();
90107 diff --git a/kernel/softirq.c b/kernel/softirq.c
90108 index 92f24f5..db41501 100644
90109 --- a/kernel/softirq.c
90110 +++ b/kernel/softirq.c
90111 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90112 EXPORT_SYMBOL(irq_stat);
90113 #endif
90114
90115 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90116 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90117
90118 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90119
90120 @@ -268,7 +268,7 @@ restart:
90121 kstat_incr_softirqs_this_cpu(vec_nr);
90122
90123 trace_softirq_entry(vec_nr);
90124 - h->action(h);
90125 + h->action();
90126 trace_softirq_exit(vec_nr);
90127 if (unlikely(prev_count != preempt_count())) {
90128 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90129 @@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90130 or_softirq_pending(1UL << nr);
90131 }
90132
90133 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90134 +void __init open_softirq(int nr, void (*action)(void))
90135 {
90136 softirq_vec[nr].action = action;
90137 }
90138 @@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90139 }
90140 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90141
90142 -static void tasklet_action(struct softirq_action *a)
90143 +static void tasklet_action(void)
90144 {
90145 struct tasklet_struct *list;
90146
90147 @@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90148 }
90149 }
90150
90151 -static void tasklet_hi_action(struct softirq_action *a)
90152 +static __latent_entropy void tasklet_hi_action(void)
90153 {
90154 struct tasklet_struct *list;
90155
90156 @@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90157 .notifier_call = cpu_callback
90158 };
90159
90160 -static struct smp_hotplug_thread softirq_threads = {
90161 +static struct smp_hotplug_thread softirq_threads __read_only = {
90162 .store = &ksoftirqd,
90163 .thread_should_run = ksoftirqd_should_run,
90164 .thread_fn = run_ksoftirqd,
90165 diff --git a/kernel/sys.c b/kernel/sys.c
90166 index fba0f29..84400e2 100644
90167 --- a/kernel/sys.c
90168 +++ b/kernel/sys.c
90169 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90170 error = -EACCES;
90171 goto out;
90172 }
90173 +
90174 + if (gr_handle_chroot_setpriority(p, niceval)) {
90175 + error = -EACCES;
90176 + goto out;
90177 + }
90178 +
90179 no_nice = security_task_setnice(p, niceval);
90180 if (no_nice) {
90181 error = no_nice;
90182 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90183 goto error;
90184 }
90185
90186 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90187 + goto error;
90188 +
90189 if (rgid != (gid_t) -1 ||
90190 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90191 new->sgid = new->egid;
90192 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90193 old = current_cred();
90194
90195 retval = -EPERM;
90196 +
90197 + if (gr_check_group_change(kgid, kgid, kgid))
90198 + goto error;
90199 +
90200 if (ns_capable(old->user_ns, CAP_SETGID))
90201 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90202 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90203 @@ -403,7 +416,7 @@ error:
90204 /*
90205 * change the user struct in a credentials set to match the new UID
90206 */
90207 -static int set_user(struct cred *new)
90208 +int set_user(struct cred *new)
90209 {
90210 struct user_struct *new_user;
90211
90212 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90213 goto error;
90214 }
90215
90216 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90217 + goto error;
90218 +
90219 if (!uid_eq(new->uid, old->uid)) {
90220 retval = set_user(new);
90221 if (retval < 0)
90222 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90223 old = current_cred();
90224
90225 retval = -EPERM;
90226 +
90227 + if (gr_check_crash_uid(kuid))
90228 + goto error;
90229 + if (gr_check_user_change(kuid, kuid, kuid))
90230 + goto error;
90231 +
90232 if (ns_capable(old->user_ns, CAP_SETUID)) {
90233 new->suid = new->uid = kuid;
90234 if (!uid_eq(kuid, old->uid)) {
90235 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90236 goto error;
90237 }
90238
90239 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90240 + goto error;
90241 +
90242 if (ruid != (uid_t) -1) {
90243 new->uid = kruid;
90244 if (!uid_eq(kruid, old->uid)) {
90245 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90246 goto error;
90247 }
90248
90249 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90250 + goto error;
90251 +
90252 if (rgid != (gid_t) -1)
90253 new->gid = krgid;
90254 if (egid != (gid_t) -1)
90255 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90256 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90257 ns_capable(old->user_ns, CAP_SETUID)) {
90258 if (!uid_eq(kuid, old->fsuid)) {
90259 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90260 + goto error;
90261 +
90262 new->fsuid = kuid;
90263 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90264 goto change_okay;
90265 }
90266 }
90267
90268 +error:
90269 abort_creds(new);
90270 return old_fsuid;
90271
90272 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90273 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90274 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90275 ns_capable(old->user_ns, CAP_SETGID)) {
90276 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90277 + goto error;
90278 +
90279 if (!gid_eq(kgid, old->fsgid)) {
90280 new->fsgid = kgid;
90281 goto change_okay;
90282 }
90283 }
90284
90285 +error:
90286 abort_creds(new);
90287 return old_fsgid;
90288
90289 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90290 return -EFAULT;
90291
90292 down_read(&uts_sem);
90293 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
90294 + error = __copy_to_user(name->sysname, &utsname()->sysname,
90295 __OLD_UTS_LEN);
90296 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90297 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90298 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
90299 __OLD_UTS_LEN);
90300 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90301 - error |= __copy_to_user(&name->release, &utsname()->release,
90302 + error |= __copy_to_user(name->release, &utsname()->release,
90303 __OLD_UTS_LEN);
90304 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90305 - error |= __copy_to_user(&name->version, &utsname()->version,
90306 + error |= __copy_to_user(name->version, &utsname()->version,
90307 __OLD_UTS_LEN);
90308 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90309 - error |= __copy_to_user(&name->machine, &utsname()->machine,
90310 + error |= __copy_to_user(name->machine, &utsname()->machine,
90311 __OLD_UTS_LEN);
90312 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90313 up_read(&uts_sem);
90314 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90315 */
90316 new_rlim->rlim_cur = 1;
90317 }
90318 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90319 + is changed to a lower value. Since tasks can be created by the same
90320 + user in between this limit change and an execve by this task, force
90321 + a recheck only for this task by setting PF_NPROC_EXCEEDED
90322 + */
90323 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90324 + tsk->flags |= PF_NPROC_EXCEEDED;
90325 }
90326 if (!retval) {
90327 if (old_rlim)
90328 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90329 index 74f5b58..65ba165 100644
90330 --- a/kernel/sysctl.c
90331 +++ b/kernel/sysctl.c
90332 @@ -94,7 +94,6 @@
90333
90334
90335 #if defined(CONFIG_SYSCTL)
90336 -
90337 /* External variables not in a header file. */
90338 extern int max_threads;
90339 extern int suid_dumpable;
90340 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90341
90342 /* Constants used for minimum and maximum */
90343 #ifdef CONFIG_LOCKUP_DETECTOR
90344 -static int sixty = 60;
90345 +static int sixty __read_only = 60;
90346 #endif
90347
90348 -static int __maybe_unused neg_one = -1;
90349 +static int __maybe_unused neg_one __read_only = -1;
90350
90351 -static int zero;
90352 -static int __maybe_unused one = 1;
90353 -static int __maybe_unused two = 2;
90354 -static int __maybe_unused four = 4;
90355 -static unsigned long one_ul = 1;
90356 -static int one_hundred = 100;
90357 +static int zero __read_only = 0;
90358 +static int __maybe_unused one __read_only = 1;
90359 +static int __maybe_unused two __read_only = 2;
90360 +static int __maybe_unused three __read_only = 3;
90361 +static int __maybe_unused four __read_only = 4;
90362 +static unsigned long one_ul __read_only = 1;
90363 +static int one_hundred __read_only = 100;
90364 #ifdef CONFIG_PRINTK
90365 -static int ten_thousand = 10000;
90366 +static int ten_thousand __read_only = 10000;
90367 #endif
90368
90369 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90370 @@ -179,10 +179,8 @@ static int proc_taint(struct ctl_table *table, int write,
90371 void __user *buffer, size_t *lenp, loff_t *ppos);
90372 #endif
90373
90374 -#ifdef CONFIG_PRINTK
90375 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90376 void __user *buffer, size_t *lenp, loff_t *ppos);
90377 -#endif
90378
90379 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90380 void __user *buffer, size_t *lenp, loff_t *ppos);
90381 @@ -213,6 +211,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90382
90383 #endif
90384
90385 +extern struct ctl_table grsecurity_table[];
90386 +
90387 static struct ctl_table kern_table[];
90388 static struct ctl_table vm_table[];
90389 static struct ctl_table fs_table[];
90390 @@ -227,6 +227,20 @@ extern struct ctl_table epoll_table[];
90391 int sysctl_legacy_va_layout;
90392 #endif
90393
90394 +#ifdef CONFIG_PAX_SOFTMODE
90395 +static ctl_table pax_table[] = {
90396 + {
90397 + .procname = "softmode",
90398 + .data = &pax_softmode,
90399 + .maxlen = sizeof(unsigned int),
90400 + .mode = 0600,
90401 + .proc_handler = &proc_dointvec,
90402 + },
90403 +
90404 + { }
90405 +};
90406 +#endif
90407 +
90408 /* The default sysctl tables: */
90409
90410 static struct ctl_table sysctl_base_table[] = {
90411 @@ -275,6 +289,22 @@ static int max_extfrag_threshold = 1000;
90412 #endif
90413
90414 static struct ctl_table kern_table[] = {
90415 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90416 + {
90417 + .procname = "grsecurity",
90418 + .mode = 0500,
90419 + .child = grsecurity_table,
90420 + },
90421 +#endif
90422 +
90423 +#ifdef CONFIG_PAX_SOFTMODE
90424 + {
90425 + .procname = "pax",
90426 + .mode = 0500,
90427 + .child = pax_table,
90428 + },
90429 +#endif
90430 +
90431 {
90432 .procname = "sched_child_runs_first",
90433 .data = &sysctl_sched_child_runs_first,
90434 @@ -630,7 +660,7 @@ static struct ctl_table kern_table[] = {
90435 .data = &modprobe_path,
90436 .maxlen = KMOD_PATH_LEN,
90437 .mode = 0644,
90438 - .proc_handler = proc_dostring,
90439 + .proc_handler = proc_dostring_modpriv,
90440 },
90441 {
90442 .procname = "modules_disabled",
90443 @@ -797,16 +827,20 @@ static struct ctl_table kern_table[] = {
90444 .extra1 = &zero,
90445 .extra2 = &one,
90446 },
90447 +#endif
90448 {
90449 .procname = "kptr_restrict",
90450 .data = &kptr_restrict,
90451 .maxlen = sizeof(int),
90452 .mode = 0644,
90453 .proc_handler = proc_dointvec_minmax_sysadmin,
90454 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90455 + .extra1 = &two,
90456 +#else
90457 .extra1 = &zero,
90458 +#endif
90459 .extra2 = &two,
90460 },
90461 -#endif
90462 {
90463 .procname = "ngroups_max",
90464 .data = &ngroups_max,
90465 @@ -1051,10 +1085,17 @@ static struct ctl_table kern_table[] = {
90466 */
90467 {
90468 .procname = "perf_event_paranoid",
90469 - .data = &sysctl_perf_event_paranoid,
90470 - .maxlen = sizeof(sysctl_perf_event_paranoid),
90471 + .data = &sysctl_perf_event_legitimately_concerned,
90472 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90473 .mode = 0644,
90474 - .proc_handler = proc_dointvec,
90475 + /* go ahead, be a hero */
90476 + .proc_handler = proc_dointvec_minmax_sysadmin,
90477 + .extra1 = &neg_one,
90478 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90479 + .extra2 = &three,
90480 +#else
90481 + .extra2 = &two,
90482 +#endif
90483 },
90484 {
90485 .procname = "perf_event_mlock_kb",
90486 @@ -1316,6 +1357,13 @@ static struct ctl_table vm_table[] = {
90487 .proc_handler = proc_dointvec_minmax,
90488 .extra1 = &zero,
90489 },
90490 + {
90491 + .procname = "heap_stack_gap",
90492 + .data = &sysctl_heap_stack_gap,
90493 + .maxlen = sizeof(sysctl_heap_stack_gap),
90494 + .mode = 0644,
90495 + .proc_handler = proc_doulongvec_minmax,
90496 + },
90497 #else
90498 {
90499 .procname = "nr_trim_pages",
90500 @@ -1780,6 +1828,16 @@ int proc_dostring(struct ctl_table *table, int write,
90501 buffer, lenp, ppos);
90502 }
90503
90504 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90505 + void __user *buffer, size_t *lenp, loff_t *ppos)
90506 +{
90507 + if (write && !capable(CAP_SYS_MODULE))
90508 + return -EPERM;
90509 +
90510 + return _proc_do_string(table->data, table->maxlen, write,
90511 + buffer, lenp, ppos);
90512 +}
90513 +
90514 static size_t proc_skip_spaces(char **buf)
90515 {
90516 size_t ret;
90517 @@ -1885,6 +1943,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90518 len = strlen(tmp);
90519 if (len > *size)
90520 len = *size;
90521 + if (len > sizeof(tmp))
90522 + len = sizeof(tmp);
90523 if (copy_to_user(*buf, tmp, len))
90524 return -EFAULT;
90525 *size -= len;
90526 @@ -2049,7 +2109,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90527 static int proc_taint(struct ctl_table *table, int write,
90528 void __user *buffer, size_t *lenp, loff_t *ppos)
90529 {
90530 - struct ctl_table t;
90531 + ctl_table_no_const t;
90532 unsigned long tmptaint = get_taint();
90533 int err;
90534
90535 @@ -2077,7 +2137,6 @@ static int proc_taint(struct ctl_table *table, int write,
90536 return err;
90537 }
90538
90539 -#ifdef CONFIG_PRINTK
90540 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90541 void __user *buffer, size_t *lenp, loff_t *ppos)
90542 {
90543 @@ -2086,7 +2145,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90544
90545 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90546 }
90547 -#endif
90548
90549 struct do_proc_dointvec_minmax_conv_param {
90550 int *min;
90551 @@ -2633,6 +2691,12 @@ int proc_dostring(struct ctl_table *table, int write,
90552 return -ENOSYS;
90553 }
90554
90555 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90556 + void __user *buffer, size_t *lenp, loff_t *ppos)
90557 +{
90558 + return -ENOSYS;
90559 +}
90560 +
90561 int proc_dointvec(struct ctl_table *table, int write,
90562 void __user *buffer, size_t *lenp, loff_t *ppos)
90563 {
90564 @@ -2689,5 +2753,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90565 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90566 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90567 EXPORT_SYMBOL(proc_dostring);
90568 +EXPORT_SYMBOL(proc_dostring_modpriv);
90569 EXPORT_SYMBOL(proc_doulongvec_minmax);
90570 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90571 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90572 index 13d2f7c..c93d0b0 100644
90573 --- a/kernel/taskstats.c
90574 +++ b/kernel/taskstats.c
90575 @@ -28,9 +28,12 @@
90576 #include <linux/fs.h>
90577 #include <linux/file.h>
90578 #include <linux/pid_namespace.h>
90579 +#include <linux/grsecurity.h>
90580 #include <net/genetlink.h>
90581 #include <linux/atomic.h>
90582
90583 +extern int gr_is_taskstats_denied(int pid);
90584 +
90585 /*
90586 * Maximum length of a cpumask that can be specified in
90587 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90588 @@ -576,6 +579,9 @@ err:
90589
90590 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90591 {
90592 + if (gr_is_taskstats_denied(current->pid))
90593 + return -EACCES;
90594 +
90595 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90596 return cmd_attr_register_cpumask(info);
90597 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90598 diff --git a/kernel/time.c b/kernel/time.c
90599 index 7c7964c..2a0d412 100644
90600 --- a/kernel/time.c
90601 +++ b/kernel/time.c
90602 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90603 return error;
90604
90605 if (tz) {
90606 + /* we log in do_settimeofday called below, so don't log twice
90607 + */
90608 + if (!tv)
90609 + gr_log_timechange();
90610 +
90611 sys_tz = *tz;
90612 update_vsyscall_tz();
90613 if (firsttime) {
90614 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90615 index 88c9c65..7497ebc 100644
90616 --- a/kernel/time/alarmtimer.c
90617 +++ b/kernel/time/alarmtimer.c
90618 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90619 struct platform_device *pdev;
90620 int error = 0;
90621 int i;
90622 - struct k_clock alarm_clock = {
90623 + static struct k_clock alarm_clock = {
90624 .clock_getres = alarm_clock_getres,
90625 .clock_get = alarm_clock_get,
90626 .timer_create = alarm_timer_create,
90627 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90628 index f7df8ea..0810193 100644
90629 --- a/kernel/time/timekeeping.c
90630 +++ b/kernel/time/timekeeping.c
90631 @@ -15,6 +15,7 @@
90632 #include <linux/init.h>
90633 #include <linux/mm.h>
90634 #include <linux/sched.h>
90635 +#include <linux/grsecurity.h>
90636 #include <linux/syscore_ops.h>
90637 #include <linux/clocksource.h>
90638 #include <linux/jiffies.h>
90639 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
90640 if (!timespec_valid_strict(tv))
90641 return -EINVAL;
90642
90643 + gr_log_timechange();
90644 +
90645 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90646 write_seqcount_begin(&timekeeper_seq);
90647
90648 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90649 index 61ed862..3b52c65 100644
90650 --- a/kernel/time/timer_list.c
90651 +++ b/kernel/time/timer_list.c
90652 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90653
90654 static void print_name_offset(struct seq_file *m, void *sym)
90655 {
90656 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90657 + SEQ_printf(m, "<%p>", NULL);
90658 +#else
90659 char symname[KSYM_NAME_LEN];
90660
90661 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90662 SEQ_printf(m, "<%pK>", sym);
90663 else
90664 SEQ_printf(m, "%s", symname);
90665 +#endif
90666 }
90667
90668 static void
90669 @@ -119,7 +123,11 @@ next_one:
90670 static void
90671 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90672 {
90673 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90674 + SEQ_printf(m, " .base: %p\n", NULL);
90675 +#else
90676 SEQ_printf(m, " .base: %pK\n", base);
90677 +#endif
90678 SEQ_printf(m, " .index: %d\n",
90679 base->index);
90680 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90681 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90682 {
90683 struct proc_dir_entry *pe;
90684
90685 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90686 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90687 +#else
90688 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90689 +#endif
90690 if (!pe)
90691 return -ENOMEM;
90692 return 0;
90693 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90694 index 1fb08f2..ca4bb1e 100644
90695 --- a/kernel/time/timer_stats.c
90696 +++ b/kernel/time/timer_stats.c
90697 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90698 static unsigned long nr_entries;
90699 static struct entry entries[MAX_ENTRIES];
90700
90701 -static atomic_t overflow_count;
90702 +static atomic_unchecked_t overflow_count;
90703
90704 /*
90705 * The entries are in a hash-table, for fast lookup:
90706 @@ -140,7 +140,7 @@ static void reset_entries(void)
90707 nr_entries = 0;
90708 memset(entries, 0, sizeof(entries));
90709 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90710 - atomic_set(&overflow_count, 0);
90711 + atomic_set_unchecked(&overflow_count, 0);
90712 }
90713
90714 static struct entry *alloc_entry(void)
90715 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90716 if (likely(entry))
90717 entry->count++;
90718 else
90719 - atomic_inc(&overflow_count);
90720 + atomic_inc_unchecked(&overflow_count);
90721
90722 out_unlock:
90723 raw_spin_unlock_irqrestore(lock, flags);
90724 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90725
90726 static void print_name_offset(struct seq_file *m, unsigned long addr)
90727 {
90728 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90729 + seq_printf(m, "<%p>", NULL);
90730 +#else
90731 char symname[KSYM_NAME_LEN];
90732
90733 if (lookup_symbol_name(addr, symname) < 0)
90734 - seq_printf(m, "<%p>", (void *)addr);
90735 + seq_printf(m, "<%pK>", (void *)addr);
90736 else
90737 seq_printf(m, "%s", symname);
90738 +#endif
90739 }
90740
90741 static int tstats_show(struct seq_file *m, void *v)
90742 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90743
90744 seq_puts(m, "Timer Stats Version: v0.3\n");
90745 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90746 - if (atomic_read(&overflow_count))
90747 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90748 + if (atomic_read_unchecked(&overflow_count))
90749 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90750 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90751
90752 for (i = 0; i < nr_entries; i++) {
90753 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90754 {
90755 struct proc_dir_entry *pe;
90756
90757 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90758 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90759 +#else
90760 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90761 +#endif
90762 if (!pe)
90763 return -ENOMEM;
90764 return 0;
90765 diff --git a/kernel/timer.c b/kernel/timer.c
90766 index 3bb01a3..0e7760e 100644
90767 --- a/kernel/timer.c
90768 +++ b/kernel/timer.c
90769 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
90770 /*
90771 * This function runs timers and the timer-tq in bottom half context.
90772 */
90773 -static void run_timer_softirq(struct softirq_action *h)
90774 +static __latent_entropy void run_timer_softirq(void)
90775 {
90776 struct tvec_base *base = __this_cpu_read(tvec_bases);
90777
90778 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
90779 *
90780 * In all cases the return value is guaranteed to be non-negative.
90781 */
90782 -signed long __sched schedule_timeout(signed long timeout)
90783 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90784 {
90785 struct timer_list timer;
90786 unsigned long expire;
90787 diff --git a/kernel/torture.c b/kernel/torture.c
90788 index acc9afc..4f9eb49 100644
90789 --- a/kernel/torture.c
90790 +++ b/kernel/torture.c
90791 @@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
90792 mutex_lock(&fullstop_mutex);
90793 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
90794 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
90795 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
90796 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
90797 } else {
90798 pr_warn("Concurrent rmmod and shutdown illegal!\n");
90799 }
90800 @@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
90801 do {
90802 if (!torture_must_stop()) {
90803 schedule_timeout_interruptible(stutter);
90804 - ACCESS_ONCE(stutter_pause_test) = 1;
90805 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
90806 }
90807 if (!torture_must_stop())
90808 schedule_timeout_interruptible(stutter);
90809 - ACCESS_ONCE(stutter_pause_test) = 0;
90810 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
90811 torture_shutdown_absorb("torture_stutter");
90812 } while (!torture_must_stop());
90813 torture_kthread_stopping("torture_stutter");
90814 @@ -636,7 +636,7 @@ bool torture_cleanup(void)
90815 schedule_timeout_uninterruptible(10);
90816 return true;
90817 }
90818 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
90819 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
90820 mutex_unlock(&fullstop_mutex);
90821 torture_shutdown_cleanup();
90822 torture_shuffle_cleanup();
90823 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90824 index c1bd4ad..4b861dc 100644
90825 --- a/kernel/trace/blktrace.c
90826 +++ b/kernel/trace/blktrace.c
90827 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90828 struct blk_trace *bt = filp->private_data;
90829 char buf[16];
90830
90831 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90832 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90833
90834 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90835 }
90836 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90837 return 1;
90838
90839 bt = buf->chan->private_data;
90840 - atomic_inc(&bt->dropped);
90841 + atomic_inc_unchecked(&bt->dropped);
90842 return 0;
90843 }
90844
90845 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90846
90847 bt->dir = dir;
90848 bt->dev = dev;
90849 - atomic_set(&bt->dropped, 0);
90850 + atomic_set_unchecked(&bt->dropped, 0);
90851 INIT_LIST_HEAD(&bt->running_list);
90852
90853 ret = -EIO;
90854 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90855 index 4a54a25..7ca9c89 100644
90856 --- a/kernel/trace/ftrace.c
90857 +++ b/kernel/trace/ftrace.c
90858 @@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90859 if (unlikely(ftrace_disabled))
90860 return 0;
90861
90862 + ret = ftrace_arch_code_modify_prepare();
90863 + FTRACE_WARN_ON(ret);
90864 + if (ret)
90865 + return 0;
90866 +
90867 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90868 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90869 if (ret) {
90870 ftrace_bug(ret, ip);
90871 - return 0;
90872 }
90873 - return 1;
90874 + return ret ? 0 : 1;
90875 }
90876
90877 /*
90878 @@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
90879 if (!count)
90880 return 0;
90881
90882 + pax_open_kernel();
90883 sort(start, count, sizeof(*start),
90884 ftrace_cmp_ips, ftrace_swap_ips);
90885 + pax_close_kernel();
90886
90887 start_pg = ftrace_allocate_pages(count);
90888 if (!start_pg)
90889 @@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90890 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90891
90892 static int ftrace_graph_active;
90893 -static struct notifier_block ftrace_suspend_notifier;
90894 -
90895 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90896 {
90897 return 0;
90898 @@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
90899 ftrace_graph_entry = ftrace_graph_entry_test;
90900 }
90901
90902 +static struct notifier_block ftrace_suspend_notifier = {
90903 + .notifier_call = ftrace_suspend_notifier_call
90904 +};
90905 +
90906 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90907 trace_func_graph_ent_t entryfunc)
90908 {
90909 @@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90910 goto out;
90911 }
90912
90913 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90914 register_pm_notifier(&ftrace_suspend_notifier);
90915
90916 ftrace_graph_active++;
90917 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90918 index c634868..00d0d19 100644
90919 --- a/kernel/trace/ring_buffer.c
90920 +++ b/kernel/trace/ring_buffer.c
90921 @@ -352,9 +352,9 @@ struct buffer_data_page {
90922 */
90923 struct buffer_page {
90924 struct list_head list; /* list of buffer pages */
90925 - local_t write; /* index for next write */
90926 + local_unchecked_t write; /* index for next write */
90927 unsigned read; /* index for next read */
90928 - local_t entries; /* entries on this page */
90929 + local_unchecked_t entries; /* entries on this page */
90930 unsigned long real_end; /* real end of data */
90931 struct buffer_data_page *page; /* Actual data page */
90932 };
90933 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90934 unsigned long last_overrun;
90935 local_t entries_bytes;
90936 local_t entries;
90937 - local_t overrun;
90938 - local_t commit_overrun;
90939 + local_unchecked_t overrun;
90940 + local_unchecked_t commit_overrun;
90941 local_t dropped_events;
90942 local_t committing;
90943 local_t commits;
90944 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90945 *
90946 * We add a counter to the write field to denote this.
90947 */
90948 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90949 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90950 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90951 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90952
90953 /*
90954 * Just make sure we have seen our old_write and synchronize
90955 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90956 * cmpxchg to only update if an interrupt did not already
90957 * do it for us. If the cmpxchg fails, we don't care.
90958 */
90959 - (void)local_cmpxchg(&next_page->write, old_write, val);
90960 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90961 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90962 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90963
90964 /*
90965 * No need to worry about races with clearing out the commit.
90966 @@ -1389,12 +1389,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90967
90968 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90969 {
90970 - return local_read(&bpage->entries) & RB_WRITE_MASK;
90971 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90972 }
90973
90974 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90975 {
90976 - return local_read(&bpage->write) & RB_WRITE_MASK;
90977 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90978 }
90979
90980 static int
90981 @@ -1489,7 +1489,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90982 * bytes consumed in ring buffer from here.
90983 * Increment overrun to account for the lost events.
90984 */
90985 - local_add(page_entries, &cpu_buffer->overrun);
90986 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
90987 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90988 }
90989
90990 @@ -2067,7 +2067,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90991 * it is our responsibility to update
90992 * the counters.
90993 */
90994 - local_add(entries, &cpu_buffer->overrun);
90995 + local_add_unchecked(entries, &cpu_buffer->overrun);
90996 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90997
90998 /*
90999 @@ -2217,7 +2217,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91000 if (tail == BUF_PAGE_SIZE)
91001 tail_page->real_end = 0;
91002
91003 - local_sub(length, &tail_page->write);
91004 + local_sub_unchecked(length, &tail_page->write);
91005 return;
91006 }
91007
91008 @@ -2252,7 +2252,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91009 rb_event_set_padding(event);
91010
91011 /* Set the write back to the previous setting */
91012 - local_sub(length, &tail_page->write);
91013 + local_sub_unchecked(length, &tail_page->write);
91014 return;
91015 }
91016
91017 @@ -2264,7 +2264,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91018
91019 /* Set write to end of buffer */
91020 length = (tail + length) - BUF_PAGE_SIZE;
91021 - local_sub(length, &tail_page->write);
91022 + local_sub_unchecked(length, &tail_page->write);
91023 }
91024
91025 /*
91026 @@ -2290,7 +2290,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91027 * about it.
91028 */
91029 if (unlikely(next_page == commit_page)) {
91030 - local_inc(&cpu_buffer->commit_overrun);
91031 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91032 goto out_reset;
91033 }
91034
91035 @@ -2346,7 +2346,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91036 cpu_buffer->tail_page) &&
91037 (cpu_buffer->commit_page ==
91038 cpu_buffer->reader_page))) {
91039 - local_inc(&cpu_buffer->commit_overrun);
91040 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91041 goto out_reset;
91042 }
91043 }
91044 @@ -2394,7 +2394,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91045 length += RB_LEN_TIME_EXTEND;
91046
91047 tail_page = cpu_buffer->tail_page;
91048 - write = local_add_return(length, &tail_page->write);
91049 + write = local_add_return_unchecked(length, &tail_page->write);
91050
91051 /* set write to only the index of the write */
91052 write &= RB_WRITE_MASK;
91053 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91054 kmemcheck_annotate_bitfield(event, bitfield);
91055 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91056
91057 - local_inc(&tail_page->entries);
91058 + local_inc_unchecked(&tail_page->entries);
91059
91060 /*
91061 * If this is the first commit on the page, then update
91062 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91063
91064 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91065 unsigned long write_mask =
91066 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91067 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91068 unsigned long event_length = rb_event_length(event);
91069 /*
91070 * This is on the tail page. It is possible that
91071 @@ -2461,7 +2461,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91072 */
91073 old_index += write_mask;
91074 new_index += write_mask;
91075 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91076 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91077 if (index == old_index) {
91078 /* update counters */
91079 local_sub(event_length, &cpu_buffer->entries_bytes);
91080 @@ -2853,7 +2853,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91081
91082 /* Do the likely case first */
91083 if (likely(bpage->page == (void *)addr)) {
91084 - local_dec(&bpage->entries);
91085 + local_dec_unchecked(&bpage->entries);
91086 return;
91087 }
91088
91089 @@ -2865,7 +2865,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91090 start = bpage;
91091 do {
91092 if (bpage->page == (void *)addr) {
91093 - local_dec(&bpage->entries);
91094 + local_dec_unchecked(&bpage->entries);
91095 return;
91096 }
91097 rb_inc_page(cpu_buffer, &bpage);
91098 @@ -3149,7 +3149,7 @@ static inline unsigned long
91099 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91100 {
91101 return local_read(&cpu_buffer->entries) -
91102 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91103 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91104 }
91105
91106 /**
91107 @@ -3238,7 +3238,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91108 return 0;
91109
91110 cpu_buffer = buffer->buffers[cpu];
91111 - ret = local_read(&cpu_buffer->overrun);
91112 + ret = local_read_unchecked(&cpu_buffer->overrun);
91113
91114 return ret;
91115 }
91116 @@ -3261,7 +3261,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91117 return 0;
91118
91119 cpu_buffer = buffer->buffers[cpu];
91120 - ret = local_read(&cpu_buffer->commit_overrun);
91121 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91122
91123 return ret;
91124 }
91125 @@ -3346,7 +3346,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91126 /* if you care about this being correct, lock the buffer */
91127 for_each_buffer_cpu(buffer, cpu) {
91128 cpu_buffer = buffer->buffers[cpu];
91129 - overruns += local_read(&cpu_buffer->overrun);
91130 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91131 }
91132
91133 return overruns;
91134 @@ -3522,8 +3522,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91135 /*
91136 * Reset the reader page to size zero.
91137 */
91138 - local_set(&cpu_buffer->reader_page->write, 0);
91139 - local_set(&cpu_buffer->reader_page->entries, 0);
91140 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91141 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91142 local_set(&cpu_buffer->reader_page->page->commit, 0);
91143 cpu_buffer->reader_page->real_end = 0;
91144
91145 @@ -3557,7 +3557,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91146 * want to compare with the last_overrun.
91147 */
91148 smp_mb();
91149 - overwrite = local_read(&(cpu_buffer->overrun));
91150 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91151
91152 /*
91153 * Here's the tricky part.
91154 @@ -4127,8 +4127,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91155
91156 cpu_buffer->head_page
91157 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91158 - local_set(&cpu_buffer->head_page->write, 0);
91159 - local_set(&cpu_buffer->head_page->entries, 0);
91160 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91161 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91162 local_set(&cpu_buffer->head_page->page->commit, 0);
91163
91164 cpu_buffer->head_page->read = 0;
91165 @@ -4138,14 +4138,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91166
91167 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91168 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91169 - local_set(&cpu_buffer->reader_page->write, 0);
91170 - local_set(&cpu_buffer->reader_page->entries, 0);
91171 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91172 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91173 local_set(&cpu_buffer->reader_page->page->commit, 0);
91174 cpu_buffer->reader_page->read = 0;
91175
91176 local_set(&cpu_buffer->entries_bytes, 0);
91177 - local_set(&cpu_buffer->overrun, 0);
91178 - local_set(&cpu_buffer->commit_overrun, 0);
91179 + local_set_unchecked(&cpu_buffer->overrun, 0);
91180 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91181 local_set(&cpu_buffer->dropped_events, 0);
91182 local_set(&cpu_buffer->entries, 0);
91183 local_set(&cpu_buffer->committing, 0);
91184 @@ -4550,8 +4550,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91185 rb_init_page(bpage);
91186 bpage = reader->page;
91187 reader->page = *data_page;
91188 - local_set(&reader->write, 0);
91189 - local_set(&reader->entries, 0);
91190 + local_set_unchecked(&reader->write, 0);
91191 + local_set_unchecked(&reader->entries, 0);
91192 reader->read = 0;
91193 *data_page = bpage;
91194
91195 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91196 index 737b0ef..bd21ea6 100644
91197 --- a/kernel/trace/trace.c
91198 +++ b/kernel/trace/trace.c
91199 @@ -3448,7 +3448,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91200 return 0;
91201 }
91202
91203 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91204 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91205 {
91206 /* do nothing if flag is already set */
91207 if (!!(trace_flags & mask) == !!enabled)
91208 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91209 index 2e29d7b..61367d7 100644
91210 --- a/kernel/trace/trace.h
91211 +++ b/kernel/trace/trace.h
91212 @@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91213 void trace_printk_init_buffers(void);
91214 void trace_printk_start_comm(void);
91215 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91216 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91217 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91218
91219 /*
91220 * Normal trace_printk() and friends allocates special buffers
91221 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91222 index 26dc348..8708ca7 100644
91223 --- a/kernel/trace/trace_clock.c
91224 +++ b/kernel/trace/trace_clock.c
91225 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91226 return now;
91227 }
91228
91229 -static atomic64_t trace_counter;
91230 +static atomic64_unchecked_t trace_counter;
91231
91232 /*
91233 * trace_clock_counter(): simply an atomic counter.
91234 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91235 */
91236 u64 notrace trace_clock_counter(void)
91237 {
91238 - return atomic64_add_return(1, &trace_counter);
91239 + return atomic64_inc_return_unchecked(&trace_counter);
91240 }
91241 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91242 index 3ddfd8f..41a10fe 100644
91243 --- a/kernel/trace/trace_events.c
91244 +++ b/kernel/trace/trace_events.c
91245 @@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91246 return 0;
91247 }
91248
91249 -struct ftrace_module_file_ops;
91250 static void __add_event_to_tracers(struct ftrace_event_call *call);
91251
91252 /* Add an additional event_call dynamically */
91253 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91254 index 0abd9b8..6a663a2 100644
91255 --- a/kernel/trace/trace_mmiotrace.c
91256 +++ b/kernel/trace/trace_mmiotrace.c
91257 @@ -24,7 +24,7 @@ struct header_iter {
91258 static struct trace_array *mmio_trace_array;
91259 static bool overrun_detected;
91260 static unsigned long prev_overruns;
91261 -static atomic_t dropped_count;
91262 +static atomic_unchecked_t dropped_count;
91263
91264 static void mmio_reset_data(struct trace_array *tr)
91265 {
91266 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91267
91268 static unsigned long count_overruns(struct trace_iterator *iter)
91269 {
91270 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91271 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91272 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91273
91274 if (over > prev_overruns)
91275 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91276 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91277 sizeof(*entry), 0, pc);
91278 if (!event) {
91279 - atomic_inc(&dropped_count);
91280 + atomic_inc_unchecked(&dropped_count);
91281 return;
91282 }
91283 entry = ring_buffer_event_data(event);
91284 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91285 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91286 sizeof(*entry), 0, pc);
91287 if (!event) {
91288 - atomic_inc(&dropped_count);
91289 + atomic_inc_unchecked(&dropped_count);
91290 return;
91291 }
91292 entry = ring_buffer_event_data(event);
91293 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91294 index a436de1..f64dde2 100644
91295 --- a/kernel/trace/trace_output.c
91296 +++ b/kernel/trace/trace_output.c
91297 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91298
91299 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91300 if (!IS_ERR(p)) {
91301 - p = mangle_path(s->buffer + s->len, p, "\n");
91302 + p = mangle_path(s->buffer + s->len, p, "\n\\");
91303 if (p) {
91304 s->len = p - s->buffer;
91305 return 1;
91306 @@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91307 goto out;
91308 }
91309
91310 + pax_open_kernel();
91311 if (event->funcs->trace == NULL)
91312 - event->funcs->trace = trace_nop_print;
91313 + *(void **)&event->funcs->trace = trace_nop_print;
91314 if (event->funcs->raw == NULL)
91315 - event->funcs->raw = trace_nop_print;
91316 + *(void **)&event->funcs->raw = trace_nop_print;
91317 if (event->funcs->hex == NULL)
91318 - event->funcs->hex = trace_nop_print;
91319 + *(void **)&event->funcs->hex = trace_nop_print;
91320 if (event->funcs->binary == NULL)
91321 - event->funcs->binary = trace_nop_print;
91322 + *(void **)&event->funcs->binary = trace_nop_print;
91323 + pax_close_kernel();
91324
91325 key = event->type & (EVENT_HASHSIZE - 1);
91326
91327 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91328 index 21b320e..40607bc 100644
91329 --- a/kernel/trace/trace_stack.c
91330 +++ b/kernel/trace/trace_stack.c
91331 @@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91332 return;
91333
91334 /* we do not handle interrupt stacks yet */
91335 - if (!object_is_on_stack(stack))
91336 + if (!object_starts_on_stack(stack))
91337 return;
91338
91339 local_irq_save(flags);
91340 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91341 index bf71b4b..04dee68 100644
91342 --- a/kernel/user_namespace.c
91343 +++ b/kernel/user_namespace.c
91344 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91345 !kgid_has_mapping(parent_ns, group))
91346 return -EPERM;
91347
91348 +#ifdef CONFIG_GRKERNSEC
91349 + /*
91350 + * This doesn't really inspire confidence:
91351 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91352 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91353 + * Increases kernel attack surface in areas developers
91354 + * previously cared little about ("low importance due
91355 + * to requiring "root" capability")
91356 + * To be removed when this code receives *proper* review
91357 + */
91358 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91359 + !capable(CAP_SETGID))
91360 + return -EPERM;
91361 +#endif
91362 +
91363 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91364 if (!ns)
91365 return -ENOMEM;
91366 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91367 if (atomic_read(&current->mm->mm_users) > 1)
91368 return -EINVAL;
91369
91370 - if (current->fs->users != 1)
91371 + if (atomic_read(&current->fs->users) != 1)
91372 return -EINVAL;
91373
91374 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91375 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91376 index 4f69f9a..7c6f8f8 100644
91377 --- a/kernel/utsname_sysctl.c
91378 +++ b/kernel/utsname_sysctl.c
91379 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91380 static int proc_do_uts_string(ctl_table *table, int write,
91381 void __user *buffer, size_t *lenp, loff_t *ppos)
91382 {
91383 - struct ctl_table uts_table;
91384 + ctl_table_no_const uts_table;
91385 int r;
91386 memcpy(&uts_table, table, sizeof(uts_table));
91387 uts_table.data = get_uts(table, write);
91388 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91389 index 516203e..ecc58d1 100644
91390 --- a/kernel/watchdog.c
91391 +++ b/kernel/watchdog.c
91392 @@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91393 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91394 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91395
91396 -static struct smp_hotplug_thread watchdog_threads = {
91397 +static struct smp_hotplug_thread watchdog_threads __read_only = {
91398 .store = &softlockup_watchdog,
91399 .thread_should_run = watchdog_should_run,
91400 .thread_fn = watchdog,
91401 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91402 index 8edc8718..b6a70b9 100644
91403 --- a/kernel/workqueue.c
91404 +++ b/kernel/workqueue.c
91405 @@ -4709,7 +4709,7 @@ static void rebind_workers(struct worker_pool *pool)
91406 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91407 worker_flags |= WORKER_REBOUND;
91408 worker_flags &= ~WORKER_UNBOUND;
91409 - ACCESS_ONCE(worker->flags) = worker_flags;
91410 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
91411 }
91412
91413 spin_unlock_irq(&pool->lock);
91414 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91415 index 819ac51..1c8a65e 100644
91416 --- a/lib/Kconfig.debug
91417 +++ b/lib/Kconfig.debug
91418 @@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91419
91420 config DEBUG_WW_MUTEX_SLOWPATH
91421 bool "Wait/wound mutex debugging: Slowpath testing"
91422 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91423 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91424 select DEBUG_LOCK_ALLOC
91425 select DEBUG_SPINLOCK
91426 select DEBUG_MUTEXES
91427 @@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91428
91429 config DEBUG_LOCK_ALLOC
91430 bool "Lock debugging: detect incorrect freeing of live locks"
91431 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91432 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91433 select DEBUG_SPINLOCK
91434 select DEBUG_MUTEXES
91435 select LOCKDEP
91436 @@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91437
91438 config PROVE_LOCKING
91439 bool "Lock debugging: prove locking correctness"
91440 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91441 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91442 select LOCKDEP
91443 select DEBUG_SPINLOCK
91444 select DEBUG_MUTEXES
91445 @@ -931,7 +931,7 @@ config LOCKDEP
91446
91447 config LOCK_STAT
91448 bool "Lock usage statistics"
91449 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91450 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91451 select LOCKDEP
91452 select DEBUG_SPINLOCK
91453 select DEBUG_MUTEXES
91454 @@ -1403,6 +1403,7 @@ config LATENCYTOP
91455 depends on DEBUG_KERNEL
91456 depends on STACKTRACE_SUPPORT
91457 depends on PROC_FS
91458 + depends on !GRKERNSEC_HIDESYM
91459 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91460 select KALLSYMS
91461 select KALLSYMS_ALL
91462 @@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91463 config DEBUG_STRICT_USER_COPY_CHECKS
91464 bool "Strict user copy size checks"
91465 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91466 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91467 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91468 help
91469 Enabling this option turns a certain set of sanity checks for user
91470 copy operations into compile time failures.
91471 @@ -1538,7 +1539,7 @@ endmenu # runtime tests
91472
91473 config PROVIDE_OHCI1394_DMA_INIT
91474 bool "Remote debugging over FireWire early on boot"
91475 - depends on PCI && X86
91476 + depends on PCI && X86 && !GRKERNSEC
91477 help
91478 If you want to debug problems which hang or crash the kernel early
91479 on boot and the crashing machine has a FireWire port, you can use
91480 diff --git a/lib/Makefile b/lib/Makefile
91481 index 0cd7b68..e149e37 100644
91482 --- a/lib/Makefile
91483 +++ b/lib/Makefile
91484 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91485 obj-$(CONFIG_BTREE) += btree.o
91486 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91487 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91488 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91489 +obj-y += list_debug.o
91490 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91491
91492 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91493 diff --git a/lib/average.c b/lib/average.c
91494 index 114d1be..ab0350c 100644
91495 --- a/lib/average.c
91496 +++ b/lib/average.c
91497 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91498 {
91499 unsigned long internal = ACCESS_ONCE(avg->internal);
91500
91501 - ACCESS_ONCE(avg->internal) = internal ?
91502 + ACCESS_ONCE_RW(avg->internal) = internal ?
91503 (((internal << avg->weight) - internal) +
91504 (val << avg->factor)) >> avg->weight :
91505 (val << avg->factor);
91506 diff --git a/lib/bitmap.c b/lib/bitmap.c
91507 index 06f7e4f..f3cf2b0 100644
91508 --- a/lib/bitmap.c
91509 +++ b/lib/bitmap.c
91510 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91511 {
91512 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91513 u32 chunk;
91514 - const char __user __force *ubuf = (const char __user __force *)buf;
91515 + const char __user *ubuf = (const char __force_user *)buf;
91516
91517 bitmap_zero(maskp, nmaskbits);
91518
91519 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91520 {
91521 if (!access_ok(VERIFY_READ, ubuf, ulen))
91522 return -EFAULT;
91523 - return __bitmap_parse((const char __force *)ubuf,
91524 + return __bitmap_parse((const char __force_kernel *)ubuf,
91525 ulen, 1, maskp, nmaskbits);
91526
91527 }
91528 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91529 {
91530 unsigned a, b;
91531 int c, old_c, totaldigits;
91532 - const char __user __force *ubuf = (const char __user __force *)buf;
91533 + const char __user *ubuf = (const char __force_user *)buf;
91534 int exp_digit, in_range;
91535
91536 totaldigits = c = 0;
91537 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91538 {
91539 if (!access_ok(VERIFY_READ, ubuf, ulen))
91540 return -EFAULT;
91541 - return __bitmap_parselist((const char __force *)ubuf,
91542 + return __bitmap_parselist((const char __force_kernel *)ubuf,
91543 ulen, 1, maskp, nmaskbits);
91544 }
91545 EXPORT_SYMBOL(bitmap_parselist_user);
91546 diff --git a/lib/bug.c b/lib/bug.c
91547 index 1686034..a9c00c8 100644
91548 --- a/lib/bug.c
91549 +++ b/lib/bug.c
91550 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91551 return BUG_TRAP_TYPE_NONE;
91552
91553 bug = find_bug(bugaddr);
91554 + if (!bug)
91555 + return BUG_TRAP_TYPE_NONE;
91556
91557 file = NULL;
91558 line = 0;
91559 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91560 index e0731c3..ad66444 100644
91561 --- a/lib/debugobjects.c
91562 +++ b/lib/debugobjects.c
91563 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91564 if (limit > 4)
91565 return;
91566
91567 - is_on_stack = object_is_on_stack(addr);
91568 + is_on_stack = object_starts_on_stack(addr);
91569 if (is_on_stack == onstack)
91570 return;
91571
91572 diff --git a/lib/div64.c b/lib/div64.c
91573 index 4382ad7..08aa558 100644
91574 --- a/lib/div64.c
91575 +++ b/lib/div64.c
91576 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91577 EXPORT_SYMBOL(__div64_32);
91578
91579 #ifndef div_s64_rem
91580 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91581 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91582 {
91583 u64 quotient;
91584
91585 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91586 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91587 */
91588 #ifndef div64_u64
91589 -u64 div64_u64(u64 dividend, u64 divisor)
91590 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91591 {
91592 u32 high = divisor >> 32;
91593 u64 quot;
91594 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91595 index 98f2d7e..899da5c 100644
91596 --- a/lib/dma-debug.c
91597 +++ b/lib/dma-debug.c
91598 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91599
91600 void dma_debug_add_bus(struct bus_type *bus)
91601 {
91602 - struct notifier_block *nb;
91603 + notifier_block_no_const *nb;
91604
91605 if (global_disable)
91606 return;
91607 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91608
91609 static void check_for_stack(struct device *dev, void *addr)
91610 {
91611 - if (object_is_on_stack(addr))
91612 + if (object_starts_on_stack(addr))
91613 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91614 "stack [addr=%p]\n", addr);
91615 }
91616 diff --git a/lib/hash.c b/lib/hash.c
91617 index fea973f..386626f 100644
91618 --- a/lib/hash.c
91619 +++ b/lib/hash.c
91620 @@ -14,7 +14,7 @@
91621 #include <linux/hash.h>
91622 #include <linux/cache.h>
91623
91624 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
91625 +static struct fast_hash_ops arch_hash_ops __read_only = {
91626 .hash = jhash,
91627 .hash2 = jhash2,
91628 };
91629 diff --git a/lib/inflate.c b/lib/inflate.c
91630 index 013a761..c28f3fc 100644
91631 --- a/lib/inflate.c
91632 +++ b/lib/inflate.c
91633 @@ -269,7 +269,7 @@ static void free(void *where)
91634 malloc_ptr = free_mem_ptr;
91635 }
91636 #else
91637 -#define malloc(a) kmalloc(a, GFP_KERNEL)
91638 +#define malloc(a) kmalloc((a), GFP_KERNEL)
91639 #define free(a) kfree(a)
91640 #endif
91641
91642 diff --git a/lib/ioremap.c b/lib/ioremap.c
91643 index 0c9216c..863bd89 100644
91644 --- a/lib/ioremap.c
91645 +++ b/lib/ioremap.c
91646 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91647 unsigned long next;
91648
91649 phys_addr -= addr;
91650 - pmd = pmd_alloc(&init_mm, pud, addr);
91651 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91652 if (!pmd)
91653 return -ENOMEM;
91654 do {
91655 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91656 unsigned long next;
91657
91658 phys_addr -= addr;
91659 - pud = pud_alloc(&init_mm, pgd, addr);
91660 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
91661 if (!pud)
91662 return -ENOMEM;
91663 do {
91664 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91665 index bd2bea9..6b3c95e 100644
91666 --- a/lib/is_single_threaded.c
91667 +++ b/lib/is_single_threaded.c
91668 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91669 struct task_struct *p, *t;
91670 bool ret;
91671
91672 + if (!mm)
91673 + return true;
91674 +
91675 if (atomic_read(&task->signal->live) != 1)
91676 return false;
91677
91678 diff --git a/lib/kobject.c b/lib/kobject.c
91679 index 58751bb..93a1853 100644
91680 --- a/lib/kobject.c
91681 +++ b/lib/kobject.c
91682 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91683
91684
91685 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91686 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91687 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91688
91689 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91690 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91691 {
91692 enum kobj_ns_type type = ops->type;
91693 int error;
91694 diff --git a/lib/list_debug.c b/lib/list_debug.c
91695 index c24c2f7..f0296f4 100644
91696 --- a/lib/list_debug.c
91697 +++ b/lib/list_debug.c
91698 @@ -11,7 +11,9 @@
91699 #include <linux/bug.h>
91700 #include <linux/kernel.h>
91701 #include <linux/rculist.h>
91702 +#include <linux/mm.h>
91703
91704 +#ifdef CONFIG_DEBUG_LIST
91705 /*
91706 * Insert a new entry between two known consecutive entries.
91707 *
91708 @@ -19,21 +21,40 @@
91709 * the prev/next entries already!
91710 */
91711
91712 +static bool __list_add_debug(struct list_head *new,
91713 + struct list_head *prev,
91714 + struct list_head *next)
91715 +{
91716 + if (unlikely(next->prev != prev)) {
91717 + printk(KERN_ERR "list_add corruption. next->prev should be "
91718 + "prev (%p), but was %p. (next=%p).\n",
91719 + prev, next->prev, next);
91720 + BUG();
91721 + return false;
91722 + }
91723 + if (unlikely(prev->next != next)) {
91724 + printk(KERN_ERR "list_add corruption. prev->next should be "
91725 + "next (%p), but was %p. (prev=%p).\n",
91726 + next, prev->next, prev);
91727 + BUG();
91728 + return false;
91729 + }
91730 + if (unlikely(new == prev || new == next)) {
91731 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91732 + new, prev, next);
91733 + BUG();
91734 + return false;
91735 + }
91736 + return true;
91737 +}
91738 +
91739 void __list_add(struct list_head *new,
91740 - struct list_head *prev,
91741 - struct list_head *next)
91742 + struct list_head *prev,
91743 + struct list_head *next)
91744 {
91745 - WARN(next->prev != prev,
91746 - "list_add corruption. next->prev should be "
91747 - "prev (%p), but was %p. (next=%p).\n",
91748 - prev, next->prev, next);
91749 - WARN(prev->next != next,
91750 - "list_add corruption. prev->next should be "
91751 - "next (%p), but was %p. (prev=%p).\n",
91752 - next, prev->next, prev);
91753 - WARN(new == prev || new == next,
91754 - "list_add double add: new=%p, prev=%p, next=%p.\n",
91755 - new, prev, next);
91756 + if (!__list_add_debug(new, prev, next))
91757 + return;
91758 +
91759 next->prev = new;
91760 new->next = next;
91761 new->prev = prev;
91762 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91763 }
91764 EXPORT_SYMBOL(__list_add);
91765
91766 -void __list_del_entry(struct list_head *entry)
91767 +static bool __list_del_entry_debug(struct list_head *entry)
91768 {
91769 struct list_head *prev, *next;
91770
91771 prev = entry->prev;
91772 next = entry->next;
91773
91774 - if (WARN(next == LIST_POISON1,
91775 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91776 - entry, LIST_POISON1) ||
91777 - WARN(prev == LIST_POISON2,
91778 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91779 - entry, LIST_POISON2) ||
91780 - WARN(prev->next != entry,
91781 - "list_del corruption. prev->next should be %p, "
91782 - "but was %p\n", entry, prev->next) ||
91783 - WARN(next->prev != entry,
91784 - "list_del corruption. next->prev should be %p, "
91785 - "but was %p\n", entry, next->prev))
91786 + if (unlikely(next == LIST_POISON1)) {
91787 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91788 + entry, LIST_POISON1);
91789 + BUG();
91790 + return false;
91791 + }
91792 + if (unlikely(prev == LIST_POISON2)) {
91793 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91794 + entry, LIST_POISON2);
91795 + BUG();
91796 + return false;
91797 + }
91798 + if (unlikely(entry->prev->next != entry)) {
91799 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91800 + "but was %p\n", entry, prev->next);
91801 + BUG();
91802 + return false;
91803 + }
91804 + if (unlikely(entry->next->prev != entry)) {
91805 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91806 + "but was %p\n", entry, next->prev);
91807 + BUG();
91808 + return false;
91809 + }
91810 + return true;
91811 +}
91812 +
91813 +void __list_del_entry(struct list_head *entry)
91814 +{
91815 + if (!__list_del_entry_debug(entry))
91816 return;
91817
91818 - __list_del(prev, next);
91819 + __list_del(entry->prev, entry->next);
91820 }
91821 EXPORT_SYMBOL(__list_del_entry);
91822
91823 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91824 void __list_add_rcu(struct list_head *new,
91825 struct list_head *prev, struct list_head *next)
91826 {
91827 - WARN(next->prev != prev,
91828 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91829 - prev, next->prev, next);
91830 - WARN(prev->next != next,
91831 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91832 - next, prev->next, prev);
91833 + if (!__list_add_debug(new, prev, next))
91834 + return;
91835 +
91836 new->next = next;
91837 new->prev = prev;
91838 rcu_assign_pointer(list_next_rcu(prev), new);
91839 next->prev = new;
91840 }
91841 EXPORT_SYMBOL(__list_add_rcu);
91842 +#endif
91843 +
91844 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91845 +{
91846 +#ifdef CONFIG_DEBUG_LIST
91847 + if (!__list_add_debug(new, prev, next))
91848 + return;
91849 +#endif
91850 +
91851 + pax_open_kernel();
91852 + next->prev = new;
91853 + new->next = next;
91854 + new->prev = prev;
91855 + prev->next = new;
91856 + pax_close_kernel();
91857 +}
91858 +EXPORT_SYMBOL(__pax_list_add);
91859 +
91860 +void pax_list_del(struct list_head *entry)
91861 +{
91862 +#ifdef CONFIG_DEBUG_LIST
91863 + if (!__list_del_entry_debug(entry))
91864 + return;
91865 +#endif
91866 +
91867 + pax_open_kernel();
91868 + __list_del(entry->prev, entry->next);
91869 + entry->next = LIST_POISON1;
91870 + entry->prev = LIST_POISON2;
91871 + pax_close_kernel();
91872 +}
91873 +EXPORT_SYMBOL(pax_list_del);
91874 +
91875 +void pax_list_del_init(struct list_head *entry)
91876 +{
91877 + pax_open_kernel();
91878 + __list_del(entry->prev, entry->next);
91879 + INIT_LIST_HEAD(entry);
91880 + pax_close_kernel();
91881 +}
91882 +EXPORT_SYMBOL(pax_list_del_init);
91883 +
91884 +void __pax_list_add_rcu(struct list_head *new,
91885 + struct list_head *prev, struct list_head *next)
91886 +{
91887 +#ifdef CONFIG_DEBUG_LIST
91888 + if (!__list_add_debug(new, prev, next))
91889 + return;
91890 +#endif
91891 +
91892 + pax_open_kernel();
91893 + new->next = next;
91894 + new->prev = prev;
91895 + rcu_assign_pointer(list_next_rcu(prev), new);
91896 + next->prev = new;
91897 + pax_close_kernel();
91898 +}
91899 +EXPORT_SYMBOL(__pax_list_add_rcu);
91900 +
91901 +void pax_list_del_rcu(struct list_head *entry)
91902 +{
91903 +#ifdef CONFIG_DEBUG_LIST
91904 + if (!__list_del_entry_debug(entry))
91905 + return;
91906 +#endif
91907 +
91908 + pax_open_kernel();
91909 + __list_del(entry->prev, entry->next);
91910 + entry->next = LIST_POISON1;
91911 + entry->prev = LIST_POISON2;
91912 + pax_close_kernel();
91913 +}
91914 +EXPORT_SYMBOL(pax_list_del_rcu);
91915 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91916 index 963b703..438bc51 100644
91917 --- a/lib/percpu-refcount.c
91918 +++ b/lib/percpu-refcount.c
91919 @@ -29,7 +29,7 @@
91920 * can't hit 0 before we've added up all the percpu refs.
91921 */
91922
91923 -#define PCPU_COUNT_BIAS (1U << 31)
91924 +#define PCPU_COUNT_BIAS (1U << 30)
91925
91926 /**
91927 * percpu_ref_init - initialize a percpu refcount
91928 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91929 index 9599aa7..9cf6c72 100644
91930 --- a/lib/radix-tree.c
91931 +++ b/lib/radix-tree.c
91932 @@ -66,7 +66,7 @@ struct radix_tree_preload {
91933 int nr;
91934 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91935 };
91936 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91937 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91938
91939 static inline void *ptr_to_indirect(void *ptr)
91940 {
91941 diff --git a/lib/random32.c b/lib/random32.c
91942 index fa5da61..35fe9af 100644
91943 --- a/lib/random32.c
91944 +++ b/lib/random32.c
91945 @@ -42,7 +42,7 @@
91946 static void __init prandom_state_selftest(void);
91947 #endif
91948
91949 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91950 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91951
91952 /**
91953 * prandom_u32_state - seeded pseudo-random number generator.
91954 diff --git a/lib/rbtree.c b/lib/rbtree.c
91955 index 65f4eff..2cfa167 100644
91956 --- a/lib/rbtree.c
91957 +++ b/lib/rbtree.c
91958 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91959 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91960
91961 static const struct rb_augment_callbacks dummy_callbacks = {
91962 - dummy_propagate, dummy_copy, dummy_rotate
91963 + .propagate = dummy_propagate,
91964 + .copy = dummy_copy,
91965 + .rotate = dummy_rotate
91966 };
91967
91968 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91969 diff --git a/lib/show_mem.c b/lib/show_mem.c
91970 index 0922579..9d7adb9 100644
91971 --- a/lib/show_mem.c
91972 +++ b/lib/show_mem.c
91973 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91974 quicklist_total_size());
91975 #endif
91976 #ifdef CONFIG_MEMORY_FAILURE
91977 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91978 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91979 #endif
91980 }
91981 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91982 index bb2b201..46abaf9 100644
91983 --- a/lib/strncpy_from_user.c
91984 +++ b/lib/strncpy_from_user.c
91985 @@ -21,7 +21,7 @@
91986 */
91987 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91988 {
91989 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91990 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91991 long res = 0;
91992
91993 /*
91994 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91995 index a28df52..3d55877 100644
91996 --- a/lib/strnlen_user.c
91997 +++ b/lib/strnlen_user.c
91998 @@ -26,7 +26,7 @@
91999 */
92000 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92001 {
92002 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92003 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92004 long align, res = 0;
92005 unsigned long c;
92006
92007 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92008 index b604b83..c0547f6 100644
92009 --- a/lib/swiotlb.c
92010 +++ b/lib/swiotlb.c
92011 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92012
92013 void
92014 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92015 - dma_addr_t dev_addr)
92016 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92017 {
92018 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92019
92020 diff --git a/lib/usercopy.c b/lib/usercopy.c
92021 index 4f5b1dd..7cab418 100644
92022 --- a/lib/usercopy.c
92023 +++ b/lib/usercopy.c
92024 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92025 WARN(1, "Buffer overflow detected!\n");
92026 }
92027 EXPORT_SYMBOL(copy_from_user_overflow);
92028 +
92029 +void copy_to_user_overflow(void)
92030 +{
92031 + WARN(1, "Buffer overflow detected!\n");
92032 +}
92033 +EXPORT_SYMBOL(copy_to_user_overflow);
92034 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92035 index 0648291..42bf42b 100644
92036 --- a/lib/vsprintf.c
92037 +++ b/lib/vsprintf.c
92038 @@ -16,6 +16,9 @@
92039 * - scnprintf and vscnprintf
92040 */
92041
92042 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92043 +#define __INCLUDED_BY_HIDESYM 1
92044 +#endif
92045 #include <stdarg.h>
92046 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92047 #include <linux/types.h>
92048 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92049 return number(buf, end, num, spec);
92050 }
92051
92052 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92053 +int kptr_restrict __read_mostly = 2;
92054 +#else
92055 int kptr_restrict __read_mostly;
92056 +#endif
92057
92058 /*
92059 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92060 @@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92061 * - 'f' For simple symbolic function names without offset
92062 * - 'S' For symbolic direct pointers with offset
92063 * - 's' For symbolic direct pointers without offset
92064 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92065 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92066 * - 'B' For backtraced symbolic direct pointers with offset
92067 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92068 @@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92069
92070 if (!ptr && *fmt != 'K') {
92071 /*
92072 - * Print (null) with the same width as a pointer so it makes
92073 + * Print (nil) with the same width as a pointer so it makes
92074 * tabular output look nice.
92075 */
92076 if (spec.field_width == -1)
92077 spec.field_width = default_width;
92078 - return string(buf, end, "(null)", spec);
92079 + return string(buf, end, "(nil)", spec);
92080 }
92081
92082 switch (*fmt) {
92083 @@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92084 /* Fallthrough */
92085 case 'S':
92086 case 's':
92087 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92088 + break;
92089 +#else
92090 + return symbol_string(buf, end, ptr, spec, fmt);
92091 +#endif
92092 + case 'A':
92093 case 'B':
92094 return symbol_string(buf, end, ptr, spec, fmt);
92095 case 'R':
92096 @@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92097 va_end(va);
92098 return buf;
92099 }
92100 + case 'P':
92101 + break;
92102 case 'K':
92103 /*
92104 * %pK cannot be used in IRQ context because its test
92105 @@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92106 ((const struct file *)ptr)->f_path.dentry,
92107 spec, fmt);
92108 }
92109 +
92110 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92111 + /* 'P' = approved pointers to copy to userland,
92112 + as in the /proc/kallsyms case, as we make it display nothing
92113 + for non-root users, and the real contents for root users
92114 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92115 + above
92116 + */
92117 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92118 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92119 + dump_stack();
92120 + ptr = NULL;
92121 + }
92122 +#endif
92123 +
92124 spec.flags |= SMALL;
92125 if (spec.field_width == -1) {
92126 spec.field_width = default_width;
92127 @@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92128 typeof(type) value; \
92129 if (sizeof(type) == 8) { \
92130 args = PTR_ALIGN(args, sizeof(u32)); \
92131 - *(u32 *)&value = *(u32 *)args; \
92132 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92133 + *(u32 *)&value = *(const u32 *)args; \
92134 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92135 } else { \
92136 args = PTR_ALIGN(args, sizeof(type)); \
92137 - value = *(typeof(type) *)args; \
92138 + value = *(const typeof(type) *)args; \
92139 } \
92140 args += sizeof(type); \
92141 value; \
92142 @@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92143 case FORMAT_TYPE_STR: {
92144 const char *str_arg = args;
92145 args += strlen(str_arg) + 1;
92146 - str = string(str, end, (char *)str_arg, spec);
92147 + str = string(str, end, str_arg, spec);
92148 break;
92149 }
92150
92151 diff --git a/localversion-grsec b/localversion-grsec
92152 new file mode 100644
92153 index 0000000..7cd6065
92154 --- /dev/null
92155 +++ b/localversion-grsec
92156 @@ -0,0 +1 @@
92157 +-grsec
92158 diff --git a/mm/Kconfig b/mm/Kconfig
92159 index 2f42b9c..6095e14 100644
92160 --- a/mm/Kconfig
92161 +++ b/mm/Kconfig
92162 @@ -330,10 +330,11 @@ config KSM
92163 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92164
92165 config DEFAULT_MMAP_MIN_ADDR
92166 - int "Low address space to protect from user allocation"
92167 + int "Low address space to protect from user allocation"
92168 depends on MMU
92169 - default 4096
92170 - help
92171 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92172 + default 65536
92173 + help
92174 This is the portion of low virtual memory which should be protected
92175 from userspace allocation. Keeping a user from writing to low pages
92176 can help reduce the impact of kernel NULL pointer bugs.
92177 @@ -364,7 +365,7 @@ config MEMORY_FAILURE
92178
92179 config HWPOISON_INJECT
92180 tristate "HWPoison pages injector"
92181 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92182 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92183 select PROC_PAGE_MONITOR
92184
92185 config NOMMU_INITIAL_TRIM_EXCESS
92186 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92187 index 09d9591..165bb75 100644
92188 --- a/mm/backing-dev.c
92189 +++ b/mm/backing-dev.c
92190 @@ -12,7 +12,7 @@
92191 #include <linux/device.h>
92192 #include <trace/events/writeback.h>
92193
92194 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92195 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92196
92197 struct backing_dev_info default_backing_dev_info = {
92198 .name = "default",
92199 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92200 return err;
92201
92202 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92203 - atomic_long_inc_return(&bdi_seq));
92204 + atomic_long_inc_return_unchecked(&bdi_seq));
92205 if (err) {
92206 bdi_destroy(bdi);
92207 return err;
92208 diff --git a/mm/filemap.c b/mm/filemap.c
92209 index 088358c..bb415bf 100644
92210 --- a/mm/filemap.c
92211 +++ b/mm/filemap.c
92212 @@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92213 struct address_space *mapping = file->f_mapping;
92214
92215 if (!mapping->a_ops->readpage)
92216 - return -ENOEXEC;
92217 + return -ENODEV;
92218 file_accessed(file);
92219 vma->vm_ops = &generic_file_vm_ops;
92220 return 0;
92221 @@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92222 *pos = i_size_read(inode);
92223
92224 if (limit != RLIM_INFINITY) {
92225 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92226 if (*pos >= limit) {
92227 send_sig(SIGXFSZ, current, 0);
92228 return -EFBIG;
92229 diff --git a/mm/fremap.c b/mm/fremap.c
92230 index 34feba6..315fe78 100644
92231 --- a/mm/fremap.c
92232 +++ b/mm/fremap.c
92233 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92234 retry:
92235 vma = find_vma(mm, start);
92236
92237 +#ifdef CONFIG_PAX_SEGMEXEC
92238 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92239 + goto out;
92240 +#endif
92241 +
92242 /*
92243 * Make sure the vma is shared, that it supports prefaulting,
92244 * and that the remapped range is valid and fully within
92245 diff --git a/mm/highmem.c b/mm/highmem.c
92246 index b32b70c..e512eb0 100644
92247 --- a/mm/highmem.c
92248 +++ b/mm/highmem.c
92249 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92250 * So no dangers, even with speculative execution.
92251 */
92252 page = pte_page(pkmap_page_table[i]);
92253 + pax_open_kernel();
92254 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92255 -
92256 + pax_close_kernel();
92257 set_page_address(page, NULL);
92258 need_flush = 1;
92259 }
92260 @@ -198,9 +199,11 @@ start:
92261 }
92262 }
92263 vaddr = PKMAP_ADDR(last_pkmap_nr);
92264 +
92265 + pax_open_kernel();
92266 set_pte_at(&init_mm, vaddr,
92267 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92268 -
92269 + pax_close_kernel();
92270 pkmap_count[last_pkmap_nr] = 1;
92271 set_page_address(page, (void *)vaddr);
92272
92273 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92274 index c82290b..863d466 100644
92275 --- a/mm/hugetlb.c
92276 +++ b/mm/hugetlb.c
92277 @@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92278 struct hstate *h = &default_hstate;
92279 unsigned long tmp;
92280 int ret;
92281 + ctl_table_no_const hugetlb_table;
92282
92283 if (!hugepages_supported())
92284 return -ENOTSUPP;
92285 @@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92286 if (write && h->order >= MAX_ORDER)
92287 return -EINVAL;
92288
92289 - table->data = &tmp;
92290 - table->maxlen = sizeof(unsigned long);
92291 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92292 + hugetlb_table = *table;
92293 + hugetlb_table.data = &tmp;
92294 + hugetlb_table.maxlen = sizeof(unsigned long);
92295 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92296 if (ret)
92297 goto out;
92298
92299 @@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92300 struct hstate *h = &default_hstate;
92301 unsigned long tmp;
92302 int ret;
92303 + ctl_table_no_const hugetlb_table;
92304
92305 if (!hugepages_supported())
92306 return -ENOTSUPP;
92307 @@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92308 if (write && h->order >= MAX_ORDER)
92309 return -EINVAL;
92310
92311 - table->data = &tmp;
92312 - table->maxlen = sizeof(unsigned long);
92313 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92314 + hugetlb_table = *table;
92315 + hugetlb_table.data = &tmp;
92316 + hugetlb_table.maxlen = sizeof(unsigned long);
92317 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92318 if (ret)
92319 goto out;
92320
92321 @@ -2639,6 +2643,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92322 return 1;
92323 }
92324
92325 +#ifdef CONFIG_PAX_SEGMEXEC
92326 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92327 +{
92328 + struct mm_struct *mm = vma->vm_mm;
92329 + struct vm_area_struct *vma_m;
92330 + unsigned long address_m;
92331 + pte_t *ptep_m;
92332 +
92333 + vma_m = pax_find_mirror_vma(vma);
92334 + if (!vma_m)
92335 + return;
92336 +
92337 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92338 + address_m = address + SEGMEXEC_TASK_SIZE;
92339 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92340 + get_page(page_m);
92341 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
92342 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92343 +}
92344 +#endif
92345 +
92346 /*
92347 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92348 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92349 @@ -2756,6 +2781,11 @@ retry_avoidcopy:
92350 make_huge_pte(vma, new_page, 1));
92351 page_remove_rmap(old_page);
92352 hugepage_add_new_anon_rmap(new_page, vma, address);
92353 +
92354 +#ifdef CONFIG_PAX_SEGMEXEC
92355 + pax_mirror_huge_pte(vma, address, new_page);
92356 +#endif
92357 +
92358 /* Make the old page be freed below */
92359 new_page = old_page;
92360 }
92361 @@ -2915,6 +2945,10 @@ retry:
92362 && (vma->vm_flags & VM_SHARED)));
92363 set_huge_pte_at(mm, address, ptep, new_pte);
92364
92365 +#ifdef CONFIG_PAX_SEGMEXEC
92366 + pax_mirror_huge_pte(vma, address, page);
92367 +#endif
92368 +
92369 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92370 /* Optimization, do the COW without a second fault */
92371 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92372 @@ -2981,6 +3015,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92373 struct hstate *h = hstate_vma(vma);
92374 struct address_space *mapping;
92375
92376 +#ifdef CONFIG_PAX_SEGMEXEC
92377 + struct vm_area_struct *vma_m;
92378 +#endif
92379 +
92380 address &= huge_page_mask(h);
92381
92382 ptep = huge_pte_offset(mm, address);
92383 @@ -2994,6 +3032,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92384 VM_FAULT_SET_HINDEX(hstate_index(h));
92385 }
92386
92387 +#ifdef CONFIG_PAX_SEGMEXEC
92388 + vma_m = pax_find_mirror_vma(vma);
92389 + if (vma_m) {
92390 + unsigned long address_m;
92391 +
92392 + if (vma->vm_start > vma_m->vm_start) {
92393 + address_m = address;
92394 + address -= SEGMEXEC_TASK_SIZE;
92395 + vma = vma_m;
92396 + h = hstate_vma(vma);
92397 + } else
92398 + address_m = address + SEGMEXEC_TASK_SIZE;
92399 +
92400 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92401 + return VM_FAULT_OOM;
92402 + address_m &= HPAGE_MASK;
92403 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92404 + }
92405 +#endif
92406 +
92407 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92408 if (!ptep)
92409 return VM_FAULT_OOM;
92410 diff --git a/mm/internal.h b/mm/internal.h
92411 index 07b6736..ae8da20 100644
92412 --- a/mm/internal.h
92413 +++ b/mm/internal.h
92414 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92415 * in mm/page_alloc.c
92416 */
92417 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92418 +extern void free_compound_page(struct page *page);
92419 extern void prep_compound_page(struct page *page, unsigned long order);
92420 #ifdef CONFIG_MEMORY_FAILURE
92421 extern bool is_free_buddy_page(struct page *page);
92422 @@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92423
92424 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92425 unsigned long, unsigned long,
92426 - unsigned long, unsigned long);
92427 + unsigned long, unsigned long) __intentional_overflow(-1);
92428
92429 extern void set_pageblock_order(void);
92430 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92431 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92432 index 10e46cd..e3052f6 100644
92433 --- a/mm/iov_iter.c
92434 +++ b/mm/iov_iter.c
92435 @@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92436
92437 while (bytes) {
92438 char __user *buf = iov->iov_base + base;
92439 - int copy = min(bytes, iov->iov_len - base);
92440 + size_t copy = min(bytes, iov->iov_len - base);
92441
92442 base = 0;
92443 left = __copy_from_user_inatomic(vaddr, buf, copy);
92444 @@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92445
92446 kaddr = kmap_atomic(page);
92447 if (likely(i->nr_segs == 1)) {
92448 - int left;
92449 + size_t left;
92450 char __user *buf = i->iov->iov_base + i->iov_offset;
92451 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92452 copied = bytes - left;
92453 @@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92454
92455 kaddr = kmap(page);
92456 if (likely(i->nr_segs == 1)) {
92457 - int left;
92458 + size_t left;
92459 char __user *buf = i->iov->iov_base + i->iov_offset;
92460 left = __copy_from_user(kaddr + offset, buf, bytes);
92461 copied = bytes - left;
92462 @@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92463 * zero-length segments (without overruning the iovec).
92464 */
92465 while (bytes || unlikely(i->count && !iov->iov_len)) {
92466 - int copy;
92467 + size_t copy;
92468
92469 copy = min(bytes, iov->iov_len - base);
92470 BUG_ON(!i->count || i->count < copy);
92471 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92472 index 8d2fcdf..6dd9f1a 100644
92473 --- a/mm/kmemleak.c
92474 +++ b/mm/kmemleak.c
92475 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92476
92477 for (i = 0; i < object->trace_len; i++) {
92478 void *ptr = (void *)object->trace[i];
92479 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92480 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92481 }
92482 }
92483
92484 @@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92485 return -ENOMEM;
92486 }
92487
92488 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92489 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92490 &kmemleak_fops);
92491 if (!dentry)
92492 pr_warning("Failed to create the debugfs kmemleak file\n");
92493 diff --git a/mm/maccess.c b/mm/maccess.c
92494 index d53adf9..03a24bf 100644
92495 --- a/mm/maccess.c
92496 +++ b/mm/maccess.c
92497 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92498 set_fs(KERNEL_DS);
92499 pagefault_disable();
92500 ret = __copy_from_user_inatomic(dst,
92501 - (__force const void __user *)src, size);
92502 + (const void __force_user *)src, size);
92503 pagefault_enable();
92504 set_fs(old_fs);
92505
92506 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92507
92508 set_fs(KERNEL_DS);
92509 pagefault_disable();
92510 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92511 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92512 pagefault_enable();
92513 set_fs(old_fs);
92514
92515 diff --git a/mm/madvise.c b/mm/madvise.c
92516 index a402f8f..f5e5daa 100644
92517 --- a/mm/madvise.c
92518 +++ b/mm/madvise.c
92519 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92520 pgoff_t pgoff;
92521 unsigned long new_flags = vma->vm_flags;
92522
92523 +#ifdef CONFIG_PAX_SEGMEXEC
92524 + struct vm_area_struct *vma_m;
92525 +#endif
92526 +
92527 switch (behavior) {
92528 case MADV_NORMAL:
92529 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92530 @@ -126,6 +130,13 @@ success:
92531 /*
92532 * vm_flags is protected by the mmap_sem held in write mode.
92533 */
92534 +
92535 +#ifdef CONFIG_PAX_SEGMEXEC
92536 + vma_m = pax_find_mirror_vma(vma);
92537 + if (vma_m)
92538 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92539 +#endif
92540 +
92541 vma->vm_flags = new_flags;
92542
92543 out:
92544 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92545 struct vm_area_struct **prev,
92546 unsigned long start, unsigned long end)
92547 {
92548 +
92549 +#ifdef CONFIG_PAX_SEGMEXEC
92550 + struct vm_area_struct *vma_m;
92551 +#endif
92552 +
92553 *prev = vma;
92554 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92555 return -EINVAL;
92556 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92557 zap_page_range(vma, start, end - start, &details);
92558 } else
92559 zap_page_range(vma, start, end - start, NULL);
92560 +
92561 +#ifdef CONFIG_PAX_SEGMEXEC
92562 + vma_m = pax_find_mirror_vma(vma);
92563 + if (vma_m) {
92564 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92565 + struct zap_details details = {
92566 + .nonlinear_vma = vma_m,
92567 + .last_index = ULONG_MAX,
92568 + };
92569 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92570 + } else
92571 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92572 + }
92573 +#endif
92574 +
92575 return 0;
92576 }
92577
92578 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92579 if (end < start)
92580 return error;
92581
92582 +#ifdef CONFIG_PAX_SEGMEXEC
92583 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92584 + if (end > SEGMEXEC_TASK_SIZE)
92585 + return error;
92586 + } else
92587 +#endif
92588 +
92589 + if (end > TASK_SIZE)
92590 + return error;
92591 +
92592 error = 0;
92593 if (end == start)
92594 return error;
92595 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92596 index eb8fb72..ae36cf3 100644
92597 --- a/mm/memory-failure.c
92598 +++ b/mm/memory-failure.c
92599 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92600
92601 int sysctl_memory_failure_recovery __read_mostly = 1;
92602
92603 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92604 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92605
92606 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92607
92608 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92609 pfn, t->comm, t->pid);
92610 si.si_signo = SIGBUS;
92611 si.si_errno = 0;
92612 - si.si_addr = (void *)addr;
92613 + si.si_addr = (void __user *)addr;
92614 #ifdef __ARCH_SI_TRAPNO
92615 si.si_trapno = trapno;
92616 #endif
92617 @@ -791,7 +791,7 @@ static struct page_state {
92618 unsigned long res;
92619 char *msg;
92620 int (*action)(struct page *p, unsigned long pfn);
92621 -} error_states[] = {
92622 +} __do_const error_states[] = {
92623 { reserved, reserved, "reserved kernel", me_kernel },
92624 /*
92625 * free pages are specially detected outside this table:
92626 @@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92627 nr_pages = 1 << compound_order(hpage);
92628 else /* normal page or thp */
92629 nr_pages = 1;
92630 - atomic_long_add(nr_pages, &num_poisoned_pages);
92631 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92632
92633 /*
92634 * We need/can do nothing about count=0 pages.
92635 @@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92636 if (PageHWPoison(hpage)) {
92637 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92638 || (p != hpage && TestSetPageHWPoison(hpage))) {
92639 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92640 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92641 unlock_page(hpage);
92642 return 0;
92643 }
92644 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92645 */
92646 if (!PageHWPoison(p)) {
92647 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92648 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92649 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92650 put_page(hpage);
92651 res = 0;
92652 goto out;
92653 }
92654 if (hwpoison_filter(p)) {
92655 if (TestClearPageHWPoison(p))
92656 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92657 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92658 unlock_page(hpage);
92659 put_page(hpage);
92660 return 0;
92661 @@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
92662 return 0;
92663 }
92664 if (TestClearPageHWPoison(p))
92665 - atomic_long_dec(&num_poisoned_pages);
92666 + atomic_long_dec_unchecked(&num_poisoned_pages);
92667 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92668 return 0;
92669 }
92670 @@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
92671 */
92672 if (TestClearPageHWPoison(page)) {
92673 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92674 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92675 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92676 freeit = 1;
92677 if (PageHuge(page))
92678 clear_page_hwpoison_huge_page(page);
92679 @@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92680 if (PageHuge(page)) {
92681 set_page_hwpoison_huge_page(hpage);
92682 dequeue_hwpoisoned_huge_page(hpage);
92683 - atomic_long_add(1 << compound_order(hpage),
92684 + atomic_long_add_unchecked(1 << compound_order(hpage),
92685 &num_poisoned_pages);
92686 } else {
92687 SetPageHWPoison(page);
92688 - atomic_long_inc(&num_poisoned_pages);
92689 + atomic_long_inc_unchecked(&num_poisoned_pages);
92690 }
92691 }
92692 return ret;
92693 @@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
92694 put_page(page);
92695 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92696 SetPageHWPoison(page);
92697 - atomic_long_inc(&num_poisoned_pages);
92698 + atomic_long_inc_unchecked(&num_poisoned_pages);
92699 return 0;
92700 }
92701
92702 @@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
92703 if (!is_free_buddy_page(page))
92704 pr_info("soft offline: %#lx: page leaked\n",
92705 pfn);
92706 - atomic_long_inc(&num_poisoned_pages);
92707 + atomic_long_inc_unchecked(&num_poisoned_pages);
92708 }
92709 } else {
92710 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92711 @@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
92712 if (PageHuge(page)) {
92713 set_page_hwpoison_huge_page(hpage);
92714 dequeue_hwpoisoned_huge_page(hpage);
92715 - atomic_long_add(1 << compound_order(hpage),
92716 + atomic_long_add_unchecked(1 << compound_order(hpage),
92717 &num_poisoned_pages);
92718 } else {
92719 SetPageHWPoison(page);
92720 - atomic_long_inc(&num_poisoned_pages);
92721 + atomic_long_inc_unchecked(&num_poisoned_pages);
92722 }
92723 }
92724 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92725 diff --git a/mm/memory.c b/mm/memory.c
92726 index 037b812..948123c 100644
92727 --- a/mm/memory.c
92728 +++ b/mm/memory.c
92729 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92730 free_pte_range(tlb, pmd, addr);
92731 } while (pmd++, addr = next, addr != end);
92732
92733 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92734 start &= PUD_MASK;
92735 if (start < floor)
92736 return;
92737 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92738 pmd = pmd_offset(pud, start);
92739 pud_clear(pud);
92740 pmd_free_tlb(tlb, pmd, start);
92741 +#endif
92742 +
92743 }
92744
92745 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92746 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92747 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92748 } while (pud++, addr = next, addr != end);
92749
92750 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92751 start &= PGDIR_MASK;
92752 if (start < floor)
92753 return;
92754 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92755 pud = pud_offset(pgd, start);
92756 pgd_clear(pgd);
92757 pud_free_tlb(tlb, pud, start);
92758 +#endif
92759 +
92760 }
92761
92762 /*
92763 @@ -1652,12 +1658,6 @@ no_page_table:
92764 return page;
92765 }
92766
92767 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92768 -{
92769 - return stack_guard_page_start(vma, addr) ||
92770 - stack_guard_page_end(vma, addr+PAGE_SIZE);
92771 -}
92772 -
92773 /**
92774 * __get_user_pages() - pin user pages in memory
92775 * @tsk: task_struct of target task
92776 @@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92777
92778 i = 0;
92779
92780 - do {
92781 + while (nr_pages) {
92782 struct vm_area_struct *vma;
92783
92784 - vma = find_extend_vma(mm, start);
92785 + vma = find_vma(mm, start);
92786 if (!vma && in_gate_area(mm, start)) {
92787 unsigned long pg = start & PAGE_MASK;
92788 pgd_t *pgd;
92789 @@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92790 goto next_page;
92791 }
92792
92793 - if (!vma)
92794 + if (!vma || start < vma->vm_start)
92795 goto efault;
92796 vm_flags = vma->vm_flags;
92797 if (vm_flags & (VM_IO | VM_PFNMAP))
92798 @@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92799 int ret;
92800 unsigned int fault_flags = 0;
92801
92802 - /* For mlock, just skip the stack guard page. */
92803 - if (foll_flags & FOLL_MLOCK) {
92804 - if (stack_guard_page(vma, start))
92805 - goto next_page;
92806 - }
92807 if (foll_flags & FOLL_WRITE)
92808 fault_flags |= FAULT_FLAG_WRITE;
92809 if (nonblocking)
92810 @@ -1932,7 +1927,7 @@ next_page:
92811 start += page_increm * PAGE_SIZE;
92812 nr_pages -= page_increm;
92813 } while (nr_pages && start < vma->vm_end);
92814 - } while (nr_pages);
92815 + }
92816 return i;
92817 efault:
92818 return i ? : -EFAULT;
92819 @@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92820 page_add_file_rmap(page);
92821 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92822
92823 +#ifdef CONFIG_PAX_SEGMEXEC
92824 + pax_mirror_file_pte(vma, addr, page, ptl);
92825 +#endif
92826 +
92827 retval = 0;
92828 pte_unmap_unlock(pte, ptl);
92829 return retval;
92830 @@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92831 if (!page_count(page))
92832 return -EINVAL;
92833 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92834 +
92835 +#ifdef CONFIG_PAX_SEGMEXEC
92836 + struct vm_area_struct *vma_m;
92837 +#endif
92838 +
92839 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92840 BUG_ON(vma->vm_flags & VM_PFNMAP);
92841 vma->vm_flags |= VM_MIXEDMAP;
92842 +
92843 +#ifdef CONFIG_PAX_SEGMEXEC
92844 + vma_m = pax_find_mirror_vma(vma);
92845 + if (vma_m)
92846 + vma_m->vm_flags |= VM_MIXEDMAP;
92847 +#endif
92848 +
92849 }
92850 return insert_page(vma, addr, page, vma->vm_page_prot);
92851 }
92852 @@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92853 unsigned long pfn)
92854 {
92855 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92856 + BUG_ON(vma->vm_mirror);
92857
92858 if (addr < vma->vm_start || addr >= vma->vm_end)
92859 return -EFAULT;
92860 @@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92861
92862 BUG_ON(pud_huge(*pud));
92863
92864 - pmd = pmd_alloc(mm, pud, addr);
92865 + pmd = (mm == &init_mm) ?
92866 + pmd_alloc_kernel(mm, pud, addr) :
92867 + pmd_alloc(mm, pud, addr);
92868 if (!pmd)
92869 return -ENOMEM;
92870 do {
92871 @@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92872 unsigned long next;
92873 int err;
92874
92875 - pud = pud_alloc(mm, pgd, addr);
92876 + pud = (mm == &init_mm) ?
92877 + pud_alloc_kernel(mm, pgd, addr) :
92878 + pud_alloc(mm, pgd, addr);
92879 if (!pud)
92880 return -ENOMEM;
92881 do {
92882 @@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
92883 return ret;
92884 }
92885
92886 +#ifdef CONFIG_PAX_SEGMEXEC
92887 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92888 +{
92889 + struct mm_struct *mm = vma->vm_mm;
92890 + spinlock_t *ptl;
92891 + pte_t *pte, entry;
92892 +
92893 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92894 + entry = *pte;
92895 + if (!pte_present(entry)) {
92896 + if (!pte_none(entry)) {
92897 + BUG_ON(pte_file(entry));
92898 + free_swap_and_cache(pte_to_swp_entry(entry));
92899 + pte_clear_not_present_full(mm, address, pte, 0);
92900 + }
92901 + } else {
92902 + struct page *page;
92903 +
92904 + flush_cache_page(vma, address, pte_pfn(entry));
92905 + entry = ptep_clear_flush(vma, address, pte);
92906 + BUG_ON(pte_dirty(entry));
92907 + page = vm_normal_page(vma, address, entry);
92908 + if (page) {
92909 + update_hiwater_rss(mm);
92910 + if (PageAnon(page))
92911 + dec_mm_counter_fast(mm, MM_ANONPAGES);
92912 + else
92913 + dec_mm_counter_fast(mm, MM_FILEPAGES);
92914 + page_remove_rmap(page);
92915 + page_cache_release(page);
92916 + }
92917 + }
92918 + pte_unmap_unlock(pte, ptl);
92919 +}
92920 +
92921 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
92922 + *
92923 + * the ptl of the lower mapped page is held on entry and is not released on exit
92924 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92925 + */
92926 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92927 +{
92928 + struct mm_struct *mm = vma->vm_mm;
92929 + unsigned long address_m;
92930 + spinlock_t *ptl_m;
92931 + struct vm_area_struct *vma_m;
92932 + pmd_t *pmd_m;
92933 + pte_t *pte_m, entry_m;
92934 +
92935 + BUG_ON(!page_m || !PageAnon(page_m));
92936 +
92937 + vma_m = pax_find_mirror_vma(vma);
92938 + if (!vma_m)
92939 + return;
92940 +
92941 + BUG_ON(!PageLocked(page_m));
92942 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92943 + address_m = address + SEGMEXEC_TASK_SIZE;
92944 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92945 + pte_m = pte_offset_map(pmd_m, address_m);
92946 + ptl_m = pte_lockptr(mm, pmd_m);
92947 + if (ptl != ptl_m) {
92948 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92949 + if (!pte_none(*pte_m))
92950 + goto out;
92951 + }
92952 +
92953 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92954 + page_cache_get(page_m);
92955 + page_add_anon_rmap(page_m, vma_m, address_m);
92956 + inc_mm_counter_fast(mm, MM_ANONPAGES);
92957 + set_pte_at(mm, address_m, pte_m, entry_m);
92958 + update_mmu_cache(vma_m, address_m, pte_m);
92959 +out:
92960 + if (ptl != ptl_m)
92961 + spin_unlock(ptl_m);
92962 + pte_unmap(pte_m);
92963 + unlock_page(page_m);
92964 +}
92965 +
92966 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92967 +{
92968 + struct mm_struct *mm = vma->vm_mm;
92969 + unsigned long address_m;
92970 + spinlock_t *ptl_m;
92971 + struct vm_area_struct *vma_m;
92972 + pmd_t *pmd_m;
92973 + pte_t *pte_m, entry_m;
92974 +
92975 + BUG_ON(!page_m || PageAnon(page_m));
92976 +
92977 + vma_m = pax_find_mirror_vma(vma);
92978 + if (!vma_m)
92979 + return;
92980 +
92981 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92982 + address_m = address + SEGMEXEC_TASK_SIZE;
92983 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92984 + pte_m = pte_offset_map(pmd_m, address_m);
92985 + ptl_m = pte_lockptr(mm, pmd_m);
92986 + if (ptl != ptl_m) {
92987 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92988 + if (!pte_none(*pte_m))
92989 + goto out;
92990 + }
92991 +
92992 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92993 + page_cache_get(page_m);
92994 + page_add_file_rmap(page_m);
92995 + inc_mm_counter_fast(mm, MM_FILEPAGES);
92996 + set_pte_at(mm, address_m, pte_m, entry_m);
92997 + update_mmu_cache(vma_m, address_m, pte_m);
92998 +out:
92999 + if (ptl != ptl_m)
93000 + spin_unlock(ptl_m);
93001 + pte_unmap(pte_m);
93002 +}
93003 +
93004 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93005 +{
93006 + struct mm_struct *mm = vma->vm_mm;
93007 + unsigned long address_m;
93008 + spinlock_t *ptl_m;
93009 + struct vm_area_struct *vma_m;
93010 + pmd_t *pmd_m;
93011 + pte_t *pte_m, entry_m;
93012 +
93013 + vma_m = pax_find_mirror_vma(vma);
93014 + if (!vma_m)
93015 + return;
93016 +
93017 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93018 + address_m = address + SEGMEXEC_TASK_SIZE;
93019 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93020 + pte_m = pte_offset_map(pmd_m, address_m);
93021 + ptl_m = pte_lockptr(mm, pmd_m);
93022 + if (ptl != ptl_m) {
93023 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93024 + if (!pte_none(*pte_m))
93025 + goto out;
93026 + }
93027 +
93028 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93029 + set_pte_at(mm, address_m, pte_m, entry_m);
93030 +out:
93031 + if (ptl != ptl_m)
93032 + spin_unlock(ptl_m);
93033 + pte_unmap(pte_m);
93034 +}
93035 +
93036 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93037 +{
93038 + struct page *page_m;
93039 + pte_t entry;
93040 +
93041 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93042 + goto out;
93043 +
93044 + entry = *pte;
93045 + page_m = vm_normal_page(vma, address, entry);
93046 + if (!page_m)
93047 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93048 + else if (PageAnon(page_m)) {
93049 + if (pax_find_mirror_vma(vma)) {
93050 + pte_unmap_unlock(pte, ptl);
93051 + lock_page(page_m);
93052 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93053 + if (pte_same(entry, *pte))
93054 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93055 + else
93056 + unlock_page(page_m);
93057 + }
93058 + } else
93059 + pax_mirror_file_pte(vma, address, page_m, ptl);
93060 +
93061 +out:
93062 + pte_unmap_unlock(pte, ptl);
93063 +}
93064 +#endif
93065 +
93066 /*
93067 * This routine handles present pages, when users try to write
93068 * to a shared page. It is done by copying the page to a new address
93069 @@ -2860,6 +3056,12 @@ gotten:
93070 */
93071 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93072 if (likely(pte_same(*page_table, orig_pte))) {
93073 +
93074 +#ifdef CONFIG_PAX_SEGMEXEC
93075 + if (pax_find_mirror_vma(vma))
93076 + BUG_ON(!trylock_page(new_page));
93077 +#endif
93078 +
93079 if (old_page) {
93080 if (!PageAnon(old_page)) {
93081 dec_mm_counter_fast(mm, MM_FILEPAGES);
93082 @@ -2911,6 +3113,10 @@ gotten:
93083 page_remove_rmap(old_page);
93084 }
93085
93086 +#ifdef CONFIG_PAX_SEGMEXEC
93087 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93088 +#endif
93089 +
93090 /* Free the old page.. */
93091 new_page = old_page;
93092 ret |= VM_FAULT_WRITE;
93093 @@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93094 swap_free(entry);
93095 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93096 try_to_free_swap(page);
93097 +
93098 +#ifdef CONFIG_PAX_SEGMEXEC
93099 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93100 +#endif
93101 +
93102 unlock_page(page);
93103 if (page != swapcache) {
93104 /*
93105 @@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93106
93107 /* No need to invalidate - it was non-present before */
93108 update_mmu_cache(vma, address, page_table);
93109 +
93110 +#ifdef CONFIG_PAX_SEGMEXEC
93111 + pax_mirror_anon_pte(vma, address, page, ptl);
93112 +#endif
93113 +
93114 unlock:
93115 pte_unmap_unlock(page_table, ptl);
93116 out:
93117 @@ -3226,40 +3442,6 @@ out_release:
93118 }
93119
93120 /*
93121 - * This is like a special single-page "expand_{down|up}wards()",
93122 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93123 - * doesn't hit another vma.
93124 - */
93125 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93126 -{
93127 - address &= PAGE_MASK;
93128 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93129 - struct vm_area_struct *prev = vma->vm_prev;
93130 -
93131 - /*
93132 - * Is there a mapping abutting this one below?
93133 - *
93134 - * That's only ok if it's the same stack mapping
93135 - * that has gotten split..
93136 - */
93137 - if (prev && prev->vm_end == address)
93138 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93139 -
93140 - expand_downwards(vma, address - PAGE_SIZE);
93141 - }
93142 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93143 - struct vm_area_struct *next = vma->vm_next;
93144 -
93145 - /* As VM_GROWSDOWN but s/below/above/ */
93146 - if (next && next->vm_start == address + PAGE_SIZE)
93147 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93148 -
93149 - expand_upwards(vma, address + PAGE_SIZE);
93150 - }
93151 - return 0;
93152 -}
93153 -
93154 -/*
93155 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93156 * but allow concurrent faults), and pte mapped but not yet locked.
93157 * We return with mmap_sem still held, but pte unmapped and unlocked.
93158 @@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93159 unsigned long address, pte_t *page_table, pmd_t *pmd,
93160 unsigned int flags)
93161 {
93162 - struct page *page;
93163 + struct page *page = NULL;
93164 spinlock_t *ptl;
93165 pte_t entry;
93166
93167 - pte_unmap(page_table);
93168 -
93169 - /* Check if we need to add a guard page to the stack */
93170 - if (check_stack_guard_page(vma, address) < 0)
93171 - return VM_FAULT_SIGBUS;
93172 -
93173 - /* Use the zero-page for reads */
93174 if (!(flags & FAULT_FLAG_WRITE)) {
93175 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93176 vma->vm_page_prot));
93177 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93178 + ptl = pte_lockptr(mm, pmd);
93179 + spin_lock(ptl);
93180 if (!pte_none(*page_table))
93181 goto unlock;
93182 goto setpte;
93183 }
93184
93185 /* Allocate our own private page. */
93186 + pte_unmap(page_table);
93187 +
93188 if (unlikely(anon_vma_prepare(vma)))
93189 goto oom;
93190 page = alloc_zeroed_user_highpage_movable(vma, address);
93191 @@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93192 if (!pte_none(*page_table))
93193 goto release;
93194
93195 +#ifdef CONFIG_PAX_SEGMEXEC
93196 + if (pax_find_mirror_vma(vma))
93197 + BUG_ON(!trylock_page(page));
93198 +#endif
93199 +
93200 inc_mm_counter_fast(mm, MM_ANONPAGES);
93201 page_add_new_anon_rmap(page, vma, address);
93202 setpte:
93203 @@ -3319,6 +3502,12 @@ setpte:
93204
93205 /* No need to invalidate - it was non-present before */
93206 update_mmu_cache(vma, address, page_table);
93207 +
93208 +#ifdef CONFIG_PAX_SEGMEXEC
93209 + if (page)
93210 + pax_mirror_anon_pte(vma, address, page, ptl);
93211 +#endif
93212 +
93213 unlock:
93214 pte_unmap_unlock(page_table, ptl);
93215 return 0;
93216 @@ -3535,6 +3724,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93217 return ret;
93218 }
93219 do_set_pte(vma, address, fault_page, pte, false, false);
93220 +
93221 +#ifdef CONFIG_PAX_SEGMEXEC
93222 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93223 +#endif
93224 +
93225 unlock_page(fault_page);
93226 unlock_out:
93227 pte_unmap_unlock(pte, ptl);
93228 @@ -3576,7 +3770,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93229 page_cache_release(fault_page);
93230 goto uncharge_out;
93231 }
93232 +
93233 +#ifdef CONFIG_PAX_SEGMEXEC
93234 + if (pax_find_mirror_vma(vma))
93235 + BUG_ON(!trylock_page(new_page));
93236 +#endif
93237 +
93238 do_set_pte(vma, address, new_page, pte, true, true);
93239 +
93240 +#ifdef CONFIG_PAX_SEGMEXEC
93241 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93242 +#endif
93243 +
93244 pte_unmap_unlock(pte, ptl);
93245 unlock_page(fault_page);
93246 page_cache_release(fault_page);
93247 @@ -3624,6 +3829,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93248 return ret;
93249 }
93250 do_set_pte(vma, address, fault_page, pte, true, false);
93251 +
93252 +#ifdef CONFIG_PAX_SEGMEXEC
93253 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93254 +#endif
93255 +
93256 pte_unmap_unlock(pte, ptl);
93257
93258 if (set_page_dirty(fault_page))
93259 @@ -3854,6 +4064,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93260 if (flags & FAULT_FLAG_WRITE)
93261 flush_tlb_fix_spurious_fault(vma, address);
93262 }
93263 +
93264 +#ifdef CONFIG_PAX_SEGMEXEC
93265 + pax_mirror_pte(vma, address, pte, pmd, ptl);
93266 + return 0;
93267 +#endif
93268 +
93269 unlock:
93270 pte_unmap_unlock(pte, ptl);
93271 return 0;
93272 @@ -3870,9 +4086,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93273 pmd_t *pmd;
93274 pte_t *pte;
93275
93276 +#ifdef CONFIG_PAX_SEGMEXEC
93277 + struct vm_area_struct *vma_m;
93278 +#endif
93279 +
93280 if (unlikely(is_vm_hugetlb_page(vma)))
93281 return hugetlb_fault(mm, vma, address, flags);
93282
93283 +#ifdef CONFIG_PAX_SEGMEXEC
93284 + vma_m = pax_find_mirror_vma(vma);
93285 + if (vma_m) {
93286 + unsigned long address_m;
93287 + pgd_t *pgd_m;
93288 + pud_t *pud_m;
93289 + pmd_t *pmd_m;
93290 +
93291 + if (vma->vm_start > vma_m->vm_start) {
93292 + address_m = address;
93293 + address -= SEGMEXEC_TASK_SIZE;
93294 + vma = vma_m;
93295 + } else
93296 + address_m = address + SEGMEXEC_TASK_SIZE;
93297 +
93298 + pgd_m = pgd_offset(mm, address_m);
93299 + pud_m = pud_alloc(mm, pgd_m, address_m);
93300 + if (!pud_m)
93301 + return VM_FAULT_OOM;
93302 + pmd_m = pmd_alloc(mm, pud_m, address_m);
93303 + if (!pmd_m)
93304 + return VM_FAULT_OOM;
93305 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93306 + return VM_FAULT_OOM;
93307 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93308 + }
93309 +#endif
93310 +
93311 pgd = pgd_offset(mm, address);
93312 pud = pud_alloc(mm, pgd, address);
93313 if (!pud)
93314 @@ -4003,6 +4251,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93315 spin_unlock(&mm->page_table_lock);
93316 return 0;
93317 }
93318 +
93319 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93320 +{
93321 + pud_t *new = pud_alloc_one(mm, address);
93322 + if (!new)
93323 + return -ENOMEM;
93324 +
93325 + smp_wmb(); /* See comment in __pte_alloc */
93326 +
93327 + spin_lock(&mm->page_table_lock);
93328 + if (pgd_present(*pgd)) /* Another has populated it */
93329 + pud_free(mm, new);
93330 + else
93331 + pgd_populate_kernel(mm, pgd, new);
93332 + spin_unlock(&mm->page_table_lock);
93333 + return 0;
93334 +}
93335 #endif /* __PAGETABLE_PUD_FOLDED */
93336
93337 #ifndef __PAGETABLE_PMD_FOLDED
93338 @@ -4033,6 +4298,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93339 spin_unlock(&mm->page_table_lock);
93340 return 0;
93341 }
93342 +
93343 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93344 +{
93345 + pmd_t *new = pmd_alloc_one(mm, address);
93346 + if (!new)
93347 + return -ENOMEM;
93348 +
93349 + smp_wmb(); /* See comment in __pte_alloc */
93350 +
93351 + spin_lock(&mm->page_table_lock);
93352 +#ifndef __ARCH_HAS_4LEVEL_HACK
93353 + if (pud_present(*pud)) /* Another has populated it */
93354 + pmd_free(mm, new);
93355 + else
93356 + pud_populate_kernel(mm, pud, new);
93357 +#else
93358 + if (pgd_present(*pud)) /* Another has populated it */
93359 + pmd_free(mm, new);
93360 + else
93361 + pgd_populate_kernel(mm, pud, new);
93362 +#endif /* __ARCH_HAS_4LEVEL_HACK */
93363 + spin_unlock(&mm->page_table_lock);
93364 + return 0;
93365 +}
93366 #endif /* __PAGETABLE_PMD_FOLDED */
93367
93368 #if !defined(__HAVE_ARCH_GATE_AREA)
93369 @@ -4046,7 +4335,7 @@ static int __init gate_vma_init(void)
93370 gate_vma.vm_start = FIXADDR_USER_START;
93371 gate_vma.vm_end = FIXADDR_USER_END;
93372 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93373 - gate_vma.vm_page_prot = __P101;
93374 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93375
93376 return 0;
93377 }
93378 @@ -4180,8 +4469,8 @@ out:
93379 return ret;
93380 }
93381
93382 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93383 - void *buf, int len, int write)
93384 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93385 + void *buf, size_t len, int write)
93386 {
93387 resource_size_t phys_addr;
93388 unsigned long prot = 0;
93389 @@ -4207,8 +4496,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93390 * Access another process' address space as given in mm. If non-NULL, use the
93391 * given task for page fault accounting.
93392 */
93393 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93394 - unsigned long addr, void *buf, int len, int write)
93395 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93396 + unsigned long addr, void *buf, size_t len, int write)
93397 {
93398 struct vm_area_struct *vma;
93399 void *old_buf = buf;
93400 @@ -4216,7 +4505,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93401 down_read(&mm->mmap_sem);
93402 /* ignore errors, just check how much was successfully transferred */
93403 while (len) {
93404 - int bytes, ret, offset;
93405 + ssize_t bytes, ret, offset;
93406 void *maddr;
93407 struct page *page = NULL;
93408
93409 @@ -4275,8 +4564,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93410 *
93411 * The caller must hold a reference on @mm.
93412 */
93413 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93414 - void *buf, int len, int write)
93415 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93416 + void *buf, size_t len, int write)
93417 {
93418 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93419 }
93420 @@ -4286,11 +4575,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93421 * Source/target buffer must be kernel space,
93422 * Do not walk the page table directly, use get_user_pages
93423 */
93424 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
93425 - void *buf, int len, int write)
93426 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93427 + void *buf, size_t len, int write)
93428 {
93429 struct mm_struct *mm;
93430 - int ret;
93431 + ssize_t ret;
93432
93433 mm = get_task_mm(tsk);
93434 if (!mm)
93435 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93436 index 30cc47f8..c12ef34 100644
93437 --- a/mm/mempolicy.c
93438 +++ b/mm/mempolicy.c
93439 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93440 unsigned long vmstart;
93441 unsigned long vmend;
93442
93443 +#ifdef CONFIG_PAX_SEGMEXEC
93444 + struct vm_area_struct *vma_m;
93445 +#endif
93446 +
93447 vma = find_vma(mm, start);
93448 if (!vma || vma->vm_start > start)
93449 return -EFAULT;
93450 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93451 err = vma_replace_policy(vma, new_pol);
93452 if (err)
93453 goto out;
93454 +
93455 +#ifdef CONFIG_PAX_SEGMEXEC
93456 + vma_m = pax_find_mirror_vma(vma);
93457 + if (vma_m) {
93458 + err = vma_replace_policy(vma_m, new_pol);
93459 + if (err)
93460 + goto out;
93461 + }
93462 +#endif
93463 +
93464 }
93465
93466 out:
93467 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93468
93469 if (end < start)
93470 return -EINVAL;
93471 +
93472 +#ifdef CONFIG_PAX_SEGMEXEC
93473 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93474 + if (end > SEGMEXEC_TASK_SIZE)
93475 + return -EINVAL;
93476 + } else
93477 +#endif
93478 +
93479 + if (end > TASK_SIZE)
93480 + return -EINVAL;
93481 +
93482 if (end == start)
93483 return 0;
93484
93485 @@ -1453,8 +1478,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93486 */
93487 tcred = __task_cred(task);
93488 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93489 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93490 - !capable(CAP_SYS_NICE)) {
93491 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93492 rcu_read_unlock();
93493 err = -EPERM;
93494 goto out_put;
93495 @@ -1485,6 +1509,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93496 goto out;
93497 }
93498
93499 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93500 + if (mm != current->mm &&
93501 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93502 + mmput(mm);
93503 + err = -EPERM;
93504 + goto out;
93505 + }
93506 +#endif
93507 +
93508 err = do_migrate_pages(mm, old, new,
93509 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93510
93511 diff --git a/mm/migrate.c b/mm/migrate.c
93512 index bed4880..a493f67 100644
93513 --- a/mm/migrate.c
93514 +++ b/mm/migrate.c
93515 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93516 */
93517 tcred = __task_cred(task);
93518 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93519 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93520 - !capable(CAP_SYS_NICE)) {
93521 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93522 rcu_read_unlock();
93523 err = -EPERM;
93524 goto out;
93525 diff --git a/mm/mlock.c b/mm/mlock.c
93526 index b1eb536..091d154 100644
93527 --- a/mm/mlock.c
93528 +++ b/mm/mlock.c
93529 @@ -14,6 +14,7 @@
93530 #include <linux/pagevec.h>
93531 #include <linux/mempolicy.h>
93532 #include <linux/syscalls.h>
93533 +#include <linux/security.h>
93534 #include <linux/sched.h>
93535 #include <linux/export.h>
93536 #include <linux/rmap.h>
93537 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93538 {
93539 unsigned long nstart, end, tmp;
93540 struct vm_area_struct * vma, * prev;
93541 - int error;
93542 + int error = 0;
93543
93544 VM_BUG_ON(start & ~PAGE_MASK);
93545 VM_BUG_ON(len != PAGE_ALIGN(len));
93546 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93547 return -EINVAL;
93548 if (end == start)
93549 return 0;
93550 + if (end > TASK_SIZE)
93551 + return -EINVAL;
93552 +
93553 vma = find_vma(current->mm, start);
93554 if (!vma || vma->vm_start > start)
93555 return -ENOMEM;
93556 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93557 for (nstart = start ; ; ) {
93558 vm_flags_t newflags;
93559
93560 +#ifdef CONFIG_PAX_SEGMEXEC
93561 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93562 + break;
93563 +#endif
93564 +
93565 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93566
93567 newflags = vma->vm_flags & ~VM_LOCKED;
93568 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93569 locked += current->mm->locked_vm;
93570
93571 /* check against resource limits */
93572 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93573 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93574 error = do_mlock(start, len, 1);
93575
93576 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93577 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93578 vm_flags_t newflags;
93579
93580 +#ifdef CONFIG_PAX_SEGMEXEC
93581 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93582 + break;
93583 +#endif
93584 +
93585 newflags = vma->vm_flags & ~VM_LOCKED;
93586 if (flags & MCL_CURRENT)
93587 newflags |= VM_LOCKED;
93588 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93589 lock_limit >>= PAGE_SHIFT;
93590
93591 ret = -ENOMEM;
93592 +
93593 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93594 +
93595 down_write(&current->mm->mmap_sem);
93596 -
93597 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93598 capable(CAP_IPC_LOCK))
93599 ret = do_mlockall(flags);
93600 diff --git a/mm/mmap.c b/mm/mmap.c
93601 index b1202cf..ee487f8 100644
93602 --- a/mm/mmap.c
93603 +++ b/mm/mmap.c
93604 @@ -37,6 +37,7 @@
93605 #include <linux/sched/sysctl.h>
93606 #include <linux/notifier.h>
93607 #include <linux/memory.h>
93608 +#include <linux/random.h>
93609
93610 #include <asm/uaccess.h>
93611 #include <asm/cacheflush.h>
93612 @@ -53,6 +54,16 @@
93613 #define arch_rebalance_pgtables(addr, len) (addr)
93614 #endif
93615
93616 +static inline void verify_mm_writelocked(struct mm_struct *mm)
93617 +{
93618 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93619 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93620 + up_read(&mm->mmap_sem);
93621 + BUG();
93622 + }
93623 +#endif
93624 +}
93625 +
93626 static void unmap_region(struct mm_struct *mm,
93627 struct vm_area_struct *vma, struct vm_area_struct *prev,
93628 unsigned long start, unsigned long end);
93629 @@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
93630 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93631 *
93632 */
93633 -pgprot_t protection_map[16] = {
93634 +pgprot_t protection_map[16] __read_only = {
93635 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93636 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93637 };
93638
93639 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
93640 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93641 {
93642 - return __pgprot(pgprot_val(protection_map[vm_flags &
93643 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93644 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93645 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93646 +
93647 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93648 + if (!(__supported_pte_mask & _PAGE_NX) &&
93649 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93650 + (vm_flags & (VM_READ | VM_WRITE)))
93651 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93652 +#endif
93653 +
93654 + return prot;
93655 }
93656 EXPORT_SYMBOL(vm_get_page_prot);
93657
93658 @@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93659 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93660 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93661 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93662 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93663 /*
93664 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93665 * other variables. It can be updated by several CPUs frequently.
93666 @@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93667 struct vm_area_struct *next = vma->vm_next;
93668
93669 might_sleep();
93670 + BUG_ON(vma->vm_mirror);
93671 if (vma->vm_ops && vma->vm_ops->close)
93672 vma->vm_ops->close(vma);
93673 if (vma->vm_file)
93674 @@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93675 * not page aligned -Ram Gupta
93676 */
93677 rlim = rlimit(RLIMIT_DATA);
93678 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93679 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93680 (mm->end_data - mm->start_data) > rlim)
93681 goto out;
93682 @@ -942,6 +965,12 @@ static int
93683 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93684 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93685 {
93686 +
93687 +#ifdef CONFIG_PAX_SEGMEXEC
93688 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93689 + return 0;
93690 +#endif
93691 +
93692 if (is_mergeable_vma(vma, file, vm_flags) &&
93693 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93694 if (vma->vm_pgoff == vm_pgoff)
93695 @@ -961,6 +990,12 @@ static int
93696 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93697 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93698 {
93699 +
93700 +#ifdef CONFIG_PAX_SEGMEXEC
93701 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93702 + return 0;
93703 +#endif
93704 +
93705 if (is_mergeable_vma(vma, file, vm_flags) &&
93706 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93707 pgoff_t vm_pglen;
93708 @@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93709 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93710 struct vm_area_struct *prev, unsigned long addr,
93711 unsigned long end, unsigned long vm_flags,
93712 - struct anon_vma *anon_vma, struct file *file,
93713 + struct anon_vma *anon_vma, struct file *file,
93714 pgoff_t pgoff, struct mempolicy *policy)
93715 {
93716 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93717 struct vm_area_struct *area, *next;
93718 int err;
93719
93720 +#ifdef CONFIG_PAX_SEGMEXEC
93721 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93722 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93723 +
93724 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93725 +#endif
93726 +
93727 /*
93728 * We later require that vma->vm_flags == vm_flags,
93729 * so this tests vma->vm_flags & VM_SPECIAL, too.
93730 @@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93731 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93732 next = next->vm_next;
93733
93734 +#ifdef CONFIG_PAX_SEGMEXEC
93735 + if (prev)
93736 + prev_m = pax_find_mirror_vma(prev);
93737 + if (area)
93738 + area_m = pax_find_mirror_vma(area);
93739 + if (next)
93740 + next_m = pax_find_mirror_vma(next);
93741 +#endif
93742 +
93743 /*
93744 * Can it merge with the predecessor?
93745 */
93746 @@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93747 /* cases 1, 6 */
93748 err = vma_adjust(prev, prev->vm_start,
93749 next->vm_end, prev->vm_pgoff, NULL);
93750 - } else /* cases 2, 5, 7 */
93751 +
93752 +#ifdef CONFIG_PAX_SEGMEXEC
93753 + if (!err && prev_m)
93754 + err = vma_adjust(prev_m, prev_m->vm_start,
93755 + next_m->vm_end, prev_m->vm_pgoff, NULL);
93756 +#endif
93757 +
93758 + } else { /* cases 2, 5, 7 */
93759 err = vma_adjust(prev, prev->vm_start,
93760 end, prev->vm_pgoff, NULL);
93761 +
93762 +#ifdef CONFIG_PAX_SEGMEXEC
93763 + if (!err && prev_m)
93764 + err = vma_adjust(prev_m, prev_m->vm_start,
93765 + end_m, prev_m->vm_pgoff, NULL);
93766 +#endif
93767 +
93768 + }
93769 if (err)
93770 return NULL;
93771 khugepaged_enter_vma_merge(prev);
93772 @@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93773 mpol_equal(policy, vma_policy(next)) &&
93774 can_vma_merge_before(next, vm_flags,
93775 anon_vma, file, pgoff+pglen)) {
93776 - if (prev && addr < prev->vm_end) /* case 4 */
93777 + if (prev && addr < prev->vm_end) { /* case 4 */
93778 err = vma_adjust(prev, prev->vm_start,
93779 addr, prev->vm_pgoff, NULL);
93780 - else /* cases 3, 8 */
93781 +
93782 +#ifdef CONFIG_PAX_SEGMEXEC
93783 + if (!err && prev_m)
93784 + err = vma_adjust(prev_m, prev_m->vm_start,
93785 + addr_m, prev_m->vm_pgoff, NULL);
93786 +#endif
93787 +
93788 + } else { /* cases 3, 8 */
93789 err = vma_adjust(area, addr, next->vm_end,
93790 next->vm_pgoff - pglen, NULL);
93791 +
93792 +#ifdef CONFIG_PAX_SEGMEXEC
93793 + if (!err && area_m)
93794 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
93795 + next_m->vm_pgoff - pglen, NULL);
93796 +#endif
93797 +
93798 + }
93799 if (err)
93800 return NULL;
93801 khugepaged_enter_vma_merge(area);
93802 @@ -1174,8 +1255,10 @@ none:
93803 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93804 struct file *file, long pages)
93805 {
93806 - const unsigned long stack_flags
93807 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93808 +
93809 +#ifdef CONFIG_PAX_RANDMMAP
93810 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93811 +#endif
93812
93813 mm->total_vm += pages;
93814
93815 @@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93816 mm->shared_vm += pages;
93817 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93818 mm->exec_vm += pages;
93819 - } else if (flags & stack_flags)
93820 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93821 mm->stack_vm += pages;
93822 }
93823 #endif /* CONFIG_PROC_FS */
93824 @@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93825 locked += mm->locked_vm;
93826 lock_limit = rlimit(RLIMIT_MEMLOCK);
93827 lock_limit >>= PAGE_SHIFT;
93828 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93829 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93830 return -EAGAIN;
93831 }
93832 @@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93833 * (the exception is when the underlying filesystem is noexec
93834 * mounted, in which case we dont add PROT_EXEC.)
93835 */
93836 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93837 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93838 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93839 prot |= PROT_EXEC;
93840
93841 @@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93842 /* Obtain the address to map to. we verify (or select) it and ensure
93843 * that it represents a valid section of the address space.
93844 */
93845 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
93846 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93847 if (addr & ~PAGE_MASK)
93848 return addr;
93849
93850 @@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93851 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93852 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93853
93854 +#ifdef CONFIG_PAX_MPROTECT
93855 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93856 +
93857 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93858 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93859 + mm->binfmt->handle_mmap)
93860 + mm->binfmt->handle_mmap(file);
93861 +#endif
93862 +
93863 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93864 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93865 + gr_log_rwxmmap(file);
93866 +
93867 +#ifdef CONFIG_PAX_EMUPLT
93868 + vm_flags &= ~VM_EXEC;
93869 +#else
93870 + return -EPERM;
93871 +#endif
93872 +
93873 + }
93874 +
93875 + if (!(vm_flags & VM_EXEC))
93876 + vm_flags &= ~VM_MAYEXEC;
93877 +#else
93878 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93879 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93880 +#endif
93881 + else
93882 + vm_flags &= ~VM_MAYWRITE;
93883 + }
93884 +#endif
93885 +
93886 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93887 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93888 + vm_flags &= ~VM_PAGEEXEC;
93889 +#endif
93890 +
93891 if (flags & MAP_LOCKED)
93892 if (!can_do_mlock())
93893 return -EPERM;
93894 @@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93895 vm_flags |= VM_NORESERVE;
93896 }
93897
93898 + if (!gr_acl_handle_mmap(file, prot))
93899 + return -EACCES;
93900 +
93901 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93902 if (!IS_ERR_VALUE(addr) &&
93903 ((vm_flags & VM_LOCKED) ||
93904 @@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93905 vm_flags_t vm_flags = vma->vm_flags;
93906
93907 /* If it was private or non-writable, the write bit is already clear */
93908 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93909 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93910 return 0;
93911
93912 /* The backer wishes to know when pages are first written to? */
93913 @@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93914 struct rb_node **rb_link, *rb_parent;
93915 unsigned long charged = 0;
93916
93917 +#ifdef CONFIG_PAX_SEGMEXEC
93918 + struct vm_area_struct *vma_m = NULL;
93919 +#endif
93920 +
93921 + /*
93922 + * mm->mmap_sem is required to protect against another thread
93923 + * changing the mappings in case we sleep.
93924 + */
93925 + verify_mm_writelocked(mm);
93926 +
93927 /* Check against address space limit. */
93928 +
93929 +#ifdef CONFIG_PAX_RANDMMAP
93930 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93931 +#endif
93932 +
93933 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93934 unsigned long nr_pages;
93935
93936 @@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93937
93938 /* Clear old maps */
93939 error = -ENOMEM;
93940 -munmap_back:
93941 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93942 if (do_munmap(mm, addr, len))
93943 return -ENOMEM;
93944 - goto munmap_back;
93945 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93946 }
93947
93948 /*
93949 @@ -1556,6 +1694,16 @@ munmap_back:
93950 goto unacct_error;
93951 }
93952
93953 +#ifdef CONFIG_PAX_SEGMEXEC
93954 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93955 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93956 + if (!vma_m) {
93957 + error = -ENOMEM;
93958 + goto free_vma;
93959 + }
93960 + }
93961 +#endif
93962 +
93963 vma->vm_mm = mm;
93964 vma->vm_start = addr;
93965 vma->vm_end = addr + len;
93966 @@ -1575,6 +1723,13 @@ munmap_back:
93967 if (error)
93968 goto unmap_and_free_vma;
93969
93970 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93971 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93972 + vma->vm_flags |= VM_PAGEEXEC;
93973 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93974 + }
93975 +#endif
93976 +
93977 /* Can addr have changed??
93978 *
93979 * Answer: Yes, several device drivers can do it in their
93980 @@ -1608,6 +1763,12 @@ munmap_back:
93981 }
93982
93983 vma_link(mm, vma, prev, rb_link, rb_parent);
93984 +
93985 +#ifdef CONFIG_PAX_SEGMEXEC
93986 + if (vma_m)
93987 + BUG_ON(pax_mirror_vma(vma_m, vma));
93988 +#endif
93989 +
93990 /* Once vma denies write, undo our temporary denial count */
93991 if (vm_flags & VM_DENYWRITE)
93992 allow_write_access(file);
93993 @@ -1616,6 +1777,7 @@ out:
93994 perf_event_mmap(vma);
93995
93996 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93997 + track_exec_limit(mm, addr, addr + len, vm_flags);
93998 if (vm_flags & VM_LOCKED) {
93999 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94000 vma == get_gate_vma(current->mm)))
94001 @@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94002 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94003 charged = 0;
94004 free_vma:
94005 +
94006 +#ifdef CONFIG_PAX_SEGMEXEC
94007 + if (vma_m)
94008 + kmem_cache_free(vm_area_cachep, vma_m);
94009 +#endif
94010 +
94011 kmem_cache_free(vm_area_cachep, vma);
94012 unacct_error:
94013 if (charged)
94014 @@ -1655,7 +1823,63 @@ unacct_error:
94015 return error;
94016 }
94017
94018 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94019 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94020 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94021 +{
94022 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94023 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94024 +
94025 + return 0;
94026 +}
94027 +#endif
94028 +
94029 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94030 +{
94031 + if (!vma) {
94032 +#ifdef CONFIG_STACK_GROWSUP
94033 + if (addr > sysctl_heap_stack_gap)
94034 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94035 + else
94036 + vma = find_vma(current->mm, 0);
94037 + if (vma && (vma->vm_flags & VM_GROWSUP))
94038 + return false;
94039 +#endif
94040 + return true;
94041 + }
94042 +
94043 + if (addr + len > vma->vm_start)
94044 + return false;
94045 +
94046 + if (vma->vm_flags & VM_GROWSDOWN)
94047 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94048 +#ifdef CONFIG_STACK_GROWSUP
94049 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94050 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94051 +#endif
94052 + else if (offset)
94053 + return offset <= vma->vm_start - addr - len;
94054 +
94055 + return true;
94056 +}
94057 +
94058 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94059 +{
94060 + if (vma->vm_start < len)
94061 + return -ENOMEM;
94062 +
94063 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94064 + if (offset <= vma->vm_start - len)
94065 + return vma->vm_start - len - offset;
94066 + else
94067 + return -ENOMEM;
94068 + }
94069 +
94070 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94071 + return vma->vm_start - len - sysctl_heap_stack_gap;
94072 + return -ENOMEM;
94073 +}
94074 +
94075 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94076 {
94077 /*
94078 * We implement the search by looking for an rbtree node that
94079 @@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94080 }
94081 }
94082
94083 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94084 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94085 check_current:
94086 /* Check if current node has a suitable gap */
94087 if (gap_start > high_limit)
94088 return -ENOMEM;
94089 +
94090 + if (gap_end - gap_start > info->threadstack_offset)
94091 + gap_start += info->threadstack_offset;
94092 + else
94093 + gap_start = gap_end;
94094 +
94095 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94096 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94097 + gap_start += sysctl_heap_stack_gap;
94098 + else
94099 + gap_start = gap_end;
94100 + }
94101 + if (vma->vm_flags & VM_GROWSDOWN) {
94102 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94103 + gap_end -= sysctl_heap_stack_gap;
94104 + else
94105 + gap_end = gap_start;
94106 + }
94107 if (gap_end >= low_limit && gap_end - gap_start >= length)
94108 goto found;
94109
94110 @@ -1757,7 +1999,7 @@ found:
94111 return gap_start;
94112 }
94113
94114 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94115 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94116 {
94117 struct mm_struct *mm = current->mm;
94118 struct vm_area_struct *vma;
94119 @@ -1811,6 +2053,24 @@ check_current:
94120 gap_end = vma->vm_start;
94121 if (gap_end < low_limit)
94122 return -ENOMEM;
94123 +
94124 + if (gap_end - gap_start > info->threadstack_offset)
94125 + gap_end -= info->threadstack_offset;
94126 + else
94127 + gap_end = gap_start;
94128 +
94129 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94130 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94131 + gap_start += sysctl_heap_stack_gap;
94132 + else
94133 + gap_start = gap_end;
94134 + }
94135 + if (vma->vm_flags & VM_GROWSDOWN) {
94136 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94137 + gap_end -= sysctl_heap_stack_gap;
94138 + else
94139 + gap_end = gap_start;
94140 + }
94141 if (gap_start <= high_limit && gap_end - gap_start >= length)
94142 goto found;
94143
94144 @@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94145 struct mm_struct *mm = current->mm;
94146 struct vm_area_struct *vma;
94147 struct vm_unmapped_area_info info;
94148 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94149
94150 if (len > TASK_SIZE - mmap_min_addr)
94151 return -ENOMEM;
94152 @@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94153 if (flags & MAP_FIXED)
94154 return addr;
94155
94156 +#ifdef CONFIG_PAX_RANDMMAP
94157 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94158 +#endif
94159 +
94160 if (addr) {
94161 addr = PAGE_ALIGN(addr);
94162 vma = find_vma(mm, addr);
94163 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94164 - (!vma || addr + len <= vma->vm_start))
94165 + check_heap_stack_gap(vma, addr, len, offset))
94166 return addr;
94167 }
94168
94169 @@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94170 info.low_limit = mm->mmap_base;
94171 info.high_limit = TASK_SIZE;
94172 info.align_mask = 0;
94173 + info.threadstack_offset = offset;
94174 return vm_unmapped_area(&info);
94175 }
94176 #endif
94177 @@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94178 struct mm_struct *mm = current->mm;
94179 unsigned long addr = addr0;
94180 struct vm_unmapped_area_info info;
94181 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94182
94183 /* requested length too big for entire address space */
94184 if (len > TASK_SIZE - mmap_min_addr)
94185 @@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94186 if (flags & MAP_FIXED)
94187 return addr;
94188
94189 +#ifdef CONFIG_PAX_RANDMMAP
94190 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94191 +#endif
94192 +
94193 /* requesting a specific address */
94194 if (addr) {
94195 addr = PAGE_ALIGN(addr);
94196 vma = find_vma(mm, addr);
94197 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94198 - (!vma || addr + len <= vma->vm_start))
94199 + check_heap_stack_gap(vma, addr, len, offset))
94200 return addr;
94201 }
94202
94203 @@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94204 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94205 info.high_limit = mm->mmap_base;
94206 info.align_mask = 0;
94207 + info.threadstack_offset = offset;
94208 addr = vm_unmapped_area(&info);
94209
94210 /*
94211 @@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94212 VM_BUG_ON(addr != -ENOMEM);
94213 info.flags = 0;
94214 info.low_limit = TASK_UNMAPPED_BASE;
94215 +
94216 +#ifdef CONFIG_PAX_RANDMMAP
94217 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94218 + info.low_limit += mm->delta_mmap;
94219 +#endif
94220 +
94221 info.high_limit = TASK_SIZE;
94222 addr = vm_unmapped_area(&info);
94223 }
94224 @@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94225 return vma;
94226 }
94227
94228 +#ifdef CONFIG_PAX_SEGMEXEC
94229 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94230 +{
94231 + struct vm_area_struct *vma_m;
94232 +
94233 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94234 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94235 + BUG_ON(vma->vm_mirror);
94236 + return NULL;
94237 + }
94238 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94239 + vma_m = vma->vm_mirror;
94240 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94241 + BUG_ON(vma->vm_file != vma_m->vm_file);
94242 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94243 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94244 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94245 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94246 + return vma_m;
94247 +}
94248 +#endif
94249 +
94250 /*
94251 * Verify that the stack growth is acceptable and
94252 * update accounting. This is shared with both the
94253 @@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94254 return -ENOMEM;
94255
94256 /* Stack limit test */
94257 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94258 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94259 return -ENOMEM;
94260
94261 @@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94262 locked = mm->locked_vm + grow;
94263 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94264 limit >>= PAGE_SHIFT;
94265 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94266 if (locked > limit && !capable(CAP_IPC_LOCK))
94267 return -ENOMEM;
94268 }
94269 @@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94270 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94271 * vma is the last one with address > vma->vm_end. Have to extend vma.
94272 */
94273 +#ifndef CONFIG_IA64
94274 +static
94275 +#endif
94276 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94277 {
94278 int error;
94279 + bool locknext;
94280
94281 if (!(vma->vm_flags & VM_GROWSUP))
94282 return -EFAULT;
94283
94284 + /* Also guard against wrapping around to address 0. */
94285 + if (address < PAGE_ALIGN(address+1))
94286 + address = PAGE_ALIGN(address+1);
94287 + else
94288 + return -ENOMEM;
94289 +
94290 /*
94291 * We must make sure the anon_vma is allocated
94292 * so that the anon_vma locking is not a noop.
94293 */
94294 if (unlikely(anon_vma_prepare(vma)))
94295 return -ENOMEM;
94296 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94297 + if (locknext && anon_vma_prepare(vma->vm_next))
94298 + return -ENOMEM;
94299 vma_lock_anon_vma(vma);
94300 + if (locknext)
94301 + vma_lock_anon_vma(vma->vm_next);
94302
94303 /*
94304 * vma->vm_start/vm_end cannot change under us because the caller
94305 * is required to hold the mmap_sem in read mode. We need the
94306 - * anon_vma lock to serialize against concurrent expand_stacks.
94307 - * Also guard against wrapping around to address 0.
94308 + * anon_vma locks to serialize against concurrent expand_stacks
94309 + * and expand_upwards.
94310 */
94311 - if (address < PAGE_ALIGN(address+4))
94312 - address = PAGE_ALIGN(address+4);
94313 - else {
94314 - vma_unlock_anon_vma(vma);
94315 - return -ENOMEM;
94316 - }
94317 error = 0;
94318
94319 /* Somebody else might have raced and expanded it already */
94320 - if (address > vma->vm_end) {
94321 + 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)
94322 + error = -ENOMEM;
94323 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94324 unsigned long size, grow;
94325
94326 size = address - vma->vm_start;
94327 @@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94328 }
94329 }
94330 }
94331 + if (locknext)
94332 + vma_unlock_anon_vma(vma->vm_next);
94333 vma_unlock_anon_vma(vma);
94334 khugepaged_enter_vma_merge(vma);
94335 validate_mm(vma->vm_mm);
94336 @@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94337 unsigned long address)
94338 {
94339 int error;
94340 + bool lockprev = false;
94341 + struct vm_area_struct *prev;
94342
94343 /*
94344 * We must make sure the anon_vma is allocated
94345 @@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94346 if (error)
94347 return error;
94348
94349 + prev = vma->vm_prev;
94350 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94351 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94352 +#endif
94353 + if (lockprev && anon_vma_prepare(prev))
94354 + return -ENOMEM;
94355 + if (lockprev)
94356 + vma_lock_anon_vma(prev);
94357 +
94358 vma_lock_anon_vma(vma);
94359
94360 /*
94361 @@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94362 */
94363
94364 /* Somebody else might have raced and expanded it already */
94365 - if (address < vma->vm_start) {
94366 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94367 + error = -ENOMEM;
94368 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94369 unsigned long size, grow;
94370
94371 +#ifdef CONFIG_PAX_SEGMEXEC
94372 + struct vm_area_struct *vma_m;
94373 +
94374 + vma_m = pax_find_mirror_vma(vma);
94375 +#endif
94376 +
94377 size = vma->vm_end - address;
94378 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94379
94380 @@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94381 vma->vm_pgoff -= grow;
94382 anon_vma_interval_tree_post_update_vma(vma);
94383 vma_gap_update(vma);
94384 +
94385 +#ifdef CONFIG_PAX_SEGMEXEC
94386 + if (vma_m) {
94387 + anon_vma_interval_tree_pre_update_vma(vma_m);
94388 + vma_m->vm_start -= grow << PAGE_SHIFT;
94389 + vma_m->vm_pgoff -= grow;
94390 + anon_vma_interval_tree_post_update_vma(vma_m);
94391 + vma_gap_update(vma_m);
94392 + }
94393 +#endif
94394 +
94395 spin_unlock(&vma->vm_mm->page_table_lock);
94396
94397 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94398 perf_event_mmap(vma);
94399 }
94400 }
94401 }
94402 vma_unlock_anon_vma(vma);
94403 + if (lockprev)
94404 + vma_unlock_anon_vma(prev);
94405 khugepaged_enter_vma_merge(vma);
94406 validate_mm(vma->vm_mm);
94407 return error;
94408 @@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94409 do {
94410 long nrpages = vma_pages(vma);
94411
94412 +#ifdef CONFIG_PAX_SEGMEXEC
94413 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94414 + vma = remove_vma(vma);
94415 + continue;
94416 + }
94417 +#endif
94418 +
94419 if (vma->vm_flags & VM_ACCOUNT)
94420 nr_accounted += nrpages;
94421 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94422 @@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94423 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94424 vma->vm_prev = NULL;
94425 do {
94426 +
94427 +#ifdef CONFIG_PAX_SEGMEXEC
94428 + if (vma->vm_mirror) {
94429 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94430 + vma->vm_mirror->vm_mirror = NULL;
94431 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
94432 + vma->vm_mirror = NULL;
94433 + }
94434 +#endif
94435 +
94436 vma_rb_erase(vma, &mm->mm_rb);
94437 mm->map_count--;
94438 tail_vma = vma;
94439 @@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94440 struct vm_area_struct *new;
94441 int err = -ENOMEM;
94442
94443 +#ifdef CONFIG_PAX_SEGMEXEC
94444 + struct vm_area_struct *vma_m, *new_m = NULL;
94445 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94446 +#endif
94447 +
94448 if (is_vm_hugetlb_page(vma) && (addr &
94449 ~(huge_page_mask(hstate_vma(vma)))))
94450 return -EINVAL;
94451
94452 +#ifdef CONFIG_PAX_SEGMEXEC
94453 + vma_m = pax_find_mirror_vma(vma);
94454 +#endif
94455 +
94456 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94457 if (!new)
94458 goto out_err;
94459
94460 +#ifdef CONFIG_PAX_SEGMEXEC
94461 + if (vma_m) {
94462 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94463 + if (!new_m) {
94464 + kmem_cache_free(vm_area_cachep, new);
94465 + goto out_err;
94466 + }
94467 + }
94468 +#endif
94469 +
94470 /* most fields are the same, copy all, and then fixup */
94471 *new = *vma;
94472
94473 @@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94474 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94475 }
94476
94477 +#ifdef CONFIG_PAX_SEGMEXEC
94478 + if (vma_m) {
94479 + *new_m = *vma_m;
94480 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
94481 + new_m->vm_mirror = new;
94482 + new->vm_mirror = new_m;
94483 +
94484 + if (new_below)
94485 + new_m->vm_end = addr_m;
94486 + else {
94487 + new_m->vm_start = addr_m;
94488 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94489 + }
94490 + }
94491 +#endif
94492 +
94493 err = vma_dup_policy(vma, new);
94494 if (err)
94495 goto out_free_vma;
94496 @@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94497 else
94498 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94499
94500 +#ifdef CONFIG_PAX_SEGMEXEC
94501 + if (!err && vma_m) {
94502 + struct mempolicy *pol = vma_policy(new);
94503 +
94504 + if (anon_vma_clone(new_m, vma_m))
94505 + goto out_free_mpol;
94506 +
94507 + mpol_get(pol);
94508 + set_vma_policy(new_m, pol);
94509 +
94510 + if (new_m->vm_file)
94511 + get_file(new_m->vm_file);
94512 +
94513 + if (new_m->vm_ops && new_m->vm_ops->open)
94514 + new_m->vm_ops->open(new_m);
94515 +
94516 + if (new_below)
94517 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94518 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94519 + else
94520 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94521 +
94522 + if (err) {
94523 + if (new_m->vm_ops && new_m->vm_ops->close)
94524 + new_m->vm_ops->close(new_m);
94525 + if (new_m->vm_file)
94526 + fput(new_m->vm_file);
94527 + mpol_put(pol);
94528 + }
94529 + }
94530 +#endif
94531 +
94532 /* Success. */
94533 if (!err)
94534 return 0;
94535 @@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94536 new->vm_ops->close(new);
94537 if (new->vm_file)
94538 fput(new->vm_file);
94539 - unlink_anon_vmas(new);
94540 out_free_mpol:
94541 mpol_put(vma_policy(new));
94542 out_free_vma:
94543 +
94544 +#ifdef CONFIG_PAX_SEGMEXEC
94545 + if (new_m) {
94546 + unlink_anon_vmas(new_m);
94547 + kmem_cache_free(vm_area_cachep, new_m);
94548 + }
94549 +#endif
94550 +
94551 + unlink_anon_vmas(new);
94552 kmem_cache_free(vm_area_cachep, new);
94553 out_err:
94554 return err;
94555 @@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94556 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94557 unsigned long addr, int new_below)
94558 {
94559 +
94560 +#ifdef CONFIG_PAX_SEGMEXEC
94561 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94562 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94563 + if (mm->map_count >= sysctl_max_map_count-1)
94564 + return -ENOMEM;
94565 + } else
94566 +#endif
94567 +
94568 if (mm->map_count >= sysctl_max_map_count)
94569 return -ENOMEM;
94570
94571 @@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94572 * work. This now handles partial unmappings.
94573 * Jeremy Fitzhardinge <jeremy@goop.org>
94574 */
94575 +#ifdef CONFIG_PAX_SEGMEXEC
94576 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94577 {
94578 + int ret = __do_munmap(mm, start, len);
94579 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94580 + return ret;
94581 +
94582 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94583 +}
94584 +
94585 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94586 +#else
94587 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94588 +#endif
94589 +{
94590 unsigned long end;
94591 struct vm_area_struct *vma, *prev, *last;
94592
94593 + /*
94594 + * mm->mmap_sem is required to protect against another thread
94595 + * changing the mappings in case we sleep.
94596 + */
94597 + verify_mm_writelocked(mm);
94598 +
94599 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94600 return -EINVAL;
94601
94602 @@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94603 /* Fix up all other VM information */
94604 remove_vma_list(mm, vma);
94605
94606 + track_exec_limit(mm, start, end, 0UL);
94607 +
94608 return 0;
94609 }
94610
94611 @@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94612 int ret;
94613 struct mm_struct *mm = current->mm;
94614
94615 +
94616 +#ifdef CONFIG_PAX_SEGMEXEC
94617 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94618 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94619 + return -EINVAL;
94620 +#endif
94621 +
94622 down_write(&mm->mmap_sem);
94623 ret = do_munmap(mm, start, len);
94624 up_write(&mm->mmap_sem);
94625 @@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94626 return vm_munmap(addr, len);
94627 }
94628
94629 -static inline void verify_mm_writelocked(struct mm_struct *mm)
94630 -{
94631 -#ifdef CONFIG_DEBUG_VM
94632 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94633 - WARN_ON(1);
94634 - up_read(&mm->mmap_sem);
94635 - }
94636 -#endif
94637 -}
94638 -
94639 /*
94640 * this is really a simplified "do_mmap". it only handles
94641 * anonymous maps. eventually we may be able to do some
94642 @@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94643 struct rb_node ** rb_link, * rb_parent;
94644 pgoff_t pgoff = addr >> PAGE_SHIFT;
94645 int error;
94646 + unsigned long charged;
94647
94648 len = PAGE_ALIGN(len);
94649 if (!len)
94650 @@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94651
94652 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94653
94654 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94655 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94656 + flags &= ~VM_EXEC;
94657 +
94658 +#ifdef CONFIG_PAX_MPROTECT
94659 + if (mm->pax_flags & MF_PAX_MPROTECT)
94660 + flags &= ~VM_MAYEXEC;
94661 +#endif
94662 +
94663 + }
94664 +#endif
94665 +
94666 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94667 if (error & ~PAGE_MASK)
94668 return error;
94669
94670 + charged = len >> PAGE_SHIFT;
94671 +
94672 error = mlock_future_check(mm, mm->def_flags, len);
94673 if (error)
94674 return error;
94675 @@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94676 /*
94677 * Clear old maps. this also does some error checking for us
94678 */
94679 - munmap_back:
94680 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94681 if (do_munmap(mm, addr, len))
94682 return -ENOMEM;
94683 - goto munmap_back;
94684 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94685 }
94686
94687 /* Check against address space limits *after* clearing old maps... */
94688 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94689 + if (!may_expand_vm(mm, charged))
94690 return -ENOMEM;
94691
94692 if (mm->map_count > sysctl_max_map_count)
94693 return -ENOMEM;
94694
94695 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94696 + if (security_vm_enough_memory_mm(mm, charged))
94697 return -ENOMEM;
94698
94699 /* Can we just expand an old private anonymous mapping? */
94700 @@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94701 */
94702 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94703 if (!vma) {
94704 - vm_unacct_memory(len >> PAGE_SHIFT);
94705 + vm_unacct_memory(charged);
94706 return -ENOMEM;
94707 }
94708
94709 @@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94710 vma_link(mm, vma, prev, rb_link, rb_parent);
94711 out:
94712 perf_event_mmap(vma);
94713 - mm->total_vm += len >> PAGE_SHIFT;
94714 + mm->total_vm += charged;
94715 if (flags & VM_LOCKED)
94716 - mm->locked_vm += (len >> PAGE_SHIFT);
94717 + mm->locked_vm += charged;
94718 vma->vm_flags |= VM_SOFTDIRTY;
94719 + track_exec_limit(mm, addr, addr + len, flags);
94720 return addr;
94721 }
94722
94723 @@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
94724 while (vma) {
94725 if (vma->vm_flags & VM_ACCOUNT)
94726 nr_accounted += vma_pages(vma);
94727 + vma->vm_mirror = NULL;
94728 vma = remove_vma(vma);
94729 }
94730 vm_unacct_memory(nr_accounted);
94731 @@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94732 struct vm_area_struct *prev;
94733 struct rb_node **rb_link, *rb_parent;
94734
94735 +#ifdef CONFIG_PAX_SEGMEXEC
94736 + struct vm_area_struct *vma_m = NULL;
94737 +#endif
94738 +
94739 + if (security_mmap_addr(vma->vm_start))
94740 + return -EPERM;
94741 +
94742 /*
94743 * The vm_pgoff of a purely anonymous vma should be irrelevant
94744 * until its first write fault, when page's anon_vma and index
94745 @@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94746 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94747 return -ENOMEM;
94748
94749 +#ifdef CONFIG_PAX_SEGMEXEC
94750 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94751 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94752 + if (!vma_m)
94753 + return -ENOMEM;
94754 + }
94755 +#endif
94756 +
94757 vma_link(mm, vma, prev, rb_link, rb_parent);
94758 +
94759 +#ifdef CONFIG_PAX_SEGMEXEC
94760 + if (vma_m)
94761 + BUG_ON(pax_mirror_vma(vma_m, vma));
94762 +#endif
94763 +
94764 return 0;
94765 }
94766
94767 @@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94768 struct rb_node **rb_link, *rb_parent;
94769 bool faulted_in_anon_vma = true;
94770
94771 + BUG_ON(vma->vm_mirror);
94772 +
94773 /*
94774 * If anonymous vma has not yet been faulted, update new pgoff
94775 * to match new location, to increase its chance of merging.
94776 @@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94777 return NULL;
94778 }
94779
94780 +#ifdef CONFIG_PAX_SEGMEXEC
94781 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94782 +{
94783 + struct vm_area_struct *prev_m;
94784 + struct rb_node **rb_link_m, *rb_parent_m;
94785 + struct mempolicy *pol_m;
94786 +
94787 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94788 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94789 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94790 + *vma_m = *vma;
94791 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94792 + if (anon_vma_clone(vma_m, vma))
94793 + return -ENOMEM;
94794 + pol_m = vma_policy(vma_m);
94795 + mpol_get(pol_m);
94796 + set_vma_policy(vma_m, pol_m);
94797 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94798 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94799 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94800 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94801 + if (vma_m->vm_file)
94802 + get_file(vma_m->vm_file);
94803 + if (vma_m->vm_ops && vma_m->vm_ops->open)
94804 + vma_m->vm_ops->open(vma_m);
94805 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94806 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94807 + vma_m->vm_mirror = vma;
94808 + vma->vm_mirror = vma_m;
94809 + return 0;
94810 +}
94811 +#endif
94812 +
94813 /*
94814 * Return true if the calling process may expand its vm space by the passed
94815 * number of pages
94816 @@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94817
94818 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94819
94820 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94821 if (cur + npages > lim)
94822 return 0;
94823 return 1;
94824 @@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
94825 vma->vm_start = addr;
94826 vma->vm_end = addr + len;
94827
94828 +#ifdef CONFIG_PAX_MPROTECT
94829 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94830 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94831 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94832 + return ERR_PTR(-EPERM);
94833 + if (!(vm_flags & VM_EXEC))
94834 + vm_flags &= ~VM_MAYEXEC;
94835 +#else
94836 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94837 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94838 +#endif
94839 + else
94840 + vm_flags &= ~VM_MAYWRITE;
94841 + }
94842 +#endif
94843 +
94844 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94845 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94846
94847 diff --git a/mm/mprotect.c b/mm/mprotect.c
94848 index c43d557..0b7ccd2 100644
94849 --- a/mm/mprotect.c
94850 +++ b/mm/mprotect.c
94851 @@ -24,10 +24,18 @@
94852 #include <linux/migrate.h>
94853 #include <linux/perf_event.h>
94854 #include <linux/ksm.h>
94855 +#include <linux/sched/sysctl.h>
94856 +
94857 +#ifdef CONFIG_PAX_MPROTECT
94858 +#include <linux/elf.h>
94859 +#include <linux/binfmts.h>
94860 +#endif
94861 +
94862 #include <asm/uaccess.h>
94863 #include <asm/pgtable.h>
94864 #include <asm/cacheflush.h>
94865 #include <asm/tlbflush.h>
94866 +#include <asm/mmu_context.h>
94867
94868 #ifndef pgprot_modify
94869 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94870 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94871 return pages;
94872 }
94873
94874 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94875 +/* called while holding the mmap semaphor for writing except stack expansion */
94876 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94877 +{
94878 + unsigned long oldlimit, newlimit = 0UL;
94879 +
94880 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94881 + return;
94882 +
94883 + spin_lock(&mm->page_table_lock);
94884 + oldlimit = mm->context.user_cs_limit;
94885 + if ((prot & VM_EXEC) && oldlimit < end)
94886 + /* USER_CS limit moved up */
94887 + newlimit = end;
94888 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94889 + /* USER_CS limit moved down */
94890 + newlimit = start;
94891 +
94892 + if (newlimit) {
94893 + mm->context.user_cs_limit = newlimit;
94894 +
94895 +#ifdef CONFIG_SMP
94896 + wmb();
94897 + cpus_clear(mm->context.cpu_user_cs_mask);
94898 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94899 +#endif
94900 +
94901 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94902 + }
94903 + spin_unlock(&mm->page_table_lock);
94904 + if (newlimit == end) {
94905 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
94906 +
94907 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
94908 + if (is_vm_hugetlb_page(vma))
94909 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94910 + else
94911 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94912 + }
94913 +}
94914 +#endif
94915 +
94916 int
94917 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94918 unsigned long start, unsigned long end, unsigned long newflags)
94919 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94920 int error;
94921 int dirty_accountable = 0;
94922
94923 +#ifdef CONFIG_PAX_SEGMEXEC
94924 + struct vm_area_struct *vma_m = NULL;
94925 + unsigned long start_m, end_m;
94926 +
94927 + start_m = start + SEGMEXEC_TASK_SIZE;
94928 + end_m = end + SEGMEXEC_TASK_SIZE;
94929 +#endif
94930 +
94931 if (newflags == oldflags) {
94932 *pprev = vma;
94933 return 0;
94934 }
94935
94936 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94937 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94938 +
94939 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94940 + return -ENOMEM;
94941 +
94942 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94943 + return -ENOMEM;
94944 + }
94945 +
94946 /*
94947 * If we make a private mapping writable we increase our commit;
94948 * but (without finer accounting) cannot reduce our commit if we
94949 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94950 }
94951 }
94952
94953 +#ifdef CONFIG_PAX_SEGMEXEC
94954 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94955 + if (start != vma->vm_start) {
94956 + error = split_vma(mm, vma, start, 1);
94957 + if (error)
94958 + goto fail;
94959 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94960 + *pprev = (*pprev)->vm_next;
94961 + }
94962 +
94963 + if (end != vma->vm_end) {
94964 + error = split_vma(mm, vma, end, 0);
94965 + if (error)
94966 + goto fail;
94967 + }
94968 +
94969 + if (pax_find_mirror_vma(vma)) {
94970 + error = __do_munmap(mm, start_m, end_m - start_m);
94971 + if (error)
94972 + goto fail;
94973 + } else {
94974 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94975 + if (!vma_m) {
94976 + error = -ENOMEM;
94977 + goto fail;
94978 + }
94979 + vma->vm_flags = newflags;
94980 + error = pax_mirror_vma(vma_m, vma);
94981 + if (error) {
94982 + vma->vm_flags = oldflags;
94983 + goto fail;
94984 + }
94985 + }
94986 + }
94987 +#endif
94988 +
94989 /*
94990 * First try to merge with previous and/or next vma.
94991 */
94992 @@ -319,9 +423,21 @@ success:
94993 * vm_flags and vm_page_prot are protected by the mmap_sem
94994 * held in write mode.
94995 */
94996 +
94997 +#ifdef CONFIG_PAX_SEGMEXEC
94998 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94999 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95000 +#endif
95001 +
95002 vma->vm_flags = newflags;
95003 +
95004 +#ifdef CONFIG_PAX_MPROTECT
95005 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95006 + mm->binfmt->handle_mprotect(vma, newflags);
95007 +#endif
95008 +
95009 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95010 - vm_get_page_prot(newflags));
95011 + vm_get_page_prot(vma->vm_flags));
95012
95013 if (vma_wants_writenotify(vma)) {
95014 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95015 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95016 end = start + len;
95017 if (end <= start)
95018 return -ENOMEM;
95019 +
95020 +#ifdef CONFIG_PAX_SEGMEXEC
95021 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95022 + if (end > SEGMEXEC_TASK_SIZE)
95023 + return -EINVAL;
95024 + } else
95025 +#endif
95026 +
95027 + if (end > TASK_SIZE)
95028 + return -EINVAL;
95029 +
95030 if (!arch_validate_prot(prot))
95031 return -EINVAL;
95032
95033 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95034 /*
95035 * Does the application expect PROT_READ to imply PROT_EXEC:
95036 */
95037 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95038 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95039 prot |= PROT_EXEC;
95040
95041 vm_flags = calc_vm_prot_bits(prot);
95042 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95043 if (start > vma->vm_start)
95044 prev = vma;
95045
95046 +#ifdef CONFIG_PAX_MPROTECT
95047 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95048 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95049 +#endif
95050 +
95051 for (nstart = start ; ; ) {
95052 unsigned long newflags;
95053
95054 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95055
95056 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95057 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95058 + if (prot & (PROT_WRITE | PROT_EXEC))
95059 + gr_log_rwxmprotect(vma);
95060 +
95061 + error = -EACCES;
95062 + goto out;
95063 + }
95064 +
95065 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95066 error = -EACCES;
95067 goto out;
95068 }
95069 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95070 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95071 if (error)
95072 goto out;
95073 +
95074 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95075 +
95076 nstart = tmp;
95077
95078 if (nstart < prev->vm_end)
95079 diff --git a/mm/mremap.c b/mm/mremap.c
95080 index 05f1180..c3cde48 100644
95081 --- a/mm/mremap.c
95082 +++ b/mm/mremap.c
95083 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95084 continue;
95085 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95086 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95087 +
95088 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95089 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95090 + pte = pte_exprotect(pte);
95091 +#endif
95092 +
95093 pte = move_soft_dirty_pte(pte);
95094 set_pte_at(mm, new_addr, new_pte, pte);
95095 }
95096 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95097 if (is_vm_hugetlb_page(vma))
95098 goto Einval;
95099
95100 +#ifdef CONFIG_PAX_SEGMEXEC
95101 + if (pax_find_mirror_vma(vma))
95102 + goto Einval;
95103 +#endif
95104 +
95105 /* We can't remap across vm area boundaries */
95106 if (old_len > vma->vm_end - addr)
95107 goto Efault;
95108 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95109 unsigned long ret = -EINVAL;
95110 unsigned long charged = 0;
95111 unsigned long map_flags;
95112 + unsigned long pax_task_size = TASK_SIZE;
95113
95114 if (new_addr & ~PAGE_MASK)
95115 goto out;
95116
95117 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95118 +#ifdef CONFIG_PAX_SEGMEXEC
95119 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95120 + pax_task_size = SEGMEXEC_TASK_SIZE;
95121 +#endif
95122 +
95123 + pax_task_size -= PAGE_SIZE;
95124 +
95125 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95126 goto out;
95127
95128 /* Check if the location we're moving into overlaps the
95129 * old location at all, and fail if it does.
95130 */
95131 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95132 - goto out;
95133 -
95134 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95135 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95136 goto out;
95137
95138 ret = do_munmap(mm, new_addr, new_len);
95139 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95140 unsigned long ret = -EINVAL;
95141 unsigned long charged = 0;
95142 bool locked = false;
95143 + unsigned long pax_task_size = TASK_SIZE;
95144
95145 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95146 return ret;
95147 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95148 if (!new_len)
95149 return ret;
95150
95151 +#ifdef CONFIG_PAX_SEGMEXEC
95152 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95153 + pax_task_size = SEGMEXEC_TASK_SIZE;
95154 +#endif
95155 +
95156 + pax_task_size -= PAGE_SIZE;
95157 +
95158 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95159 + old_len > pax_task_size || addr > pax_task_size-old_len)
95160 + return ret;
95161 +
95162 down_write(&current->mm->mmap_sem);
95163
95164 if (flags & MREMAP_FIXED) {
95165 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95166 new_addr = addr;
95167 }
95168 ret = addr;
95169 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95170 goto out;
95171 }
95172 }
95173 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95174 goto out;
95175 }
95176
95177 + map_flags = vma->vm_flags;
95178 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95179 + if (!(ret & ~PAGE_MASK)) {
95180 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95181 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95182 + }
95183 }
95184 out:
95185 if (ret & ~PAGE_MASK)
95186 diff --git a/mm/nommu.c b/mm/nommu.c
95187 index 85f8d66..b3375fa 100644
95188 --- a/mm/nommu.c
95189 +++ b/mm/nommu.c
95190 @@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95191 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95192 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95193 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95194 -int heap_stack_gap = 0;
95195
95196 atomic_long_t mmap_pages_allocated;
95197
95198 @@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95199 EXPORT_SYMBOL(find_vma);
95200
95201 /*
95202 - * find a VMA
95203 - * - we don't extend stack VMAs under NOMMU conditions
95204 - */
95205 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95206 -{
95207 - return find_vma(mm, addr);
95208 -}
95209 -
95210 -/*
95211 * expand a stack to a given address
95212 * - not supported under NOMMU conditions
95213 */
95214 @@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95215
95216 /* most fields are the same, copy all, and then fixup */
95217 *new = *vma;
95218 + INIT_LIST_HEAD(&new->anon_vma_chain);
95219 *region = *vma->vm_region;
95220 new->vm_region = region;
95221
95222 @@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95223 }
95224 EXPORT_SYMBOL(generic_file_remap_pages);
95225
95226 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95227 - unsigned long addr, void *buf, int len, int write)
95228 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95229 + unsigned long addr, void *buf, size_t len, int write)
95230 {
95231 struct vm_area_struct *vma;
95232
95233 @@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95234 *
95235 * The caller must hold a reference on @mm.
95236 */
95237 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95238 - void *buf, int len, int write)
95239 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95240 + void *buf, size_t len, int write)
95241 {
95242 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95243 }
95244 @@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95245 * Access another process' address space.
95246 * - source/target buffer must be kernel space
95247 */
95248 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95249 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95250 {
95251 struct mm_struct *mm;
95252
95253 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95254 index 154af21..86e447f 100644
95255 --- a/mm/page-writeback.c
95256 +++ b/mm/page-writeback.c
95257 @@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95258 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95259 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95260 */
95261 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95262 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95263 unsigned long thresh,
95264 unsigned long bg_thresh,
95265 unsigned long dirty,
95266 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95267 index 56eb0eb..bb5e928 100644
95268 --- a/mm/page_alloc.c
95269 +++ b/mm/page_alloc.c
95270 @@ -61,6 +61,7 @@
95271 #include <linux/page-debug-flags.h>
95272 #include <linux/hugetlb.h>
95273 #include <linux/sched/rt.h>
95274 +#include <linux/random.h>
95275
95276 #include <asm/sections.h>
95277 #include <asm/tlbflush.h>
95278 @@ -355,7 +356,7 @@ out:
95279 * This usage means that zero-order pages may not be compound.
95280 */
95281
95282 -static void free_compound_page(struct page *page)
95283 +void free_compound_page(struct page *page)
95284 {
95285 __free_pages_ok(page, compound_order(page));
95286 }
95287 @@ -729,6 +730,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95288 int i;
95289 int bad = 0;
95290
95291 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95292 + unsigned long index = 1UL << order;
95293 +#endif
95294 +
95295 trace_mm_page_free(page, order);
95296 kmemcheck_free_shadow(page, order);
95297
95298 @@ -745,6 +750,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95299 debug_check_no_obj_freed(page_address(page),
95300 PAGE_SIZE << order);
95301 }
95302 +
95303 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95304 + for (; index; --index)
95305 + sanitize_highpage(page + index - 1);
95306 +#endif
95307 +
95308 arch_free_page(page, order);
95309 kernel_map_pages(page, 1 << order, 0);
95310
95311 @@ -767,6 +778,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95312 local_irq_restore(flags);
95313 }
95314
95315 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95316 +bool __meminitdata extra_latent_entropy;
95317 +
95318 +static int __init setup_pax_extra_latent_entropy(char *str)
95319 +{
95320 + extra_latent_entropy = true;
95321 + return 0;
95322 +}
95323 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95324 +
95325 +volatile u64 latent_entropy __latent_entropy;
95326 +EXPORT_SYMBOL(latent_entropy);
95327 +#endif
95328 +
95329 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95330 {
95331 unsigned int nr_pages = 1 << order;
95332 @@ -782,6 +807,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95333 __ClearPageReserved(p);
95334 set_page_count(p, 0);
95335
95336 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95337 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95338 + u64 hash = 0;
95339 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95340 + const u64 *data = lowmem_page_address(page);
95341 +
95342 + for (index = 0; index < end; index++)
95343 + hash ^= hash + data[index];
95344 + latent_entropy ^= hash;
95345 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95346 + }
95347 +#endif
95348 +
95349 page_zone(page)->managed_pages += nr_pages;
95350 set_page_refcounted(page);
95351 __free_pages(page, order);
95352 @@ -898,8 +936,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95353 arch_alloc_page(page, order);
95354 kernel_map_pages(page, 1 << order, 1);
95355
95356 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
95357 if (gfp_flags & __GFP_ZERO)
95358 prep_zero_page(page, order, gfp_flags);
95359 +#endif
95360
95361 if (order && (gfp_flags & __GFP_COMP))
95362 prep_compound_page(page, order);
95363 @@ -2402,7 +2442,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95364 continue;
95365 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95366 high_wmark_pages(zone) - low_wmark_pages(zone) -
95367 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95368 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95369 }
95370 }
95371
95372 diff --git a/mm/page_io.c b/mm/page_io.c
95373 index 7c59ef6..1358905 100644
95374 --- a/mm/page_io.c
95375 +++ b/mm/page_io.c
95376 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95377 struct file *swap_file = sis->swap_file;
95378 struct address_space *mapping = swap_file->f_mapping;
95379 struct iovec iov = {
95380 - .iov_base = kmap(page),
95381 + .iov_base = (void __force_user *)kmap(page),
95382 .iov_len = PAGE_SIZE,
95383 };
95384
95385 diff --git a/mm/percpu.c b/mm/percpu.c
95386 index 2ddf9a9..f8fc075 100644
95387 --- a/mm/percpu.c
95388 +++ b/mm/percpu.c
95389 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95390 static unsigned int pcpu_high_unit_cpu __read_mostly;
95391
95392 /* the address of the first chunk which starts with the kernel static area */
95393 -void *pcpu_base_addr __read_mostly;
95394 +void *pcpu_base_addr __read_only;
95395 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95396
95397 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95398 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95399 index 8505c92..946bfc9 100644
95400 --- a/mm/process_vm_access.c
95401 +++ b/mm/process_vm_access.c
95402 @@ -13,6 +13,7 @@
95403 #include <linux/uio.h>
95404 #include <linux/sched.h>
95405 #include <linux/highmem.h>
95406 +#include <linux/security.h>
95407 #include <linux/ptrace.h>
95408 #include <linux/slab.h>
95409 #include <linux/syscalls.h>
95410 @@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95411 ssize_t iov_len;
95412 size_t total_len = iov_iter_count(iter);
95413
95414 + return -ENOSYS; // PaX: until properly audited
95415 +
95416 /*
95417 * Work out how many pages of struct pages we're going to need
95418 * when eventually calling get_user_pages
95419 */
95420 for (i = 0; i < riovcnt; i++) {
95421 iov_len = rvec[i].iov_len;
95422 - if (iov_len > 0) {
95423 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
95424 - + iov_len)
95425 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95426 - / PAGE_SIZE + 1;
95427 - nr_pages = max(nr_pages, nr_pages_iov);
95428 - }
95429 + if (iov_len <= 0)
95430 + continue;
95431 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95432 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95433 + nr_pages = max(nr_pages, nr_pages_iov);
95434 }
95435
95436 if (nr_pages == 0)
95437 @@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95438 goto free_proc_pages;
95439 }
95440
95441 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95442 + rc = -EPERM;
95443 + goto put_task_struct;
95444 + }
95445 +
95446 mm = mm_access(task, PTRACE_MODE_ATTACH);
95447 if (!mm || IS_ERR(mm)) {
95448 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95449 diff --git a/mm/rmap.c b/mm/rmap.c
95450 index 14d1e28..3777962 100644
95451 --- a/mm/rmap.c
95452 +++ b/mm/rmap.c
95453 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95454 struct anon_vma *anon_vma = vma->anon_vma;
95455 struct anon_vma_chain *avc;
95456
95457 +#ifdef CONFIG_PAX_SEGMEXEC
95458 + struct anon_vma_chain *avc_m = NULL;
95459 +#endif
95460 +
95461 might_sleep();
95462 if (unlikely(!anon_vma)) {
95463 struct mm_struct *mm = vma->vm_mm;
95464 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95465 if (!avc)
95466 goto out_enomem;
95467
95468 +#ifdef CONFIG_PAX_SEGMEXEC
95469 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95470 + if (!avc_m)
95471 + goto out_enomem_free_avc;
95472 +#endif
95473 +
95474 anon_vma = find_mergeable_anon_vma(vma);
95475 allocated = NULL;
95476 if (!anon_vma) {
95477 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95478 /* page_table_lock to protect against threads */
95479 spin_lock(&mm->page_table_lock);
95480 if (likely(!vma->anon_vma)) {
95481 +
95482 +#ifdef CONFIG_PAX_SEGMEXEC
95483 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95484 +
95485 + if (vma_m) {
95486 + BUG_ON(vma_m->anon_vma);
95487 + vma_m->anon_vma = anon_vma;
95488 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
95489 + avc_m = NULL;
95490 + }
95491 +#endif
95492 +
95493 vma->anon_vma = anon_vma;
95494 anon_vma_chain_link(vma, avc, anon_vma);
95495 allocated = NULL;
95496 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95497
95498 if (unlikely(allocated))
95499 put_anon_vma(allocated);
95500 +
95501 +#ifdef CONFIG_PAX_SEGMEXEC
95502 + if (unlikely(avc_m))
95503 + anon_vma_chain_free(avc_m);
95504 +#endif
95505 +
95506 if (unlikely(avc))
95507 anon_vma_chain_free(avc);
95508 }
95509 return 0;
95510
95511 out_enomem_free_avc:
95512 +
95513 +#ifdef CONFIG_PAX_SEGMEXEC
95514 + if (avc_m)
95515 + anon_vma_chain_free(avc_m);
95516 +#endif
95517 +
95518 anon_vma_chain_free(avc);
95519 out_enomem:
95520 return -ENOMEM;
95521 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95522 * Attach the anon_vmas from src to dst.
95523 * Returns 0 on success, -ENOMEM on failure.
95524 */
95525 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95526 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95527 {
95528 struct anon_vma_chain *avc, *pavc;
95529 struct anon_vma *root = NULL;
95530 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95531 * the corresponding VMA in the parent process is attached to.
95532 * Returns 0 on success, non-zero on failure.
95533 */
95534 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95535 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95536 {
95537 struct anon_vma_chain *avc;
95538 struct anon_vma *anon_vma;
95539 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95540 void __init anon_vma_init(void)
95541 {
95542 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95543 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95544 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95545 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95546 + anon_vma_ctor);
95547 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95548 + SLAB_PANIC|SLAB_NO_SANITIZE);
95549 }
95550
95551 /*
95552 diff --git a/mm/shmem.c b/mm/shmem.c
95553 index a2801ba..b8651e6 100644
95554 --- a/mm/shmem.c
95555 +++ b/mm/shmem.c
95556 @@ -33,7 +33,7 @@
95557 #include <linux/swap.h>
95558 #include <linux/aio.h>
95559
95560 -static struct vfsmount *shm_mnt;
95561 +struct vfsmount *shm_mnt;
95562
95563 #ifdef CONFIG_SHMEM
95564 /*
95565 @@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95566 #define BOGO_DIRENT_SIZE 20
95567
95568 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95569 -#define SHORT_SYMLINK_LEN 128
95570 +#define SHORT_SYMLINK_LEN 64
95571
95572 /*
95573 - * shmem_fallocate and shmem_writepage communicate via inode->i_private
95574 - * (with i_mutex making sure that it has only one user at a time):
95575 - * we would prefer not to enlarge the shmem inode just for that.
95576 + * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95577 + * inode->i_private (with i_mutex making sure that it has only one user at
95578 + * a time): we would prefer not to enlarge the shmem inode just for that.
95579 */
95580 struct shmem_falloc {
95581 + int mode; /* FALLOC_FL mode currently operating */
95582 pgoff_t start; /* start of range currently being fallocated */
95583 pgoff_t next; /* the next page offset to be fallocated */
95584 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95585 @@ -759,6 +760,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95586 spin_lock(&inode->i_lock);
95587 shmem_falloc = inode->i_private;
95588 if (shmem_falloc &&
95589 + !shmem_falloc->mode &&
95590 index >= shmem_falloc->start &&
95591 index < shmem_falloc->next)
95592 shmem_falloc->nr_unswapped++;
95593 @@ -1233,6 +1235,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95594 int error;
95595 int ret = VM_FAULT_LOCKED;
95596
95597 + /*
95598 + * Trinity finds that probing a hole which tmpfs is punching can
95599 + * prevent the hole-punch from ever completing: which in turn
95600 + * locks writers out with its hold on i_mutex. So refrain from
95601 + * faulting pages into the hole while it's being punched, and
95602 + * wait on i_mutex to be released if vmf->flags permits,
95603 + */
95604 + if (unlikely(inode->i_private)) {
95605 + struct shmem_falloc *shmem_falloc;
95606 + spin_lock(&inode->i_lock);
95607 + shmem_falloc = inode->i_private;
95608 + if (!shmem_falloc ||
95609 + shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95610 + vmf->pgoff < shmem_falloc->start ||
95611 + vmf->pgoff >= shmem_falloc->next)
95612 + shmem_falloc = NULL;
95613 + spin_unlock(&inode->i_lock);
95614 + /*
95615 + * i_lock has protected us from taking shmem_falloc seriously
95616 + * once return from shmem_fallocate() went back up that stack.
95617 + * i_lock does not serialize with i_mutex at all, but it does
95618 + * not matter if sometimes we wait unnecessarily, or sometimes
95619 + * miss out on waiting: we just need to make those cases rare.
95620 + */
95621 + if (shmem_falloc) {
95622 + if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95623 + !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95624 + up_read(&vma->vm_mm->mmap_sem);
95625 + mutex_lock(&inode->i_mutex);
95626 + mutex_unlock(&inode->i_mutex);
95627 + return VM_FAULT_RETRY;
95628 + }
95629 + /* cond_resched? Leave that to GUP or return to user */
95630 + return VM_FAULT_NOPAGE;
95631 + }
95632 + }
95633 +
95634 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95635 if (error)
95636 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95637 @@ -1733,18 +1772,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95638
95639 mutex_lock(&inode->i_mutex);
95640
95641 + shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95642 +
95643 if (mode & FALLOC_FL_PUNCH_HOLE) {
95644 struct address_space *mapping = file->f_mapping;
95645 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95646 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95647
95648 + shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95649 + shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95650 + spin_lock(&inode->i_lock);
95651 + inode->i_private = &shmem_falloc;
95652 + spin_unlock(&inode->i_lock);
95653 +
95654 if ((u64)unmap_end > (u64)unmap_start)
95655 unmap_mapping_range(mapping, unmap_start,
95656 1 + unmap_end - unmap_start, 0);
95657 shmem_truncate_range(inode, offset, offset + len - 1);
95658 /* No need to unmap again: hole-punching leaves COWed pages */
95659 error = 0;
95660 - goto out;
95661 + goto undone;
95662 }
95663
95664 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95665 @@ -2138,6 +2185,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95666 static int shmem_xattr_validate(const char *name)
95667 {
95668 struct { const char *prefix; size_t len; } arr[] = {
95669 +
95670 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95671 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95672 +#endif
95673 +
95674 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95675 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95676 };
95677 @@ -2193,6 +2245,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95678 if (err)
95679 return err;
95680
95681 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95682 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95683 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95684 + return -EOPNOTSUPP;
95685 + if (size > 8)
95686 + return -EINVAL;
95687 + }
95688 +#endif
95689 +
95690 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95691 }
95692
95693 @@ -2505,8 +2566,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95694 int err = -ENOMEM;
95695
95696 /* Round up to L1_CACHE_BYTES to resist false sharing */
95697 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95698 - L1_CACHE_BYTES), GFP_KERNEL);
95699 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95700 if (!sbinfo)
95701 return -ENOMEM;
95702
95703 diff --git a/mm/slab.c b/mm/slab.c
95704 index 9432556..e0dc685 100644
95705 --- a/mm/slab.c
95706 +++ b/mm/slab.c
95707 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95708 if ((x)->max_freeable < i) \
95709 (x)->max_freeable = i; \
95710 } while (0)
95711 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95712 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95713 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95714 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95715 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95716 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95717 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95718 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95719 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95720 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95721 #else
95722 #define STATS_INC_ACTIVE(x) do { } while (0)
95723 #define STATS_DEC_ACTIVE(x) do { } while (0)
95724 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95725 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95726 #define STATS_INC_FREEHIT(x) do { } while (0)
95727 #define STATS_INC_FREEMISS(x) do { } while (0)
95728 +#define STATS_INC_SANITIZED(x) do { } while (0)
95729 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95730 #endif
95731
95732 #if DEBUG
95733 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95734 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95735 */
95736 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95737 - const struct page *page, void *obj)
95738 + const struct page *page, const void *obj)
95739 {
95740 u32 offset = (obj - page->s_mem);
95741 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95742 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
95743 */
95744
95745 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95746 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95747 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95748
95749 if (INDEX_AC != INDEX_NODE)
95750 kmalloc_caches[INDEX_NODE] =
95751 create_kmalloc_cache("kmalloc-node",
95752 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95753 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95754
95755 slab_early_init = 0;
95756
95757 @@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95758 struct array_cache *ac = cpu_cache_get(cachep);
95759
95760 check_irq_off();
95761 +
95762 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95763 + if (pax_sanitize_slab) {
95764 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95765 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95766 +
95767 + if (cachep->ctor)
95768 + cachep->ctor(objp);
95769 +
95770 + STATS_INC_SANITIZED(cachep);
95771 + } else
95772 + STATS_INC_NOT_SANITIZED(cachep);
95773 + }
95774 +#endif
95775 +
95776 kmemleak_free_recursive(objp, cachep->flags);
95777 objp = cache_free_debugcheck(cachep, objp, caller);
95778
95779 @@ -3748,6 +3767,7 @@ void kfree(const void *objp)
95780
95781 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95782 return;
95783 + VM_BUG_ON(!virt_addr_valid(objp));
95784 local_irq_save(flags);
95785 kfree_debugcheck(objp);
95786 c = virt_to_cache(objp);
95787 @@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95788 }
95789 /* cpu stats */
95790 {
95791 - unsigned long allochit = atomic_read(&cachep->allochit);
95792 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95793 - unsigned long freehit = atomic_read(&cachep->freehit);
95794 - unsigned long freemiss = atomic_read(&cachep->freemiss);
95795 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95796 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95797 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95798 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95799
95800 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95801 allochit, allocmiss, freehit, freemiss);
95802 }
95803 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95804 + {
95805 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95806 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95807 +
95808 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95809 + }
95810 +#endif
95811 #endif
95812 }
95813
95814 @@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
95815 static int __init slab_proc_init(void)
95816 {
95817 #ifdef CONFIG_DEBUG_SLAB_LEAK
95818 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95819 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95820 #endif
95821 return 0;
95822 }
95823 module_init(slab_proc_init);
95824 #endif
95825
95826 +bool is_usercopy_object(const void *ptr)
95827 +{
95828 + struct page *page;
95829 + struct kmem_cache *cachep;
95830 +
95831 + if (ZERO_OR_NULL_PTR(ptr))
95832 + return false;
95833 +
95834 + if (!slab_is_available())
95835 + return false;
95836 +
95837 + if (!virt_addr_valid(ptr))
95838 + return false;
95839 +
95840 + page = virt_to_head_page(ptr);
95841 +
95842 + if (!PageSlab(page))
95843 + return false;
95844 +
95845 + cachep = page->slab_cache;
95846 + return cachep->flags & SLAB_USERCOPY;
95847 +}
95848 +
95849 +#ifdef CONFIG_PAX_USERCOPY
95850 +const char *check_heap_object(const void *ptr, unsigned long n)
95851 +{
95852 + struct page *page;
95853 + struct kmem_cache *cachep;
95854 + unsigned int objnr;
95855 + unsigned long offset;
95856 +
95857 + if (ZERO_OR_NULL_PTR(ptr))
95858 + return "<null>";
95859 +
95860 + if (!virt_addr_valid(ptr))
95861 + return NULL;
95862 +
95863 + page = virt_to_head_page(ptr);
95864 +
95865 + if (!PageSlab(page))
95866 + return NULL;
95867 +
95868 + cachep = page->slab_cache;
95869 + if (!(cachep->flags & SLAB_USERCOPY))
95870 + return cachep->name;
95871 +
95872 + objnr = obj_to_index(cachep, page, ptr);
95873 + BUG_ON(objnr >= cachep->num);
95874 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95875 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95876 + return NULL;
95877 +
95878 + return cachep->name;
95879 +}
95880 +#endif
95881 +
95882 /**
95883 * ksize - get the actual amount of memory allocated for a given object
95884 * @objp: Pointer to the object
95885 diff --git a/mm/slab.h b/mm/slab.h
95886 index 6bd4c35..97565a1 100644
95887 --- a/mm/slab.h
95888 +++ b/mm/slab.h
95889 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95890 /* The slab cache that manages slab cache information */
95891 extern struct kmem_cache *kmem_cache;
95892
95893 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95894 +#ifdef CONFIG_X86_64
95895 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95896 +#else
95897 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95898 +#endif
95899 +extern bool pax_sanitize_slab;
95900 +#endif
95901 +
95902 unsigned long calculate_alignment(unsigned long flags,
95903 unsigned long align, unsigned long size);
95904
95905 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
95906
95907 /* Legal flag mask for kmem_cache_create(), for various configurations */
95908 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95909 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95910 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95911 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
95912
95913 #if defined(CONFIG_DEBUG_SLAB)
95914 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95915 @@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95916 return s;
95917
95918 page = virt_to_head_page(x);
95919 +
95920 + BUG_ON(!PageSlab(page));
95921 +
95922 cachep = page->slab_cache;
95923 if (slab_equal_or_root(cachep, s))
95924 return cachep;
95925 diff --git a/mm/slab_common.c b/mm/slab_common.c
95926 index 102cc6f..c7aab3d 100644
95927 --- a/mm/slab_common.c
95928 +++ b/mm/slab_common.c
95929 @@ -23,11 +23,22 @@
95930
95931 #include "slab.h"
95932
95933 -enum slab_state slab_state;
95934 +enum slab_state slab_state __read_only;
95935 LIST_HEAD(slab_caches);
95936 DEFINE_MUTEX(slab_mutex);
95937 struct kmem_cache *kmem_cache;
95938
95939 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95940 +bool pax_sanitize_slab __read_only = true;
95941 +static int __init pax_sanitize_slab_setup(char *str)
95942 +{
95943 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95944 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95945 + return 1;
95946 +}
95947 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95948 +#endif
95949 +
95950 #ifdef CONFIG_DEBUG_VM
95951 static int kmem_cache_sanity_check(const char *name, size_t size)
95952 {
95953 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
95954 if (err)
95955 goto out_free_cache;
95956
95957 - s->refcount = 1;
95958 + atomic_set(&s->refcount, 1);
95959 list_add(&s->list, &slab_caches);
95960 memcg_register_cache(s);
95961 out:
95962 @@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95963 get_online_cpus();
95964 mutex_lock(&slab_mutex);
95965
95966 - s->refcount--;
95967 - if (s->refcount)
95968 + if (!atomic_dec_and_test(&s->refcount))
95969 goto out_unlock;
95970
95971 if (kmem_cache_destroy_memcg_children(s) != 0)
95972 @@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95973 rcu_barrier();
95974
95975 memcg_free_cache_params(s);
95976 -#ifdef SLAB_SUPPORTS_SYSFS
95977 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95978 sysfs_slab_remove(s);
95979 #else
95980 slab_kmem_cache_release(s);
95981 @@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95982 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95983 name, size, err);
95984
95985 - s->refcount = -1; /* Exempt from merging for now */
95986 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95987 }
95988
95989 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95990 @@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95991
95992 create_boot_cache(s, name, size, flags);
95993 list_add(&s->list, &slab_caches);
95994 - s->refcount = 1;
95995 + atomic_set(&s->refcount, 1);
95996 return s;
95997 }
95998
95999 @@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96000 EXPORT_SYMBOL(kmalloc_dma_caches);
96001 #endif
96002
96003 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96004 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96005 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
96006 +#endif
96007 +
96008 /*
96009 * Conversion table for small slabs sizes / 8 to the index in the
96010 * kmalloc array. This is necessary for slabs < 192 since we have non power
96011 @@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96012 return kmalloc_dma_caches[index];
96013
96014 #endif
96015 +
96016 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96017 + if (unlikely((flags & GFP_USERCOPY)))
96018 + return kmalloc_usercopy_caches[index];
96019 +
96020 +#endif
96021 +
96022 return kmalloc_caches[index];
96023 }
96024
96025 @@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96026 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96027 if (!kmalloc_caches[i]) {
96028 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96029 - 1 << i, flags);
96030 + 1 << i, SLAB_USERCOPY | flags);
96031 }
96032
96033 /*
96034 @@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96035 * earlier power of two caches
96036 */
96037 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96038 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96039 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96040
96041 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96042 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96043 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96044 }
96045
96046 /* Kmalloc array is now usable */
96047 @@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96048 }
96049 }
96050 #endif
96051 +
96052 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96053 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96054 + struct kmem_cache *s = kmalloc_caches[i];
96055 +
96056 + if (s) {
96057 + int size = kmalloc_size(i);
96058 + char *n = kasprintf(GFP_NOWAIT,
96059 + "usercopy-kmalloc-%d", size);
96060 +
96061 + BUG_ON(!n);
96062 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96063 + size, SLAB_USERCOPY | flags);
96064 + }
96065 + }
96066 +#endif
96067 +
96068 }
96069 #endif /* !CONFIG_SLOB */
96070
96071 @@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96072 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96073 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96074 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96075 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96076 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96077 +#endif
96078 #endif
96079 seq_putc(m, '\n');
96080 }
96081 diff --git a/mm/slob.c b/mm/slob.c
96082 index 730cad4..8cfd442 100644
96083 --- a/mm/slob.c
96084 +++ b/mm/slob.c
96085 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96086 /*
96087 * Return the size of a slob block.
96088 */
96089 -static slobidx_t slob_units(slob_t *s)
96090 +static slobidx_t slob_units(const slob_t *s)
96091 {
96092 if (s->units > 0)
96093 return s->units;
96094 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96095 /*
96096 * Return the next free slob block pointer after this one.
96097 */
96098 -static slob_t *slob_next(slob_t *s)
96099 +static slob_t *slob_next(const slob_t *s)
96100 {
96101 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96102 slobidx_t next;
96103 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96104 /*
96105 * Returns true if s is the last free block in its page.
96106 */
96107 -static int slob_last(slob_t *s)
96108 +static int slob_last(const slob_t *s)
96109 {
96110 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96111 }
96112
96113 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96114 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96115 {
96116 - void *page;
96117 + struct page *page;
96118
96119 #ifdef CONFIG_NUMA
96120 if (node != NUMA_NO_NODE)
96121 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96122 if (!page)
96123 return NULL;
96124
96125 - return page_address(page);
96126 + __SetPageSlab(page);
96127 + return page;
96128 }
96129
96130 -static void slob_free_pages(void *b, int order)
96131 +static void slob_free_pages(struct page *sp, int order)
96132 {
96133 if (current->reclaim_state)
96134 current->reclaim_state->reclaimed_slab += 1 << order;
96135 - free_pages((unsigned long)b, order);
96136 + __ClearPageSlab(sp);
96137 + page_mapcount_reset(sp);
96138 + sp->private = 0;
96139 + __free_pages(sp, order);
96140 }
96141
96142 /*
96143 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96144
96145 /* Not enough space: must allocate a new page */
96146 if (!b) {
96147 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96148 - if (!b)
96149 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96150 + if (!sp)
96151 return NULL;
96152 - sp = virt_to_page(b);
96153 - __SetPageSlab(sp);
96154 + b = page_address(sp);
96155
96156 spin_lock_irqsave(&slob_lock, flags);
96157 sp->units = SLOB_UNITS(PAGE_SIZE);
96158 sp->freelist = b;
96159 + sp->private = 0;
96160 INIT_LIST_HEAD(&sp->lru);
96161 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96162 set_slob_page_free(sp, slob_list);
96163 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96164 if (slob_page_free(sp))
96165 clear_slob_page_free(sp);
96166 spin_unlock_irqrestore(&slob_lock, flags);
96167 - __ClearPageSlab(sp);
96168 - page_mapcount_reset(sp);
96169 - slob_free_pages(b, 0);
96170 + slob_free_pages(sp, 0);
96171 return;
96172 }
96173
96174 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96175 + if (pax_sanitize_slab)
96176 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96177 +#endif
96178 +
96179 if (!slob_page_free(sp)) {
96180 /* This slob page is about to become partially free. Easy! */
96181 sp->units = units;
96182 @@ -424,11 +431,10 @@ out:
96183 */
96184
96185 static __always_inline void *
96186 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96187 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96188 {
96189 - unsigned int *m;
96190 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96191 - void *ret;
96192 + slob_t *m;
96193 + void *ret = NULL;
96194
96195 gfp &= gfp_allowed_mask;
96196
96197 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96198
96199 if (!m)
96200 return NULL;
96201 - *m = size;
96202 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96203 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96204 + m[0].units = size;
96205 + m[1].units = align;
96206 ret = (void *)m + align;
96207
96208 trace_kmalloc_node(caller, ret,
96209 size, size + align, gfp, node);
96210 } else {
96211 unsigned int order = get_order(size);
96212 + struct page *page;
96213
96214 if (likely(order))
96215 gfp |= __GFP_COMP;
96216 - ret = slob_new_pages(gfp, order, node);
96217 + page = slob_new_pages(gfp, order, node);
96218 + if (page) {
96219 + ret = page_address(page);
96220 + page->private = size;
96221 + }
96222
96223 trace_kmalloc_node(caller, ret,
96224 size, PAGE_SIZE << order, gfp, node);
96225 }
96226
96227 - kmemleak_alloc(ret, size, 1, gfp);
96228 + return ret;
96229 +}
96230 +
96231 +static __always_inline void *
96232 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96233 +{
96234 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96235 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96236 +
96237 + if (!ZERO_OR_NULL_PTR(ret))
96238 + kmemleak_alloc(ret, size, 1, gfp);
96239 return ret;
96240 }
96241
96242 @@ -493,34 +517,112 @@ void kfree(const void *block)
96243 return;
96244 kmemleak_free(block);
96245
96246 + VM_BUG_ON(!virt_addr_valid(block));
96247 sp = virt_to_page(block);
96248 - if (PageSlab(sp)) {
96249 + VM_BUG_ON(!PageSlab(sp));
96250 + if (!sp->private) {
96251 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96252 - unsigned int *m = (unsigned int *)(block - align);
96253 - slob_free(m, *m + align);
96254 - } else
96255 + slob_t *m = (slob_t *)(block - align);
96256 + slob_free(m, m[0].units + align);
96257 + } else {
96258 + __ClearPageSlab(sp);
96259 + page_mapcount_reset(sp);
96260 + sp->private = 0;
96261 __free_pages(sp, compound_order(sp));
96262 + }
96263 }
96264 EXPORT_SYMBOL(kfree);
96265
96266 +bool is_usercopy_object(const void *ptr)
96267 +{
96268 + if (!slab_is_available())
96269 + return false;
96270 +
96271 + // PAX: TODO
96272 +
96273 + return false;
96274 +}
96275 +
96276 +#ifdef CONFIG_PAX_USERCOPY
96277 +const char *check_heap_object(const void *ptr, unsigned long n)
96278 +{
96279 + struct page *page;
96280 + const slob_t *free;
96281 + const void *base;
96282 + unsigned long flags;
96283 +
96284 + if (ZERO_OR_NULL_PTR(ptr))
96285 + return "<null>";
96286 +
96287 + if (!virt_addr_valid(ptr))
96288 + return NULL;
96289 +
96290 + page = virt_to_head_page(ptr);
96291 + if (!PageSlab(page))
96292 + return NULL;
96293 +
96294 + if (page->private) {
96295 + base = page;
96296 + if (base <= ptr && n <= page->private - (ptr - base))
96297 + return NULL;
96298 + return "<slob>";
96299 + }
96300 +
96301 + /* some tricky double walking to find the chunk */
96302 + spin_lock_irqsave(&slob_lock, flags);
96303 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96304 + free = page->freelist;
96305 +
96306 + while (!slob_last(free) && (void *)free <= ptr) {
96307 + base = free + slob_units(free);
96308 + free = slob_next(free);
96309 + }
96310 +
96311 + while (base < (void *)free) {
96312 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96313 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96314 + int offset;
96315 +
96316 + if (ptr < base + align)
96317 + break;
96318 +
96319 + offset = ptr - base - align;
96320 + if (offset >= m) {
96321 + base += size;
96322 + continue;
96323 + }
96324 +
96325 + if (n > m - offset)
96326 + break;
96327 +
96328 + spin_unlock_irqrestore(&slob_lock, flags);
96329 + return NULL;
96330 + }
96331 +
96332 + spin_unlock_irqrestore(&slob_lock, flags);
96333 + return "<slob>";
96334 +}
96335 +#endif
96336 +
96337 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96338 size_t ksize(const void *block)
96339 {
96340 struct page *sp;
96341 int align;
96342 - unsigned int *m;
96343 + slob_t *m;
96344
96345 BUG_ON(!block);
96346 if (unlikely(block == ZERO_SIZE_PTR))
96347 return 0;
96348
96349 sp = virt_to_page(block);
96350 - if (unlikely(!PageSlab(sp)))
96351 - return PAGE_SIZE << compound_order(sp);
96352 + VM_BUG_ON(!PageSlab(sp));
96353 + if (sp->private)
96354 + return sp->private;
96355
96356 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96357 - m = (unsigned int *)(block - align);
96358 - return SLOB_UNITS(*m) * SLOB_UNIT;
96359 + m = (slob_t *)(block - align);
96360 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96361 }
96362 EXPORT_SYMBOL(ksize);
96363
96364 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96365
96366 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96367 {
96368 - void *b;
96369 + void *b = NULL;
96370
96371 flags &= gfp_allowed_mask;
96372
96373 lockdep_trace_alloc(flags);
96374
96375 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96376 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96377 +#else
96378 if (c->size < PAGE_SIZE) {
96379 b = slob_alloc(c->size, flags, c->align, node);
96380 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96381 SLOB_UNITS(c->size) * SLOB_UNIT,
96382 flags, node);
96383 } else {
96384 - b = slob_new_pages(flags, get_order(c->size), node);
96385 + struct page *sp;
96386 +
96387 + sp = slob_new_pages(flags, get_order(c->size), node);
96388 + if (sp) {
96389 + b = page_address(sp);
96390 + sp->private = c->size;
96391 + }
96392 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96393 PAGE_SIZE << get_order(c->size),
96394 flags, node);
96395 }
96396 +#endif
96397
96398 if (b && c->ctor)
96399 c->ctor(b);
96400 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96401
96402 static void __kmem_cache_free(void *b, int size)
96403 {
96404 - if (size < PAGE_SIZE)
96405 + struct page *sp;
96406 +
96407 + sp = virt_to_page(b);
96408 + BUG_ON(!PageSlab(sp));
96409 + if (!sp->private)
96410 slob_free(b, size);
96411 else
96412 - slob_free_pages(b, get_order(size));
96413 + slob_free_pages(sp, get_order(size));
96414 }
96415
96416 static void kmem_rcu_free(struct rcu_head *head)
96417 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96418
96419 void kmem_cache_free(struct kmem_cache *c, void *b)
96420 {
96421 + int size = c->size;
96422 +
96423 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96424 + if (size + c->align < PAGE_SIZE) {
96425 + size += c->align;
96426 + b -= c->align;
96427 + }
96428 +#endif
96429 +
96430 kmemleak_free_recursive(b, c->flags);
96431 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96432 struct slob_rcu *slob_rcu;
96433 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96434 - slob_rcu->size = c->size;
96435 + slob_rcu = b + (size - sizeof(struct slob_rcu));
96436 + slob_rcu->size = size;
96437 call_rcu(&slob_rcu->head, kmem_rcu_free);
96438 } else {
96439 - __kmem_cache_free(b, c->size);
96440 + __kmem_cache_free(b, size);
96441 }
96442
96443 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96444 + trace_kfree(_RET_IP_, b);
96445 +#else
96446 trace_kmem_cache_free(_RET_IP_, b);
96447 +#endif
96448 +
96449 }
96450 EXPORT_SYMBOL(kmem_cache_free);
96451
96452 diff --git a/mm/slub.c b/mm/slub.c
96453 index 2b1ce69..4a2193f 100644
96454 --- a/mm/slub.c
96455 +++ b/mm/slub.c
96456 @@ -207,7 +207,7 @@ struct track {
96457
96458 enum track_item { TRACK_ALLOC, TRACK_FREE };
96459
96460 -#ifdef CONFIG_SYSFS
96461 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96462 static int sysfs_slab_add(struct kmem_cache *);
96463 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96464 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96465 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96466 if (!t->addr)
96467 return;
96468
96469 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96470 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96471 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96472 #ifdef CONFIG_STACKTRACE
96473 {
96474 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96475
96476 slab_free_hook(s, x);
96477
96478 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96479 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96480 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96481 + if (s->ctor)
96482 + s->ctor(x);
96483 + }
96484 +#endif
96485 +
96486 redo:
96487 /*
96488 * Determine the currently cpus per cpu slab.
96489 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
96490 * Merge control. If this is set then no merging of slab caches will occur.
96491 * (Could be removed. This was introduced to pacify the merge skeptics.)
96492 */
96493 -static int slub_nomerge;
96494 +static int slub_nomerge = 1;
96495
96496 /*
96497 * Calculate the order of allocation given an slab object size.
96498 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96499 s->inuse = size;
96500
96501 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96502 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96503 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96504 +#endif
96505 s->ctor)) {
96506 /*
96507 * Relocate free pointer after the object if it is not
96508 @@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96509 EXPORT_SYMBOL(__kmalloc_node);
96510 #endif
96511
96512 +bool is_usercopy_object(const void *ptr)
96513 +{
96514 + struct page *page;
96515 + struct kmem_cache *s;
96516 +
96517 + if (ZERO_OR_NULL_PTR(ptr))
96518 + return false;
96519 +
96520 + if (!slab_is_available())
96521 + return false;
96522 +
96523 + if (!virt_addr_valid(ptr))
96524 + return false;
96525 +
96526 + page = virt_to_head_page(ptr);
96527 +
96528 + if (!PageSlab(page))
96529 + return false;
96530 +
96531 + s = page->slab_cache;
96532 + return s->flags & SLAB_USERCOPY;
96533 +}
96534 +
96535 +#ifdef CONFIG_PAX_USERCOPY
96536 +const char *check_heap_object(const void *ptr, unsigned long n)
96537 +{
96538 + struct page *page;
96539 + struct kmem_cache *s;
96540 + unsigned long offset;
96541 +
96542 + if (ZERO_OR_NULL_PTR(ptr))
96543 + return "<null>";
96544 +
96545 + if (!virt_addr_valid(ptr))
96546 + return NULL;
96547 +
96548 + page = virt_to_head_page(ptr);
96549 +
96550 + if (!PageSlab(page))
96551 + return NULL;
96552 +
96553 + s = page->slab_cache;
96554 + if (!(s->flags & SLAB_USERCOPY))
96555 + return s->name;
96556 +
96557 + offset = (ptr - page_address(page)) % s->size;
96558 + if (offset <= s->object_size && n <= s->object_size - offset)
96559 + return NULL;
96560 +
96561 + return s->name;
96562 +}
96563 +#endif
96564 +
96565 size_t ksize(const void *object)
96566 {
96567 struct page *page;
96568 @@ -3371,6 +3435,7 @@ void kfree(const void *x)
96569 if (unlikely(ZERO_OR_NULL_PTR(x)))
96570 return;
96571
96572 + VM_BUG_ON(!virt_addr_valid(x));
96573 page = virt_to_head_page(x);
96574 if (unlikely(!PageSlab(page))) {
96575 BUG_ON(!PageCompound(page));
96576 @@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96577 /*
96578 * We may have set a slab to be unmergeable during bootstrap.
96579 */
96580 - if (s->refcount < 0)
96581 + if (atomic_read(&s->refcount) < 0)
96582 return 1;
96583
96584 return 0;
96585 @@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96586 int i;
96587 struct kmem_cache *c;
96588
96589 - s->refcount++;
96590 + atomic_inc(&s->refcount);
96591
96592 /*
96593 * Adjust the object sizes so that we clear
96594 @@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96595 }
96596
96597 if (sysfs_slab_alias(s, name)) {
96598 - s->refcount--;
96599 + atomic_dec(&s->refcount);
96600 s = NULL;
96601 }
96602 }
96603 @@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96604 }
96605 #endif
96606
96607 -#ifdef CONFIG_SYSFS
96608 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96609 static int count_inuse(struct page *page)
96610 {
96611 return page->inuse;
96612 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96613 len += sprintf(buf + len, "%7ld ", l->count);
96614
96615 if (l->addr)
96616 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96617 + len += sprintf(buf + len, "%pS", NULL);
96618 +#else
96619 len += sprintf(buf + len, "%pS", (void *)l->addr);
96620 +#endif
96621 else
96622 len += sprintf(buf + len, "<not-available>");
96623
96624 @@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96625 validate_slab_cache(kmalloc_caches[9]);
96626 }
96627 #else
96628 -#ifdef CONFIG_SYSFS
96629 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96630 static void resiliency_test(void) {};
96631 #endif
96632 #endif
96633
96634 -#ifdef CONFIG_SYSFS
96635 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96636 enum slab_stat_type {
96637 SL_ALL, /* All slabs */
96638 SL_PARTIAL, /* Only partially allocated slabs */
96639 @@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96640 {
96641 if (!s->ctor)
96642 return 0;
96643 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96644 + return sprintf(buf, "%pS\n", NULL);
96645 +#else
96646 return sprintf(buf, "%pS\n", s->ctor);
96647 +#endif
96648 }
96649 SLAB_ATTR_RO(ctor);
96650
96651 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96652 {
96653 - return sprintf(buf, "%d\n", s->refcount - 1);
96654 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96655 }
96656 SLAB_ATTR_RO(aliases);
96657
96658 @@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96659 SLAB_ATTR_RO(cache_dma);
96660 #endif
96661
96662 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96663 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96664 +{
96665 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96666 +}
96667 +SLAB_ATTR_RO(usercopy);
96668 +#endif
96669 +
96670 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96671 {
96672 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96673 @@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
96674 #ifdef CONFIG_ZONE_DMA
96675 &cache_dma_attr.attr,
96676 #endif
96677 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96678 + &usercopy_attr.attr,
96679 +#endif
96680 #ifdef CONFIG_NUMA
96681 &remote_node_defrag_ratio_attr.attr,
96682 #endif
96683 @@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
96684 return name;
96685 }
96686
96687 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96688 static int sysfs_slab_add(struct kmem_cache *s)
96689 {
96690 int err;
96691 @@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
96692 kobject_del(&s->kobj);
96693 kobject_put(&s->kobj);
96694 }
96695 +#endif
96696
96697 /*
96698 * Need to buffer aliases during bootup until sysfs becomes
96699 @@ -5270,6 +5356,7 @@ struct saved_alias {
96700
96701 static struct saved_alias *alias_list;
96702
96703 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96704 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96705 {
96706 struct saved_alias *al;
96707 @@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96708 alias_list = al;
96709 return 0;
96710 }
96711 +#endif
96712
96713 static int __init slab_sysfs_init(void)
96714 {
96715 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96716 index 4cba9c2..b4f9fcc 100644
96717 --- a/mm/sparse-vmemmap.c
96718 +++ b/mm/sparse-vmemmap.c
96719 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96720 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96721 if (!p)
96722 return NULL;
96723 - pud_populate(&init_mm, pud, p);
96724 + pud_populate_kernel(&init_mm, pud, p);
96725 }
96726 return pud;
96727 }
96728 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96729 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96730 if (!p)
96731 return NULL;
96732 - pgd_populate(&init_mm, pgd, p);
96733 + pgd_populate_kernel(&init_mm, pgd, p);
96734 }
96735 return pgd;
96736 }
96737 diff --git a/mm/sparse.c b/mm/sparse.c
96738 index d1b48b6..6e8590e 100644
96739 --- a/mm/sparse.c
96740 +++ b/mm/sparse.c
96741 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96742
96743 for (i = 0; i < PAGES_PER_SECTION; i++) {
96744 if (PageHWPoison(&memmap[i])) {
96745 - atomic_long_sub(1, &num_poisoned_pages);
96746 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
96747 ClearPageHWPoison(&memmap[i]);
96748 }
96749 }
96750 diff --git a/mm/swap.c b/mm/swap.c
96751 index 9ce43ba..43bdc4c 100644
96752 --- a/mm/swap.c
96753 +++ b/mm/swap.c
96754 @@ -31,6 +31,7 @@
96755 #include <linux/memcontrol.h>
96756 #include <linux/gfp.h>
96757 #include <linux/uio.h>
96758 +#include <linux/hugetlb.h>
96759
96760 #include "internal.h"
96761
96762 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96763
96764 __page_cache_release(page);
96765 dtor = get_compound_page_dtor(page);
96766 + if (!PageHuge(page))
96767 + BUG_ON(dtor != free_compound_page);
96768 (*dtor)(page);
96769 }
96770
96771 diff --git a/mm/swapfile.c b/mm/swapfile.c
96772 index 4a7f7e6..22cddf5 100644
96773 --- a/mm/swapfile.c
96774 +++ b/mm/swapfile.c
96775 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96776
96777 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96778 /* Activity counter to indicate that a swapon or swapoff has occurred */
96779 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
96780 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96781
96782 static inline unsigned char swap_count(unsigned char ent)
96783 {
96784 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96785 spin_unlock(&swap_lock);
96786
96787 err = 0;
96788 - atomic_inc(&proc_poll_event);
96789 + atomic_inc_unchecked(&proc_poll_event);
96790 wake_up_interruptible(&proc_poll_wait);
96791
96792 out_dput:
96793 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96794
96795 poll_wait(file, &proc_poll_wait, wait);
96796
96797 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
96798 - seq->poll_event = atomic_read(&proc_poll_event);
96799 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96800 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96801 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96802 }
96803
96804 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96805 return ret;
96806
96807 seq = file->private_data;
96808 - seq->poll_event = atomic_read(&proc_poll_event);
96809 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96810 return 0;
96811 }
96812
96813 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96814 (frontswap_map) ? "FS" : "");
96815
96816 mutex_unlock(&swapon_mutex);
96817 - atomic_inc(&proc_poll_event);
96818 + atomic_inc_unchecked(&proc_poll_event);
96819 wake_up_interruptible(&proc_poll_wait);
96820
96821 if (S_ISREG(inode->i_mode))
96822 diff --git a/mm/util.c b/mm/util.c
96823 index d5ea733..e8953f9 100644
96824 --- a/mm/util.c
96825 +++ b/mm/util.c
96826 @@ -299,6 +299,12 @@ done:
96827 void arch_pick_mmap_layout(struct mm_struct *mm)
96828 {
96829 mm->mmap_base = TASK_UNMAPPED_BASE;
96830 +
96831 +#ifdef CONFIG_PAX_RANDMMAP
96832 + if (mm->pax_flags & MF_PAX_RANDMMAP)
96833 + mm->mmap_base += mm->delta_mmap;
96834 +#endif
96835 +
96836 mm->get_unmapped_area = arch_get_unmapped_area;
96837 }
96838 #endif
96839 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
96840 if (!mm->arg_end)
96841 goto out_mm; /* Shh! No looking before we're done */
96842
96843 + if (gr_acl_handle_procpidmem(task))
96844 + goto out_mm;
96845 +
96846 len = mm->arg_end - mm->arg_start;
96847
96848 if (len > buflen)
96849 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96850 index bf233b2..1dfa1bc 100644
96851 --- a/mm/vmalloc.c
96852 +++ b/mm/vmalloc.c
96853 @@ -40,6 +40,21 @@ struct vfree_deferred {
96854 };
96855 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
96856
96857 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96858 +struct stack_deferred_llist {
96859 + struct llist_head list;
96860 + void *stack;
96861 + void *lowmem_stack;
96862 +};
96863 +
96864 +struct stack_deferred {
96865 + struct stack_deferred_llist list;
96866 + struct work_struct wq;
96867 +};
96868 +
96869 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
96870 +#endif
96871 +
96872 static void __vunmap(const void *, int);
96873
96874 static void free_work(struct work_struct *w)
96875 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
96876 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
96877 struct llist_node *llnode = llist_del_all(&p->list);
96878 while (llnode) {
96879 - void *p = llnode;
96880 + void *x = llnode;
96881 llnode = llist_next(llnode);
96882 - __vunmap(p, 1);
96883 + __vunmap(x, 1);
96884 }
96885 }
96886
96887 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96888 +static void unmap_work(struct work_struct *w)
96889 +{
96890 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
96891 + struct llist_node *llnode = llist_del_all(&p->list.list);
96892 + while (llnode) {
96893 + struct stack_deferred_llist *x =
96894 + llist_entry((struct llist_head *)llnode,
96895 + struct stack_deferred_llist, list);
96896 + void *stack = ACCESS_ONCE(x->stack);
96897 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
96898 + llnode = llist_next(llnode);
96899 + __vunmap(stack, 0);
96900 + free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
96901 + }
96902 +}
96903 +#endif
96904 +
96905 /*** Page table manipulation functions ***/
96906
96907 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96908 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96909
96910 pte = pte_offset_kernel(pmd, addr);
96911 do {
96912 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96913 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96914 +
96915 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96916 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96917 + BUG_ON(!pte_exec(*pte));
96918 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96919 + continue;
96920 + }
96921 +#endif
96922 +
96923 + {
96924 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96925 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96926 + }
96927 } while (pte++, addr += PAGE_SIZE, addr != end);
96928 }
96929
96930 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96931 pte = pte_alloc_kernel(pmd, addr);
96932 if (!pte)
96933 return -ENOMEM;
96934 +
96935 + pax_open_kernel();
96936 do {
96937 struct page *page = pages[*nr];
96938
96939 - if (WARN_ON(!pte_none(*pte)))
96940 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96941 + if (pgprot_val(prot) & _PAGE_NX)
96942 +#endif
96943 +
96944 + if (!pte_none(*pte)) {
96945 + pax_close_kernel();
96946 + WARN_ON(1);
96947 return -EBUSY;
96948 - if (WARN_ON(!page))
96949 + }
96950 + if (!page) {
96951 + pax_close_kernel();
96952 + WARN_ON(1);
96953 return -ENOMEM;
96954 + }
96955 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96956 (*nr)++;
96957 } while (pte++, addr += PAGE_SIZE, addr != end);
96958 + pax_close_kernel();
96959 return 0;
96960 }
96961
96962 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96963 pmd_t *pmd;
96964 unsigned long next;
96965
96966 - pmd = pmd_alloc(&init_mm, pud, addr);
96967 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96968 if (!pmd)
96969 return -ENOMEM;
96970 do {
96971 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96972 pud_t *pud;
96973 unsigned long next;
96974
96975 - pud = pud_alloc(&init_mm, pgd, addr);
96976 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
96977 if (!pud)
96978 return -ENOMEM;
96979 do {
96980 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
96981 if (addr >= MODULES_VADDR && addr < MODULES_END)
96982 return 1;
96983 #endif
96984 +
96985 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96986 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96987 + return 1;
96988 +#endif
96989 +
96990 return is_vmalloc_addr(x);
96991 }
96992
96993 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96994
96995 if (!pgd_none(*pgd)) {
96996 pud_t *pud = pud_offset(pgd, addr);
96997 +#ifdef CONFIG_X86
96998 + if (!pud_large(*pud))
96999 +#endif
97000 if (!pud_none(*pud)) {
97001 pmd_t *pmd = pmd_offset(pud, addr);
97002 +#ifdef CONFIG_X86
97003 + if (!pmd_large(*pmd))
97004 +#endif
97005 if (!pmd_none(*pmd)) {
97006 pte_t *ptep, pte;
97007
97008 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97009 for_each_possible_cpu(i) {
97010 struct vmap_block_queue *vbq;
97011 struct vfree_deferred *p;
97012 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97013 + struct stack_deferred *p2;
97014 +#endif
97015
97016 vbq = &per_cpu(vmap_block_queue, i);
97017 spin_lock_init(&vbq->lock);
97018 INIT_LIST_HEAD(&vbq->free);
97019 +
97020 p = &per_cpu(vfree_deferred, i);
97021 init_llist_head(&p->list);
97022 INIT_WORK(&p->wq, free_work);
97023 +
97024 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97025 + p2 = &per_cpu(stack_deferred, i);
97026 + init_llist_head(&p2->list.list);
97027 + INIT_WORK(&p2->wq, unmap_work);
97028 +#endif
97029 }
97030
97031 /* Import existing vmlist entries. */
97032 @@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97033 struct vm_struct *area;
97034
97035 BUG_ON(in_interrupt());
97036 +
97037 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97038 + if (flags & VM_KERNEXEC) {
97039 + if (start != VMALLOC_START || end != VMALLOC_END)
97040 + return NULL;
97041 + start = (unsigned long)MODULES_EXEC_VADDR;
97042 + end = (unsigned long)MODULES_EXEC_END;
97043 + }
97044 +#endif
97045 +
97046 if (flags & VM_IOREMAP)
97047 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97048
97049 @@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97050 }
97051 EXPORT_SYMBOL(vunmap);
97052
97053 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97054 +void unmap_process_stacks(struct task_struct *task)
97055 +{
97056 + if (unlikely(in_interrupt())) {
97057 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97058 + struct stack_deferred_llist *list = task->stack;
97059 + list->stack = task->stack;
97060 + list->lowmem_stack = task->lowmem_stack;
97061 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
97062 + schedule_work(&p->wq);
97063 + } else {
97064 + __vunmap(task->stack, 0);
97065 + free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97066 + }
97067 +}
97068 +#endif
97069 +
97070 /**
97071 * vmap - map an array of pages into virtually contiguous space
97072 * @pages: array of page pointers
97073 @@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97074 if (count > totalram_pages)
97075 return NULL;
97076
97077 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97078 + if (!(pgprot_val(prot) & _PAGE_NX))
97079 + flags |= VM_KERNEXEC;
97080 +#endif
97081 +
97082 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97083 __builtin_return_address(0));
97084 if (!area)
97085 @@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97086 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97087 goto fail;
97088
97089 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97090 + if (!(pgprot_val(prot) & _PAGE_NX))
97091 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97092 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97093 + else
97094 +#endif
97095 +
97096 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97097 start, end, node, gfp_mask, caller);
97098 if (!area)
97099 @@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97100 * For tight control over page level allocator and protection flags
97101 * use __vmalloc() instead.
97102 */
97103 -
97104 void *vmalloc_exec(unsigned long size)
97105 {
97106 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97107 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97108 NUMA_NO_NODE, __builtin_return_address(0));
97109 }
97110
97111 @@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97112 {
97113 struct vm_struct *area;
97114
97115 + BUG_ON(vma->vm_mirror);
97116 +
97117 size = PAGE_ALIGN(size);
97118
97119 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97120 @@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97121 v->addr, v->addr + v->size, v->size);
97122
97123 if (v->caller)
97124 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97125 + seq_printf(m, " %pK", v->caller);
97126 +#else
97127 seq_printf(m, " %pS", v->caller);
97128 +#endif
97129
97130 if (v->nr_pages)
97131 seq_printf(m, " pages=%d", v->nr_pages);
97132 diff --git a/mm/vmstat.c b/mm/vmstat.c
97133 index 302dd07..3841f1c 100644
97134 --- a/mm/vmstat.c
97135 +++ b/mm/vmstat.c
97136 @@ -20,6 +20,7 @@
97137 #include <linux/writeback.h>
97138 #include <linux/compaction.h>
97139 #include <linux/mm_inline.h>
97140 +#include <linux/grsecurity.h>
97141
97142 #include "internal.h"
97143
97144 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97145 *
97146 * vm_stat contains the global counters
97147 */
97148 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97149 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97150 EXPORT_SYMBOL(vm_stat);
97151
97152 #ifdef CONFIG_SMP
97153 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97154
97155 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97156 if (diff[i])
97157 - atomic_long_add(diff[i], &vm_stat[i]);
97158 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97159 }
97160
97161 /*
97162 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97163 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97164 if (v) {
97165
97166 - atomic_long_add(v, &zone->vm_stat[i]);
97167 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97168 global_diff[i] += v;
97169 #ifdef CONFIG_NUMA
97170 /* 3 seconds idle till flush */
97171 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97172
97173 v = p->vm_stat_diff[i];
97174 p->vm_stat_diff[i] = 0;
97175 - atomic_long_add(v, &zone->vm_stat[i]);
97176 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97177 global_diff[i] += v;
97178 }
97179 }
97180 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97181 if (pset->vm_stat_diff[i]) {
97182 int v = pset->vm_stat_diff[i];
97183 pset->vm_stat_diff[i] = 0;
97184 - atomic_long_add(v, &zone->vm_stat[i]);
97185 - atomic_long_add(v, &vm_stat[i]);
97186 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97187 + atomic_long_add_unchecked(v, &vm_stat[i]);
97188 }
97189 }
97190 #endif
97191 @@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97192 stat_items_size += sizeof(struct vm_event_state);
97193 #endif
97194
97195 - v = kmalloc(stat_items_size, GFP_KERNEL);
97196 + v = kzalloc(stat_items_size, GFP_KERNEL);
97197 m->private = v;
97198 if (!v)
97199 return ERR_PTR(-ENOMEM);
97200 +
97201 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97202 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97203 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97204 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97205 + && !in_group_p(grsec_proc_gid)
97206 +#endif
97207 + )
97208 + return (unsigned long *)m->private + *pos;
97209 +#endif
97210 +#endif
97211 +
97212 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97213 v[i] = global_page_state(i);
97214 v += NR_VM_ZONE_STAT_ITEMS;
97215 @@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97216 cpu_notifier_register_done();
97217 #endif
97218 #ifdef CONFIG_PROC_FS
97219 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97220 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97221 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97222 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97223 + {
97224 + mode_t gr_mode = S_IRUGO;
97225 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97226 + gr_mode = S_IRUSR;
97227 +#endif
97228 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97229 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97230 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97231 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97232 + }
97233 #endif
97234 return 0;
97235 }
97236 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97237 index 44ebd5c..1f732bae 100644
97238 --- a/net/8021q/vlan.c
97239 +++ b/net/8021q/vlan.c
97240 @@ -475,7 +475,7 @@ out:
97241 return NOTIFY_DONE;
97242 }
97243
97244 -static struct notifier_block vlan_notifier_block __read_mostly = {
97245 +static struct notifier_block vlan_notifier_block = {
97246 .notifier_call = vlan_device_event,
97247 };
97248
97249 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97250 err = -EPERM;
97251 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97252 break;
97253 - if ((args.u.name_type >= 0) &&
97254 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97255 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97256 struct vlan_net *vn;
97257
97258 vn = net_generic(net, vlan_net_id);
97259 diff --git a/net/9p/client.c b/net/9p/client.c
97260 index 0004cba..feba240 100644
97261 --- a/net/9p/client.c
97262 +++ b/net/9p/client.c
97263 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97264 len - inline_len);
97265 } else {
97266 err = copy_from_user(ename + inline_len,
97267 - uidata, len - inline_len);
97268 + (char __force_user *)uidata, len - inline_len);
97269 if (err) {
97270 err = -EFAULT;
97271 goto out_err;
97272 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97273 kernel_buf = 1;
97274 indata = data;
97275 } else
97276 - indata = (__force char *)udata;
97277 + indata = (__force_kernel char *)udata;
97278 /*
97279 * response header len is 11
97280 * PDU Header(7) + IO Size (4)
97281 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97282 kernel_buf = 1;
97283 odata = data;
97284 } else
97285 - odata = (char *)udata;
97286 + odata = (char __force_kernel *)udata;
97287 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97288 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97289 fid->fid, offset, rsize);
97290 diff --git a/net/9p/mod.c b/net/9p/mod.c
97291 index 6ab36ae..6f1841b 100644
97292 --- a/net/9p/mod.c
97293 +++ b/net/9p/mod.c
97294 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97295 void v9fs_register_trans(struct p9_trans_module *m)
97296 {
97297 spin_lock(&v9fs_trans_lock);
97298 - list_add_tail(&m->list, &v9fs_trans_list);
97299 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97300 spin_unlock(&v9fs_trans_lock);
97301 }
97302 EXPORT_SYMBOL(v9fs_register_trans);
97303 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97304 void v9fs_unregister_trans(struct p9_trans_module *m)
97305 {
97306 spin_lock(&v9fs_trans_lock);
97307 - list_del_init(&m->list);
97308 + pax_list_del_init((struct list_head *)&m->list);
97309 spin_unlock(&v9fs_trans_lock);
97310 }
97311 EXPORT_SYMBOL(v9fs_unregister_trans);
97312 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97313 index 80d08f6..de63fd1 100644
97314 --- a/net/9p/trans_fd.c
97315 +++ b/net/9p/trans_fd.c
97316 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97317 oldfs = get_fs();
97318 set_fs(get_ds());
97319 /* The cast to a user pointer is valid due to the set_fs() */
97320 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97321 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97322 set_fs(oldfs);
97323
97324 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97325 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97326 index af46bc4..f9adfcd 100644
97327 --- a/net/appletalk/atalk_proc.c
97328 +++ b/net/appletalk/atalk_proc.c
97329 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97330 struct proc_dir_entry *p;
97331 int rc = -ENOMEM;
97332
97333 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97334 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97335 if (!atalk_proc_dir)
97336 goto out;
97337
97338 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97339 index 876fbe8..8bbea9f 100644
97340 --- a/net/atm/atm_misc.c
97341 +++ b/net/atm/atm_misc.c
97342 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97343 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97344 return 1;
97345 atm_return(vcc, truesize);
97346 - atomic_inc(&vcc->stats->rx_drop);
97347 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97348 return 0;
97349 }
97350 EXPORT_SYMBOL(atm_charge);
97351 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97352 }
97353 }
97354 atm_return(vcc, guess);
97355 - atomic_inc(&vcc->stats->rx_drop);
97356 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97357 return NULL;
97358 }
97359 EXPORT_SYMBOL(atm_alloc_charge);
97360 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97361
97362 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97363 {
97364 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97365 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97366 __SONET_ITEMS
97367 #undef __HANDLE_ITEM
97368 }
97369 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97370
97371 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97372 {
97373 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97374 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97375 __SONET_ITEMS
97376 #undef __HANDLE_ITEM
97377 }
97378 diff --git a/net/atm/lec.c b/net/atm/lec.c
97379 index 4c5b8ba..95f7005 100644
97380 --- a/net/atm/lec.c
97381 +++ b/net/atm/lec.c
97382 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97383 }
97384
97385 static struct lane2_ops lane2_ops = {
97386 - lane2_resolve, /* resolve, spec 3.1.3 */
97387 - lane2_associate_req, /* associate_req, spec 3.1.4 */
97388 - NULL /* associate indicator, spec 3.1.5 */
97389 + .resolve = lane2_resolve,
97390 + .associate_req = lane2_associate_req,
97391 + .associate_indicator = NULL
97392 };
97393
97394 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97395 diff --git a/net/atm/lec.h b/net/atm/lec.h
97396 index 4149db1..f2ab682 100644
97397 --- a/net/atm/lec.h
97398 +++ b/net/atm/lec.h
97399 @@ -48,7 +48,7 @@ struct lane2_ops {
97400 const u8 *tlvs, u32 sizeoftlvs);
97401 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97402 const u8 *tlvs, u32 sizeoftlvs);
97403 -};
97404 +} __no_const;
97405
97406 /*
97407 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97408 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97409 index d1b2d9a..d549f7f 100644
97410 --- a/net/atm/mpoa_caches.c
97411 +++ b/net/atm/mpoa_caches.c
97412 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97413
97414
97415 static struct in_cache_ops ingress_ops = {
97416 - in_cache_add_entry, /* add_entry */
97417 - in_cache_get, /* get */
97418 - in_cache_get_with_mask, /* get_with_mask */
97419 - in_cache_get_by_vcc, /* get_by_vcc */
97420 - in_cache_put, /* put */
97421 - in_cache_remove_entry, /* remove_entry */
97422 - cache_hit, /* cache_hit */
97423 - clear_count_and_expired, /* clear_count */
97424 - check_resolving_entries, /* check_resolving */
97425 - refresh_entries, /* refresh */
97426 - in_destroy_cache /* destroy_cache */
97427 + .add_entry = in_cache_add_entry,
97428 + .get = in_cache_get,
97429 + .get_with_mask = in_cache_get_with_mask,
97430 + .get_by_vcc = in_cache_get_by_vcc,
97431 + .put = in_cache_put,
97432 + .remove_entry = in_cache_remove_entry,
97433 + .cache_hit = cache_hit,
97434 + .clear_count = clear_count_and_expired,
97435 + .check_resolving = check_resolving_entries,
97436 + .refresh = refresh_entries,
97437 + .destroy_cache = in_destroy_cache
97438 };
97439
97440 static struct eg_cache_ops egress_ops = {
97441 - eg_cache_add_entry, /* add_entry */
97442 - eg_cache_get_by_cache_id, /* get_by_cache_id */
97443 - eg_cache_get_by_tag, /* get_by_tag */
97444 - eg_cache_get_by_vcc, /* get_by_vcc */
97445 - eg_cache_get_by_src_ip, /* get_by_src_ip */
97446 - eg_cache_put, /* put */
97447 - eg_cache_remove_entry, /* remove_entry */
97448 - update_eg_cache_entry, /* update */
97449 - clear_expired, /* clear_expired */
97450 - eg_destroy_cache /* destroy_cache */
97451 + .add_entry = eg_cache_add_entry,
97452 + .get_by_cache_id = eg_cache_get_by_cache_id,
97453 + .get_by_tag = eg_cache_get_by_tag,
97454 + .get_by_vcc = eg_cache_get_by_vcc,
97455 + .get_by_src_ip = eg_cache_get_by_src_ip,
97456 + .put = eg_cache_put,
97457 + .remove_entry = eg_cache_remove_entry,
97458 + .update = update_eg_cache_entry,
97459 + .clear_expired = clear_expired,
97460 + .destroy_cache = eg_destroy_cache
97461 };
97462
97463
97464 diff --git a/net/atm/proc.c b/net/atm/proc.c
97465 index bbb6461..cf04016 100644
97466 --- a/net/atm/proc.c
97467 +++ b/net/atm/proc.c
97468 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97469 const struct k_atm_aal_stats *stats)
97470 {
97471 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97472 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97473 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97474 - atomic_read(&stats->rx_drop));
97475 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97476 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97477 + atomic_read_unchecked(&stats->rx_drop));
97478 }
97479
97480 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97481 diff --git a/net/atm/resources.c b/net/atm/resources.c
97482 index 0447d5d..3cf4728 100644
97483 --- a/net/atm/resources.c
97484 +++ b/net/atm/resources.c
97485 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97486 static void copy_aal_stats(struct k_atm_aal_stats *from,
97487 struct atm_aal_stats *to)
97488 {
97489 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97490 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97491 __AAL_STAT_ITEMS
97492 #undef __HANDLE_ITEM
97493 }
97494 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97495 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97496 struct atm_aal_stats *to)
97497 {
97498 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97499 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97500 __AAL_STAT_ITEMS
97501 #undef __HANDLE_ITEM
97502 }
97503 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97504 index 919a5ce..cc6b444 100644
97505 --- a/net/ax25/sysctl_net_ax25.c
97506 +++ b/net/ax25/sysctl_net_ax25.c
97507 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97508 {
97509 char path[sizeof("net/ax25/") + IFNAMSIZ];
97510 int k;
97511 - struct ctl_table *table;
97512 + ctl_table_no_const *table;
97513
97514 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97515 if (!table)
97516 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97517 index f04224c..f326579 100644
97518 --- a/net/batman-adv/bat_iv_ogm.c
97519 +++ b/net/batman-adv/bat_iv_ogm.c
97520 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97521
97522 /* randomize initial seqno to avoid collision */
97523 get_random_bytes(&random_seqno, sizeof(random_seqno));
97524 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97525 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97526
97527 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97528 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97529 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97530 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97531
97532 /* change sequence number to network order */
97533 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97534 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97535 batadv_ogm_packet->seqno = htonl(seqno);
97536 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97537 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97538
97539 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97540
97541 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97542 return;
97543
97544 /* could be changed by schedule_own_packet() */
97545 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97546 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97547
97548 if (ogm_packet->flags & BATADV_DIRECTLINK)
97549 has_directlink_flag = true;
97550 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97551 index f14e54a..66f3e2e 100644
97552 --- a/net/batman-adv/fragmentation.c
97553 +++ b/net/batman-adv/fragmentation.c
97554 @@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97555 frag_header.packet_type = BATADV_UNICAST_FRAG;
97556 frag_header.version = BATADV_COMPAT_VERSION;
97557 frag_header.ttl = BATADV_TTL;
97558 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97559 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97560 frag_header.reserved = 0;
97561 frag_header.no = 0;
97562 frag_header.total_size = htons(skb->len);
97563 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97564 index 744a59b..8fd037c 100644
97565 --- a/net/batman-adv/soft-interface.c
97566 +++ b/net/batman-adv/soft-interface.c
97567 @@ -296,7 +296,7 @@ send:
97568 primary_if->net_dev->dev_addr);
97569
97570 /* set broadcast sequence number */
97571 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97572 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97573 bcast_packet->seqno = htonl(seqno);
97574
97575 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97576 @@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97577 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97578
97579 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97580 - atomic_set(&bat_priv->bcast_seqno, 1);
97581 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97582 atomic_set(&bat_priv->tt.vn, 0);
97583 atomic_set(&bat_priv->tt.local_changes, 0);
97584 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97585 @@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97586
97587 /* randomize initial seqno to avoid collision */
97588 get_random_bytes(&random_seqno, sizeof(random_seqno));
97589 - atomic_set(&bat_priv->frag_seqno, random_seqno);
97590 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97591
97592 bat_priv->primary_if = NULL;
97593 bat_priv->num_ifaces = 0;
97594 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97595 index 34891a5..3cfece0 100644
97596 --- a/net/batman-adv/types.h
97597 +++ b/net/batman-adv/types.h
97598 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97599 struct batadv_hard_iface_bat_iv {
97600 unsigned char *ogm_buff;
97601 int ogm_buff_len;
97602 - atomic_t ogm_seqno;
97603 + atomic_unchecked_t ogm_seqno;
97604 };
97605
97606 /**
97607 @@ -766,7 +766,7 @@ struct batadv_priv {
97608 atomic_t bonding;
97609 atomic_t fragmentation;
97610 atomic_t packet_size_max;
97611 - atomic_t frag_seqno;
97612 + atomic_unchecked_t frag_seqno;
97613 #ifdef CONFIG_BATMAN_ADV_BLA
97614 atomic_t bridge_loop_avoidance;
97615 #endif
97616 @@ -785,7 +785,7 @@ struct batadv_priv {
97617 #endif
97618 uint32_t isolation_mark;
97619 uint32_t isolation_mark_mask;
97620 - atomic_t bcast_seqno;
97621 + atomic_unchecked_t bcast_seqno;
97622 atomic_t bcast_queue_left;
97623 atomic_t batman_queue_left;
97624 char num_ifaces;
97625 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97626 index b9a418e..2af862a 100644
97627 --- a/net/bluetooth/hci_sock.c
97628 +++ b/net/bluetooth/hci_sock.c
97629 @@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97630 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97631 }
97632
97633 - len = min_t(unsigned int, len, sizeof(uf));
97634 + len = min((size_t)len, sizeof(uf));
97635 if (copy_from_user(&uf, optval, len)) {
97636 err = -EFAULT;
97637 break;
97638 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97639 index dc4d301..4975bac 100644
97640 --- a/net/bluetooth/l2cap_core.c
97641 +++ b/net/bluetooth/l2cap_core.c
97642 @@ -3536,8 +3536,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97643 break;
97644
97645 case L2CAP_CONF_RFC:
97646 - if (olen == sizeof(rfc))
97647 - memcpy(&rfc, (void *)val, olen);
97648 + if (olen != sizeof(rfc))
97649 + break;
97650 +
97651 + memcpy(&rfc, (void *)val, olen);
97652
97653 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97654 rfc.mode != chan->mode)
97655 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97656 index ade3fb4..df37cb4 100644
97657 --- a/net/bluetooth/l2cap_sock.c
97658 +++ b/net/bluetooth/l2cap_sock.c
97659 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97660 struct sock *sk = sock->sk;
97661 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97662 struct l2cap_options opts;
97663 - int len, err = 0;
97664 + int err = 0;
97665 + size_t len = optlen;
97666 u32 opt;
97667
97668 BT_DBG("sk %p", sk);
97669 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97670 opts.max_tx = chan->max_tx;
97671 opts.txwin_size = chan->tx_win;
97672
97673 - len = min_t(unsigned int, sizeof(opts), optlen);
97674 + len = min(sizeof(opts), len);
97675 if (copy_from_user((char *) &opts, optval, len)) {
97676 err = -EFAULT;
97677 break;
97678 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97679 struct bt_security sec;
97680 struct bt_power pwr;
97681 struct l2cap_conn *conn;
97682 - int len, err = 0;
97683 + int err = 0;
97684 + size_t len = optlen;
97685 u32 opt;
97686
97687 BT_DBG("sk %p", sk);
97688 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97689
97690 sec.level = BT_SECURITY_LOW;
97691
97692 - len = min_t(unsigned int, sizeof(sec), optlen);
97693 + len = min(sizeof(sec), len);
97694 if (copy_from_user((char *) &sec, optval, len)) {
97695 err = -EFAULT;
97696 break;
97697 @@ -866,7 +868,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97698
97699 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97700
97701 - len = min_t(unsigned int, sizeof(pwr), optlen);
97702 + len = min(sizeof(pwr), len);
97703 if (copy_from_user((char *) &pwr, optval, len)) {
97704 err = -EFAULT;
97705 break;
97706 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97707 index c603a5e..7f08991 100644
97708 --- a/net/bluetooth/rfcomm/sock.c
97709 +++ b/net/bluetooth/rfcomm/sock.c
97710 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97711 struct sock *sk = sock->sk;
97712 struct bt_security sec;
97713 int err = 0;
97714 - size_t len;
97715 + size_t len = optlen;
97716 u32 opt;
97717
97718 BT_DBG("sk %p", sk);
97719 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97720
97721 sec.level = BT_SECURITY_LOW;
97722
97723 - len = min_t(unsigned int, sizeof(sec), optlen);
97724 + len = min(sizeof(sec), len);
97725 if (copy_from_user((char *) &sec, optval, len)) {
97726 err = -EFAULT;
97727 break;
97728 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97729 index 403ec09..a21a003 100644
97730 --- a/net/bluetooth/rfcomm/tty.c
97731 +++ b/net/bluetooth/rfcomm/tty.c
97732 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97733 BT_DBG("tty %p id %d", tty, tty->index);
97734
97735 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97736 - dev->channel, dev->port.count);
97737 + dev->channel, atomic_read(&dev->port.count));
97738
97739 err = tty_port_open(&dev->port, tty, filp);
97740 if (err)
97741 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97742 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97743
97744 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97745 - dev->port.count);
97746 + atomic_read(&dev->port.count));
97747
97748 tty_port_close(&dev->port, tty, filp);
97749 }
97750 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97751 index 1059ed3..d70846a 100644
97752 --- a/net/bridge/netfilter/ebtables.c
97753 +++ b/net/bridge/netfilter/ebtables.c
97754 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97755 tmp.valid_hooks = t->table->valid_hooks;
97756 }
97757 mutex_unlock(&ebt_mutex);
97758 - if (copy_to_user(user, &tmp, *len) != 0) {
97759 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97760 BUGPRINT("c2u Didn't work\n");
97761 ret = -EFAULT;
97762 break;
97763 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97764 goto out;
97765 tmp.valid_hooks = t->valid_hooks;
97766
97767 - if (copy_to_user(user, &tmp, *len) != 0) {
97768 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97769 ret = -EFAULT;
97770 break;
97771 }
97772 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97773 tmp.entries_size = t->table->entries_size;
97774 tmp.valid_hooks = t->table->valid_hooks;
97775
97776 - if (copy_to_user(user, &tmp, *len) != 0) {
97777 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97778 ret = -EFAULT;
97779 break;
97780 }
97781 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97782 index 0f45522..dab651f 100644
97783 --- a/net/caif/cfctrl.c
97784 +++ b/net/caif/cfctrl.c
97785 @@ -10,6 +10,7 @@
97786 #include <linux/spinlock.h>
97787 #include <linux/slab.h>
97788 #include <linux/pkt_sched.h>
97789 +#include <linux/sched.h>
97790 #include <net/caif/caif_layer.h>
97791 #include <net/caif/cfpkt.h>
97792 #include <net/caif/cfctrl.h>
97793 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97794 memset(&dev_info, 0, sizeof(dev_info));
97795 dev_info.id = 0xff;
97796 cfsrvl_init(&this->serv, 0, &dev_info, false);
97797 - atomic_set(&this->req_seq_no, 1);
97798 - atomic_set(&this->rsp_seq_no, 1);
97799 + atomic_set_unchecked(&this->req_seq_no, 1);
97800 + atomic_set_unchecked(&this->rsp_seq_no, 1);
97801 this->serv.layer.receive = cfctrl_recv;
97802 sprintf(this->serv.layer.name, "ctrl");
97803 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97804 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97805 struct cfctrl_request_info *req)
97806 {
97807 spin_lock_bh(&ctrl->info_list_lock);
97808 - atomic_inc(&ctrl->req_seq_no);
97809 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
97810 + atomic_inc_unchecked(&ctrl->req_seq_no);
97811 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97812 list_add_tail(&req->list, &ctrl->list);
97813 spin_unlock_bh(&ctrl->info_list_lock);
97814 }
97815 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97816 if (p != first)
97817 pr_warn("Requests are not received in order\n");
97818
97819 - atomic_set(&ctrl->rsp_seq_no,
97820 + atomic_set_unchecked(&ctrl->rsp_seq_no,
97821 p->sequence_no);
97822 list_del(&p->list);
97823 goto out;
97824 diff --git a/net/can/af_can.c b/net/can/af_can.c
97825 index a27f8aa..67174a3 100644
97826 --- a/net/can/af_can.c
97827 +++ b/net/can/af_can.c
97828 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97829 };
97830
97831 /* notifier block for netdevice event */
97832 -static struct notifier_block can_netdev_notifier __read_mostly = {
97833 +static struct notifier_block can_netdev_notifier = {
97834 .notifier_call = can_notifier,
97835 };
97836
97837 diff --git a/net/can/bcm.c b/net/can/bcm.c
97838 index dcb75c0..24b1b43 100644
97839 --- a/net/can/bcm.c
97840 +++ b/net/can/bcm.c
97841 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97842 }
97843
97844 /* create /proc/net/can-bcm directory */
97845 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97846 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97847 return 0;
97848 }
97849
97850 diff --git a/net/can/gw.c b/net/can/gw.c
97851 index 050a211..bb9fe33 100644
97852 --- a/net/can/gw.c
97853 +++ b/net/can/gw.c
97854 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97855 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97856
97857 static HLIST_HEAD(cgw_list);
97858 -static struct notifier_block notifier;
97859
97860 static struct kmem_cache *cgw_cache __read_mostly;
97861
97862 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97863 return err;
97864 }
97865
97866 +static struct notifier_block notifier = {
97867 + .notifier_call = cgw_notifier
97868 +};
97869 +
97870 static __init int cgw_module_init(void)
97871 {
97872 /* sanitize given module parameter */
97873 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97874 return -ENOMEM;
97875
97876 /* set notifier */
97877 - notifier.notifier_call = cgw_notifier;
97878 register_netdevice_notifier(&notifier);
97879
97880 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97881 diff --git a/net/can/proc.c b/net/can/proc.c
97882 index b543470..d2ddae2 100644
97883 --- a/net/can/proc.c
97884 +++ b/net/can/proc.c
97885 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97886 void can_init_proc(void)
97887 {
97888 /* create /proc/net/can directory */
97889 - can_dir = proc_mkdir("can", init_net.proc_net);
97890 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97891
97892 if (!can_dir) {
97893 printk(KERN_INFO "can: failed to create /proc/net/can . "
97894 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97895 index 1948d59..9e854d5 100644
97896 --- a/net/ceph/messenger.c
97897 +++ b/net/ceph/messenger.c
97898 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97899 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97900
97901 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97902 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
97903 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97904
97905 static struct page *zero_page; /* used in certain error cases */
97906
97907 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97908 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97909 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97910
97911 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97912 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97913 s = addr_str[i];
97914
97915 switch (ss->ss_family) {
97916 diff --git a/net/compat.c b/net/compat.c
97917 index 9a76eaf..5b8ccfd 100644
97918 --- a/net/compat.c
97919 +++ b/net/compat.c
97920 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97921 return -EFAULT;
97922 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97923 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97924 - kmsg->msg_name = compat_ptr(tmp1);
97925 - kmsg->msg_iov = compat_ptr(tmp2);
97926 - kmsg->msg_control = compat_ptr(tmp3);
97927 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97928 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97929 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97930 return 0;
97931 }
97932
97933 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97934
97935 if (kern_msg->msg_namelen) {
97936 if (mode == VERIFY_READ) {
97937 - int err = move_addr_to_kernel(kern_msg->msg_name,
97938 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97939 kern_msg->msg_namelen,
97940 kern_address);
97941 if (err < 0)
97942 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97943 kern_msg->msg_name = NULL;
97944
97945 tot_len = iov_from_user_compat_to_kern(kern_iov,
97946 - (struct compat_iovec __user *)kern_msg->msg_iov,
97947 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
97948 kern_msg->msg_iovlen);
97949 if (tot_len >= 0)
97950 kern_msg->msg_iov = kern_iov;
97951 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97952
97953 #define CMSG_COMPAT_FIRSTHDR(msg) \
97954 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97955 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97956 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97957 (struct compat_cmsghdr __user *)NULL)
97958
97959 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97960 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97961 (ucmlen) <= (unsigned long) \
97962 ((mhdr)->msg_controllen - \
97963 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97964 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97965
97966 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97967 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97968 {
97969 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97970 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97971 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97972 msg->msg_controllen)
97973 return NULL;
97974 return (struct compat_cmsghdr __user *)ptr;
97975 @@ -222,7 +222,7 @@ Efault:
97976
97977 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97978 {
97979 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97980 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97981 struct compat_cmsghdr cmhdr;
97982 struct compat_timeval ctv;
97983 struct compat_timespec cts[3];
97984 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97985
97986 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97987 {
97988 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97989 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97990 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97991 int fdnum = scm->fp->count;
97992 struct file **fp = scm->fp->fp;
97993 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97994 return -EFAULT;
97995 old_fs = get_fs();
97996 set_fs(KERNEL_DS);
97997 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97998 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97999 set_fs(old_fs);
98000
98001 return err;
98002 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98003 len = sizeof(ktime);
98004 old_fs = get_fs();
98005 set_fs(KERNEL_DS);
98006 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98007 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98008 set_fs(old_fs);
98009
98010 if (!err) {
98011 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98012 case MCAST_JOIN_GROUP:
98013 case MCAST_LEAVE_GROUP:
98014 {
98015 - struct compat_group_req __user *gr32 = (void *)optval;
98016 + struct compat_group_req __user *gr32 = (void __user *)optval;
98017 struct group_req __user *kgr =
98018 compat_alloc_user_space(sizeof(struct group_req));
98019 u32 interface;
98020 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98021 case MCAST_BLOCK_SOURCE:
98022 case MCAST_UNBLOCK_SOURCE:
98023 {
98024 - struct compat_group_source_req __user *gsr32 = (void *)optval;
98025 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98026 struct group_source_req __user *kgsr = compat_alloc_user_space(
98027 sizeof(struct group_source_req));
98028 u32 interface;
98029 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98030 }
98031 case MCAST_MSFILTER:
98032 {
98033 - struct compat_group_filter __user *gf32 = (void *)optval;
98034 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98035 struct group_filter __user *kgf;
98036 u32 interface, fmode, numsrc;
98037
98038 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98039 char __user *optval, int __user *optlen,
98040 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98041 {
98042 - struct compat_group_filter __user *gf32 = (void *)optval;
98043 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98044 struct group_filter __user *kgf;
98045 int __user *koptlen;
98046 u32 interface, fmode, numsrc;
98047 @@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98048
98049 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98050 return -EINVAL;
98051 - if (copy_from_user(a, args, nas[call]))
98052 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98053 return -EFAULT;
98054 a0 = a[0];
98055 a1 = a[1];
98056 diff --git a/net/core/datagram.c b/net/core/datagram.c
98057 index a16ed7b..eb44d17 100644
98058 --- a/net/core/datagram.c
98059 +++ b/net/core/datagram.c
98060 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98061 }
98062
98063 kfree_skb(skb);
98064 - atomic_inc(&sk->sk_drops);
98065 + atomic_inc_unchecked(&sk->sk_drops);
98066 sk_mem_reclaim_partial(sk);
98067
98068 return err;
98069 diff --git a/net/core/dev.c b/net/core/dev.c
98070 index a30bef1..51d3e33 100644
98071 --- a/net/core/dev.c
98072 +++ b/net/core/dev.c
98073 @@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98074 {
98075 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98076 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98077 - atomic_long_inc(&dev->rx_dropped);
98078 + atomic_long_inc_unchecked(&dev->rx_dropped);
98079 kfree_skb(skb);
98080 return NET_RX_DROP;
98081 }
98082 }
98083
98084 if (unlikely(!is_skb_forwardable(dev, skb))) {
98085 - atomic_long_inc(&dev->rx_dropped);
98086 + atomic_long_inc_unchecked(&dev->rx_dropped);
98087 kfree_skb(skb);
98088 return NET_RX_DROP;
98089 }
98090 @@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98091
98092 struct dev_gso_cb {
98093 void (*destructor)(struct sk_buff *skb);
98094 -};
98095 +} __no_const;
98096
98097 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98098
98099 @@ -2893,7 +2893,7 @@ recursion_alert:
98100 rc = -ENETDOWN;
98101 rcu_read_unlock_bh();
98102
98103 - atomic_long_inc(&dev->tx_dropped);
98104 + atomic_long_inc_unchecked(&dev->tx_dropped);
98105 kfree_skb(skb);
98106 return rc;
98107 out:
98108 @@ -3237,7 +3237,7 @@ enqueue:
98109
98110 local_irq_restore(flags);
98111
98112 - atomic_long_inc(&skb->dev->rx_dropped);
98113 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98114 kfree_skb(skb);
98115 return NET_RX_DROP;
98116 }
98117 @@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98118 }
98119 EXPORT_SYMBOL(netif_rx_ni);
98120
98121 -static void net_tx_action(struct softirq_action *h)
98122 +static __latent_entropy void net_tx_action(void)
98123 {
98124 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98125
98126 @@ -3647,7 +3647,7 @@ ncls:
98127 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98128 } else {
98129 drop:
98130 - atomic_long_inc(&skb->dev->rx_dropped);
98131 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98132 kfree_skb(skb);
98133 /* Jamal, now you will not able to escape explaining
98134 * me how you were going to use this. :-)
98135 @@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98136 }
98137 EXPORT_SYMBOL(netif_napi_del);
98138
98139 -static void net_rx_action(struct softirq_action *h)
98140 +static __latent_entropy void net_rx_action(void)
98141 {
98142 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98143 unsigned long time_limit = jiffies + 2;
98144 @@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98145 } else {
98146 netdev_stats_to_stats64(storage, &dev->stats);
98147 }
98148 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98149 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98150 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98151 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98152 return storage;
98153 }
98154 EXPORT_SYMBOL(dev_get_stats);
98155 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98156 index cf999e0..c59a975 100644
98157 --- a/net/core/dev_ioctl.c
98158 +++ b/net/core/dev_ioctl.c
98159 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98160 if (no_module && capable(CAP_NET_ADMIN))
98161 no_module = request_module("netdev-%s", name);
98162 if (no_module && capable(CAP_SYS_MODULE)) {
98163 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
98164 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
98165 +#else
98166 if (!request_module("%s", name))
98167 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98168 name);
98169 +#endif
98170 }
98171 }
98172 EXPORT_SYMBOL(dev_load);
98173 diff --git a/net/core/dst.c b/net/core/dst.c
98174 index 80d6286..a028409 100644
98175 --- a/net/core/dst.c
98176 +++ b/net/core/dst.c
98177 @@ -269,6 +269,15 @@ again:
98178 }
98179 EXPORT_SYMBOL(dst_destroy);
98180
98181 +static void dst_destroy_rcu(struct rcu_head *head)
98182 +{
98183 + struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98184 +
98185 + dst = dst_destroy(dst);
98186 + if (dst)
98187 + __dst_free(dst);
98188 +}
98189 +
98190 void dst_release(struct dst_entry *dst)
98191 {
98192 if (dst) {
98193 @@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98194
98195 newrefcnt = atomic_dec_return(&dst->__refcnt);
98196 WARN_ON(newrefcnt < 0);
98197 - if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98198 - dst = dst_destroy(dst);
98199 - if (dst)
98200 - __dst_free(dst);
98201 - }
98202 + if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98203 + call_rcu(&dst->rcu_head, dst_destroy_rcu);
98204 }
98205 }
98206 EXPORT_SYMBOL(dst_release);
98207 diff --git a/net/core/filter.c b/net/core/filter.c
98208 index 4aec7b9..5cf605c 100644
98209 --- a/net/core/filter.c
98210 +++ b/net/core/filter.c
98211 @@ -1121,7 +1121,11 @@ do_pass:
98212 break;
98213
98214 default:
98215 - goto err;
98216 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98217 + fp->code, fp->jt, fp->jf, fp->k);
98218 + kfree(addrs);
98219 + BUG();
98220 + return -EINVAL;
98221 }
98222
98223 insn++;
98224 @@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98225 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98226 int pc, ret = 0;
98227
98228 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98229 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98230 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98231 if (!masks)
98232 return -ENOMEM;
98233 @@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98234 if (!fp)
98235 return -ENOMEM;
98236
98237 - memcpy(fp->insns, fprog->filter, fsize);
98238 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98239
98240 atomic_set(&fp->refcnt, 1);
98241 fp->len = fprog->len;
98242 diff --git a/net/core/flow.c b/net/core/flow.c
98243 index a0348fd..6951c76 100644
98244 --- a/net/core/flow.c
98245 +++ b/net/core/flow.c
98246 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98247 static int flow_entry_valid(struct flow_cache_entry *fle,
98248 struct netns_xfrm *xfrm)
98249 {
98250 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98251 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98252 return 0;
98253 if (fle->object && !fle->object->ops->check(fle->object))
98254 return 0;
98255 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98256 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98257 fcp->hash_count++;
98258 }
98259 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98260 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98261 flo = fle->object;
98262 if (!flo)
98263 goto ret_object;
98264 @@ -263,7 +263,7 @@ nocache:
98265 }
98266 flo = resolver(net, key, family, dir, flo, ctx);
98267 if (fle) {
98268 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98269 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98270 if (!IS_ERR(flo))
98271 fle->object = flo;
98272 else
98273 diff --git a/net/core/iovec.c b/net/core/iovec.c
98274 index b618694..192bbba 100644
98275 --- a/net/core/iovec.c
98276 +++ b/net/core/iovec.c
98277 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98278 if (m->msg_namelen) {
98279 if (mode == VERIFY_READ) {
98280 void __user *namep;
98281 - namep = (void __user __force *) m->msg_name;
98282 + namep = (void __force_user *) m->msg_name;
98283 err = move_addr_to_kernel(namep, m->msg_namelen,
98284 address);
98285 if (err < 0)
98286 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98287 }
98288
98289 size = m->msg_iovlen * sizeof(struct iovec);
98290 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98291 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98292 return -EFAULT;
98293
98294 m->msg_iov = iov;
98295 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98296 index 32d872e..487e769 100644
98297 --- a/net/core/neighbour.c
98298 +++ b/net/core/neighbour.c
98299 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98300 void __user *buffer, size_t *lenp, loff_t *ppos)
98301 {
98302 int size, ret;
98303 - struct ctl_table tmp = *ctl;
98304 + ctl_table_no_const tmp = *ctl;
98305
98306 tmp.extra1 = &zero;
98307 tmp.extra2 = &unres_qlen_max;
98308 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98309 void __user *buffer,
98310 size_t *lenp, loff_t *ppos)
98311 {
98312 - struct ctl_table tmp = *ctl;
98313 + ctl_table_no_const tmp = *ctl;
98314 int ret;
98315
98316 tmp.extra1 = &zero;
98317 @@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98318 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98319 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98320 } else {
98321 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98322 dev_name_source = "default";
98323 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98324 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98325 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98326 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98327 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98328 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98329 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98330 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98331 }
98332
98333 if (handler) {
98334 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98335 index 2bf8329..2eb1423 100644
98336 --- a/net/core/net-procfs.c
98337 +++ b/net/core/net-procfs.c
98338 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98339 struct rtnl_link_stats64 temp;
98340 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98341
98342 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98343 + if (gr_proc_is_restricted())
98344 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98345 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98346 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98347 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98348 + else
98349 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98350 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98351 dev->name, stats->rx_bytes, stats->rx_packets,
98352 stats->rx_errors,
98353 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98354 return 0;
98355 }
98356
98357 -static const struct seq_operations dev_seq_ops = {
98358 +const struct seq_operations dev_seq_ops = {
98359 .start = dev_seq_start,
98360 .next = dev_seq_next,
98361 .stop = dev_seq_stop,
98362 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98363
98364 static int softnet_seq_open(struct inode *inode, struct file *file)
98365 {
98366 - return seq_open(file, &softnet_seq_ops);
98367 + return seq_open_restrict(file, &softnet_seq_ops);
98368 }
98369
98370 static const struct file_operations softnet_seq_fops = {
98371 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98372 else
98373 seq_printf(seq, "%04x", ntohs(pt->type));
98374
98375 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98376 + seq_printf(seq, " %-8s %pf\n",
98377 + pt->dev ? pt->dev->name : "", NULL);
98378 +#else
98379 seq_printf(seq, " %-8s %pf\n",
98380 pt->dev ? pt->dev->name : "", pt->func);
98381 +#endif
98382 }
98383
98384 return 0;
98385 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98386 index 1cac29e..fb482f3 100644
98387 --- a/net/core/net-sysfs.c
98388 +++ b/net/core/net-sysfs.c
98389 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98390 {
98391 struct net_device *netdev = to_net_dev(dev);
98392 return sprintf(buf, fmt_dec,
98393 - atomic_read(&netdev->carrier_changes));
98394 + atomic_read_unchecked(&netdev->carrier_changes));
98395 }
98396 static DEVICE_ATTR_RO(carrier_changes);
98397
98398 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98399 index 7c8ffd9..0cb3687 100644
98400 --- a/net/core/net_namespace.c
98401 +++ b/net/core/net_namespace.c
98402 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98403 int error;
98404 LIST_HEAD(net_exit_list);
98405
98406 - list_add_tail(&ops->list, list);
98407 + pax_list_add_tail((struct list_head *)&ops->list, list);
98408 if (ops->init || (ops->id && ops->size)) {
98409 for_each_net(net) {
98410 error = ops_init(ops, net);
98411 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98412
98413 out_undo:
98414 /* If I have an error cleanup all namespaces I initialized */
98415 - list_del(&ops->list);
98416 + pax_list_del((struct list_head *)&ops->list);
98417 ops_exit_list(ops, &net_exit_list);
98418 ops_free_list(ops, &net_exit_list);
98419 return error;
98420 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98421 struct net *net;
98422 LIST_HEAD(net_exit_list);
98423
98424 - list_del(&ops->list);
98425 + pax_list_del((struct list_head *)&ops->list);
98426 for_each_net(net)
98427 list_add_tail(&net->exit_list, &net_exit_list);
98428 ops_exit_list(ops, &net_exit_list);
98429 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98430 mutex_lock(&net_mutex);
98431 error = register_pernet_operations(&pernet_list, ops);
98432 if (!error && (first_device == &pernet_list))
98433 - first_device = &ops->list;
98434 + first_device = (struct list_head *)&ops->list;
98435 mutex_unlock(&net_mutex);
98436 return error;
98437 }
98438 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98439 index e33937f..b2b4981 100644
98440 --- a/net/core/netpoll.c
98441 +++ b/net/core/netpoll.c
98442 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98443 struct udphdr *udph;
98444 struct iphdr *iph;
98445 struct ethhdr *eth;
98446 - static atomic_t ip_ident;
98447 + static atomic_unchecked_t ip_ident;
98448 struct ipv6hdr *ip6h;
98449
98450 udp_len = len + sizeof(*udph);
98451 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98452 put_unaligned(0x45, (unsigned char *)iph);
98453 iph->tos = 0;
98454 put_unaligned(htons(ip_len), &(iph->tot_len));
98455 - iph->id = htons(atomic_inc_return(&ip_ident));
98456 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98457 iph->frag_off = 0;
98458 iph->ttl = 64;
98459 iph->protocol = IPPROTO_UDP;
98460 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98461 index 0304f98..ddfead6 100644
98462 --- a/net/core/pktgen.c
98463 +++ b/net/core/pktgen.c
98464 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98465 pn->net = net;
98466 INIT_LIST_HEAD(&pn->pktgen_threads);
98467 pn->pktgen_exiting = false;
98468 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98469 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98470 if (!pn->proc_dir) {
98471 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98472 return -ENODEV;
98473 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98474 index 1999ed8..1e6e58a 100644
98475 --- a/net/core/rtnetlink.c
98476 +++ b/net/core/rtnetlink.c
98477 @@ -58,7 +58,7 @@ struct rtnl_link {
98478 rtnl_doit_func doit;
98479 rtnl_dumpit_func dumpit;
98480 rtnl_calcit_func calcit;
98481 -};
98482 +} __no_const;
98483
98484 static DEFINE_MUTEX(rtnl_mutex);
98485
98486 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98487 if (rtnl_link_ops_get(ops->kind))
98488 return -EEXIST;
98489
98490 - if (!ops->dellink)
98491 - ops->dellink = unregister_netdevice_queue;
98492 + if (!ops->dellink) {
98493 + pax_open_kernel();
98494 + *(void **)&ops->dellink = unregister_netdevice_queue;
98495 + pax_close_kernel();
98496 + }
98497
98498 - list_add_tail(&ops->list, &link_ops);
98499 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98500 return 0;
98501 }
98502 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98503 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98504 for_each_net(net) {
98505 __rtnl_kill_links(net, ops);
98506 }
98507 - list_del(&ops->list);
98508 + pax_list_del((struct list_head *)&ops->list);
98509 }
98510 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98511
98512 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98513 (dev->ifalias &&
98514 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98515 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98516 - atomic_read(&dev->carrier_changes)))
98517 + atomic_read_unchecked(&dev->carrier_changes)))
98518 goto nla_put_failure;
98519
98520 if (1) {
98521 diff --git a/net/core/scm.c b/net/core/scm.c
98522 index b442e7e..6f5b5a2 100644
98523 --- a/net/core/scm.c
98524 +++ b/net/core/scm.c
98525 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98526 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98527 {
98528 struct cmsghdr __user *cm
98529 - = (__force struct cmsghdr __user *)msg->msg_control;
98530 + = (struct cmsghdr __force_user *)msg->msg_control;
98531 struct cmsghdr cmhdr;
98532 int cmlen = CMSG_LEN(len);
98533 int err;
98534 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98535 err = -EFAULT;
98536 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98537 goto out;
98538 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98539 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98540 goto out;
98541 cmlen = CMSG_SPACE(len);
98542 if (msg->msg_controllen < cmlen)
98543 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98544 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98545 {
98546 struct cmsghdr __user *cm
98547 - = (__force struct cmsghdr __user*)msg->msg_control;
98548 + = (struct cmsghdr __force_user *)msg->msg_control;
98549
98550 int fdmax = 0;
98551 int fdnum = scm->fp->count;
98552 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98553 if (fdnum < fdmax)
98554 fdmax = fdnum;
98555
98556 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98557 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98558 i++, cmfptr++)
98559 {
98560 struct socket *sock;
98561 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98562 index 8383b2b..6397efb 100644
98563 --- a/net/core/skbuff.c
98564 +++ b/net/core/skbuff.c
98565 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98566 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98567 int len, __wsum csum)
98568 {
98569 - const struct skb_checksum_ops ops = {
98570 + static const struct skb_checksum_ops ops = {
98571 .update = csum_partial_ext,
98572 .combine = csum_block_add_ext,
98573 };
98574 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
98575 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98576 sizeof(struct sk_buff),
98577 0,
98578 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98579 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98580 + SLAB_NO_SANITIZE,
98581 NULL);
98582 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98583 (2*sizeof(struct sk_buff)) +
98584 sizeof(atomic_t),
98585 0,
98586 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98587 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98588 + SLAB_NO_SANITIZE,
98589 NULL);
98590 }
98591
98592 diff --git a/net/core/sock.c b/net/core/sock.c
98593 index 664ee42..aaf9e6e 100644
98594 --- a/net/core/sock.c
98595 +++ b/net/core/sock.c
98596 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98597 struct sk_buff_head *list = &sk->sk_receive_queue;
98598
98599 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98600 - atomic_inc(&sk->sk_drops);
98601 + atomic_inc_unchecked(&sk->sk_drops);
98602 trace_sock_rcvqueue_full(sk, skb);
98603 return -ENOMEM;
98604 }
98605 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98606 return err;
98607
98608 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98609 - atomic_inc(&sk->sk_drops);
98610 + atomic_inc_unchecked(&sk->sk_drops);
98611 return -ENOBUFS;
98612 }
98613
98614 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98615 skb_dst_force(skb);
98616
98617 spin_lock_irqsave(&list->lock, flags);
98618 - skb->dropcount = atomic_read(&sk->sk_drops);
98619 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98620 __skb_queue_tail(list, skb);
98621 spin_unlock_irqrestore(&list->lock, flags);
98622
98623 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98624 skb->dev = NULL;
98625
98626 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98627 - atomic_inc(&sk->sk_drops);
98628 + atomic_inc_unchecked(&sk->sk_drops);
98629 goto discard_and_relse;
98630 }
98631 if (nested)
98632 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98633 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98634 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98635 bh_unlock_sock(sk);
98636 - atomic_inc(&sk->sk_drops);
98637 + atomic_inc_unchecked(&sk->sk_drops);
98638 goto discard_and_relse;
98639 }
98640
98641 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98642 struct timeval tm;
98643 } v;
98644
98645 - int lv = sizeof(int);
98646 - int len;
98647 + unsigned int lv = sizeof(int);
98648 + unsigned int len;
98649
98650 if (get_user(len, optlen))
98651 return -EFAULT;
98652 - if (len < 0)
98653 + if (len > INT_MAX)
98654 return -EINVAL;
98655
98656 memset(&v, 0, sizeof(v));
98657 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98658
98659 case SO_PEERNAME:
98660 {
98661 - char address[128];
98662 + char address[_K_SS_MAXSIZE];
98663
98664 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98665 return -ENOTCONN;
98666 - if (lv < len)
98667 + if (lv < len || sizeof address < len)
98668 return -EINVAL;
98669 if (copy_to_user(optval, address, len))
98670 return -EFAULT;
98671 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98672
98673 if (len > lv)
98674 len = lv;
98675 - if (copy_to_user(optval, &v, len))
98676 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
98677 return -EFAULT;
98678 lenout:
98679 if (put_user(len, optlen))
98680 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98681 */
98682 smp_wmb();
98683 atomic_set(&sk->sk_refcnt, 1);
98684 - atomic_set(&sk->sk_drops, 0);
98685 + atomic_set_unchecked(&sk->sk_drops, 0);
98686 }
98687 EXPORT_SYMBOL(sock_init_data);
98688
98689 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98690 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98691 int level, int type)
98692 {
98693 + struct sock_extended_err ee;
98694 struct sock_exterr_skb *serr;
98695 struct sk_buff *skb, *skb2;
98696 int copied, err;
98697 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98698 sock_recv_timestamp(msg, sk, skb);
98699
98700 serr = SKB_EXT_ERR(skb);
98701 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98702 + ee = serr->ee;
98703 + put_cmsg(msg, level, type, sizeof ee, &ee);
98704
98705 msg->msg_flags |= MSG_ERRQUEUE;
98706 err = copied;
98707 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98708 index a4216a4..1c07687 100644
98709 --- a/net/core/sock_diag.c
98710 +++ b/net/core/sock_diag.c
98711 @@ -9,26 +9,33 @@
98712 #include <linux/inet_diag.h>
98713 #include <linux/sock_diag.h>
98714
98715 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98716 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98717 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98718 static DEFINE_MUTEX(sock_diag_table_mutex);
98719
98720 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98721 {
98722 +#ifndef CONFIG_GRKERNSEC_HIDESYM
98723 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98724 cookie[1] != INET_DIAG_NOCOOKIE) &&
98725 ((u32)(unsigned long)sk != cookie[0] ||
98726 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98727 return -ESTALE;
98728 else
98729 +#endif
98730 return 0;
98731 }
98732 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98733
98734 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98735 {
98736 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98737 + cookie[0] = 0;
98738 + cookie[1] = 0;
98739 +#else
98740 cookie[0] = (u32)(unsigned long)sk;
98741 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98742 +#endif
98743 }
98744 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98745
98746 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98747 mutex_lock(&sock_diag_table_mutex);
98748 if (sock_diag_handlers[hndl->family])
98749 err = -EBUSY;
98750 - else
98751 + else {
98752 + pax_open_kernel();
98753 sock_diag_handlers[hndl->family] = hndl;
98754 + pax_close_kernel();
98755 + }
98756 mutex_unlock(&sock_diag_table_mutex);
98757
98758 return err;
98759 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98760
98761 mutex_lock(&sock_diag_table_mutex);
98762 BUG_ON(sock_diag_handlers[family] != hnld);
98763 + pax_open_kernel();
98764 sock_diag_handlers[family] = NULL;
98765 + pax_close_kernel();
98766 mutex_unlock(&sock_diag_table_mutex);
98767 }
98768 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98769 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98770 index cf9cd13..8b56af3 100644
98771 --- a/net/core/sysctl_net_core.c
98772 +++ b/net/core/sysctl_net_core.c
98773 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98774 {
98775 unsigned int orig_size, size;
98776 int ret, i;
98777 - struct ctl_table tmp = {
98778 + ctl_table_no_const tmp = {
98779 .data = &size,
98780 .maxlen = sizeof(size),
98781 .mode = table->mode
98782 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98783 void __user *buffer, size_t *lenp, loff_t *ppos)
98784 {
98785 char id[IFNAMSIZ];
98786 - struct ctl_table tbl = {
98787 + ctl_table_no_const tbl = {
98788 .data = id,
98789 .maxlen = IFNAMSIZ,
98790 };
98791 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98792
98793 static __net_init int sysctl_core_net_init(struct net *net)
98794 {
98795 - struct ctl_table *tbl;
98796 + ctl_table_no_const *tbl = NULL;
98797
98798 net->core.sysctl_somaxconn = SOMAXCONN;
98799
98800 - tbl = netns_core_table;
98801 if (!net_eq(net, &init_net)) {
98802 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98803 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98804 if (tbl == NULL)
98805 goto err_dup;
98806
98807 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98808 if (net->user_ns != &init_user_ns) {
98809 tbl[0].procname = NULL;
98810 }
98811 - }
98812 -
98813 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98814 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98815 + } else
98816 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98817 if (net->core.sysctl_hdr == NULL)
98818 goto err_reg;
98819
98820 return 0;
98821
98822 err_reg:
98823 - if (tbl != netns_core_table)
98824 - kfree(tbl);
98825 + kfree(tbl);
98826 err_dup:
98827 return -ENOMEM;
98828 }
98829 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98830 kfree(tbl);
98831 }
98832
98833 -static __net_initdata struct pernet_operations sysctl_core_ops = {
98834 +static __net_initconst struct pernet_operations sysctl_core_ops = {
98835 .init = sysctl_core_net_init,
98836 .exit = sysctl_core_net_exit,
98837 };
98838 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98839 index 4c04848..f575934 100644
98840 --- a/net/decnet/af_decnet.c
98841 +++ b/net/decnet/af_decnet.c
98842 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
98843 .sysctl_rmem = sysctl_decnet_rmem,
98844 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98845 .obj_size = sizeof(struct dn_sock),
98846 + .slab_flags = SLAB_USERCOPY,
98847 };
98848
98849 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98850 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98851 index 3b726f3..1af6368 100644
98852 --- a/net/decnet/dn_dev.c
98853 +++ b/net/decnet/dn_dev.c
98854 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98855 .extra1 = &min_t3,
98856 .extra2 = &max_t3
98857 },
98858 - {0}
98859 + { }
98860 },
98861 };
98862
98863 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98864 index 5325b54..a0d4d69 100644
98865 --- a/net/decnet/sysctl_net_decnet.c
98866 +++ b/net/decnet/sysctl_net_decnet.c
98867 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98868
98869 if (len > *lenp) len = *lenp;
98870
98871 - if (copy_to_user(buffer, addr, len))
98872 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
98873 return -EFAULT;
98874
98875 *lenp = len;
98876 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98877
98878 if (len > *lenp) len = *lenp;
98879
98880 - if (copy_to_user(buffer, devname, len))
98881 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
98882 return -EFAULT;
98883
98884 *lenp = len;
98885 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
98886 index ef2d543..5b9b73f 100644
98887 --- a/net/ieee802154/reassembly.c
98888 +++ b/net/ieee802154/reassembly.c
98889 @@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
98890
98891 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98892 {
98893 - struct ctl_table *table;
98894 + ctl_table_no_const *table = NULL;
98895 struct ctl_table_header *hdr;
98896
98897 - table = lowpan_frags_ns_ctl_table;
98898 if (!net_eq(net, &init_net)) {
98899 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
98900 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
98901 GFP_KERNEL);
98902 if (table == NULL)
98903 goto err_alloc;
98904 @@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98905 /* Don't export sysctls to unprivileged users */
98906 if (net->user_ns != &init_user_ns)
98907 table[0].procname = NULL;
98908 - }
98909 -
98910 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98911 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98912 + } else
98913 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
98914 if (hdr == NULL)
98915 goto err_reg;
98916
98917 @@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98918 return 0;
98919
98920 err_reg:
98921 - if (!net_eq(net, &init_net))
98922 - kfree(table);
98923 + kfree(table);
98924 err_alloc:
98925 return -ENOMEM;
98926 }
98927 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98928 index 6d6dd34..e5c9bec 100644
98929 --- a/net/ipv4/af_inet.c
98930 +++ b/net/ipv4/af_inet.c
98931 @@ -1736,13 +1736,9 @@ static int __init inet_init(void)
98932
98933 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98934
98935 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98936 - if (!sysctl_local_reserved_ports)
98937 - goto out;
98938 -
98939 rc = proto_register(&tcp_prot, 1);
98940 if (rc)
98941 - goto out_free_reserved_ports;
98942 + goto out;
98943
98944 rc = proto_register(&udp_prot, 1);
98945 if (rc)
98946 @@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
98947 proto_unregister(&udp_prot);
98948 out_unregister_tcp_proto:
98949 proto_unregister(&tcp_prot);
98950 -out_free_reserved_ports:
98951 - kfree(sysctl_local_reserved_ports);
98952 goto out;
98953 }
98954
98955 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98956 index bdbf68b..deb4759 100644
98957 --- a/net/ipv4/devinet.c
98958 +++ b/net/ipv4/devinet.c
98959 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98960 idx = 0;
98961 head = &net->dev_index_head[h];
98962 rcu_read_lock();
98963 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98964 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98965 net->dev_base_seq;
98966 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98967 if (idx < s_idx)
98968 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98969 idx = 0;
98970 head = &net->dev_index_head[h];
98971 rcu_read_lock();
98972 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98973 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98974 net->dev_base_seq;
98975 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98976 if (idx < s_idx)
98977 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98978 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98979 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98980
98981 -static struct devinet_sysctl_table {
98982 +static const struct devinet_sysctl_table {
98983 struct ctl_table_header *sysctl_header;
98984 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98985 } devinet_sysctl = {
98986 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98987 int err;
98988 struct ipv4_devconf *all, *dflt;
98989 #ifdef CONFIG_SYSCTL
98990 - struct ctl_table *tbl = ctl_forward_entry;
98991 + ctl_table_no_const *tbl = NULL;
98992 struct ctl_table_header *forw_hdr;
98993 #endif
98994
98995 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98996 goto err_alloc_dflt;
98997
98998 #ifdef CONFIG_SYSCTL
98999 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99000 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99001 if (tbl == NULL)
99002 goto err_alloc_ctl;
99003
99004 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99005 goto err_reg_dflt;
99006
99007 err = -ENOMEM;
99008 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99009 + if (!net_eq(net, &init_net))
99010 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99011 + else
99012 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99013 if (forw_hdr == NULL)
99014 goto err_reg_ctl;
99015 net->ipv4.forw_hdr = forw_hdr;
99016 @@ -2272,8 +2275,7 @@ err_reg_ctl:
99017 err_reg_dflt:
99018 __devinet_sysctl_unregister(all);
99019 err_reg_all:
99020 - if (tbl != ctl_forward_entry)
99021 - kfree(tbl);
99022 + kfree(tbl);
99023 err_alloc_ctl:
99024 #endif
99025 if (dflt != &ipv4_devconf_dflt)
99026 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99027 index 255aa99..45c78f8 100644
99028 --- a/net/ipv4/fib_frontend.c
99029 +++ b/net/ipv4/fib_frontend.c
99030 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99031 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99032 fib_sync_up(dev);
99033 #endif
99034 - atomic_inc(&net->ipv4.dev_addr_genid);
99035 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99036 rt_cache_flush(dev_net(dev));
99037 break;
99038 case NETDEV_DOWN:
99039 fib_del_ifaddr(ifa, NULL);
99040 - atomic_inc(&net->ipv4.dev_addr_genid);
99041 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99042 if (ifa->ifa_dev->ifa_list == NULL) {
99043 /* Last address was deleted from this interface.
99044 * Disable IP.
99045 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99046 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99047 fib_sync_up(dev);
99048 #endif
99049 - atomic_inc(&net->ipv4.dev_addr_genid);
99050 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99051 rt_cache_flush(net);
99052 break;
99053 case NETDEV_DOWN:
99054 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99055 index b10cd43a..22327f9 100644
99056 --- a/net/ipv4/fib_semantics.c
99057 +++ b/net/ipv4/fib_semantics.c
99058 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99059 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99060 nh->nh_gw,
99061 nh->nh_parent->fib_scope);
99062 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99063 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99064
99065 return nh->nh_saddr;
99066 }
99067 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99068 index a56b8e6..5be2a30 100644
99069 --- a/net/ipv4/inet_connection_sock.c
99070 +++ b/net/ipv4/inet_connection_sock.c
99071 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99072 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99073 #endif
99074
99075 -unsigned long *sysctl_local_reserved_ports;
99076 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99077 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99078
99079 void inet_get_local_port_range(struct net *net, int *low, int *high)
99080 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99081 index 8b9cf27..0d8d592 100644
99082 --- a/net/ipv4/inet_hashtables.c
99083 +++ b/net/ipv4/inet_hashtables.c
99084 @@ -18,6 +18,7 @@
99085 #include <linux/sched.h>
99086 #include <linux/slab.h>
99087 #include <linux/wait.h>
99088 +#include <linux/security.h>
99089
99090 #include <net/inet_connection_sock.h>
99091 #include <net/inet_hashtables.h>
99092 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99093 return inet_ehashfn(net, laddr, lport, faddr, fport);
99094 }
99095
99096 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99097 +
99098 /*
99099 * Allocate and initialize a new local port bind bucket.
99100 * The bindhash mutex for snum's hash chain must be held here.
99101 @@ -554,6 +557,8 @@ ok:
99102 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99103 spin_unlock(&head->lock);
99104
99105 + gr_update_task_in_ip_table(current, inet_sk(sk));
99106 +
99107 if (tw) {
99108 inet_twsk_deschedule(tw, death_row);
99109 while (twrefcnt) {
99110 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99111 index 48f4244..f56d83a 100644
99112 --- a/net/ipv4/inetpeer.c
99113 +++ b/net/ipv4/inetpeer.c
99114 @@ -496,8 +496,8 @@ relookup:
99115 if (p) {
99116 p->daddr = *daddr;
99117 atomic_set(&p->refcnt, 1);
99118 - atomic_set(&p->rid, 0);
99119 - atomic_set(&p->ip_id_count,
99120 + atomic_set_unchecked(&p->rid, 0);
99121 + atomic_set_unchecked(&p->ip_id_count,
99122 (daddr->family == AF_INET) ?
99123 secure_ip_id(daddr->addr.a4) :
99124 secure_ipv6_id(daddr->addr.a6));
99125 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99126 index ed32313..3762abe 100644
99127 --- a/net/ipv4/ip_fragment.c
99128 +++ b/net/ipv4/ip_fragment.c
99129 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99130 return 0;
99131
99132 start = qp->rid;
99133 - end = atomic_inc_return(&peer->rid);
99134 + end = atomic_inc_return_unchecked(&peer->rid);
99135 qp->rid = end;
99136
99137 rc = qp->q.fragments && (end - start) > max;
99138 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99139
99140 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99141 {
99142 - struct ctl_table *table;
99143 + ctl_table_no_const *table = NULL;
99144 struct ctl_table_header *hdr;
99145
99146 - table = ip4_frags_ns_ctl_table;
99147 if (!net_eq(net, &init_net)) {
99148 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99149 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99150 if (table == NULL)
99151 goto err_alloc;
99152
99153 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99154 /* Don't export sysctls to unprivileged users */
99155 if (net->user_ns != &init_user_ns)
99156 table[0].procname = NULL;
99157 - }
99158 + hdr = register_net_sysctl(net, "net/ipv4", table);
99159 + } else
99160 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99161
99162 - hdr = register_net_sysctl(net, "net/ipv4", table);
99163 if (hdr == NULL)
99164 goto err_reg;
99165
99166 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99167 return 0;
99168
99169 err_reg:
99170 - if (!net_eq(net, &init_net))
99171 - kfree(table);
99172 + kfree(table);
99173 err_alloc:
99174 return -ENOMEM;
99175 }
99176 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99177 index 94213c8..8bdb342 100644
99178 --- a/net/ipv4/ip_gre.c
99179 +++ b/net/ipv4/ip_gre.c
99180 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99181 module_param(log_ecn_error, bool, 0644);
99182 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99183
99184 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99185 +static struct rtnl_link_ops ipgre_link_ops;
99186 static int ipgre_tunnel_init(struct net_device *dev);
99187
99188 static int ipgre_net_id __read_mostly;
99189 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99190 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99191 };
99192
99193 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99194 +static struct rtnl_link_ops ipgre_link_ops = {
99195 .kind = "gre",
99196 .maxtype = IFLA_GRE_MAX,
99197 .policy = ipgre_policy,
99198 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99199 .fill_info = ipgre_fill_info,
99200 };
99201
99202 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99203 +static struct rtnl_link_ops ipgre_tap_ops = {
99204 .kind = "gretap",
99205 .maxtype = IFLA_GRE_MAX,
99206 .policy = ipgre_policy,
99207 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99208 index 64741b9..6f334a2 100644
99209 --- a/net/ipv4/ip_sockglue.c
99210 +++ b/net/ipv4/ip_sockglue.c
99211 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99212 len = min_t(unsigned int, len, opt->optlen);
99213 if (put_user(len, optlen))
99214 return -EFAULT;
99215 - if (copy_to_user(optval, opt->__data, len))
99216 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99217 + copy_to_user(optval, opt->__data, len))
99218 return -EFAULT;
99219 return 0;
99220 }
99221 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99222 if (sk->sk_type != SOCK_STREAM)
99223 return -ENOPROTOOPT;
99224
99225 - msg.msg_control = optval;
99226 + msg.msg_control = (void __force_kernel *)optval;
99227 msg.msg_controllen = len;
99228 msg.msg_flags = flags;
99229
99230 diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99231 index 2acc233..b93143f 100644
99232 --- a/net/ipv4/ip_tunnel.c
99233 +++ b/net/ipv4/ip_tunnel.c
99234 @@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99235 {
99236 struct dst_entry *old_dst;
99237
99238 - if (dst) {
99239 - if (dst->flags & DST_NOCACHE)
99240 - dst = NULL;
99241 - else
99242 - dst_clone(dst);
99243 - }
99244 + dst_clone(dst);
99245 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99246 dst_release(old_dst);
99247 }
99248 @@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99249
99250 rcu_read_lock();
99251 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99252 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99253 + dst = NULL;
99254 if (dst) {
99255 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99256 - rcu_read_unlock();
99257 tunnel_dst_reset(t);
99258 - return NULL;
99259 + dst_release(dst);
99260 + dst = NULL;
99261 }
99262 - dst_hold(dst);
99263 }
99264 rcu_read_unlock();
99265 return (struct rtable *)dst;
99266 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99267 index 13ef00f..8ffca25 100644
99268 --- a/net/ipv4/ip_vti.c
99269 +++ b/net/ipv4/ip_vti.c
99270 @@ -45,7 +45,7 @@
99271 #include <net/net_namespace.h>
99272 #include <net/netns/generic.h>
99273
99274 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99275 +static struct rtnl_link_ops vti_link_ops;
99276
99277 static int vti_net_id __read_mostly;
99278 static int vti_tunnel_init(struct net_device *dev);
99279 @@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99280 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99281 };
99282
99283 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99284 +static struct rtnl_link_ops vti_link_ops = {
99285 .kind = "vti",
99286 .maxtype = IFLA_VTI_MAX,
99287 .policy = vti_policy,
99288 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99289 index b3e86ea..18ce98c 100644
99290 --- a/net/ipv4/ipconfig.c
99291 +++ b/net/ipv4/ipconfig.c
99292 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99293
99294 mm_segment_t oldfs = get_fs();
99295 set_fs(get_ds());
99296 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99297 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99298 set_fs(oldfs);
99299 return res;
99300 }
99301 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99302
99303 mm_segment_t oldfs = get_fs();
99304 set_fs(get_ds());
99305 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99306 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99307 set_fs(oldfs);
99308 return res;
99309 }
99310 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99311
99312 mm_segment_t oldfs = get_fs();
99313 set_fs(get_ds());
99314 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99315 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99316 set_fs(oldfs);
99317 return res;
99318 }
99319 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99320 index 62eaa00..29b2dc2 100644
99321 --- a/net/ipv4/ipip.c
99322 +++ b/net/ipv4/ipip.c
99323 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99324 static int ipip_net_id __read_mostly;
99325
99326 static int ipip_tunnel_init(struct net_device *dev);
99327 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99328 +static struct rtnl_link_ops ipip_link_ops;
99329
99330 static int ipip_err(struct sk_buff *skb, u32 info)
99331 {
99332 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99333 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99334 };
99335
99336 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99337 +static struct rtnl_link_ops ipip_link_ops = {
99338 .kind = "ipip",
99339 .maxtype = IFLA_IPTUN_MAX,
99340 .policy = ipip_policy,
99341 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99342 index f95b6f9..2ee2097 100644
99343 --- a/net/ipv4/netfilter/arp_tables.c
99344 +++ b/net/ipv4/netfilter/arp_tables.c
99345 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99346 #endif
99347
99348 static int get_info(struct net *net, void __user *user,
99349 - const int *len, int compat)
99350 + int len, int compat)
99351 {
99352 char name[XT_TABLE_MAXNAMELEN];
99353 struct xt_table *t;
99354 int ret;
99355
99356 - if (*len != sizeof(struct arpt_getinfo)) {
99357 - duprintf("length %u != %Zu\n", *len,
99358 + if (len != sizeof(struct arpt_getinfo)) {
99359 + duprintf("length %u != %Zu\n", len,
99360 sizeof(struct arpt_getinfo));
99361 return -EINVAL;
99362 }
99363 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99364 info.size = private->size;
99365 strcpy(info.name, name);
99366
99367 - if (copy_to_user(user, &info, *len) != 0)
99368 + if (copy_to_user(user, &info, len) != 0)
99369 ret = -EFAULT;
99370 else
99371 ret = 0;
99372 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99373
99374 switch (cmd) {
99375 case ARPT_SO_GET_INFO:
99376 - ret = get_info(sock_net(sk), user, len, 1);
99377 + ret = get_info(sock_net(sk), user, *len, 1);
99378 break;
99379 case ARPT_SO_GET_ENTRIES:
99380 ret = compat_get_entries(sock_net(sk), user, len);
99381 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99382
99383 switch (cmd) {
99384 case ARPT_SO_GET_INFO:
99385 - ret = get_info(sock_net(sk), user, len, 0);
99386 + ret = get_info(sock_net(sk), user, *len, 0);
99387 break;
99388
99389 case ARPT_SO_GET_ENTRIES:
99390 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99391 index 99e810f..3711b81 100644
99392 --- a/net/ipv4/netfilter/ip_tables.c
99393 +++ b/net/ipv4/netfilter/ip_tables.c
99394 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99395 #endif
99396
99397 static int get_info(struct net *net, void __user *user,
99398 - const int *len, int compat)
99399 + int len, int compat)
99400 {
99401 char name[XT_TABLE_MAXNAMELEN];
99402 struct xt_table *t;
99403 int ret;
99404
99405 - if (*len != sizeof(struct ipt_getinfo)) {
99406 - duprintf("length %u != %zu\n", *len,
99407 + if (len != sizeof(struct ipt_getinfo)) {
99408 + duprintf("length %u != %zu\n", len,
99409 sizeof(struct ipt_getinfo));
99410 return -EINVAL;
99411 }
99412 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99413 info.size = private->size;
99414 strcpy(info.name, name);
99415
99416 - if (copy_to_user(user, &info, *len) != 0)
99417 + if (copy_to_user(user, &info, len) != 0)
99418 ret = -EFAULT;
99419 else
99420 ret = 0;
99421 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99422
99423 switch (cmd) {
99424 case IPT_SO_GET_INFO:
99425 - ret = get_info(sock_net(sk), user, len, 1);
99426 + ret = get_info(sock_net(sk), user, *len, 1);
99427 break;
99428 case IPT_SO_GET_ENTRIES:
99429 ret = compat_get_entries(sock_net(sk), user, len);
99430 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99431
99432 switch (cmd) {
99433 case IPT_SO_GET_INFO:
99434 - ret = get_info(sock_net(sk), user, len, 0);
99435 + ret = get_info(sock_net(sk), user, *len, 0);
99436 break;
99437
99438 case IPT_SO_GET_ENTRIES:
99439 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99440 index 2510c02..cfb34fa 100644
99441 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99442 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99443 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99444 spin_lock_init(&cn->lock);
99445
99446 #ifdef CONFIG_PROC_FS
99447 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99448 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99449 if (!cn->procdir) {
99450 pr_err("Unable to proc dir entry\n");
99451 return -ENOMEM;
99452 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99453 index 044a0dd..e0c1971 100644
99454 --- a/net/ipv4/ping.c
99455 +++ b/net/ipv4/ping.c
99456 @@ -59,7 +59,7 @@ struct ping_table {
99457 };
99458
99459 static struct ping_table ping_table;
99460 -struct pingv6_ops pingv6_ops;
99461 +struct pingv6_ops *pingv6_ops;
99462 EXPORT_SYMBOL_GPL(pingv6_ops);
99463
99464 static u16 ping_port_rover;
99465 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99466 return -ENODEV;
99467 }
99468 }
99469 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99470 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99471 scoped);
99472 rcu_read_unlock();
99473
99474 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99475 }
99476 #if IS_ENABLED(CONFIG_IPV6)
99477 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99478 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99479 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99480 #endif
99481 }
99482
99483 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99484 info, (u8 *)icmph);
99485 #if IS_ENABLED(CONFIG_IPV6)
99486 } else if (family == AF_INET6) {
99487 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99488 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99489 info, (u8 *)icmph);
99490 #endif
99491 }
99492 @@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99493 {
99494 struct inet_sock *isk = inet_sk(sk);
99495 int family = sk->sk_family;
99496 + struct sockaddr_in *sin;
99497 + struct sockaddr_in6 *sin6;
99498 struct sk_buff *skb;
99499 int copied, err;
99500
99501 @@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99502 if (flags & MSG_OOB)
99503 goto out;
99504
99505 + if (addr_len) {
99506 + if (family == AF_INET)
99507 + *addr_len = sizeof(*sin);
99508 + else if (family == AF_INET6 && addr_len)
99509 + *addr_len = sizeof(*sin6);
99510 + }
99511 +
99512 if (flags & MSG_ERRQUEUE) {
99513 if (family == AF_INET) {
99514 return ip_recv_error(sk, msg, len, addr_len);
99515 #if IS_ENABLED(CONFIG_IPV6)
99516 } else if (family == AF_INET6) {
99517 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
99518 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
99519 addr_len);
99520 #endif
99521 }
99522 @@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99523 sin->sin_port = 0 /* skb->h.uh->source */;
99524 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99525 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99526 - *addr_len = sizeof(*sin);
99527 }
99528
99529 if (isk->cmsg_flags)
99530 @@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99531 sin6->sin6_scope_id =
99532 ipv6_iface_scope_id(&sin6->sin6_addr,
99533 IP6CB(skb)->iif);
99534 - *addr_len = sizeof(*sin6);
99535 }
99536
99537 if (inet6_sk(sk)->rxopt.all)
99538 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99539 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99540 if (skb->protocol == htons(ETH_P_IPV6) &&
99541 inet6_sk(sk)->rxopt.all)
99542 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99543 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99544 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99545 ip_cmsg_recv(msg, skb);
99546 #endif
99547 @@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99548 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99549 0, sock_i_ino(sp),
99550 atomic_read(&sp->sk_refcnt), sp,
99551 - atomic_read(&sp->sk_drops));
99552 + atomic_read_unchecked(&sp->sk_drops));
99553 }
99554
99555 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99556 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99557 index a9dbe58..46f577f 100644
99558 --- a/net/ipv4/raw.c
99559 +++ b/net/ipv4/raw.c
99560 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99561 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99562 {
99563 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99564 - atomic_inc(&sk->sk_drops);
99565 + atomic_inc_unchecked(&sk->sk_drops);
99566 kfree_skb(skb);
99567 return NET_RX_DROP;
99568 }
99569 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99570 if (flags & MSG_OOB)
99571 goto out;
99572
99573 + if (addr_len)
99574 + *addr_len = sizeof(*sin);
99575 +
99576 if (flags & MSG_ERRQUEUE) {
99577 err = ip_recv_error(sk, msg, len, addr_len);
99578 goto out;
99579 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99580 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99581 sin->sin_port = 0;
99582 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99583 - *addr_len = sizeof(*sin);
99584 }
99585 if (inet->cmsg_flags)
99586 ip_cmsg_recv(msg, skb);
99587 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99588
99589 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99590 {
99591 + struct icmp_filter filter;
99592 +
99593 if (optlen > sizeof(struct icmp_filter))
99594 optlen = sizeof(struct icmp_filter);
99595 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99596 + if (copy_from_user(&filter, optval, optlen))
99597 return -EFAULT;
99598 + raw_sk(sk)->filter = filter;
99599 return 0;
99600 }
99601
99602 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99603 {
99604 int len, ret = -EFAULT;
99605 + struct icmp_filter filter;
99606
99607 if (get_user(len, optlen))
99608 goto out;
99609 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99610 if (len > sizeof(struct icmp_filter))
99611 len = sizeof(struct icmp_filter);
99612 ret = -EFAULT;
99613 - if (put_user(len, optlen) ||
99614 - copy_to_user(optval, &raw_sk(sk)->filter, len))
99615 + filter = raw_sk(sk)->filter;
99616 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99617 goto out;
99618 ret = 0;
99619 out: return ret;
99620 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99621 0, 0L, 0,
99622 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99623 0, sock_i_ino(sp),
99624 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99625 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99626 }
99627
99628 static int raw_seq_show(struct seq_file *seq, void *v)
99629 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99630 index 5e676be..f6c62f1 100644
99631 --- a/net/ipv4/route.c
99632 +++ b/net/ipv4/route.c
99633 @@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99634
99635 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99636 {
99637 - return seq_open(file, &rt_cache_seq_ops);
99638 + return seq_open_restrict(file, &rt_cache_seq_ops);
99639 }
99640
99641 static const struct file_operations rt_cache_seq_fops = {
99642 @@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99643
99644 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99645 {
99646 - return seq_open(file, &rt_cpu_seq_ops);
99647 + return seq_open_restrict(file, &rt_cpu_seq_ops);
99648 }
99649
99650 static const struct file_operations rt_cpu_seq_fops = {
99651 @@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99652
99653 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99654 {
99655 - return single_open(file, rt_acct_proc_show, NULL);
99656 + return single_open_restrict(file, rt_acct_proc_show, NULL);
99657 }
99658
99659 static const struct file_operations rt_acct_proc_fops = {
99660 @@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99661 .maxlen = sizeof(int),
99662 .mode = 0200,
99663 .proc_handler = ipv4_sysctl_rtcache_flush,
99664 + .extra1 = &init_net,
99665 },
99666 { },
99667 };
99668
99669 static __net_init int sysctl_route_net_init(struct net *net)
99670 {
99671 - struct ctl_table *tbl;
99672 + ctl_table_no_const *tbl = NULL;
99673
99674 - tbl = ipv4_route_flush_table;
99675 if (!net_eq(net, &init_net)) {
99676 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99677 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99678 if (tbl == NULL)
99679 goto err_dup;
99680
99681 /* Don't export sysctls to unprivileged users */
99682 if (net->user_ns != &init_user_ns)
99683 tbl[0].procname = NULL;
99684 - }
99685 - tbl[0].extra1 = net;
99686 + tbl[0].extra1 = net;
99687 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99688 + } else
99689 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99690
99691 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99692 if (net->ipv4.route_hdr == NULL)
99693 goto err_reg;
99694 return 0;
99695
99696 err_reg:
99697 - if (tbl != ipv4_route_flush_table)
99698 - kfree(tbl);
99699 + kfree(tbl);
99700 err_dup:
99701 return -ENOMEM;
99702 }
99703 @@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99704
99705 static __net_init int rt_genid_init(struct net *net)
99706 {
99707 - atomic_set(&net->ipv4.rt_genid, 0);
99708 - atomic_set(&net->fnhe_genid, 0);
99709 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99710 + atomic_set_unchecked(&net->fnhe_genid, 0);
99711 get_random_bytes(&net->ipv4.dev_addr_genid,
99712 sizeof(net->ipv4.dev_addr_genid));
99713 return 0;
99714 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99715 index 5cde8f2..5f5684e 100644
99716 --- a/net/ipv4/sysctl_net_ipv4.c
99717 +++ b/net/ipv4/sysctl_net_ipv4.c
99718 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99719 container_of(table->data, struct net, ipv4.ip_local_ports.range);
99720 int ret;
99721 int range[2];
99722 - struct ctl_table tmp = {
99723 + ctl_table_no_const tmp = {
99724 .data = &range,
99725 .maxlen = sizeof(range),
99726 .mode = table->mode,
99727 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99728 int ret;
99729 gid_t urange[2];
99730 kgid_t low, high;
99731 - struct ctl_table tmp = {
99732 + ctl_table_no_const tmp = {
99733 .data = &urange,
99734 .maxlen = sizeof(urange),
99735 .mode = table->mode,
99736 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99737 void __user *buffer, size_t *lenp, loff_t *ppos)
99738 {
99739 char val[TCP_CA_NAME_MAX];
99740 - struct ctl_table tbl = {
99741 + ctl_table_no_const tbl = {
99742 .data = val,
99743 .maxlen = TCP_CA_NAME_MAX,
99744 };
99745 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99746 void __user *buffer, size_t *lenp,
99747 loff_t *ppos)
99748 {
99749 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99750 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99751 int ret;
99752
99753 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99754 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99755 void __user *buffer, size_t *lenp,
99756 loff_t *ppos)
99757 {
99758 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99759 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99760 int ret;
99761
99762 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99763 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99764 void __user *buffer, size_t *lenp,
99765 loff_t *ppos)
99766 {
99767 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99768 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99769 struct tcp_fastopen_context *ctxt;
99770 int ret;
99771 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99772 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99773 },
99774 {
99775 .procname = "ip_local_reserved_ports",
99776 - .data = NULL, /* initialized in sysctl_ipv4_init */
99777 + .data = sysctl_local_reserved_ports,
99778 .maxlen = 65536,
99779 .mode = 0644,
99780 .proc_handler = proc_do_large_bitmap,
99781 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99782
99783 static __net_init int ipv4_sysctl_init_net(struct net *net)
99784 {
99785 - struct ctl_table *table;
99786 + ctl_table_no_const *table = NULL;
99787
99788 - table = ipv4_net_table;
99789 if (!net_eq(net, &init_net)) {
99790 int i;
99791
99792 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99793 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99794 if (table == NULL)
99795 goto err_alloc;
99796
99797 @@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99798 table[i].data += (void *)net - (void *)&init_net;
99799 }
99800
99801 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99802 + if (!net_eq(net, &init_net))
99803 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99804 + else
99805 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99806 if (net->ipv4.ipv4_hdr == NULL)
99807 goto err_reg;
99808
99809 return 0;
99810
99811 err_reg:
99812 - if (!net_eq(net, &init_net))
99813 - kfree(table);
99814 + kfree(table);
99815 err_alloc:
99816 return -ENOMEM;
99817 }
99818 @@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99819 static __init int sysctl_ipv4_init(void)
99820 {
99821 struct ctl_table_header *hdr;
99822 - struct ctl_table *i;
99823 -
99824 - for (i = ipv4_table; i->procname; i++) {
99825 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99826 - i->data = sysctl_local_reserved_ports;
99827 - break;
99828 - }
99829 - }
99830 - if (!i->procname)
99831 - return -EINVAL;
99832
99833 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99834 if (hdr == NULL)
99835 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99836 index 3a26b3b..8bbe4ae 100644
99837 --- a/net/ipv4/tcp_input.c
99838 +++ b/net/ipv4/tcp_input.c
99839 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99840 * without any lock. We want to make sure compiler wont store
99841 * intermediate values in this location.
99842 */
99843 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99844 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99845 sk->sk_max_pacing_rate);
99846 }
99847
99848 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99849 * simplifies code)
99850 */
99851 static void
99852 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99853 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99854 struct sk_buff *head, struct sk_buff *tail,
99855 u32 start, u32 end)
99856 {
99857 @@ -5558,6 +5558,7 @@ discard:
99858 tcp_paws_reject(&tp->rx_opt, 0))
99859 goto discard_and_undo;
99860
99861 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99862 if (th->syn) {
99863 /* We see SYN without ACK. It is attempt of
99864 * simultaneous connect with crossed SYNs.
99865 @@ -5608,6 +5609,7 @@ discard:
99866 goto discard;
99867 #endif
99868 }
99869 +#endif
99870 /* "fifth, if neither of the SYN or RST bits is set then
99871 * drop the segment and return."
99872 */
99873 @@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99874 goto discard;
99875
99876 if (th->syn) {
99877 - if (th->fin)
99878 + if (th->fin || th->urg || th->psh)
99879 goto discard;
99880 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99881 return 1;
99882 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99883 index 438f3b9..bc9e1ad 100644
99884 --- a/net/ipv4/tcp_ipv4.c
99885 +++ b/net/ipv4/tcp_ipv4.c
99886 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99887 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99888
99889
99890 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99891 +extern int grsec_enable_blackhole;
99892 +#endif
99893 +
99894 #ifdef CONFIG_TCP_MD5SIG
99895 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99896 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99897 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99898 return 0;
99899
99900 reset:
99901 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99902 + if (!grsec_enable_blackhole)
99903 +#endif
99904 tcp_v4_send_reset(rsk, skb);
99905 discard:
99906 kfree_skb(skb);
99907 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99908 TCP_SKB_CB(skb)->sacked = 0;
99909
99910 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99911 - if (!sk)
99912 + if (!sk) {
99913 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99914 + ret = 1;
99915 +#endif
99916 goto no_tcp_socket;
99917 -
99918 + }
99919 process:
99920 - if (sk->sk_state == TCP_TIME_WAIT)
99921 + if (sk->sk_state == TCP_TIME_WAIT) {
99922 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99923 + ret = 2;
99924 +#endif
99925 goto do_time_wait;
99926 + }
99927
99928 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99929 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99930 @@ -2033,6 +2047,10 @@ csum_error:
99931 bad_packet:
99932 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99933 } else {
99934 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99935 + if (!grsec_enable_blackhole || (ret == 1 &&
99936 + (skb->dev->flags & IFF_LOOPBACK)))
99937 +#endif
99938 tcp_v4_send_reset(NULL, skb);
99939 }
99940
99941 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99942 index 05c1b15..3e9344b 100644
99943 --- a/net/ipv4/tcp_minisocks.c
99944 +++ b/net/ipv4/tcp_minisocks.c
99945 @@ -27,6 +27,10 @@
99946 #include <net/inet_common.h>
99947 #include <net/xfrm.h>
99948
99949 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99950 +extern int grsec_enable_blackhole;
99951 +#endif
99952 +
99953 int sysctl_tcp_syncookies __read_mostly = 1;
99954 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99955
99956 @@ -709,7 +713,10 @@ embryonic_reset:
99957 * avoid becoming vulnerable to outside attack aiming at
99958 * resetting legit local connections.
99959 */
99960 - req->rsk_ops->send_reset(sk, skb);
99961 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99962 + if (!grsec_enable_blackhole)
99963 +#endif
99964 + req->rsk_ops->send_reset(sk, skb);
99965 } else if (fastopen) { /* received a valid RST pkt */
99966 reqsk_fastopen_remove(sk, req, true);
99967 tcp_reset(sk);
99968 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99969 index 3b66610..bfbe23a 100644
99970 --- a/net/ipv4/tcp_probe.c
99971 +++ b/net/ipv4/tcp_probe.c
99972 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99973 if (cnt + width >= len)
99974 break;
99975
99976 - if (copy_to_user(buf + cnt, tbuf, width))
99977 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99978 return -EFAULT;
99979 cnt += width;
99980 }
99981 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99982 index 286227a..c495a76 100644
99983 --- a/net/ipv4/tcp_timer.c
99984 +++ b/net/ipv4/tcp_timer.c
99985 @@ -22,6 +22,10 @@
99986 #include <linux/gfp.h>
99987 #include <net/tcp.h>
99988
99989 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99990 +extern int grsec_lastack_retries;
99991 +#endif
99992 +
99993 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99994 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99995 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99996 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
99997 }
99998 }
99999
100000 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100001 + if ((sk->sk_state == TCP_LAST_ACK) &&
100002 + (grsec_lastack_retries > 0) &&
100003 + (grsec_lastack_retries < retry_until))
100004 + retry_until = grsec_lastack_retries;
100005 +#endif
100006 +
100007 if (retransmits_timed_out(sk, retry_until,
100008 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100009 /* Has it gone just too far? */
100010 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100011 index 54a5fe9..78fea00 100644
100012 --- a/net/ipv4/udp.c
100013 +++ b/net/ipv4/udp.c
100014 @@ -87,6 +87,7 @@
100015 #include <linux/types.h>
100016 #include <linux/fcntl.h>
100017 #include <linux/module.h>
100018 +#include <linux/security.h>
100019 #include <linux/socket.h>
100020 #include <linux/sockios.h>
100021 #include <linux/igmp.h>
100022 @@ -113,6 +114,10 @@
100023 #include <net/busy_poll.h>
100024 #include "udp_impl.h"
100025
100026 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100027 +extern int grsec_enable_blackhole;
100028 +#endif
100029 +
100030 struct udp_table udp_table __read_mostly;
100031 EXPORT_SYMBOL(udp_table);
100032
100033 @@ -615,6 +620,9 @@ found:
100034 return s;
100035 }
100036
100037 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100038 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100039 +
100040 /*
100041 * This routine is called by the ICMP module when it gets some
100042 * sort of error condition. If err < 0 then the socket should
100043 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100044 dport = usin->sin_port;
100045 if (dport == 0)
100046 return -EINVAL;
100047 +
100048 + err = gr_search_udp_sendmsg(sk, usin);
100049 + if (err)
100050 + return err;
100051 } else {
100052 if (sk->sk_state != TCP_ESTABLISHED)
100053 return -EDESTADDRREQ;
100054 +
100055 + err = gr_search_udp_sendmsg(sk, NULL);
100056 + if (err)
100057 + return err;
100058 +
100059 daddr = inet->inet_daddr;
100060 dport = inet->inet_dport;
100061 /* Open fast path for connected socket.
100062 @@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100063 IS_UDPLITE(sk));
100064 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100065 IS_UDPLITE(sk));
100066 - atomic_inc(&sk->sk_drops);
100067 + atomic_inc_unchecked(&sk->sk_drops);
100068 __skb_unlink(skb, rcvq);
100069 __skb_queue_tail(&list_kill, skb);
100070 }
100071 @@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100072 int is_udplite = IS_UDPLITE(sk);
100073 bool slow;
100074
100075 + /*
100076 + * Check any passed addresses
100077 + */
100078 + if (addr_len)
100079 + *addr_len = sizeof(*sin);
100080 +
100081 if (flags & MSG_ERRQUEUE)
100082 return ip_recv_error(sk, msg, len, addr_len);
100083
100084 @@ -1244,6 +1267,10 @@ try_again:
100085 if (!skb)
100086 goto out;
100087
100088 + err = gr_search_udp_recvmsg(sk, skb);
100089 + if (err)
100090 + goto out_free;
100091 +
100092 ulen = skb->len - sizeof(struct udphdr);
100093 copied = len;
100094 if (copied > ulen)
100095 @@ -1277,7 +1304,7 @@ try_again:
100096 if (unlikely(err)) {
100097 trace_kfree_skb(skb, udp_recvmsg);
100098 if (!peeked) {
100099 - atomic_inc(&sk->sk_drops);
100100 + atomic_inc_unchecked(&sk->sk_drops);
100101 UDP_INC_STATS_USER(sock_net(sk),
100102 UDP_MIB_INERRORS, is_udplite);
100103 }
100104 @@ -1296,7 +1323,6 @@ try_again:
100105 sin->sin_port = udp_hdr(skb)->source;
100106 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100107 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100108 - *addr_len = sizeof(*sin);
100109 }
100110 if (inet->cmsg_flags)
100111 ip_cmsg_recv(msg, skb);
100112 @@ -1567,7 +1593,7 @@ csum_error:
100113 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100114 drop:
100115 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100116 - atomic_inc(&sk->sk_drops);
100117 + atomic_inc_unchecked(&sk->sk_drops);
100118 kfree_skb(skb);
100119 return -1;
100120 }
100121 @@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100122 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100123
100124 if (!skb1) {
100125 - atomic_inc(&sk->sk_drops);
100126 + atomic_inc_unchecked(&sk->sk_drops);
100127 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100128 IS_UDPLITE(sk));
100129 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100130 @@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100131 goto csum_error;
100132
100133 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100134 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100135 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100136 +#endif
100137 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100138
100139 /*
100140 @@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100141 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100142 0, sock_i_ino(sp),
100143 atomic_read(&sp->sk_refcnt), sp,
100144 - atomic_read(&sp->sk_drops));
100145 + atomic_read_unchecked(&sp->sk_drops));
100146 }
100147
100148 int udp4_seq_show(struct seq_file *seq, void *v)
100149 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100150 index 6156f68..d6ab46d 100644
100151 --- a/net/ipv4/xfrm4_policy.c
100152 +++ b/net/ipv4/xfrm4_policy.c
100153 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100154 fl4->flowi4_tos = iph->tos;
100155 }
100156
100157 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100158 +static int xfrm4_garbage_collect(struct dst_ops *ops)
100159 {
100160 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100161
100162 - xfrm4_policy_afinfo.garbage_collect(net);
100163 + xfrm_garbage_collect_deferred(net);
100164 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100165 }
100166
100167 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100168
100169 static int __net_init xfrm4_net_init(struct net *net)
100170 {
100171 - struct ctl_table *table;
100172 + ctl_table_no_const *table = NULL;
100173 struct ctl_table_header *hdr;
100174
100175 - table = xfrm4_policy_table;
100176 if (!net_eq(net, &init_net)) {
100177 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100178 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100179 if (!table)
100180 goto err_alloc;
100181
100182 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100183 - }
100184 -
100185 - hdr = register_net_sysctl(net, "net/ipv4", table);
100186 + hdr = register_net_sysctl(net, "net/ipv4", table);
100187 + } else
100188 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100189 if (!hdr)
100190 goto err_reg;
100191
100192 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100193 return 0;
100194
100195 err_reg:
100196 - if (!net_eq(net, &init_net))
100197 - kfree(table);
100198 + kfree(table);
100199 err_alloc:
100200 return -ENOMEM;
100201 }
100202 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100203 index 6c7fa08..285086c 100644
100204 --- a/net/ipv6/addrconf.c
100205 +++ b/net/ipv6/addrconf.c
100206 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100207 idx = 0;
100208 head = &net->dev_index_head[h];
100209 rcu_read_lock();
100210 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100211 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100212 net->dev_base_seq;
100213 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100214 if (idx < s_idx)
100215 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100216 p.iph.ihl = 5;
100217 p.iph.protocol = IPPROTO_IPV6;
100218 p.iph.ttl = 64;
100219 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100220 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100221
100222 if (ops->ndo_do_ioctl) {
100223 mm_segment_t oldfs = get_fs();
100224 @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100225 s_ip_idx = ip_idx = cb->args[2];
100226
100227 rcu_read_lock();
100228 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100229 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100230 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100231 idx = 0;
100232 head = &net->dev_index_head[h];
100233 @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100234 dst_free(&ifp->rt->dst);
100235 break;
100236 }
100237 - atomic_inc(&net->ipv6.dev_addr_genid);
100238 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100239 rt_genid_bump_ipv6(net);
100240 }
100241
100242 @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100243 int *valp = ctl->data;
100244 int val = *valp;
100245 loff_t pos = *ppos;
100246 - struct ctl_table lctl;
100247 + ctl_table_no_const lctl;
100248 int ret;
100249
100250 /*
100251 @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100252 int *valp = ctl->data;
100253 int val = *valp;
100254 loff_t pos = *ppos;
100255 - struct ctl_table lctl;
100256 + ctl_table_no_const lctl;
100257 int ret;
100258
100259 /*
100260 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100261 index d935889..2f64330 100644
100262 --- a/net/ipv6/af_inet6.c
100263 +++ b/net/ipv6/af_inet6.c
100264 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100265 net->ipv6.sysctl.bindv6only = 0;
100266 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100267 net->ipv6.sysctl.flowlabel_consistency = 1;
100268 - atomic_set(&net->ipv6.rt_genid, 0);
100269 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100270
100271 err = ipv6_init_mibs(net);
100272 if (err)
100273 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100274 index c3bf2d2..1f00573 100644
100275 --- a/net/ipv6/datagram.c
100276 +++ b/net/ipv6/datagram.c
100277 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100278 0,
100279 sock_i_ino(sp),
100280 atomic_read(&sp->sk_refcnt), sp,
100281 - atomic_read(&sp->sk_drops));
100282 + atomic_read_unchecked(&sp->sk_drops));
100283 }
100284 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100285 index 7b32652..0bc348b 100644
100286 --- a/net/ipv6/icmp.c
100287 +++ b/net/ipv6/icmp.c
100288 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100289
100290 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100291 {
100292 - struct ctl_table *table;
100293 + ctl_table_no_const *table;
100294
100295 table = kmemdup(ipv6_icmp_table_template,
100296 sizeof(ipv6_icmp_table_template),
100297 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100298 index 9d92146..d986c6a 100644
100299 --- a/net/ipv6/ip6_gre.c
100300 +++ b/net/ipv6/ip6_gre.c
100301 @@ -71,7 +71,7 @@ struct ip6gre_net {
100302 struct net_device *fb_tunnel_dev;
100303 };
100304
100305 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100306 +static struct rtnl_link_ops ip6gre_link_ops;
100307 static int ip6gre_tunnel_init(struct net_device *dev);
100308 static void ip6gre_tunnel_setup(struct net_device *dev);
100309 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100310 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100311 }
100312
100313
100314 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100315 +static struct inet6_protocol ip6gre_protocol = {
100316 .handler = ip6gre_rcv,
100317 .err_handler = ip6gre_err,
100318 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100319 @@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100320 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100321 };
100322
100323 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100324 +static struct rtnl_link_ops ip6gre_link_ops = {
100325 .kind = "ip6gre",
100326 .maxtype = IFLA_GRE_MAX,
100327 .policy = ip6gre_policy,
100328 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100329 .fill_info = ip6gre_fill_info,
100330 };
100331
100332 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100333 +static struct rtnl_link_ops ip6gre_tap_ops = {
100334 .kind = "ip6gretap",
100335 .maxtype = IFLA_GRE_MAX,
100336 .policy = ip6gre_policy,
100337 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100338 index afa0824..04ba530 100644
100339 --- a/net/ipv6/ip6_tunnel.c
100340 +++ b/net/ipv6/ip6_tunnel.c
100341 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100342
100343 static int ip6_tnl_dev_init(struct net_device *dev);
100344 static void ip6_tnl_dev_setup(struct net_device *dev);
100345 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100346 +static struct rtnl_link_ops ip6_link_ops;
100347
100348 static int ip6_tnl_net_id __read_mostly;
100349 struct ip6_tnl_net {
100350 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100351 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100352 };
100353
100354 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100355 +static struct rtnl_link_ops ip6_link_ops = {
100356 .kind = "ip6tnl",
100357 .maxtype = IFLA_IPTUN_MAX,
100358 .policy = ip6_tnl_policy,
100359 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100360 index 6cc9f93..6e5bb7c 100644
100361 --- a/net/ipv6/ip6_vti.c
100362 +++ b/net/ipv6/ip6_vti.c
100363 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100364
100365 static int vti6_dev_init(struct net_device *dev);
100366 static void vti6_dev_setup(struct net_device *dev);
100367 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100368 +static struct rtnl_link_ops vti6_link_ops;
100369
100370 static int vti6_net_id __read_mostly;
100371 struct vti6_net {
100372 @@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100373 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100374 };
100375
100376 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100377 +static struct rtnl_link_ops vti6_link_ops = {
100378 .kind = "vti6",
100379 .maxtype = IFLA_VTI_MAX,
100380 .policy = vti6_policy,
100381 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100382 index edb58af..78de133 100644
100383 --- a/net/ipv6/ipv6_sockglue.c
100384 +++ b/net/ipv6/ipv6_sockglue.c
100385 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100386 if (sk->sk_type != SOCK_STREAM)
100387 return -ENOPROTOOPT;
100388
100389 - msg.msg_control = optval;
100390 + msg.msg_control = (void __force_kernel *)optval;
100391 msg.msg_controllen = len;
100392 msg.msg_flags = flags;
100393
100394 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100395 index e080fbb..412b3cf 100644
100396 --- a/net/ipv6/netfilter/ip6_tables.c
100397 +++ b/net/ipv6/netfilter/ip6_tables.c
100398 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100399 #endif
100400
100401 static int get_info(struct net *net, void __user *user,
100402 - const int *len, int compat)
100403 + int len, int compat)
100404 {
100405 char name[XT_TABLE_MAXNAMELEN];
100406 struct xt_table *t;
100407 int ret;
100408
100409 - if (*len != sizeof(struct ip6t_getinfo)) {
100410 - duprintf("length %u != %zu\n", *len,
100411 + if (len != sizeof(struct ip6t_getinfo)) {
100412 + duprintf("length %u != %zu\n", len,
100413 sizeof(struct ip6t_getinfo));
100414 return -EINVAL;
100415 }
100416 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100417 info.size = private->size;
100418 strcpy(info.name, name);
100419
100420 - if (copy_to_user(user, &info, *len) != 0)
100421 + if (copy_to_user(user, &info, len) != 0)
100422 ret = -EFAULT;
100423 else
100424 ret = 0;
100425 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100426
100427 switch (cmd) {
100428 case IP6T_SO_GET_INFO:
100429 - ret = get_info(sock_net(sk), user, len, 1);
100430 + ret = get_info(sock_net(sk), user, *len, 1);
100431 break;
100432 case IP6T_SO_GET_ENTRIES:
100433 ret = compat_get_entries(sock_net(sk), user, len);
100434 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100435
100436 switch (cmd) {
100437 case IP6T_SO_GET_INFO:
100438 - ret = get_info(sock_net(sk), user, len, 0);
100439 + ret = get_info(sock_net(sk), user, *len, 0);
100440 break;
100441
100442 case IP6T_SO_GET_ENTRIES:
100443 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100444 index 767ab8d..c5ec70a 100644
100445 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100446 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100447 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100448
100449 static int nf_ct_frag6_sysctl_register(struct net *net)
100450 {
100451 - struct ctl_table *table;
100452 + ctl_table_no_const *table = NULL;
100453 struct ctl_table_header *hdr;
100454
100455 - table = nf_ct_frag6_sysctl_table;
100456 if (!net_eq(net, &init_net)) {
100457 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100458 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100459 GFP_KERNEL);
100460 if (table == NULL)
100461 goto err_alloc;
100462 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100463 table[0].data = &net->nf_frag.frags.timeout;
100464 table[1].data = &net->nf_frag.frags.low_thresh;
100465 table[2].data = &net->nf_frag.frags.high_thresh;
100466 - }
100467 -
100468 - hdr = register_net_sysctl(net, "net/netfilter", table);
100469 + hdr = register_net_sysctl(net, "net/netfilter", table);
100470 + } else
100471 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100472 if (hdr == NULL)
100473 goto err_reg;
100474
100475 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100476 return 0;
100477
100478 err_reg:
100479 - if (!net_eq(net, &init_net))
100480 - kfree(table);
100481 + kfree(table);
100482 err_alloc:
100483 return -ENOMEM;
100484 }
100485 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100486 index 56596ce..c734618 100644
100487 --- a/net/ipv6/output_core.c
100488 +++ b/net/ipv6/output_core.c
100489 @@ -10,7 +10,7 @@
100490
100491 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100492 {
100493 - static atomic_t ipv6_fragmentation_id;
100494 + static atomic_unchecked_t ipv6_fragmentation_id;
100495 struct in6_addr addr;
100496 int ident;
100497
100498 @@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100499 return;
100500 }
100501 #endif
100502 - ident = atomic_inc_return(&ipv6_fragmentation_id);
100503 + ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100504
100505 addr = rt->rt6i_dst.addr;
100506 addr.s6_addr32[0] ^= (__force __be32)ident;
100507 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100508 index bda7429..469b26b 100644
100509 --- a/net/ipv6/ping.c
100510 +++ b/net/ipv6/ping.c
100511 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100512 };
100513 #endif
100514
100515 +static struct pingv6_ops real_pingv6_ops = {
100516 + .ipv6_recv_error = ipv6_recv_error,
100517 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100518 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100519 + .icmpv6_err_convert = icmpv6_err_convert,
100520 + .ipv6_icmp_error = ipv6_icmp_error,
100521 + .ipv6_chk_addr = ipv6_chk_addr,
100522 +};
100523 +
100524 +static struct pingv6_ops dummy_pingv6_ops = {
100525 + .ipv6_recv_error = dummy_ipv6_recv_error,
100526 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100527 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100528 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
100529 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
100530 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
100531 +};
100532 +
100533 int __init pingv6_init(void)
100534 {
100535 #ifdef CONFIG_PROC_FS
100536 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
100537 if (ret)
100538 return ret;
100539 #endif
100540 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100541 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100542 - pingv6_ops.ip6_datagram_recv_specific_ctl =
100543 - ip6_datagram_recv_specific_ctl;
100544 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100545 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100546 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100547 + pingv6_ops = &real_pingv6_ops;
100548 return inet6_register_protosw(&pingv6_protosw);
100549 }
100550
100551 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
100552 */
100553 void pingv6_exit(void)
100554 {
100555 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100556 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100557 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100558 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100559 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100560 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100561 #ifdef CONFIG_PROC_FS
100562 unregister_pernet_subsys(&ping_v6_net_ops);
100563 #endif
100564 + pingv6_ops = &dummy_pingv6_ops;
100565 inet6_unregister_protosw(&pingv6_protosw);
100566 }
100567 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100568 index 091d066..139d410 100644
100569 --- a/net/ipv6/proc.c
100570 +++ b/net/ipv6/proc.c
100571 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100572 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100573 goto proc_snmp6_fail;
100574
100575 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100576 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100577 if (!net->mib.proc_net_devsnmp6)
100578 goto proc_dev_snmp6_fail;
100579 return 0;
100580 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100581 index 1f29996..46fe0c7 100644
100582 --- a/net/ipv6/raw.c
100583 +++ b/net/ipv6/raw.c
100584 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100585 {
100586 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100587 skb_checksum_complete(skb)) {
100588 - atomic_inc(&sk->sk_drops);
100589 + atomic_inc_unchecked(&sk->sk_drops);
100590 kfree_skb(skb);
100591 return NET_RX_DROP;
100592 }
100593 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100594 struct raw6_sock *rp = raw6_sk(sk);
100595
100596 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100597 - atomic_inc(&sk->sk_drops);
100598 + atomic_inc_unchecked(&sk->sk_drops);
100599 kfree_skb(skb);
100600 return NET_RX_DROP;
100601 }
100602 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100603
100604 if (inet->hdrincl) {
100605 if (skb_checksum_complete(skb)) {
100606 - atomic_inc(&sk->sk_drops);
100607 + atomic_inc_unchecked(&sk->sk_drops);
100608 kfree_skb(skb);
100609 return NET_RX_DROP;
100610 }
100611 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100612 if (flags & MSG_OOB)
100613 return -EOPNOTSUPP;
100614
100615 + if (addr_len)
100616 + *addr_len=sizeof(*sin6);
100617 +
100618 if (flags & MSG_ERRQUEUE)
100619 return ipv6_recv_error(sk, msg, len, addr_len);
100620
100621 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100622 sin6->sin6_flowinfo = 0;
100623 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100624 IP6CB(skb)->iif);
100625 - *addr_len = sizeof(*sin6);
100626 }
100627
100628 sock_recv_ts_and_drops(msg, sk, skb);
100629 @@ -610,7 +612,7 @@ out:
100630 return err;
100631 }
100632
100633 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100634 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100635 struct flowi6 *fl6, struct dst_entry **dstp,
100636 unsigned int flags)
100637 {
100638 @@ -922,12 +924,15 @@ do_confirm:
100639 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100640 char __user *optval, int optlen)
100641 {
100642 + struct icmp6_filter filter;
100643 +
100644 switch (optname) {
100645 case ICMPV6_FILTER:
100646 if (optlen > sizeof(struct icmp6_filter))
100647 optlen = sizeof(struct icmp6_filter);
100648 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100649 + if (copy_from_user(&filter, optval, optlen))
100650 return -EFAULT;
100651 + raw6_sk(sk)->filter = filter;
100652 return 0;
100653 default:
100654 return -ENOPROTOOPT;
100655 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100656 char __user *optval, int __user *optlen)
100657 {
100658 int len;
100659 + struct icmp6_filter filter;
100660
100661 switch (optname) {
100662 case ICMPV6_FILTER:
100663 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100664 len = sizeof(struct icmp6_filter);
100665 if (put_user(len, optlen))
100666 return -EFAULT;
100667 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100668 + filter = raw6_sk(sk)->filter;
100669 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
100670 return -EFAULT;
100671 return 0;
100672 default:
100673 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100674 index cc85a9b..526a133 100644
100675 --- a/net/ipv6/reassembly.c
100676 +++ b/net/ipv6/reassembly.c
100677 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100678
100679 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100680 {
100681 - struct ctl_table *table;
100682 + ctl_table_no_const *table = NULL;
100683 struct ctl_table_header *hdr;
100684
100685 - table = ip6_frags_ns_ctl_table;
100686 if (!net_eq(net, &init_net)) {
100687 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100688 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100689 if (table == NULL)
100690 goto err_alloc;
100691
100692 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100693 /* Don't export sysctls to unprivileged users */
100694 if (net->user_ns != &init_user_ns)
100695 table[0].procname = NULL;
100696 - }
100697 + hdr = register_net_sysctl(net, "net/ipv6", table);
100698 + } else
100699 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100700
100701 - hdr = register_net_sysctl(net, "net/ipv6", table);
100702 if (hdr == NULL)
100703 goto err_reg;
100704
100705 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100706 return 0;
100707
100708 err_reg:
100709 - if (!net_eq(net, &init_net))
100710 - kfree(table);
100711 + kfree(table);
100712 err_alloc:
100713 return -ENOMEM;
100714 }
100715 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100716 index 6ebdb7b6..f225ab1 100644
100717 --- a/net/ipv6/route.c
100718 +++ b/net/ipv6/route.c
100719 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
100720
100721 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100722 {
100723 - struct ctl_table *table;
100724 + ctl_table_no_const *table;
100725
100726 table = kmemdup(ipv6_route_table_template,
100727 sizeof(ipv6_route_table_template),
100728 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100729 index 4f40817..54dcbef 100644
100730 --- a/net/ipv6/sit.c
100731 +++ b/net/ipv6/sit.c
100732 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100733 static void ipip6_dev_free(struct net_device *dev);
100734 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100735 __be32 *v4dst);
100736 -static struct rtnl_link_ops sit_link_ops __read_mostly;
100737 +static struct rtnl_link_ops sit_link_ops;
100738
100739 static int sit_net_id __read_mostly;
100740 struct sit_net {
100741 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100742 unregister_netdevice_queue(dev, head);
100743 }
100744
100745 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
100746 +static struct rtnl_link_ops sit_link_ops = {
100747 .kind = "sit",
100748 .maxtype = IFLA_IPTUN_MAX,
100749 .policy = ipip6_policy,
100750 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100751 index 7f405a1..eabef92 100644
100752 --- a/net/ipv6/sysctl_net_ipv6.c
100753 +++ b/net/ipv6/sysctl_net_ipv6.c
100754 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100755
100756 static int __net_init ipv6_sysctl_net_init(struct net *net)
100757 {
100758 - struct ctl_table *ipv6_table;
100759 + ctl_table_no_const *ipv6_table;
100760 struct ctl_table *ipv6_route_table;
100761 struct ctl_table *ipv6_icmp_table;
100762 int err;
100763 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100764 index e289830..79a5718 100644
100765 --- a/net/ipv6/tcp_ipv6.c
100766 +++ b/net/ipv6/tcp_ipv6.c
100767 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100768 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100769 }
100770
100771 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100772 +extern int grsec_enable_blackhole;
100773 +#endif
100774 +
100775 static void tcp_v6_hash(struct sock *sk)
100776 {
100777 if (sk->sk_state != TCP_CLOSE) {
100778 @@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100779 return 0;
100780
100781 reset:
100782 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100783 + if (!grsec_enable_blackhole)
100784 +#endif
100785 tcp_v6_send_reset(sk, skb);
100786 discard:
100787 if (opt_skb)
100788 @@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100789 TCP_SKB_CB(skb)->sacked = 0;
100790
100791 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100792 - if (!sk)
100793 + if (!sk) {
100794 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100795 + ret = 1;
100796 +#endif
100797 goto no_tcp_socket;
100798 + }
100799
100800 process:
100801 - if (sk->sk_state == TCP_TIME_WAIT)
100802 + if (sk->sk_state == TCP_TIME_WAIT) {
100803 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100804 + ret = 2;
100805 +#endif
100806 goto do_time_wait;
100807 + }
100808
100809 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100810 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100811 @@ -1557,6 +1572,10 @@ csum_error:
100812 bad_packet:
100813 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100814 } else {
100815 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100816 + if (!grsec_enable_blackhole || (ret == 1 &&
100817 + (skb->dev->flags & IFF_LOOPBACK)))
100818 +#endif
100819 tcp_v6_send_reset(NULL, skb);
100820 }
100821
100822 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100823 index 20b63d2..13be908 100644
100824 --- a/net/ipv6/udp.c
100825 +++ b/net/ipv6/udp.c
100826 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100827 udp_ipv6_hash_secret + net_hash_mix(net));
100828 }
100829
100830 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100831 +extern int grsec_enable_blackhole;
100832 +#endif
100833 +
100834 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100835 {
100836 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100837 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100838 int is_udp4;
100839 bool slow;
100840
100841 + if (addr_len)
100842 + *addr_len = sizeof(struct sockaddr_in6);
100843 +
100844 if (flags & MSG_ERRQUEUE)
100845 return ipv6_recv_error(sk, msg, len, addr_len);
100846
100847 @@ -435,7 +442,7 @@ try_again:
100848 if (unlikely(err)) {
100849 trace_kfree_skb(skb, udpv6_recvmsg);
100850 if (!peeked) {
100851 - atomic_inc(&sk->sk_drops);
100852 + atomic_inc_unchecked(&sk->sk_drops);
100853 if (is_udp4)
100854 UDP_INC_STATS_USER(sock_net(sk),
100855 UDP_MIB_INERRORS,
100856 @@ -475,7 +482,7 @@ try_again:
100857 ipv6_iface_scope_id(&sin6->sin6_addr,
100858 IP6CB(skb)->iif);
100859 }
100860 - *addr_len = sizeof(*sin6);
100861 +
100862 }
100863
100864 if (np->rxopt.all)
100865 @@ -690,7 +697,7 @@ csum_error:
100866 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100867 drop:
100868 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100869 - atomic_inc(&sk->sk_drops);
100870 + atomic_inc_unchecked(&sk->sk_drops);
100871 kfree_skb(skb);
100872 return -1;
100873 }
100874 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100875 if (likely(skb1 == NULL))
100876 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100877 if (!skb1) {
100878 - atomic_inc(&sk->sk_drops);
100879 + atomic_inc_unchecked(&sk->sk_drops);
100880 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100881 IS_UDPLITE(sk));
100882 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100883 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100884 goto csum_error;
100885
100886 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100887 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100888 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100889 +#endif
100890 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100891
100892 kfree_skb(skb);
100893 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100894 index 2a0bbda..d75ca57 100644
100895 --- a/net/ipv6/xfrm6_policy.c
100896 +++ b/net/ipv6/xfrm6_policy.c
100897 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100898 }
100899 }
100900
100901 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100902 +static int xfrm6_garbage_collect(struct dst_ops *ops)
100903 {
100904 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100905
100906 - xfrm6_policy_afinfo.garbage_collect(net);
100907 + xfrm_garbage_collect_deferred(net);
100908 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100909 }
100910
100911 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100912
100913 static int __net_init xfrm6_net_init(struct net *net)
100914 {
100915 - struct ctl_table *table;
100916 + ctl_table_no_const *table = NULL;
100917 struct ctl_table_header *hdr;
100918
100919 - table = xfrm6_policy_table;
100920 if (!net_eq(net, &init_net)) {
100921 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100922 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100923 if (!table)
100924 goto err_alloc;
100925
100926 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100927 - }
100928 + hdr = register_net_sysctl(net, "net/ipv6", table);
100929 + } else
100930 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100931
100932 - hdr = register_net_sysctl(net, "net/ipv6", table);
100933 if (!hdr)
100934 goto err_reg;
100935
100936 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100937 return 0;
100938
100939 err_reg:
100940 - if (!net_eq(net, &init_net))
100941 - kfree(table);
100942 + kfree(table);
100943 err_alloc:
100944 return -ENOMEM;
100945 }
100946 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100947 index e15c16a..7cf07aa 100644
100948 --- a/net/ipx/ipx_proc.c
100949 +++ b/net/ipx/ipx_proc.c
100950 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100951 struct proc_dir_entry *p;
100952 int rc = -ENOMEM;
100953
100954 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100955 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100956
100957 if (!ipx_proc_dir)
100958 goto out;
100959 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100960 index 2ba8b97..6d33010 100644
100961 --- a/net/irda/ircomm/ircomm_tty.c
100962 +++ b/net/irda/ircomm/ircomm_tty.c
100963 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100964 add_wait_queue(&port->open_wait, &wait);
100965
100966 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100967 - __FILE__, __LINE__, tty->driver->name, port->count);
100968 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100969
100970 spin_lock_irqsave(&port->lock, flags);
100971 if (!tty_hung_up_p(filp))
100972 - port->count--;
100973 + atomic_dec(&port->count);
100974 port->blocked_open++;
100975 spin_unlock_irqrestore(&port->lock, flags);
100976
100977 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100978 }
100979
100980 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100981 - __FILE__, __LINE__, tty->driver->name, port->count);
100982 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100983
100984 schedule();
100985 }
100986 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100987
100988 spin_lock_irqsave(&port->lock, flags);
100989 if (!tty_hung_up_p(filp))
100990 - port->count++;
100991 + atomic_inc(&port->count);
100992 port->blocked_open--;
100993 spin_unlock_irqrestore(&port->lock, flags);
100994
100995 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100996 - __FILE__, __LINE__, tty->driver->name, port->count);
100997 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100998
100999 if (!retval)
101000 port->flags |= ASYNC_NORMAL_ACTIVE;
101001 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101002
101003 /* ++ is not atomic, so this should be protected - Jean II */
101004 spin_lock_irqsave(&self->port.lock, flags);
101005 - self->port.count++;
101006 + atomic_inc(&self->port.count);
101007 spin_unlock_irqrestore(&self->port.lock, flags);
101008 tty_port_tty_set(&self->port, tty);
101009
101010 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101011 - self->line, self->port.count);
101012 + self->line, atomic_read(&self->port.count));
101013
101014 /* Not really used by us, but lets do it anyway */
101015 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101016 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101017 tty_kref_put(port->tty);
101018 }
101019 port->tty = NULL;
101020 - port->count = 0;
101021 + atomic_set(&port->count, 0);
101022 spin_unlock_irqrestore(&port->lock, flags);
101023
101024 wake_up_interruptible(&port->open_wait);
101025 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101026 seq_putc(m, '\n');
101027
101028 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101029 - seq_printf(m, "Open count: %d\n", self->port.count);
101030 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101031 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101032 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101033
101034 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101035 index b9ac598..f88cc56 100644
101036 --- a/net/irda/irproc.c
101037 +++ b/net/irda/irproc.c
101038 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101039 {
101040 int i;
101041
101042 - proc_irda = proc_mkdir("irda", init_net.proc_net);
101043 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101044 if (proc_irda == NULL)
101045 return;
101046
101047 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101048 index 8c9d730..66c6305 100644
101049 --- a/net/iucv/af_iucv.c
101050 +++ b/net/iucv/af_iucv.c
101051 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101052
101053 write_lock_bh(&iucv_sk_list.lock);
101054
101055 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101056 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101057 while (__iucv_get_sock_by_name(name)) {
101058 sprintf(name, "%08x",
101059 - atomic_inc_return(&iucv_sk_list.autobind_name));
101060 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101061 }
101062
101063 write_unlock_bh(&iucv_sk_list.lock);
101064 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101065 index da78793..bdd78cf 100644
101066 --- a/net/iucv/iucv.c
101067 +++ b/net/iucv/iucv.c
101068 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101069 return NOTIFY_OK;
101070 }
101071
101072 -static struct notifier_block __refdata iucv_cpu_notifier = {
101073 +static struct notifier_block iucv_cpu_notifier = {
101074 .notifier_call = iucv_cpu_notify,
101075 };
101076
101077 diff --git a/net/key/af_key.c b/net/key/af_key.c
101078 index f3c8307..7127791 100644
101079 --- a/net/key/af_key.c
101080 +++ b/net/key/af_key.c
101081 @@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101082 static u32 get_acqseq(void)
101083 {
101084 u32 res;
101085 - static atomic_t acqseq;
101086 + static atomic_unchecked_t acqseq;
101087
101088 do {
101089 - res = atomic_inc_return(&acqseq);
101090 + res = atomic_inc_return_unchecked(&acqseq);
101091 } while (!res);
101092 return res;
101093 }
101094 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101095 index 76125c5..e474828 100644
101096 --- a/net/l2tp/l2tp_eth.c
101097 +++ b/net/l2tp/l2tp_eth.c
101098 @@ -42,12 +42,12 @@ struct l2tp_eth {
101099 struct sock *tunnel_sock;
101100 struct l2tp_session *session;
101101 struct list_head list;
101102 - atomic_long_t tx_bytes;
101103 - atomic_long_t tx_packets;
101104 - atomic_long_t tx_dropped;
101105 - atomic_long_t rx_bytes;
101106 - atomic_long_t rx_packets;
101107 - atomic_long_t rx_errors;
101108 + atomic_long_unchecked_t tx_bytes;
101109 + atomic_long_unchecked_t tx_packets;
101110 + atomic_long_unchecked_t tx_dropped;
101111 + atomic_long_unchecked_t rx_bytes;
101112 + atomic_long_unchecked_t rx_packets;
101113 + atomic_long_unchecked_t rx_errors;
101114 };
101115
101116 /* via l2tp_session_priv() */
101117 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101118 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101119
101120 if (likely(ret == NET_XMIT_SUCCESS)) {
101121 - atomic_long_add(len, &priv->tx_bytes);
101122 - atomic_long_inc(&priv->tx_packets);
101123 + atomic_long_add_unchecked(len, &priv->tx_bytes);
101124 + atomic_long_inc_unchecked(&priv->tx_packets);
101125 } else {
101126 - atomic_long_inc(&priv->tx_dropped);
101127 + atomic_long_inc_unchecked(&priv->tx_dropped);
101128 }
101129 return NETDEV_TX_OK;
101130 }
101131 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101132 {
101133 struct l2tp_eth *priv = netdev_priv(dev);
101134
101135 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101136 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
101137 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101138 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101139 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
101140 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
101141 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101142 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101143 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101144 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101145 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101146 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101147 return stats;
101148 }
101149
101150 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101151 nf_reset(skb);
101152
101153 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101154 - atomic_long_inc(&priv->rx_packets);
101155 - atomic_long_add(data_len, &priv->rx_bytes);
101156 + atomic_long_inc_unchecked(&priv->rx_packets);
101157 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101158 } else {
101159 - atomic_long_inc(&priv->rx_errors);
101160 + atomic_long_inc_unchecked(&priv->rx_errors);
101161 }
101162 return;
101163
101164 error:
101165 - atomic_long_inc(&priv->rx_errors);
101166 + atomic_long_inc_unchecked(&priv->rx_errors);
101167 kfree_skb(skb);
101168 }
101169
101170 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101171 index 3397fe6..861fd1a 100644
101172 --- a/net/l2tp/l2tp_ip.c
101173 +++ b/net/l2tp/l2tp_ip.c
101174 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101175 if (flags & MSG_OOB)
101176 goto out;
101177
101178 + if (addr_len)
101179 + *addr_len = sizeof(*sin);
101180 +
101181 skb = skb_recv_datagram(sk, flags, noblock, &err);
101182 if (!skb)
101183 goto out;
101184 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101185 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101186 sin->sin_port = 0;
101187 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101188 - *addr_len = sizeof(*sin);
101189 }
101190 if (inet->cmsg_flags)
101191 ip_cmsg_recv(msg, skb);
101192 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101193 index 1a3c7e0..80f8b0c 100644
101194 --- a/net/llc/llc_proc.c
101195 +++ b/net/llc/llc_proc.c
101196 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101197 int rc = -ENOMEM;
101198 struct proc_dir_entry *p;
101199
101200 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101201 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101202 if (!llc_proc_dir)
101203 goto out;
101204
101205 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101206 index aaa59d7..21a2c4a 100644
101207 --- a/net/mac80211/cfg.c
101208 +++ b/net/mac80211/cfg.c
101209 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101210 ret = ieee80211_vif_use_channel(sdata, chandef,
101211 IEEE80211_CHANCTX_EXCLUSIVE);
101212 }
101213 - } else if (local->open_count == local->monitors) {
101214 + } else if (local_read(&local->open_count) == local->monitors) {
101215 local->_oper_chandef = *chandef;
101216 ieee80211_hw_config(local, 0);
101217 }
101218 @@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101219 else
101220 local->probe_req_reg--;
101221
101222 - if (!local->open_count)
101223 + if (!local_read(&local->open_count))
101224 break;
101225
101226 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101227 @@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101228 if (chanctx_conf) {
101229 *chandef = chanctx_conf->def;
101230 ret = 0;
101231 - } else if (local->open_count > 0 &&
101232 - local->open_count == local->monitors &&
101233 + } else if (local_read(&local->open_count) > 0 &&
101234 + local_read(&local->open_count) == local->monitors &&
101235 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101236 if (local->use_chanctx)
101237 *chandef = local->monitor_chandef;
101238 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101239 index f169b6e..a5dc4eb 100644
101240 --- a/net/mac80211/ieee80211_i.h
101241 +++ b/net/mac80211/ieee80211_i.h
101242 @@ -28,6 +28,7 @@
101243 #include <net/ieee80211_radiotap.h>
101244 #include <net/cfg80211.h>
101245 #include <net/mac80211.h>
101246 +#include <asm/local.h>
101247 #include "key.h"
101248 #include "sta_info.h"
101249 #include "debug.h"
101250 @@ -999,7 +1000,7 @@ struct ieee80211_local {
101251 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101252 spinlock_t queue_stop_reason_lock;
101253
101254 - int open_count;
101255 + local_t open_count;
101256 int monitors, cooked_mntrs;
101257 /* number of interfaces with corresponding FIF_ flags */
101258 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101259 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101260 index 34799e0..b411290 100644
101261 --- a/net/mac80211/iface.c
101262 +++ b/net/mac80211/iface.c
101263 @@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101264 break;
101265 }
101266
101267 - if (local->open_count == 0) {
101268 + if (local_read(&local->open_count) == 0) {
101269 res = drv_start(local);
101270 if (res)
101271 goto err_del_bss;
101272 @@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101273 res = drv_add_interface(local, sdata);
101274 if (res)
101275 goto err_stop;
101276 - } else if (local->monitors == 0 && local->open_count == 0) {
101277 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101278 res = ieee80211_add_virtual_monitor(local);
101279 if (res)
101280 goto err_stop;
101281 @@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101282 atomic_inc(&local->iff_promiscs);
101283
101284 if (coming_up)
101285 - local->open_count++;
101286 + local_inc(&local->open_count);
101287
101288 if (hw_reconf_flags)
101289 ieee80211_hw_config(local, hw_reconf_flags);
101290 @@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101291 err_del_interface:
101292 drv_remove_interface(local, sdata);
101293 err_stop:
101294 - if (!local->open_count)
101295 + if (!local_read(&local->open_count))
101296 drv_stop(local);
101297 err_del_bss:
101298 sdata->bss = NULL;
101299 @@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101300 }
101301
101302 if (going_down)
101303 - local->open_count--;
101304 + local_dec(&local->open_count);
101305
101306 switch (sdata->vif.type) {
101307 case NL80211_IFTYPE_AP_VLAN:
101308 @@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101309 }
101310 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101311
101312 - if (local->open_count == 0)
101313 + if (local_read(&local->open_count) == 0)
101314 ieee80211_clear_tx_pending(local);
101315
101316 /*
101317 @@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101318
101319 ieee80211_recalc_ps(local, -1);
101320
101321 - if (local->open_count == 0) {
101322 + if (local_read(&local->open_count) == 0) {
101323 ieee80211_stop_device(local);
101324
101325 /* no reconfiguring after stop! */
101326 @@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101327 ieee80211_configure_filter(local);
101328 ieee80211_hw_config(local, hw_reconf_flags);
101329
101330 - if (local->monitors == local->open_count)
101331 + if (local->monitors == local_read(&local->open_count))
101332 ieee80211_add_virtual_monitor(local);
101333 }
101334
101335 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101336 index 4c1bf61..00b449b 100644
101337 --- a/net/mac80211/main.c
101338 +++ b/net/mac80211/main.c
101339 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101340 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101341 IEEE80211_CONF_CHANGE_POWER);
101342
101343 - if (changed && local->open_count) {
101344 + if (changed && local_read(&local->open_count)) {
101345 ret = drv_config(local, changed);
101346 /*
101347 * Goal:
101348 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101349 index d478b88..8c8d157 100644
101350 --- a/net/mac80211/pm.c
101351 +++ b/net/mac80211/pm.c
101352 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101353 struct ieee80211_sub_if_data *sdata;
101354 struct sta_info *sta;
101355
101356 - if (!local->open_count)
101357 + if (!local_read(&local->open_count))
101358 goto suspend;
101359
101360 ieee80211_scan_cancel(local);
101361 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101362 cancel_work_sync(&local->dynamic_ps_enable_work);
101363 del_timer_sync(&local->dynamic_ps_timer);
101364
101365 - local->wowlan = wowlan && local->open_count;
101366 + local->wowlan = wowlan && local_read(&local->open_count);
101367 if (local->wowlan) {
101368 int err = drv_suspend(local, wowlan);
101369 if (err < 0) {
101370 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101371 WARN_ON(!list_empty(&local->chanctx_list));
101372
101373 /* stop hardware - this must stop RX */
101374 - if (local->open_count)
101375 + if (local_read(&local->open_count))
101376 ieee80211_stop_device(local);
101377
101378 suspend:
101379 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101380 index 8fdadfd..a4f72b8 100644
101381 --- a/net/mac80211/rate.c
101382 +++ b/net/mac80211/rate.c
101383 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101384
101385 ASSERT_RTNL();
101386
101387 - if (local->open_count)
101388 + if (local_read(&local->open_count))
101389 return -EBUSY;
101390
101391 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101392 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101393 index 6ff1346..936ca9a 100644
101394 --- a/net/mac80211/rc80211_pid_debugfs.c
101395 +++ b/net/mac80211/rc80211_pid_debugfs.c
101396 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101397
101398 spin_unlock_irqrestore(&events->lock, status);
101399
101400 - if (copy_to_user(buf, pb, p))
101401 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101402 return -EFAULT;
101403
101404 return p;
101405 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101406 index 3c36583..12887fe 100644
101407 --- a/net/mac80211/util.c
101408 +++ b/net/mac80211/util.c
101409 @@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101410 }
101411 #endif
101412 /* everything else happens only if HW was up & running */
101413 - if (!local->open_count)
101414 + if (!local_read(&local->open_count))
101415 goto wake_up;
101416
101417 /*
101418 @@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101419 local->in_reconfig = false;
101420 barrier();
101421
101422 - if (local->monitors == local->open_count && local->monitors > 0)
101423 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101424 ieee80211_add_virtual_monitor(local);
101425
101426 /*
101427 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101428 index e9410d1..77b6378 100644
101429 --- a/net/netfilter/Kconfig
101430 +++ b/net/netfilter/Kconfig
101431 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101432
101433 To compile it as a module, choose M here. If unsure, say N.
101434
101435 +config NETFILTER_XT_MATCH_GRADM
101436 + tristate '"gradm" match support'
101437 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101438 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101439 + ---help---
101440 + The gradm match allows to match on grsecurity RBAC being enabled.
101441 + It is useful when iptables rules are applied early on bootup to
101442 + prevent connections to the machine (except from a trusted host)
101443 + while the RBAC system is disabled.
101444 +
101445 config NETFILTER_XT_MATCH_HASHLIMIT
101446 tristate '"hashlimit" match support'
101447 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101448 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101449 index bffdad7..f9317d1 100644
101450 --- a/net/netfilter/Makefile
101451 +++ b/net/netfilter/Makefile
101452 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101453 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101454 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101455 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101456 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101457 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101458 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101459 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101460 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101461 index 1172083..986f1c1 100644
101462 --- a/net/netfilter/ipset/ip_set_core.c
101463 +++ b/net/netfilter/ipset/ip_set_core.c
101464 @@ -1924,7 +1924,7 @@ done:
101465 return ret;
101466 }
101467
101468 -static struct nf_sockopt_ops so_set __read_mostly = {
101469 +static struct nf_sockopt_ops so_set = {
101470 .pf = PF_INET,
101471 .get_optmin = SO_IP_SET,
101472 .get_optmax = SO_IP_SET + 1,
101473 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101474 index a8eb0a8..86f2de4 100644
101475 --- a/net/netfilter/ipvs/ip_vs_conn.c
101476 +++ b/net/netfilter/ipvs/ip_vs_conn.c
101477 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101478 /* Increase the refcnt counter of the dest */
101479 ip_vs_dest_hold(dest);
101480
101481 - conn_flags = atomic_read(&dest->conn_flags);
101482 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
101483 if (cp->protocol != IPPROTO_UDP)
101484 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101485 flags = cp->flags;
101486 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101487
101488 cp->control = NULL;
101489 atomic_set(&cp->n_control, 0);
101490 - atomic_set(&cp->in_pkts, 0);
101491 + atomic_set_unchecked(&cp->in_pkts, 0);
101492
101493 cp->packet_xmit = NULL;
101494 cp->app = NULL;
101495 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101496
101497 /* Don't drop the entry if its number of incoming packets is not
101498 located in [0, 8] */
101499 - i = atomic_read(&cp->in_pkts);
101500 + i = atomic_read_unchecked(&cp->in_pkts);
101501 if (i > 8 || i < 0) return 0;
101502
101503 if (!todrop_rate[i]) return 0;
101504 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101505 index 3d2d2c8..c87e4d3 100644
101506 --- a/net/netfilter/ipvs/ip_vs_core.c
101507 +++ b/net/netfilter/ipvs/ip_vs_core.c
101508 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101509 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101510 /* do not touch skb anymore */
101511
101512 - atomic_inc(&cp->in_pkts);
101513 + atomic_inc_unchecked(&cp->in_pkts);
101514 ip_vs_conn_put(cp);
101515 return ret;
101516 }
101517 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101518 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101519 pkts = sysctl_sync_threshold(ipvs);
101520 else
101521 - pkts = atomic_add_return(1, &cp->in_pkts);
101522 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101523
101524 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101525 ip_vs_sync_conn(net, cp, pkts);
101526 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101527 index c42e83d..a6a3f8b 100644
101528 --- a/net/netfilter/ipvs/ip_vs_ctl.c
101529 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
101530 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101531 */
101532 ip_vs_rs_hash(ipvs, dest);
101533 }
101534 - atomic_set(&dest->conn_flags, conn_flags);
101535 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
101536
101537 /* bind the service */
101538 old_svc = rcu_dereference_protected(dest->svc, 1);
101539 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101540 * align with netns init in ip_vs_control_net_init()
101541 */
101542
101543 -static struct ctl_table vs_vars[] = {
101544 +static ctl_table_no_const vs_vars[] __read_only = {
101545 {
101546 .procname = "amemthresh",
101547 .maxlen = sizeof(int),
101548 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101549 " %-7s %-6d %-10d %-10d\n",
101550 &dest->addr.in6,
101551 ntohs(dest->port),
101552 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101553 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101554 atomic_read(&dest->weight),
101555 atomic_read(&dest->activeconns),
101556 atomic_read(&dest->inactconns));
101557 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101558 "%-7s %-6d %-10d %-10d\n",
101559 ntohl(dest->addr.ip),
101560 ntohs(dest->port),
101561 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101562 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101563 atomic_read(&dest->weight),
101564 atomic_read(&dest->activeconns),
101565 atomic_read(&dest->inactconns));
101566 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101567
101568 entry.addr = dest->addr.ip;
101569 entry.port = dest->port;
101570 - entry.conn_flags = atomic_read(&dest->conn_flags);
101571 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101572 entry.weight = atomic_read(&dest->weight);
101573 entry.u_threshold = dest->u_threshold;
101574 entry.l_threshold = dest->l_threshold;
101575 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101576 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101577 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101578 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101579 - (atomic_read(&dest->conn_flags) &
101580 + (atomic_read_unchecked(&dest->conn_flags) &
101581 IP_VS_CONN_F_FWD_MASK)) ||
101582 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101583 atomic_read(&dest->weight)) ||
101584 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101585 {
101586 int idx;
101587 struct netns_ipvs *ipvs = net_ipvs(net);
101588 - struct ctl_table *tbl;
101589 + ctl_table_no_const *tbl;
101590
101591 atomic_set(&ipvs->dropentry, 0);
101592 spin_lock_init(&ipvs->dropentry_lock);
101593 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101594 index 547ff33..c8c8117 100644
101595 --- a/net/netfilter/ipvs/ip_vs_lblc.c
101596 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
101597 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101598 * IPVS LBLC sysctl table
101599 */
101600 #ifdef CONFIG_SYSCTL
101601 -static struct ctl_table vs_vars_table[] = {
101602 +static ctl_table_no_const vs_vars_table[] __read_only = {
101603 {
101604 .procname = "lblc_expiration",
101605 .data = NULL,
101606 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101607 index 3f21a2f..a112e85 100644
101608 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
101609 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101610 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101611 * IPVS LBLCR sysctl table
101612 */
101613
101614 -static struct ctl_table vs_vars_table[] = {
101615 +static ctl_table_no_const vs_vars_table[] __read_only = {
101616 {
101617 .procname = "lblcr_expiration",
101618 .data = NULL,
101619 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101620 index db80126..ef7110e 100644
101621 --- a/net/netfilter/ipvs/ip_vs_sync.c
101622 +++ b/net/netfilter/ipvs/ip_vs_sync.c
101623 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101624 cp = cp->control;
101625 if (cp) {
101626 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101627 - pkts = atomic_add_return(1, &cp->in_pkts);
101628 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101629 else
101630 pkts = sysctl_sync_threshold(ipvs);
101631 ip_vs_sync_conn(net, cp->control, pkts);
101632 @@ -771,7 +771,7 @@ control:
101633 if (!cp)
101634 return;
101635 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101636 - pkts = atomic_add_return(1, &cp->in_pkts);
101637 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101638 else
101639 pkts = sysctl_sync_threshold(ipvs);
101640 goto sloop;
101641 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101642
101643 if (opt)
101644 memcpy(&cp->in_seq, opt, sizeof(*opt));
101645 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101646 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101647 cp->state = state;
101648 cp->old_state = cp->state;
101649 /*
101650 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101651 index c47444e..b0961c6 100644
101652 --- a/net/netfilter/ipvs/ip_vs_xmit.c
101653 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
101654 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101655 else
101656 rc = NF_ACCEPT;
101657 /* do not touch skb anymore */
101658 - atomic_inc(&cp->in_pkts);
101659 + atomic_inc_unchecked(&cp->in_pkts);
101660 goto out;
101661 }
101662
101663 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101664 else
101665 rc = NF_ACCEPT;
101666 /* do not touch skb anymore */
101667 - atomic_inc(&cp->in_pkts);
101668 + atomic_inc_unchecked(&cp->in_pkts);
101669 goto out;
101670 }
101671
101672 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101673 index a4b5e2a..13b1de3 100644
101674 --- a/net/netfilter/nf_conntrack_acct.c
101675 +++ b/net/netfilter/nf_conntrack_acct.c
101676 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101677 #ifdef CONFIG_SYSCTL
101678 static int nf_conntrack_acct_init_sysctl(struct net *net)
101679 {
101680 - struct ctl_table *table;
101681 + ctl_table_no_const *table;
101682
101683 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101684 GFP_KERNEL);
101685 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101686 index 75421f2..054c1fc 100644
101687 --- a/net/netfilter/nf_conntrack_core.c
101688 +++ b/net/netfilter/nf_conntrack_core.c
101689 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
101690 #define DYING_NULLS_VAL ((1<<30)+1)
101691 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101692
101693 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101694 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101695 +#endif
101696 +
101697 int nf_conntrack_init_net(struct net *net)
101698 {
101699 int ret = -ENOMEM;
101700 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
101701 if (!net->ct.stat)
101702 goto err_pcpu_lists;
101703
101704 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101705 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101706 +#else
101707 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101708 +#endif
101709 if (!net->ct.slabname)
101710 goto err_slabname;
101711
101712 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101713 index 1df1761..ce8b88a 100644
101714 --- a/net/netfilter/nf_conntrack_ecache.c
101715 +++ b/net/netfilter/nf_conntrack_ecache.c
101716 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101717 #ifdef CONFIG_SYSCTL
101718 static int nf_conntrack_event_init_sysctl(struct net *net)
101719 {
101720 - struct ctl_table *table;
101721 + ctl_table_no_const *table;
101722
101723 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101724 GFP_KERNEL);
101725 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101726 index 5b3eae7..dd4b8fe 100644
101727 --- a/net/netfilter/nf_conntrack_helper.c
101728 +++ b/net/netfilter/nf_conntrack_helper.c
101729 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101730
101731 static int nf_conntrack_helper_init_sysctl(struct net *net)
101732 {
101733 - struct ctl_table *table;
101734 + ctl_table_no_const *table;
101735
101736 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101737 GFP_KERNEL);
101738 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101739 index b65d586..beec902 100644
101740 --- a/net/netfilter/nf_conntrack_proto.c
101741 +++ b/net/netfilter/nf_conntrack_proto.c
101742 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101743
101744 static void
101745 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101746 - struct ctl_table **table,
101747 + ctl_table_no_const **table,
101748 unsigned int users)
101749 {
101750 if (users > 0)
101751 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101752 index f641751..d3c5b51 100644
101753 --- a/net/netfilter/nf_conntrack_standalone.c
101754 +++ b/net/netfilter/nf_conntrack_standalone.c
101755 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101756
101757 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101758 {
101759 - struct ctl_table *table;
101760 + ctl_table_no_const *table;
101761
101762 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101763 GFP_KERNEL);
101764 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101765 index 7a394df..bd91a8a 100644
101766 --- a/net/netfilter/nf_conntrack_timestamp.c
101767 +++ b/net/netfilter/nf_conntrack_timestamp.c
101768 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101769 #ifdef CONFIG_SYSCTL
101770 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101771 {
101772 - struct ctl_table *table;
101773 + ctl_table_no_const *table;
101774
101775 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101776 GFP_KERNEL);
101777 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101778 index 85296d4..8becdec 100644
101779 --- a/net/netfilter/nf_log.c
101780 +++ b/net/netfilter/nf_log.c
101781 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101782
101783 #ifdef CONFIG_SYSCTL
101784 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101785 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101786 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101787
101788 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101789 void __user *buffer, size_t *lenp, loff_t *ppos)
101790 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101791 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101792 mutex_unlock(&nf_log_mutex);
101793 } else {
101794 + ctl_table_no_const nf_log_table = *table;
101795 +
101796 mutex_lock(&nf_log_mutex);
101797 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101798 lockdep_is_held(&nf_log_mutex));
101799 if (!logger)
101800 - table->data = "NONE";
101801 + nf_log_table.data = "NONE";
101802 else
101803 - table->data = logger->name;
101804 - r = proc_dostring(table, write, buffer, lenp, ppos);
101805 + nf_log_table.data = logger->name;
101806 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101807 mutex_unlock(&nf_log_mutex);
101808 }
101809
101810 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101811 index f042ae5..30ea486 100644
101812 --- a/net/netfilter/nf_sockopt.c
101813 +++ b/net/netfilter/nf_sockopt.c
101814 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101815 }
101816 }
101817
101818 - list_add(&reg->list, &nf_sockopts);
101819 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101820 out:
101821 mutex_unlock(&nf_sockopt_mutex);
101822 return ret;
101823 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101824 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101825 {
101826 mutex_lock(&nf_sockopt_mutex);
101827 - list_del(&reg->list);
101828 + pax_list_del((struct list_head *)&reg->list);
101829 mutex_unlock(&nf_sockopt_mutex);
101830 }
101831 EXPORT_SYMBOL(nf_unregister_sockopt);
101832 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101833 index d292c8d..9f1e166 100644
101834 --- a/net/netfilter/nfnetlink_log.c
101835 +++ b/net/netfilter/nfnetlink_log.c
101836 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
101837 struct nfnl_log_net {
101838 spinlock_t instances_lock;
101839 struct hlist_head instance_table[INSTANCE_BUCKETS];
101840 - atomic_t global_seq;
101841 + atomic_unchecked_t global_seq;
101842 };
101843
101844 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101845 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
101846 /* global sequence number */
101847 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101848 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101849 - htonl(atomic_inc_return(&log->global_seq))))
101850 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
101851 goto nla_put_failure;
101852
101853 if (data_len) {
101854 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101855 index 8a779be..1551d4c 100644
101856 --- a/net/netfilter/nft_compat.c
101857 +++ b/net/netfilter/nft_compat.c
101858 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101859 /* We want to reuse existing compat_to_user */
101860 old_fs = get_fs();
101861 set_fs(KERNEL_DS);
101862 - t->compat_to_user(out, in);
101863 + t->compat_to_user((void __force_user *)out, in);
101864 set_fs(old_fs);
101865 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101866 kfree(out);
101867 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101868 /* We want to reuse existing compat_to_user */
101869 old_fs = get_fs();
101870 set_fs(KERNEL_DS);
101871 - m->compat_to_user(out, in);
101872 + m->compat_to_user((void __force_user *)out, in);
101873 set_fs(old_fs);
101874 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101875 kfree(out);
101876 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101877 new file mode 100644
101878 index 0000000..c566332
101879 --- /dev/null
101880 +++ b/net/netfilter/xt_gradm.c
101881 @@ -0,0 +1,51 @@
101882 +/*
101883 + * gradm match for netfilter
101884 + * Copyright © Zbigniew Krzystolik, 2010
101885 + *
101886 + * This program is free software; you can redistribute it and/or modify
101887 + * it under the terms of the GNU General Public License; either version
101888 + * 2 or 3 as published by the Free Software Foundation.
101889 + */
101890 +#include <linux/module.h>
101891 +#include <linux/moduleparam.h>
101892 +#include <linux/skbuff.h>
101893 +#include <linux/netfilter/x_tables.h>
101894 +#include <linux/grsecurity.h>
101895 +#include <linux/netfilter/xt_gradm.h>
101896 +
101897 +static bool
101898 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
101899 +{
101900 + const struct xt_gradm_mtinfo *info = par->matchinfo;
101901 + bool retval = false;
101902 + if (gr_acl_is_enabled())
101903 + retval = true;
101904 + return retval ^ info->invflags;
101905 +}
101906 +
101907 +static struct xt_match gradm_mt_reg __read_mostly = {
101908 + .name = "gradm",
101909 + .revision = 0,
101910 + .family = NFPROTO_UNSPEC,
101911 + .match = gradm_mt,
101912 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
101913 + .me = THIS_MODULE,
101914 +};
101915 +
101916 +static int __init gradm_mt_init(void)
101917 +{
101918 + return xt_register_match(&gradm_mt_reg);
101919 +}
101920 +
101921 +static void __exit gradm_mt_exit(void)
101922 +{
101923 + xt_unregister_match(&gradm_mt_reg);
101924 +}
101925 +
101926 +module_init(gradm_mt_init);
101927 +module_exit(gradm_mt_exit);
101928 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
101929 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
101930 +MODULE_LICENSE("GPL");
101931 +MODULE_ALIAS("ipt_gradm");
101932 +MODULE_ALIAS("ip6t_gradm");
101933 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
101934 index a3910fc..2d2ba14 100644
101935 --- a/net/netfilter/xt_hashlimit.c
101936 +++ b/net/netfilter/xt_hashlimit.c
101937 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
101938 {
101939 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
101940
101941 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
101942 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
101943 if (!hashlimit_net->ipt_hashlimit)
101944 return -ENOMEM;
101945 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
101946 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
101947 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
101948 if (!hashlimit_net->ip6t_hashlimit) {
101949 remove_proc_entry("ipt_hashlimit", net->proc_net);
101950 return -ENOMEM;
101951 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
101952 index 1e657cf..1eb1c34 100644
101953 --- a/net/netfilter/xt_recent.c
101954 +++ b/net/netfilter/xt_recent.c
101955 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
101956 {
101957 struct recent_net *recent_net = recent_pernet(net);
101958
101959 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
101960 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
101961 if (!recent_net->xt_recent)
101962 return -ENOMEM;
101963 return 0;
101964 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
101965 index 11de55e..f25e448 100644
101966 --- a/net/netfilter/xt_statistic.c
101967 +++ b/net/netfilter/xt_statistic.c
101968 @@ -19,7 +19,7 @@
101969 #include <linux/module.h>
101970
101971 struct xt_statistic_priv {
101972 - atomic_t count;
101973 + atomic_unchecked_t count;
101974 } ____cacheline_aligned_in_smp;
101975
101976 MODULE_LICENSE("GPL");
101977 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
101978 break;
101979 case XT_STATISTIC_MODE_NTH:
101980 do {
101981 - oval = atomic_read(&info->master->count);
101982 + oval = atomic_read_unchecked(&info->master->count);
101983 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
101984 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
101985 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
101986 if (nval == 0)
101987 ret = !ret;
101988 break;
101989 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
101990 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
101991 if (info->master == NULL)
101992 return -ENOMEM;
101993 - atomic_set(&info->master->count, info->u.nth.count);
101994 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
101995
101996 return 0;
101997 }
101998 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
101999 index f22757a..daf62a2 100644
102000 --- a/net/netlink/af_netlink.c
102001 +++ b/net/netlink/af_netlink.c
102002 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
102003 sk->sk_error_report(sk);
102004 }
102005 }
102006 - atomic_inc(&sk->sk_drops);
102007 + atomic_inc_unchecked(&sk->sk_drops);
102008 }
102009
102010 static void netlink_rcv_wake(struct sock *sk)
102011 @@ -3028,7 +3028,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
102012 sk_wmem_alloc_get(s),
102013 nlk->cb_running,
102014 atomic_read(&s->sk_refcnt),
102015 - atomic_read(&s->sk_drops),
102016 + atomic_read_unchecked(&s->sk_drops),
102017 sock_i_ino(s)
102018 );
102019
102020 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
102021 index ede50d1..d2468e6 100644
102022 --- a/net/netrom/af_netrom.c
102023 +++ b/net/netrom/af_netrom.c
102024 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
102025 *uaddr_len = sizeof(struct full_sockaddr_ax25);
102026 } else {
102027 sax->fsa_ax25.sax25_family = AF_NETROM;
102028 - sax->fsa_ax25.sax25_ndigis = 0;
102029 sax->fsa_ax25.sax25_call = nr->source_addr;
102030 *uaddr_len = sizeof(struct sockaddr_ax25);
102031 }
102032 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
102033 index b85c67c..27c3368 100644
102034 --- a/net/packet/af_packet.c
102035 +++ b/net/packet/af_packet.c
102036 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
102037
102038 return ret;
102039 drop:
102040 - atomic_long_inc(&dev->tx_dropped);
102041 + atomic_long_inc_unchecked(&dev->tx_dropped);
102042 kfree_skb(skb);
102043 return NET_XMIT_DROP;
102044 }
102045 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102046
102047 spin_lock(&sk->sk_receive_queue.lock);
102048 po->stats.stats1.tp_packets++;
102049 - skb->dropcount = atomic_read(&sk->sk_drops);
102050 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102051 __skb_queue_tail(&sk->sk_receive_queue, skb);
102052 spin_unlock(&sk->sk_receive_queue.lock);
102053 sk->sk_data_ready(sk);
102054 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102055 drop_n_acct:
102056 spin_lock(&sk->sk_receive_queue.lock);
102057 po->stats.stats1.tp_drops++;
102058 - atomic_inc(&sk->sk_drops);
102059 + atomic_inc_unchecked(&sk->sk_drops);
102060 spin_unlock(&sk->sk_receive_queue.lock);
102061
102062 drop_n_restore:
102063 @@ -3459,7 +3459,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102064 case PACKET_HDRLEN:
102065 if (len > sizeof(int))
102066 len = sizeof(int);
102067 - if (copy_from_user(&val, optval, len))
102068 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
102069 return -EFAULT;
102070 switch (val) {
102071 case TPACKET_V1:
102072 @@ -3505,7 +3505,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102073 len = lv;
102074 if (put_user(len, optlen))
102075 return -EFAULT;
102076 - if (copy_to_user(optval, data, len))
102077 + if (len > sizeof(st) || copy_to_user(optval, data, len))
102078 return -EFAULT;
102079 return 0;
102080 }
102081 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
102082 index 70a547e..23477fe 100644
102083 --- a/net/phonet/pep.c
102084 +++ b/net/phonet/pep.c
102085 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102086
102087 case PNS_PEP_CTRL_REQ:
102088 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
102089 - atomic_inc(&sk->sk_drops);
102090 + atomic_inc_unchecked(&sk->sk_drops);
102091 break;
102092 }
102093 __skb_pull(skb, 4);
102094 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102095 }
102096
102097 if (pn->rx_credits == 0) {
102098 - atomic_inc(&sk->sk_drops);
102099 + atomic_inc_unchecked(&sk->sk_drops);
102100 err = -ENOBUFS;
102101 break;
102102 }
102103 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
102104 }
102105
102106 if (pn->rx_credits == 0) {
102107 - atomic_inc(&sk->sk_drops);
102108 + atomic_inc_unchecked(&sk->sk_drops);
102109 err = NET_RX_DROP;
102110 break;
102111 }
102112 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
102113 index 008214a..bb68240 100644
102114 --- a/net/phonet/socket.c
102115 +++ b/net/phonet/socket.c
102116 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
102117 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
102118 sock_i_ino(sk),
102119 atomic_read(&sk->sk_refcnt), sk,
102120 - atomic_read(&sk->sk_drops));
102121 + atomic_read_unchecked(&sk->sk_drops));
102122 }
102123 seq_pad(seq, '\n');
102124 return 0;
102125 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
102126 index c02a8c4..3c5b600 100644
102127 --- a/net/phonet/sysctl.c
102128 +++ b/net/phonet/sysctl.c
102129 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
102130 {
102131 int ret;
102132 int range[2] = {local_port_range[0], local_port_range[1]};
102133 - struct ctl_table tmp = {
102134 + ctl_table_no_const tmp = {
102135 .data = &range,
102136 .maxlen = sizeof(range),
102137 .mode = table->mode,
102138 diff --git a/net/rds/cong.c b/net/rds/cong.c
102139 index e5b65ac..f3b6fb7 100644
102140 --- a/net/rds/cong.c
102141 +++ b/net/rds/cong.c
102142 @@ -78,7 +78,7 @@
102143 * finds that the saved generation number is smaller than the global generation
102144 * number, it wakes up the process.
102145 */
102146 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
102147 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
102148
102149 /*
102150 * Congestion monitoring
102151 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
102152 rdsdebug("waking map %p for %pI4\n",
102153 map, &map->m_addr);
102154 rds_stats_inc(s_cong_update_received);
102155 - atomic_inc(&rds_cong_generation);
102156 + atomic_inc_unchecked(&rds_cong_generation);
102157 if (waitqueue_active(&map->m_waitq))
102158 wake_up(&map->m_waitq);
102159 if (waitqueue_active(&rds_poll_waitq))
102160 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
102161
102162 int rds_cong_updated_since(unsigned long *recent)
102163 {
102164 - unsigned long gen = atomic_read(&rds_cong_generation);
102165 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
102166
102167 if (likely(*recent == gen))
102168 return 0;
102169 diff --git a/net/rds/ib.h b/net/rds/ib.h
102170 index 7280ab8..e04f4ea 100644
102171 --- a/net/rds/ib.h
102172 +++ b/net/rds/ib.h
102173 @@ -128,7 +128,7 @@ struct rds_ib_connection {
102174 /* sending acks */
102175 unsigned long i_ack_flags;
102176 #ifdef KERNEL_HAS_ATOMIC64
102177 - atomic64_t i_ack_next; /* next ACK to send */
102178 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102179 #else
102180 spinlock_t i_ack_lock; /* protect i_ack_next */
102181 u64 i_ack_next; /* next ACK to send */
102182 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
102183 index 31b74f5..dc1fbfa 100644
102184 --- a/net/rds/ib_cm.c
102185 +++ b/net/rds/ib_cm.c
102186 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
102187 /* Clear the ACK state */
102188 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102189 #ifdef KERNEL_HAS_ATOMIC64
102190 - atomic64_set(&ic->i_ack_next, 0);
102191 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102192 #else
102193 ic->i_ack_next = 0;
102194 #endif
102195 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
102196 index b7ebe23..b6352f6 100644
102197 --- a/net/rds/ib_recv.c
102198 +++ b/net/rds/ib_recv.c
102199 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102200 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
102201 int ack_required)
102202 {
102203 - atomic64_set(&ic->i_ack_next, seq);
102204 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102205 if (ack_required) {
102206 smp_mb__before_clear_bit();
102207 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102208 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102209 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102210 smp_mb__after_clear_bit();
102211
102212 - return atomic64_read(&ic->i_ack_next);
102213 + return atomic64_read_unchecked(&ic->i_ack_next);
102214 }
102215 #endif
102216
102217 diff --git a/net/rds/iw.h b/net/rds/iw.h
102218 index 04ce3b1..48119a6 100644
102219 --- a/net/rds/iw.h
102220 +++ b/net/rds/iw.h
102221 @@ -134,7 +134,7 @@ struct rds_iw_connection {
102222 /* sending acks */
102223 unsigned long i_ack_flags;
102224 #ifdef KERNEL_HAS_ATOMIC64
102225 - atomic64_t i_ack_next; /* next ACK to send */
102226 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102227 #else
102228 spinlock_t i_ack_lock; /* protect i_ack_next */
102229 u64 i_ack_next; /* next ACK to send */
102230 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102231 index a91e1db..cf3053f 100644
102232 --- a/net/rds/iw_cm.c
102233 +++ b/net/rds/iw_cm.c
102234 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102235 /* Clear the ACK state */
102236 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102237 #ifdef KERNEL_HAS_ATOMIC64
102238 - atomic64_set(&ic->i_ack_next, 0);
102239 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102240 #else
102241 ic->i_ack_next = 0;
102242 #endif
102243 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102244 index 4503335..db566b4 100644
102245 --- a/net/rds/iw_recv.c
102246 +++ b/net/rds/iw_recv.c
102247 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102248 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102249 int ack_required)
102250 {
102251 - atomic64_set(&ic->i_ack_next, seq);
102252 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102253 if (ack_required) {
102254 smp_mb__before_clear_bit();
102255 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102256 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102257 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102258 smp_mb__after_clear_bit();
102259
102260 - return atomic64_read(&ic->i_ack_next);
102261 + return atomic64_read_unchecked(&ic->i_ack_next);
102262 }
102263 #endif
102264
102265 diff --git a/net/rds/rds.h b/net/rds/rds.h
102266 index 48f8ffc..0ef3eec 100644
102267 --- a/net/rds/rds.h
102268 +++ b/net/rds/rds.h
102269 @@ -449,7 +449,7 @@ struct rds_transport {
102270 void (*sync_mr)(void *trans_private, int direction);
102271 void (*free_mr)(void *trans_private, int invalidate);
102272 void (*flush_mrs)(void);
102273 -};
102274 +} __do_const;
102275
102276 struct rds_sock {
102277 struct sock rs_sk;
102278 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102279 index edac9ef..16bcb98 100644
102280 --- a/net/rds/tcp.c
102281 +++ b/net/rds/tcp.c
102282 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102283 int val = 1;
102284
102285 set_fs(KERNEL_DS);
102286 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102287 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102288 sizeof(val));
102289 set_fs(oldfs);
102290 }
102291 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102292 index 81cf5a4..b5826ff 100644
102293 --- a/net/rds/tcp_send.c
102294 +++ b/net/rds/tcp_send.c
102295 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102296
102297 oldfs = get_fs();
102298 set_fs(KERNEL_DS);
102299 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102300 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102301 sizeof(val));
102302 set_fs(oldfs);
102303 }
102304 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102305 index 7b16704..9628ec6 100644
102306 --- a/net/rxrpc/af_rxrpc.c
102307 +++ b/net/rxrpc/af_rxrpc.c
102308 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102309 __be32 rxrpc_epoch;
102310
102311 /* current debugging ID */
102312 -atomic_t rxrpc_debug_id;
102313 +atomic_unchecked_t rxrpc_debug_id;
102314
102315 /* count of skbs currently in use */
102316 atomic_t rxrpc_n_skbs;
102317 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102318 index c6be17a..2a6200a 100644
102319 --- a/net/rxrpc/ar-ack.c
102320 +++ b/net/rxrpc/ar-ack.c
102321 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102322
102323 _enter("{%d,%d,%d,%d},",
102324 call->acks_hard, call->acks_unacked,
102325 - atomic_read(&call->sequence),
102326 + atomic_read_unchecked(&call->sequence),
102327 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102328
102329 stop = 0;
102330 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102331
102332 /* each Tx packet has a new serial number */
102333 sp->hdr.serial =
102334 - htonl(atomic_inc_return(&call->conn->serial));
102335 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102336
102337 hdr = (struct rxrpc_header *) txb->head;
102338 hdr->serial = sp->hdr.serial;
102339 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102340 */
102341 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102342 {
102343 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102344 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
102345 }
102346
102347 /*
102348 @@ -677,7 +677,7 @@ process_further:
102349
102350 latest = ntohl(sp->hdr.serial);
102351 hard = ntohl(ack.firstPacket);
102352 - tx = atomic_read(&call->sequence);
102353 + tx = atomic_read_unchecked(&call->sequence);
102354
102355 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102356 latest,
102357 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
102358 goto maybe_reschedule;
102359
102360 send_ACK_with_skew:
102361 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
102362 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
102363 ntohl(ack.serial));
102364 send_ACK:
102365 mtu = call->conn->trans->peer->if_mtu;
102366 @@ -1221,7 +1221,7 @@ send_ACK:
102367 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
102368 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
102369
102370 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102371 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102372 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102373 ntohl(hdr.serial),
102374 ntohs(ack.maxSkew),
102375 @@ -1239,7 +1239,7 @@ send_ACK:
102376 send_message:
102377 _debug("send message");
102378
102379 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102380 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102381 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
102382 send_message_2:
102383
102384 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
102385 index a9e05db..194e793 100644
102386 --- a/net/rxrpc/ar-call.c
102387 +++ b/net/rxrpc/ar-call.c
102388 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
102389 spin_lock_init(&call->lock);
102390 rwlock_init(&call->state_lock);
102391 atomic_set(&call->usage, 1);
102392 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
102393 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102394 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
102395
102396 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
102397 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
102398 index 6631f4f..bfdf056 100644
102399 --- a/net/rxrpc/ar-connection.c
102400 +++ b/net/rxrpc/ar-connection.c
102401 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
102402 rwlock_init(&conn->lock);
102403 spin_lock_init(&conn->state_lock);
102404 atomic_set(&conn->usage, 1);
102405 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
102406 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102407 conn->avail_calls = RXRPC_MAXCALLS;
102408 conn->size_align = 4;
102409 conn->header_size = sizeof(struct rxrpc_header);
102410 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
102411 index e7ed43a..6afa140 100644
102412 --- a/net/rxrpc/ar-connevent.c
102413 +++ b/net/rxrpc/ar-connevent.c
102414 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
102415
102416 len = iov[0].iov_len + iov[1].iov_len;
102417
102418 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102419 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102420 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
102421
102422 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102423 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
102424 index 63b21e5..330232e 100644
102425 --- a/net/rxrpc/ar-input.c
102426 +++ b/net/rxrpc/ar-input.c
102427 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
102428 /* track the latest serial number on this connection for ACK packet
102429 * information */
102430 serial = ntohl(sp->hdr.serial);
102431 - hi_serial = atomic_read(&call->conn->hi_serial);
102432 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
102433 while (serial > hi_serial)
102434 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
102435 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
102436 serial);
102437
102438 /* request ACK generation for any ACK or DATA packet that requests
102439 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
102440 index ba9fd36..9bbfe01 100644
102441 --- a/net/rxrpc/ar-internal.h
102442 +++ b/net/rxrpc/ar-internal.h
102443 @@ -272,8 +272,8 @@ struct rxrpc_connection {
102444 int error; /* error code for local abort */
102445 int debug_id; /* debug ID for printks */
102446 unsigned int call_counter; /* call ID counter */
102447 - atomic_t serial; /* packet serial number counter */
102448 - atomic_t hi_serial; /* highest serial number received */
102449 + atomic_unchecked_t serial; /* packet serial number counter */
102450 + atomic_unchecked_t hi_serial; /* highest serial number received */
102451 u8 avail_calls; /* number of calls available */
102452 u8 size_align; /* data size alignment (for security) */
102453 u8 header_size; /* rxrpc + security header size */
102454 @@ -346,7 +346,7 @@ struct rxrpc_call {
102455 spinlock_t lock;
102456 rwlock_t state_lock; /* lock for state transition */
102457 atomic_t usage;
102458 - atomic_t sequence; /* Tx data packet sequence counter */
102459 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
102460 u32 abort_code; /* local/remote abort code */
102461 enum { /* current state of call */
102462 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
102463 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
102464 */
102465 extern atomic_t rxrpc_n_skbs;
102466 extern __be32 rxrpc_epoch;
102467 -extern atomic_t rxrpc_debug_id;
102468 +extern atomic_unchecked_t rxrpc_debug_id;
102469 extern struct workqueue_struct *rxrpc_workqueue;
102470
102471 /*
102472 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
102473 index 87f7135..74d3703 100644
102474 --- a/net/rxrpc/ar-local.c
102475 +++ b/net/rxrpc/ar-local.c
102476 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
102477 spin_lock_init(&local->lock);
102478 rwlock_init(&local->services_lock);
102479 atomic_set(&local->usage, 1);
102480 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
102481 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102482 memcpy(&local->srx, srx, sizeof(*srx));
102483 }
102484
102485 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
102486 index 0b4b9a7..966ffbb 100644
102487 --- a/net/rxrpc/ar-output.c
102488 +++ b/net/rxrpc/ar-output.c
102489 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
102490 memset(skb_put(skb, pad), 0, pad);
102491 }
102492
102493 - seq = atomic_inc_return(&call->sequence);
102494 + seq = atomic_inc_return_unchecked(&call->sequence);
102495
102496 sp->hdr.epoch = conn->epoch;
102497 sp->hdr.cid = call->cid;
102498 sp->hdr.callNumber = call->call_id;
102499 sp->hdr.seq = htonl(seq);
102500 sp->hdr.serial =
102501 - htonl(atomic_inc_return(&conn->serial));
102502 + htonl(atomic_inc_return_unchecked(&conn->serial));
102503 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
102504 sp->hdr.userStatus = 0;
102505 sp->hdr.securityIndex = conn->security_ix;
102506 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
102507 index bebaa43..2644591 100644
102508 --- a/net/rxrpc/ar-peer.c
102509 +++ b/net/rxrpc/ar-peer.c
102510 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
102511 INIT_LIST_HEAD(&peer->error_targets);
102512 spin_lock_init(&peer->lock);
102513 atomic_set(&peer->usage, 1);
102514 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
102515 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102516 memcpy(&peer->srx, srx, sizeof(*srx));
102517
102518 rxrpc_assess_MTU_size(peer);
102519 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
102520 index 38047f7..9f48511 100644
102521 --- a/net/rxrpc/ar-proc.c
102522 +++ b/net/rxrpc/ar-proc.c
102523 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
102524 atomic_read(&conn->usage),
102525 rxrpc_conn_states[conn->state],
102526 key_serial(conn->key),
102527 - atomic_read(&conn->serial),
102528 - atomic_read(&conn->hi_serial));
102529 + atomic_read_unchecked(&conn->serial),
102530 + atomic_read_unchecked(&conn->hi_serial));
102531
102532 return 0;
102533 }
102534 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
102535 index 1976dec..aa70be5 100644
102536 --- a/net/rxrpc/ar-transport.c
102537 +++ b/net/rxrpc/ar-transport.c
102538 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
102539 spin_lock_init(&trans->client_lock);
102540 rwlock_init(&trans->conn_lock);
102541 atomic_set(&trans->usage, 1);
102542 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
102543 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102544
102545 if (peer->srx.transport.family == AF_INET) {
102546 switch (peer->srx.transport_type) {
102547 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
102548 index f226709..0e735a8 100644
102549 --- a/net/rxrpc/rxkad.c
102550 +++ b/net/rxrpc/rxkad.c
102551 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
102552
102553 len = iov[0].iov_len + iov[1].iov_len;
102554
102555 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102556 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102557 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
102558
102559 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102560 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
102561
102562 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
102563
102564 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
102565 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102566 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
102567
102568 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
102569 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
102570 index e1543b0..7ce8bd0 100644
102571 --- a/net/sched/sch_generic.c
102572 +++ b/net/sched/sch_generic.c
102573 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
102574 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102575 if (dev->reg_state == NETREG_UNINITIALIZED)
102576 return;
102577 - atomic_inc(&dev->carrier_changes);
102578 + atomic_inc_unchecked(&dev->carrier_changes);
102579 linkwatch_fire_event(dev);
102580 if (netif_running(dev))
102581 __netdev_watchdog_up(dev);
102582 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
102583 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102584 if (dev->reg_state == NETREG_UNINITIALIZED)
102585 return;
102586 - atomic_inc(&dev->carrier_changes);
102587 + atomic_inc_unchecked(&dev->carrier_changes);
102588 linkwatch_fire_event(dev);
102589 }
102590 }
102591 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
102592 index 2b1738e..a9d0fc9 100644
102593 --- a/net/sctp/ipv6.c
102594 +++ b/net/sctp/ipv6.c
102595 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
102596 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
102597 };
102598
102599 -static struct sctp_af sctp_af_inet6 = {
102600 +static struct sctp_af sctp_af_inet6 __read_only = {
102601 .sa_family = AF_INET6,
102602 .sctp_xmit = sctp_v6_xmit,
102603 .setsockopt = ipv6_setsockopt,
102604 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
102605 #endif
102606 };
102607
102608 -static struct sctp_pf sctp_pf_inet6 = {
102609 +static struct sctp_pf sctp_pf_inet6 __read_only = {
102610 .event_msgname = sctp_inet6_event_msgname,
102611 .skb_msgname = sctp_inet6_skb_msgname,
102612 .af_supported = sctp_inet6_af_supported,
102613 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
102614
102615 void sctp_v6_pf_exit(void)
102616 {
102617 - list_del(&sctp_af_inet6.list);
102618 + pax_list_del(&sctp_af_inet6.list);
102619 }
102620
102621 /* Initialize IPv6 support and register with socket layer. */
102622 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
102623 index 44cbb54..4c5dce6 100644
102624 --- a/net/sctp/protocol.c
102625 +++ b/net/sctp/protocol.c
102626 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
102627 return 0;
102628 }
102629
102630 + pax_open_kernel();
102631 INIT_LIST_HEAD(&af->list);
102632 - list_add_tail(&af->list, &sctp_address_families);
102633 + pax_close_kernel();
102634 + pax_list_add_tail(&af->list, &sctp_address_families);
102635 return 1;
102636 }
102637
102638 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
102639
102640 static struct sctp_af sctp_af_inet;
102641
102642 -static struct sctp_pf sctp_pf_inet = {
102643 +static struct sctp_pf sctp_pf_inet __read_only = {
102644 .event_msgname = sctp_inet_event_msgname,
102645 .skb_msgname = sctp_inet_skb_msgname,
102646 .af_supported = sctp_inet_af_supported,
102647 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
102648 };
102649
102650 /* IPv4 address related functions. */
102651 -static struct sctp_af sctp_af_inet = {
102652 +static struct sctp_af sctp_af_inet __read_only = {
102653 .sa_family = AF_INET,
102654 .sctp_xmit = sctp_v4_xmit,
102655 .setsockopt = ip_setsockopt,
102656 @@ -1124,7 +1126,7 @@ static void sctp_v4_pf_init(void)
102657
102658 static void sctp_v4_pf_exit(void)
102659 {
102660 - list_del(&sctp_af_inet.list);
102661 + pax_list_del(&sctp_af_inet.list);
102662 }
102663
102664 static int sctp_v4_protosw_init(void)
102665 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
102666 index fef2acd..c705c4f 100644
102667 --- a/net/sctp/sm_sideeffect.c
102668 +++ b/net/sctp/sm_sideeffect.c
102669 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
102670 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
102671 }
102672
102673 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102674 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102675 NULL,
102676 sctp_generate_t1_cookie_event,
102677 sctp_generate_t1_init_event,
102678 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
102679 index fee06b9..eabc613 100644
102680 --- a/net/sctp/socket.c
102681 +++ b/net/sctp/socket.c
102682 @@ -2175,11 +2175,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
102683 {
102684 struct sctp_association *asoc;
102685 struct sctp_ulpevent *event;
102686 + struct sctp_event_subscribe subscribe;
102687
102688 if (optlen > sizeof(struct sctp_event_subscribe))
102689 return -EINVAL;
102690 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
102691 + if (copy_from_user(&subscribe, optval, optlen))
102692 return -EFAULT;
102693 + sctp_sk(sk)->subscribe = subscribe;
102694
102695 /*
102696 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
102697 @@ -4259,13 +4261,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
102698 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102699 int __user *optlen)
102700 {
102701 + struct sctp_event_subscribe subscribe;
102702 +
102703 if (len <= 0)
102704 return -EINVAL;
102705 if (len > sizeof(struct sctp_event_subscribe))
102706 len = sizeof(struct sctp_event_subscribe);
102707 if (put_user(len, optlen))
102708 return -EFAULT;
102709 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
102710 + subscribe = sctp_sk(sk)->subscribe;
102711 + if (copy_to_user(optval, &subscribe, len))
102712 return -EFAULT;
102713 return 0;
102714 }
102715 @@ -4283,6 +4288,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102716 */
102717 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
102718 {
102719 + __u32 autoclose;
102720 +
102721 /* Applicable to UDP-style socket only */
102722 if (sctp_style(sk, TCP))
102723 return -EOPNOTSUPP;
102724 @@ -4291,7 +4298,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
102725 len = sizeof(int);
102726 if (put_user(len, optlen))
102727 return -EFAULT;
102728 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
102729 + autoclose = sctp_sk(sk)->autoclose;
102730 + if (copy_to_user(optval, &autoclose, sizeof(int)))
102731 return -EFAULT;
102732 return 0;
102733 }
102734 @@ -4666,12 +4674,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
102735 */
102736 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
102737 {
102738 + struct sctp_initmsg initmsg;
102739 +
102740 if (len < sizeof(struct sctp_initmsg))
102741 return -EINVAL;
102742 len = sizeof(struct sctp_initmsg);
102743 if (put_user(len, optlen))
102744 return -EFAULT;
102745 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
102746 + initmsg = sctp_sk(sk)->initmsg;
102747 + if (copy_to_user(optval, &initmsg, len))
102748 return -EFAULT;
102749 return 0;
102750 }
102751 @@ -4712,6 +4723,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
102752 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
102753 if (space_left < addrlen)
102754 return -ENOMEM;
102755 + if (addrlen > sizeof(temp) || addrlen < 0)
102756 + return -EFAULT;
102757 if (copy_to_user(to, &temp, addrlen))
102758 return -EFAULT;
102759 to += addrlen;
102760 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
102761 index c82fdc1..4ca1f95 100644
102762 --- a/net/sctp/sysctl.c
102763 +++ b/net/sctp/sysctl.c
102764 @@ -308,7 +308,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
102765 {
102766 struct net *net = current->nsproxy->net_ns;
102767 char tmp[8];
102768 - struct ctl_table tbl;
102769 + ctl_table_no_const tbl;
102770 int ret;
102771 int changed = 0;
102772 char *none = "none";
102773 @@ -355,7 +355,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
102774 {
102775 struct net *net = current->nsproxy->net_ns;
102776 int new_value;
102777 - struct ctl_table tbl;
102778 + ctl_table_no_const tbl;
102779 unsigned int min = *(unsigned int *) ctl->extra1;
102780 unsigned int max = *(unsigned int *) ctl->extra2;
102781 int ret;
102782 @@ -382,7 +382,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
102783 {
102784 struct net *net = current->nsproxy->net_ns;
102785 int new_value;
102786 - struct ctl_table tbl;
102787 + ctl_table_no_const tbl;
102788 unsigned int min = *(unsigned int *) ctl->extra1;
102789 unsigned int max = *(unsigned int *) ctl->extra2;
102790 int ret;
102791 @@ -408,7 +408,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
102792 loff_t *ppos)
102793 {
102794 struct net *net = current->nsproxy->net_ns;
102795 - struct ctl_table tbl;
102796 + ctl_table_no_const tbl;
102797 int new_value, ret;
102798
102799 memset(&tbl, 0, sizeof(struct ctl_table));
102800 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
102801
102802 int sctp_sysctl_net_register(struct net *net)
102803 {
102804 - struct ctl_table *table = sctp_net_table;
102805 + ctl_table_no_const *table = NULL;
102806
102807 if (!net_eq(net, &init_net)) {
102808 int i;
102809 @@ -449,7 +449,10 @@ int sctp_sysctl_net_register(struct net *net)
102810 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
102811 }
102812
102813 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
102814 + if (!net_eq(net, &init_net))
102815 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
102816 + else
102817 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
102818 return 0;
102819 }
102820
102821 diff --git a/net/socket.c b/net/socket.c
102822 index abf56b2..b8998bc 100644
102823 --- a/net/socket.c
102824 +++ b/net/socket.c
102825 @@ -89,6 +89,7 @@
102826 #include <linux/magic.h>
102827 #include <linux/slab.h>
102828 #include <linux/xattr.h>
102829 +#include <linux/in.h>
102830
102831 #include <asm/uaccess.h>
102832 #include <asm/unistd.h>
102833 @@ -112,6 +113,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
102834 unsigned int sysctl_net_busy_poll __read_mostly;
102835 #endif
102836
102837 +#include <linux/grsock.h>
102838 +
102839 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
102840 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
102841 unsigned long nr_segs, loff_t pos);
102842 @@ -163,7 +166,7 @@ static const struct file_operations socket_file_ops = {
102843 */
102844
102845 static DEFINE_SPINLOCK(net_family_lock);
102846 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
102847 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
102848
102849 /*
102850 * Statistics counters of the socket lists
102851 @@ -329,7 +332,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
102852 &sockfs_dentry_operations, SOCKFS_MAGIC);
102853 }
102854
102855 -static struct vfsmount *sock_mnt __read_mostly;
102856 +struct vfsmount *sock_mnt __read_mostly;
102857
102858 static struct file_system_type sock_fs_type = {
102859 .name = "sockfs",
102860 @@ -1257,6 +1260,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
102861 return -EAFNOSUPPORT;
102862 if (type < 0 || type >= SOCK_MAX)
102863 return -EINVAL;
102864 + if (protocol < 0)
102865 + return -EINVAL;
102866
102867 /* Compatibility.
102868
102869 @@ -1277,6 +1282,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
102870 if (err)
102871 return err;
102872
102873 + if(!kern && !gr_search_socket(family, type, protocol)) {
102874 + if (rcu_access_pointer(net_families[family]) == NULL)
102875 + return -EAFNOSUPPORT;
102876 + else
102877 + return -EACCES;
102878 + }
102879 +
102880 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
102881 + if (rcu_access_pointer(net_families[family]) == NULL)
102882 + return -EAFNOSUPPORT;
102883 + else
102884 + return -EACCES;
102885 + }
102886 +
102887 /*
102888 * Allocate the socket and allow the family to set things up. if
102889 * the protocol is 0, the family is instructed to select an appropriate
102890 @@ -1528,6 +1547,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
102891 if (sock) {
102892 err = move_addr_to_kernel(umyaddr, addrlen, &address);
102893 if (err >= 0) {
102894 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
102895 + err = -EACCES;
102896 + goto error;
102897 + }
102898 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
102899 + if (err)
102900 + goto error;
102901 +
102902 err = security_socket_bind(sock,
102903 (struct sockaddr *)&address,
102904 addrlen);
102905 @@ -1536,6 +1563,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
102906 (struct sockaddr *)
102907 &address, addrlen);
102908 }
102909 +error:
102910 fput_light(sock->file, fput_needed);
102911 }
102912 return err;
102913 @@ -1559,10 +1587,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
102914 if ((unsigned int)backlog > somaxconn)
102915 backlog = somaxconn;
102916
102917 + if (gr_handle_sock_server_other(sock->sk)) {
102918 + err = -EPERM;
102919 + goto error;
102920 + }
102921 +
102922 + err = gr_search_listen(sock);
102923 + if (err)
102924 + goto error;
102925 +
102926 err = security_socket_listen(sock, backlog);
102927 if (!err)
102928 err = sock->ops->listen(sock, backlog);
102929
102930 +error:
102931 fput_light(sock->file, fput_needed);
102932 }
102933 return err;
102934 @@ -1606,6 +1644,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
102935 newsock->type = sock->type;
102936 newsock->ops = sock->ops;
102937
102938 + if (gr_handle_sock_server_other(sock->sk)) {
102939 + err = -EPERM;
102940 + sock_release(newsock);
102941 + goto out_put;
102942 + }
102943 +
102944 + err = gr_search_accept(sock);
102945 + if (err) {
102946 + sock_release(newsock);
102947 + goto out_put;
102948 + }
102949 +
102950 /*
102951 * We don't need try_module_get here, as the listening socket (sock)
102952 * has the protocol module (sock->ops->owner) held.
102953 @@ -1651,6 +1701,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
102954 fd_install(newfd, newfile);
102955 err = newfd;
102956
102957 + gr_attach_curr_ip(newsock->sk);
102958 +
102959 out_put:
102960 fput_light(sock->file, fput_needed);
102961 out:
102962 @@ -1683,6 +1735,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
102963 int, addrlen)
102964 {
102965 struct socket *sock;
102966 + struct sockaddr *sck;
102967 struct sockaddr_storage address;
102968 int err, fput_needed;
102969
102970 @@ -1693,6 +1746,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
102971 if (err < 0)
102972 goto out_put;
102973
102974 + sck = (struct sockaddr *)&address;
102975 +
102976 + if (gr_handle_sock_client(sck)) {
102977 + err = -EACCES;
102978 + goto out_put;
102979 + }
102980 +
102981 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
102982 + if (err)
102983 + goto out_put;
102984 +
102985 err =
102986 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
102987 if (err)
102988 @@ -1774,6 +1838,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
102989 * the protocol.
102990 */
102991
102992 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
102993 +
102994 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
102995 unsigned int, flags, struct sockaddr __user *, addr,
102996 int, addr_len)
102997 @@ -1840,7 +1906,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
102998 struct socket *sock;
102999 struct iovec iov;
103000 struct msghdr msg;
103001 - struct sockaddr_storage address;
103002 + struct sockaddr_storage address = { };
103003 int err, err2;
103004 int fput_needed;
103005
103006 @@ -2066,7 +2132,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
103007 * checking falls down on this.
103008 */
103009 if (copy_from_user(ctl_buf,
103010 - (void __user __force *)msg_sys->msg_control,
103011 + (void __force_user *)msg_sys->msg_control,
103012 ctl_len))
103013 goto out_freectl;
103014 msg_sys->msg_control = ctl_buf;
103015 @@ -2217,7 +2283,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103016 int err, total_len, len;
103017
103018 /* kernel mode address */
103019 - struct sockaddr_storage addr;
103020 + struct sockaddr_storage addr = { };
103021
103022 /* user mode address pointers */
103023 struct sockaddr __user *uaddr;
103024 @@ -2246,7 +2312,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103025 /* Save the user-mode address (verify_iovec will change the
103026 * kernel msghdr to use the kernel address space)
103027 */
103028 - uaddr = (__force void __user *)msg_sys->msg_name;
103029 + uaddr = (void __force_user *)msg_sys->msg_name;
103030 uaddr_len = COMPAT_NAMELEN(msg);
103031 if (MSG_CMSG_COMPAT & flags)
103032 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
103033 @@ -2887,7 +2953,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
103034 ifr = compat_alloc_user_space(buf_size);
103035 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
103036
103037 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
103038 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
103039 return -EFAULT;
103040
103041 if (put_user(convert_in ? rxnfc : compat_ptr(data),
103042 @@ -2998,7 +3064,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
103043 old_fs = get_fs();
103044 set_fs(KERNEL_DS);
103045 err = dev_ioctl(net, cmd,
103046 - (struct ifreq __user __force *) &kifr);
103047 + (struct ifreq __force_user *) &kifr);
103048 set_fs(old_fs);
103049
103050 return err;
103051 @@ -3091,7 +3157,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
103052
103053 old_fs = get_fs();
103054 set_fs(KERNEL_DS);
103055 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
103056 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
103057 set_fs(old_fs);
103058
103059 if (cmd == SIOCGIFMAP && !err) {
103060 @@ -3175,7 +3241,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
103061 ret |= get_user(rtdev, &(ur4->rt_dev));
103062 if (rtdev) {
103063 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
103064 - r4.rt_dev = (char __user __force *)devname;
103065 + r4.rt_dev = (char __force_user *)devname;
103066 devname[15] = 0;
103067 } else
103068 r4.rt_dev = NULL;
103069 @@ -3402,8 +3468,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
103070 int __user *uoptlen;
103071 int err;
103072
103073 - uoptval = (char __user __force *) optval;
103074 - uoptlen = (int __user __force *) optlen;
103075 + uoptval = (char __force_user *) optval;
103076 + uoptlen = (int __force_user *) optlen;
103077
103078 set_fs(KERNEL_DS);
103079 if (level == SOL_SOCKET)
103080 @@ -3423,7 +3489,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
103081 char __user *uoptval;
103082 int err;
103083
103084 - uoptval = (char __user __force *) optval;
103085 + uoptval = (char __force_user *) optval;
103086
103087 set_fs(KERNEL_DS);
103088 if (level == SOL_SOCKET)
103089 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
103090 index 0f73f45..a96aa52 100644
103091 --- a/net/sunrpc/auth_gss/svcauth_gss.c
103092 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
103093 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103094 uint64_t *handle)
103095 {
103096 struct rsc rsci, *rscp = NULL;
103097 - static atomic64_t ctxhctr;
103098 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
103099 long long ctxh;
103100 struct gss_api_mech *gm = NULL;
103101 time_t expiry;
103102 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103103 status = -ENOMEM;
103104 /* the handle needs to be just a unique id,
103105 * use a static counter */
103106 - ctxh = atomic64_inc_return(&ctxhctr);
103107 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
103108
103109 /* make a copy for the caller */
103110 *handle = ctxh;
103111 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
103112 index ae333c1..18521f0 100644
103113 --- a/net/sunrpc/cache.c
103114 +++ b/net/sunrpc/cache.c
103115 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
103116 struct sunrpc_net *sn;
103117
103118 sn = net_generic(net, sunrpc_net_id);
103119 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
103120 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
103121 if (cd->u.procfs.proc_ent == NULL)
103122 goto out_nomem;
103123 cd->u.procfs.channel_ent = NULL;
103124 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
103125 index 2e6ab10..3170800 100644
103126 --- a/net/sunrpc/clnt.c
103127 +++ b/net/sunrpc/clnt.c
103128 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
103129 (RPC_IS_ASYNC(task) ? "async" : "sync"));
103130
103131 /* Increment call count */
103132 - task->tk_msg.rpc_proc->p_count++;
103133 + pax_open_kernel();
103134 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
103135 + pax_close_kernel();
103136 clnt->cl_stats->rpccnt++;
103137 task->tk_action = call_reserve;
103138 }
103139 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
103140 index 25578af..a29298d 100644
103141 --- a/net/sunrpc/sched.c
103142 +++ b/net/sunrpc/sched.c
103143 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
103144 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
103145 static void rpc_task_set_debuginfo(struct rpc_task *task)
103146 {
103147 - static atomic_t rpc_pid;
103148 + static atomic_unchecked_t rpc_pid;
103149
103150 - task->tk_pid = atomic_inc_return(&rpc_pid);
103151 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
103152 }
103153 #else
103154 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
103155 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
103156 index 5453049..465669a 100644
103157 --- a/net/sunrpc/stats.c
103158 +++ b/net/sunrpc/stats.c
103159 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
103160
103161 dprintk("RPC: registering /proc/net/rpc\n");
103162 sn = net_generic(net, sunrpc_net_id);
103163 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
103164 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
103165 if (sn->proc_net_rpc == NULL)
103166 return -ENOMEM;
103167
103168 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
103169 index 5de6801..b4e330d 100644
103170 --- a/net/sunrpc/svc.c
103171 +++ b/net/sunrpc/svc.c
103172 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
103173 svc_putnl(resv, RPC_SUCCESS);
103174
103175 /* Bump per-procedure stats counter */
103176 - procp->pc_count++;
103177 + pax_open_kernel();
103178 + (*(unsigned int *)&procp->pc_count)++;
103179 + pax_close_kernel();
103180
103181 /* Initialize storage for argp and resp */
103182 memset(rqstp->rq_argp, 0, procp->pc_argsize);
103183 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
103184 index 621ca7b..59421dd 100644
103185 --- a/net/sunrpc/svcauth_unix.c
103186 +++ b/net/sunrpc/svcauth_unix.c
103187 @@ -414,7 +414,7 @@ struct unix_gid {
103188 struct group_info *gi;
103189 };
103190
103191 -static int unix_gid_hash(kuid_t uid)
103192 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
103193 {
103194 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
103195 }
103196 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
103197 (*bpp)[-1] = '\n';
103198 }
103199
103200 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103201 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103202
103203 static int unix_gid_parse(struct cache_detail *cd,
103204 char *mesg, int mlen)
103205 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
103206 index c1b6270..05089c1 100644
103207 --- a/net/sunrpc/xprtrdma/svc_rdma.c
103208 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
103209 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
103210 static unsigned int min_max_inline = 4096;
103211 static unsigned int max_max_inline = 65536;
103212
103213 -atomic_t rdma_stat_recv;
103214 -atomic_t rdma_stat_read;
103215 -atomic_t rdma_stat_write;
103216 -atomic_t rdma_stat_sq_starve;
103217 -atomic_t rdma_stat_rq_starve;
103218 -atomic_t rdma_stat_rq_poll;
103219 -atomic_t rdma_stat_rq_prod;
103220 -atomic_t rdma_stat_sq_poll;
103221 -atomic_t rdma_stat_sq_prod;
103222 +atomic_unchecked_t rdma_stat_recv;
103223 +atomic_unchecked_t rdma_stat_read;
103224 +atomic_unchecked_t rdma_stat_write;
103225 +atomic_unchecked_t rdma_stat_sq_starve;
103226 +atomic_unchecked_t rdma_stat_rq_starve;
103227 +atomic_unchecked_t rdma_stat_rq_poll;
103228 +atomic_unchecked_t rdma_stat_rq_prod;
103229 +atomic_unchecked_t rdma_stat_sq_poll;
103230 +atomic_unchecked_t rdma_stat_sq_prod;
103231
103232 /* Temporary NFS request map and context caches */
103233 struct kmem_cache *svc_rdma_map_cachep;
103234 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
103235 len -= *ppos;
103236 if (len > *lenp)
103237 len = *lenp;
103238 - if (len && copy_to_user(buffer, str_buf, len))
103239 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
103240 return -EFAULT;
103241 *lenp = len;
103242 *ppos += len;
103243 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
103244 {
103245 .procname = "rdma_stat_read",
103246 .data = &rdma_stat_read,
103247 - .maxlen = sizeof(atomic_t),
103248 + .maxlen = sizeof(atomic_unchecked_t),
103249 .mode = 0644,
103250 .proc_handler = read_reset_stat,
103251 },
103252 {
103253 .procname = "rdma_stat_recv",
103254 .data = &rdma_stat_recv,
103255 - .maxlen = sizeof(atomic_t),
103256 + .maxlen = sizeof(atomic_unchecked_t),
103257 .mode = 0644,
103258 .proc_handler = read_reset_stat,
103259 },
103260 {
103261 .procname = "rdma_stat_write",
103262 .data = &rdma_stat_write,
103263 - .maxlen = sizeof(atomic_t),
103264 + .maxlen = sizeof(atomic_unchecked_t),
103265 .mode = 0644,
103266 .proc_handler = read_reset_stat,
103267 },
103268 {
103269 .procname = "rdma_stat_sq_starve",
103270 .data = &rdma_stat_sq_starve,
103271 - .maxlen = sizeof(atomic_t),
103272 + .maxlen = sizeof(atomic_unchecked_t),
103273 .mode = 0644,
103274 .proc_handler = read_reset_stat,
103275 },
103276 {
103277 .procname = "rdma_stat_rq_starve",
103278 .data = &rdma_stat_rq_starve,
103279 - .maxlen = sizeof(atomic_t),
103280 + .maxlen = sizeof(atomic_unchecked_t),
103281 .mode = 0644,
103282 .proc_handler = read_reset_stat,
103283 },
103284 {
103285 .procname = "rdma_stat_rq_poll",
103286 .data = &rdma_stat_rq_poll,
103287 - .maxlen = sizeof(atomic_t),
103288 + .maxlen = sizeof(atomic_unchecked_t),
103289 .mode = 0644,
103290 .proc_handler = read_reset_stat,
103291 },
103292 {
103293 .procname = "rdma_stat_rq_prod",
103294 .data = &rdma_stat_rq_prod,
103295 - .maxlen = sizeof(atomic_t),
103296 + .maxlen = sizeof(atomic_unchecked_t),
103297 .mode = 0644,
103298 .proc_handler = read_reset_stat,
103299 },
103300 {
103301 .procname = "rdma_stat_sq_poll",
103302 .data = &rdma_stat_sq_poll,
103303 - .maxlen = sizeof(atomic_t),
103304 + .maxlen = sizeof(atomic_unchecked_t),
103305 .mode = 0644,
103306 .proc_handler = read_reset_stat,
103307 },
103308 {
103309 .procname = "rdma_stat_sq_prod",
103310 .data = &rdma_stat_sq_prod,
103311 - .maxlen = sizeof(atomic_t),
103312 + .maxlen = sizeof(atomic_unchecked_t),
103313 .mode = 0644,
103314 .proc_handler = read_reset_stat,
103315 },
103316 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103317 index 8d904e4..b2fc727 100644
103318 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103319 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103320 @@ -504,7 +504,7 @@ next_sge:
103321 svc_rdma_put_context(ctxt, 0);
103322 goto out;
103323 }
103324 - atomic_inc(&rdma_stat_read);
103325 + atomic_inc_unchecked(&rdma_stat_read);
103326
103327 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103328 chl_map->ch[ch_no].count -= read_wr.num_sge;
103329 @@ -607,7 +607,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103330 dto_q);
103331 list_del_init(&ctxt->dto_q);
103332 } else {
103333 - atomic_inc(&rdma_stat_rq_starve);
103334 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103335 clear_bit(XPT_DATA, &xprt->xpt_flags);
103336 ctxt = NULL;
103337 }
103338 @@ -627,7 +627,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103339 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103340 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103341 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103342 - atomic_inc(&rdma_stat_recv);
103343 + atomic_inc_unchecked(&rdma_stat_recv);
103344
103345 /* Build up the XDR from the receive buffers. */
103346 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
103347 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103348 index 7e024a5..17f13d3 100644
103349 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103350 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103351 @@ -363,7 +363,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
103352 write_wr.wr.rdma.remote_addr = to;
103353
103354 /* Post It */
103355 - atomic_inc(&rdma_stat_write);
103356 + atomic_inc_unchecked(&rdma_stat_write);
103357 if (svc_rdma_send(xprt, &write_wr))
103358 goto err;
103359 return 0;
103360 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103361 index 25688fa..dc72003 100644
103362 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
103363 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103364 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103365 return;
103366
103367 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
103368 - atomic_inc(&rdma_stat_rq_poll);
103369 + atomic_inc_unchecked(&rdma_stat_rq_poll);
103370
103371 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
103372 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
103373 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103374 }
103375
103376 if (ctxt)
103377 - atomic_inc(&rdma_stat_rq_prod);
103378 + atomic_inc_unchecked(&rdma_stat_rq_prod);
103379
103380 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
103381 /*
103382 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103383 return;
103384
103385 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
103386 - atomic_inc(&rdma_stat_sq_poll);
103387 + atomic_inc_unchecked(&rdma_stat_sq_poll);
103388 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
103389 if (wc.status != IB_WC_SUCCESS)
103390 /* Close the transport */
103391 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103392 }
103393
103394 if (ctxt)
103395 - atomic_inc(&rdma_stat_sq_prod);
103396 + atomic_inc_unchecked(&rdma_stat_sq_prod);
103397 }
103398
103399 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
103400 @@ -1261,7 +1261,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
103401 spin_lock_bh(&xprt->sc_lock);
103402 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
103403 spin_unlock_bh(&xprt->sc_lock);
103404 - atomic_inc(&rdma_stat_sq_starve);
103405 + atomic_inc_unchecked(&rdma_stat_sq_starve);
103406
103407 /* See if we can opportunistically reap SQ WR to make room */
103408 sq_cq_reap(xprt);
103409 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
103410 index e7000be..e3b0ba7 100644
103411 --- a/net/sysctl_net.c
103412 +++ b/net/sysctl_net.c
103413 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
103414 kgid_t root_gid = make_kgid(net->user_ns, 0);
103415
103416 /* Allow network administrator to have same access as root. */
103417 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
103418 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
103419 uid_eq(root_uid, current_euid())) {
103420 int mode = (table->mode >> 6) & 7;
103421 return (mode << 6) | (mode << 3) | mode;
103422 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
103423 index 6424372..afd36e9 100644
103424 --- a/net/tipc/subscr.c
103425 +++ b/net/tipc/subscr.c
103426 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
103427 struct tipc_subscriber *subscriber = sub->subscriber;
103428 struct kvec msg_sect;
103429
103430 - msg_sect.iov_base = (void *)&sub->evt;
103431 + msg_sect.iov_base = &sub->evt;
103432 msg_sect.iov_len = sizeof(struct tipc_event);
103433 sub->evt.event = htohl(event, sub->swap);
103434 sub->evt.found_lower = htohl(found_lower, sub->swap);
103435 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
103436 index bb7e8ba..9f444c6 100644
103437 --- a/net/unix/af_unix.c
103438 +++ b/net/unix/af_unix.c
103439 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
103440 err = -ECONNREFUSED;
103441 if (!S_ISSOCK(inode->i_mode))
103442 goto put_fail;
103443 +
103444 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
103445 + err = -EACCES;
103446 + goto put_fail;
103447 + }
103448 +
103449 u = unix_find_socket_byinode(inode);
103450 if (!u)
103451 goto put_fail;
103452 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
103453 if (u) {
103454 struct dentry *dentry;
103455 dentry = unix_sk(u)->path.dentry;
103456 +
103457 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
103458 + err = -EPERM;
103459 + sock_put(u);
103460 + goto fail;
103461 + }
103462 +
103463 if (dentry)
103464 touch_atime(&unix_sk(u)->path);
103465 } else
103466 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
103467 */
103468 err = security_path_mknod(&path, dentry, mode, 0);
103469 if (!err) {
103470 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
103471 + err = -EACCES;
103472 + goto out;
103473 + }
103474 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
103475 if (!err) {
103476 res->mnt = mntget(path.mnt);
103477 res->dentry = dget(dentry);
103478 + gr_handle_create(dentry, path.mnt);
103479 }
103480 }
103481 +out:
103482 done_path_create(&path, dentry);
103483 return err;
103484 }
103485 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103486 seq_puts(seq, "Num RefCount Protocol Flags Type St "
103487 "Inode Path\n");
103488 else {
103489 - struct sock *s = v;
103490 + struct sock *s = v, *peer;
103491 struct unix_sock *u = unix_sk(s);
103492 unix_state_lock(s);
103493 + peer = unix_peer(s);
103494 + unix_state_unlock(s);
103495 +
103496 + unix_state_double_lock(s, peer);
103497
103498 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
103499 s,
103500 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103501 }
103502 for ( ; i < len; i++)
103503 seq_putc(seq, u->addr->name->sun_path[i]);
103504 - }
103505 - unix_state_unlock(s);
103506 + } else if (peer)
103507 + seq_printf(seq, " P%lu", sock_i_ino(peer));
103508 +
103509 + unix_state_double_unlock(s, peer);
103510 seq_putc(seq, '\n');
103511 }
103512
103513 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
103514 index b3d5150..ff3a837 100644
103515 --- a/net/unix/sysctl_net_unix.c
103516 +++ b/net/unix/sysctl_net_unix.c
103517 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
103518
103519 int __net_init unix_sysctl_register(struct net *net)
103520 {
103521 - struct ctl_table *table;
103522 + ctl_table_no_const *table;
103523
103524 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
103525 if (table == NULL)
103526 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
103527 index 9b7f207..2596621 100644
103528 --- a/net/vmw_vsock/vmci_transport_notify.c
103529 +++ b/net/vmw_vsock/vmci_transport_notify.c
103530 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
103531
103532 /* Socket control packet based operations. */
103533 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
103534 - vmci_transport_notify_pkt_socket_init,
103535 - vmci_transport_notify_pkt_socket_destruct,
103536 - vmci_transport_notify_pkt_poll_in,
103537 - vmci_transport_notify_pkt_poll_out,
103538 - vmci_transport_notify_pkt_handle_pkt,
103539 - vmci_transport_notify_pkt_recv_init,
103540 - vmci_transport_notify_pkt_recv_pre_block,
103541 - vmci_transport_notify_pkt_recv_pre_dequeue,
103542 - vmci_transport_notify_pkt_recv_post_dequeue,
103543 - vmci_transport_notify_pkt_send_init,
103544 - vmci_transport_notify_pkt_send_pre_block,
103545 - vmci_transport_notify_pkt_send_pre_enqueue,
103546 - vmci_transport_notify_pkt_send_post_enqueue,
103547 - vmci_transport_notify_pkt_process_request,
103548 - vmci_transport_notify_pkt_process_negotiate,
103549 + .socket_init = vmci_transport_notify_pkt_socket_init,
103550 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103551 + .poll_in = vmci_transport_notify_pkt_poll_in,
103552 + .poll_out = vmci_transport_notify_pkt_poll_out,
103553 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103554 + .recv_init = vmci_transport_notify_pkt_recv_init,
103555 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103556 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103557 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103558 + .send_init = vmci_transport_notify_pkt_send_init,
103559 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103560 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103561 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103562 + .process_request = vmci_transport_notify_pkt_process_request,
103563 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103564 };
103565 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
103566 index dc9c792..3089de0 100644
103567 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
103568 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
103569 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
103570
103571 /* Socket always on control packet based operations. */
103572 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
103573 - vmci_transport_notify_pkt_socket_init,
103574 - vmci_transport_notify_pkt_socket_destruct,
103575 - vmci_transport_notify_pkt_poll_in,
103576 - vmci_transport_notify_pkt_poll_out,
103577 - vmci_transport_notify_pkt_handle_pkt,
103578 - vmci_transport_notify_pkt_recv_init,
103579 - vmci_transport_notify_pkt_recv_pre_block,
103580 - vmci_transport_notify_pkt_recv_pre_dequeue,
103581 - vmci_transport_notify_pkt_recv_post_dequeue,
103582 - vmci_transport_notify_pkt_send_init,
103583 - vmci_transport_notify_pkt_send_pre_block,
103584 - vmci_transport_notify_pkt_send_pre_enqueue,
103585 - vmci_transport_notify_pkt_send_post_enqueue,
103586 - vmci_transport_notify_pkt_process_request,
103587 - vmci_transport_notify_pkt_process_negotiate,
103588 + .socket_init = vmci_transport_notify_pkt_socket_init,
103589 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103590 + .poll_in = vmci_transport_notify_pkt_poll_in,
103591 + .poll_out = vmci_transport_notify_pkt_poll_out,
103592 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103593 + .recv_init = vmci_transport_notify_pkt_recv_init,
103594 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103595 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103596 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103597 + .send_init = vmci_transport_notify_pkt_send_init,
103598 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103599 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103600 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103601 + .process_request = vmci_transport_notify_pkt_process_request,
103602 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103603 };
103604 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
103605 index c8717c1..08539f5 100644
103606 --- a/net/wireless/wext-core.c
103607 +++ b/net/wireless/wext-core.c
103608 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103609 */
103610
103611 /* Support for very large requests */
103612 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
103613 - (user_length > descr->max_tokens)) {
103614 + if (user_length > descr->max_tokens) {
103615 /* Allow userspace to GET more than max so
103616 * we can support any size GET requests.
103617 * There is still a limit : -ENOMEM.
103618 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103619 }
103620 }
103621
103622 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
103623 - /*
103624 - * If this is a GET, but not NOMAX, it means that the extra
103625 - * data is not bounded by userspace, but by max_tokens. Thus
103626 - * set the length to max_tokens. This matches the extra data
103627 - * allocation.
103628 - * The driver should fill it with the number of tokens it
103629 - * provided, and it may check iwp->length rather than having
103630 - * knowledge of max_tokens. If the driver doesn't change the
103631 - * iwp->length, this ioctl just copies back max_token tokens
103632 - * filled with zeroes. Hopefully the driver isn't claiming
103633 - * them to be valid data.
103634 - */
103635 - iwp->length = descr->max_tokens;
103636 - }
103637 -
103638 err = handler(dev, info, (union iwreq_data *) iwp, extra);
103639
103640 iwp->length += essid_compat;
103641 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
103642 index 4323952..a06dfe1 100644
103643 --- a/net/x25/sysctl_net_x25.c
103644 +++ b/net/x25/sysctl_net_x25.c
103645 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
103646 .mode = 0644,
103647 .proc_handler = proc_dointvec,
103648 },
103649 - { 0, },
103650 + { },
103651 };
103652
103653 void __init x25_register_sysctl(void)
103654 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
103655 index 0917f04..f4e3d8c 100644
103656 --- a/net/x25/x25_proc.c
103657 +++ b/net/x25/x25_proc.c
103658 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
103659
103660 int __init x25_proc_init(void)
103661 {
103662 - if (!proc_mkdir("x25", init_net.proc_net))
103663 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
103664 return -ENOMEM;
103665
103666 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
103667 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
103668 index c08fbd1..3d99e85 100644
103669 --- a/net/xfrm/xfrm_policy.c
103670 +++ b/net/xfrm/xfrm_policy.c
103671 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
103672 {
103673 policy->walk.dead = 1;
103674
103675 - atomic_inc(&policy->genid);
103676 + atomic_inc_unchecked(&policy->genid);
103677
103678 if (del_timer(&policy->polq.hold_timer))
103679 xfrm_pol_put(policy);
103680 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
103681 hlist_add_head(&policy->bydst, chain);
103682 xfrm_pol_hold(policy);
103683 net->xfrm.policy_count[dir]++;
103684 - atomic_inc(&net->xfrm.flow_cache_genid);
103685 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
103686
103687 /* After previous checking, family can either be AF_INET or AF_INET6 */
103688 if (policy->family == AF_INET)
103689 @@ -1759,7 +1759,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
103690
103691 xdst->num_pols = num_pols;
103692 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
103693 - xdst->policy_genid = atomic_read(&pols[0]->genid);
103694 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
103695
103696 return xdst;
103697 }
103698 @@ -2546,10 +2546,11 @@ void xfrm_garbage_collect(struct net *net)
103699 }
103700 EXPORT_SYMBOL(xfrm_garbage_collect);
103701
103702 -static void xfrm_garbage_collect_deferred(struct net *net)
103703 +void xfrm_garbage_collect_deferred(struct net *net)
103704 {
103705 flow_cache_flush_deferred(net);
103706 }
103707 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
103708
103709 static void xfrm_init_pmtu(struct dst_entry *dst)
103710 {
103711 @@ -2599,7 +2600,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
103712 if (xdst->xfrm_genid != dst->xfrm->genid)
103713 return 0;
103714 if (xdst->num_pols > 0 &&
103715 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
103716 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
103717 return 0;
103718
103719 mtu = dst_mtu(dst->child);
103720 @@ -2687,8 +2688,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
103721 dst_ops->link_failure = xfrm_link_failure;
103722 if (likely(dst_ops->neigh_lookup == NULL))
103723 dst_ops->neigh_lookup = xfrm_neigh_lookup;
103724 - if (likely(afinfo->garbage_collect == NULL))
103725 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
103726 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
103727 }
103728 spin_unlock(&xfrm_policy_afinfo_lock);
103729 @@ -2742,7 +2741,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
103730 dst_ops->check = NULL;
103731 dst_ops->negative_advice = NULL;
103732 dst_ops->link_failure = NULL;
103733 - afinfo->garbage_collect = NULL;
103734 }
103735 return err;
103736 }
103737 @@ -3137,7 +3135,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
103738 sizeof(pol->xfrm_vec[i].saddr));
103739 pol->xfrm_vec[i].encap_family = mp->new_family;
103740 /* flush bundles */
103741 - atomic_inc(&pol->genid);
103742 + atomic_inc_unchecked(&pol->genid);
103743 }
103744 }
103745
103746 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
103747 index 8e9c781..3972135 100644
103748 --- a/net/xfrm/xfrm_state.c
103749 +++ b/net/xfrm/xfrm_state.c
103750 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
103751
103752 if (unlikely(afinfo == NULL))
103753 return -EAFNOSUPPORT;
103754 - typemap = afinfo->type_map;
103755 + typemap = (const struct xfrm_type **)afinfo->type_map;
103756 spin_lock_bh(&xfrm_type_lock);
103757
103758 - if (likely(typemap[type->proto] == NULL))
103759 + if (likely(typemap[type->proto] == NULL)) {
103760 + pax_open_kernel();
103761 typemap[type->proto] = type;
103762 - else
103763 + pax_close_kernel();
103764 + } else
103765 err = -EEXIST;
103766 spin_unlock_bh(&xfrm_type_lock);
103767 xfrm_state_put_afinfo(afinfo);
103768 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
103769
103770 if (unlikely(afinfo == NULL))
103771 return -EAFNOSUPPORT;
103772 - typemap = afinfo->type_map;
103773 + typemap = (const struct xfrm_type **)afinfo->type_map;
103774 spin_lock_bh(&xfrm_type_lock);
103775
103776 if (unlikely(typemap[type->proto] != type))
103777 err = -ENOENT;
103778 - else
103779 + else {
103780 + pax_open_kernel();
103781 typemap[type->proto] = NULL;
103782 + pax_close_kernel();
103783 + }
103784 spin_unlock_bh(&xfrm_type_lock);
103785 xfrm_state_put_afinfo(afinfo);
103786 return err;
103787 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
103788 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
103789 {
103790 struct xfrm_state_afinfo *afinfo;
103791 - const struct xfrm_type **typemap;
103792 const struct xfrm_type *type;
103793 int modload_attempted = 0;
103794
103795 @@ -218,9 +222,8 @@ retry:
103796 afinfo = xfrm_state_get_afinfo(family);
103797 if (unlikely(afinfo == NULL))
103798 return NULL;
103799 - typemap = afinfo->type_map;
103800
103801 - type = typemap[proto];
103802 + type = afinfo->type_map[proto];
103803 if (unlikely(type && !try_module_get(type->owner)))
103804 type = NULL;
103805 if (!type && !modload_attempted) {
103806 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
103807 return -EAFNOSUPPORT;
103808
103809 err = -EEXIST;
103810 - modemap = afinfo->mode_map;
103811 + modemap = (struct xfrm_mode **)afinfo->mode_map;
103812 spin_lock_bh(&xfrm_mode_lock);
103813 if (modemap[mode->encap])
103814 goto out;
103815 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
103816 if (!try_module_get(afinfo->owner))
103817 goto out;
103818
103819 - mode->afinfo = afinfo;
103820 + pax_open_kernel();
103821 + *(const void **)&mode->afinfo = afinfo;
103822 modemap[mode->encap] = mode;
103823 + pax_close_kernel();
103824 err = 0;
103825
103826 out:
103827 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
103828 return -EAFNOSUPPORT;
103829
103830 err = -ENOENT;
103831 - modemap = afinfo->mode_map;
103832 + modemap = (struct xfrm_mode **)afinfo->mode_map;
103833 spin_lock_bh(&xfrm_mode_lock);
103834 if (likely(modemap[mode->encap] == mode)) {
103835 + pax_open_kernel();
103836 modemap[mode->encap] = NULL;
103837 + pax_close_kernel();
103838 module_put(mode->afinfo->owner);
103839 err = 0;
103840 }
103841 @@ -1519,10 +1526,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
103842 u32 xfrm_get_acqseq(void)
103843 {
103844 u32 res;
103845 - static atomic_t acqseq;
103846 + static atomic_unchecked_t acqseq;
103847
103848 do {
103849 - res = atomic_inc_return(&acqseq);
103850 + res = atomic_inc_return_unchecked(&acqseq);
103851 } while (!res);
103852
103853 return res;
103854 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
103855 index 05a6e3d..6716ec9 100644
103856 --- a/net/xfrm/xfrm_sysctl.c
103857 +++ b/net/xfrm/xfrm_sysctl.c
103858 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
103859
103860 int __net_init xfrm_sysctl_init(struct net *net)
103861 {
103862 - struct ctl_table *table;
103863 + ctl_table_no_const *table;
103864
103865 __xfrm_sysctl_init(net);
103866
103867 diff --git a/scripts/Makefile b/scripts/Makefile
103868 index 1d07860..f16fc22 100644
103869 --- a/scripts/Makefile
103870 +++ b/scripts/Makefile
103871 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
103872
103873 # Let clean descend into subdirs
103874 subdir- += basic kconfig package selinux
103875 +
103876 +clean-files := randstruct.seed
103877 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
103878 index 003bc26..d5f02b0 100644
103879 --- a/scripts/Makefile.build
103880 +++ b/scripts/Makefile.build
103881 @@ -121,7 +121,7 @@ endif
103882 endif
103883
103884 # Do not include host rules unless needed
103885 -ifneq ($(hostprogs-y)$(hostprogs-m),)
103886 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
103887 include scripts/Makefile.host
103888 endif
103889
103890 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
103891 index 686cb0d..9d653bf 100644
103892 --- a/scripts/Makefile.clean
103893 +++ b/scripts/Makefile.clean
103894 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
103895 __clean-files := $(extra-y) $(always) \
103896 $(targets) $(clean-files) \
103897 $(host-progs) \
103898 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
103899 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
103900 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
103901
103902 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
103903
103904 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
103905 index 1ac414f..38575f7 100644
103906 --- a/scripts/Makefile.host
103907 +++ b/scripts/Makefile.host
103908 @@ -31,6 +31,8 @@
103909 # Note: Shared libraries consisting of C++ files are not supported
103910
103911 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
103912 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
103913 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
103914
103915 # C code
103916 # Executables compiled from a single .c file
103917 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
103918 # Shared libaries (only .c supported)
103919 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
103920 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
103921 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
103922 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
103923 # Remove .so files from "xxx-objs"
103924 host-cobjs := $(filter-out %.so,$(host-cobjs))
103925 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
103926
103927 -#Object (.o) files used by the shared libaries
103928 +# Object (.o) files used by the shared libaries
103929 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
103930 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
103931
103932 # output directory for programs/.o files
103933 # hostprogs-y := tools/build may have been specified. Retrieve directory
103934 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
103935 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
103936 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
103937 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
103938 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
103939 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
103940 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
103941 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
103942
103943 obj-dirs += $(host-objdirs)
103944 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
103945 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
103946 $(call if_changed_dep,host-cshobjs)
103947
103948 +# Compile .c file, create position independent .o file
103949 +# host-cxxshobjs -> .o
103950 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
103951 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
103952 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
103953 + $(call if_changed_dep,host-cxxshobjs)
103954 +
103955 # Link a shared library, based on position independent .o files
103956 # *.o -> .so shared library (host-cshlib)
103957 quiet_cmd_host-cshlib = HOSTLLD -shared $@
103958 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
103959 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
103960 $(call if_changed,host-cshlib)
103961
103962 +# Link a shared library, based on position independent .o files
103963 +# *.o -> .so shared library (host-cxxshlib)
103964 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
103965 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
103966 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
103967 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
103968 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
103969 + $(call if_changed,host-cxxshlib)
103970 +
103971 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
103972 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
103973 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
103974
103975 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
103976 index 078fe1d..fbdb363 100644
103977 --- a/scripts/basic/fixdep.c
103978 +++ b/scripts/basic/fixdep.c
103979 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
103980 /*
103981 * Lookup a value in the configuration string.
103982 */
103983 -static int is_defined_config(const char *name, int len, unsigned int hash)
103984 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
103985 {
103986 struct item *aux;
103987
103988 @@ -211,10 +211,10 @@ static void clear_config(void)
103989 /*
103990 * Record the use of a CONFIG_* word.
103991 */
103992 -static void use_config(const char *m, int slen)
103993 +static void use_config(const char *m, unsigned int slen)
103994 {
103995 unsigned int hash = strhash(m, slen);
103996 - int c, i;
103997 + unsigned int c, i;
103998
103999 if (is_defined_config(m, slen, hash))
104000 return;
104001 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
104002
104003 static void parse_config_file(const char *map, size_t len)
104004 {
104005 - const int *end = (const int *) (map + len);
104006 + const unsigned int *end = (const unsigned int *) (map + len);
104007 /* start at +1, so that p can never be < map */
104008 - const int *m = (const int *) map + 1;
104009 + const unsigned int *m = (const unsigned int *) map + 1;
104010 const char *p, *q;
104011
104012 for (; m < end; m++) {
104013 @@ -435,7 +435,7 @@ static void print_deps(void)
104014 static void traps(void)
104015 {
104016 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
104017 - int *p = (int *)test;
104018 + unsigned int *p = (unsigned int *)test;
104019
104020 if (*p != INT_CONF) {
104021 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
104022 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
104023 new file mode 100644
104024 index 0000000..3fd3699
104025 --- /dev/null
104026 +++ b/scripts/gcc-plugin.sh
104027 @@ -0,0 +1,43 @@
104028 +#!/bin/bash
104029 +srctree=$(dirname "$0")
104030 +gccplugins_dir=$($3 -print-file-name=plugin)
104031 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104032 +#include "gcc-common.h"
104033 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
104034 +#warning $2 CXX
104035 +#else
104036 +#warning $1 CC
104037 +#endif
104038 +EOF
104039 +)
104040 +
104041 +if [ $? -ne 0 ]
104042 +then
104043 + exit 1
104044 +fi
104045 +
104046 +if [[ "$plugincc" =~ "$1 CC" ]]
104047 +then
104048 + echo "$1"
104049 + exit 0
104050 +fi
104051 +
104052 +if [[ "$plugincc" =~ "$2 CXX" ]]
104053 +then
104054 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104055 +#include "gcc-common.h"
104056 +class test {
104057 +public:
104058 + int test;
104059 +} test = {
104060 + .test = 1
104061 +};
104062 +EOF
104063 +)
104064 +if [ $? -eq 0 ]
104065 +then
104066 + echo "$2"
104067 + exit 0
104068 +fi
104069 +fi
104070 +exit 1
104071 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
104072 index 5de5660..d3deb89 100644
104073 --- a/scripts/headers_install.sh
104074 +++ b/scripts/headers_install.sh
104075 @@ -32,6 +32,7 @@ do
104076 FILE="$(basename "$i")"
104077 sed -r \
104078 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
104079 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
104080 -e 's/__attribute_const__([ \t]|$)/\1/g' \
104081 -e 's@^#include <linux/compiler.h>@@' \
104082 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
104083 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
104084 index 86a4fe7..99e91f9 100644
104085 --- a/scripts/link-vmlinux.sh
104086 +++ b/scripts/link-vmlinux.sh
104087 @@ -166,7 +166,7 @@ else
104088 fi;
104089
104090 # final build of init/
104091 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
104092 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
104093
104094 kallsymso=""
104095 kallsyms_vmlinux=""
104096 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
104097 index 1924990..3de7363 100644
104098 --- a/scripts/mod/file2alias.c
104099 +++ b/scripts/mod/file2alias.c
104100 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
104101 unsigned long size, unsigned long id_size,
104102 void *symval)
104103 {
104104 - int i;
104105 + unsigned int i;
104106
104107 if (size % id_size || size < id_size) {
104108 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
104109 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
104110 /* USB is special because the bcdDevice can be matched against a numeric range */
104111 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
104112 static void do_usb_entry(void *symval,
104113 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
104114 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
104115 unsigned char range_lo, unsigned char range_hi,
104116 unsigned char max, struct module *mod)
104117 {
104118 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
104119 {
104120 unsigned int devlo, devhi;
104121 unsigned char chi, clo, max;
104122 - int ndigits;
104123 + unsigned int ndigits;
104124
104125 DEF_FIELD(symval, usb_device_id, match_flags);
104126 DEF_FIELD(symval, usb_device_id, idVendor);
104127 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
104128 for (i = 0; i < count; i++) {
104129 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
104130 char acpi_id[sizeof(*id)];
104131 - int j;
104132 + unsigned int j;
104133
104134 buf_printf(&mod->dev_table_buf,
104135 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
104136 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104137
104138 for (j = 0; j < PNP_MAX_DEVICES; j++) {
104139 const char *id = (char *)(*devs)[j].id;
104140 - int i2, j2;
104141 + unsigned int i2, j2;
104142 int dup = 0;
104143
104144 if (!id[0])
104145 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104146 /* add an individual alias for every device entry */
104147 if (!dup) {
104148 char acpi_id[PNP_ID_LEN];
104149 - int k;
104150 + unsigned int k;
104151
104152 buf_printf(&mod->dev_table_buf,
104153 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
104154 @@ -941,7 +941,7 @@ static void dmi_ascii_filter(char *d, const char *s)
104155 static int do_dmi_entry(const char *filename, void *symval,
104156 char *alias)
104157 {
104158 - int i, j;
104159 + unsigned int i, j;
104160 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
104161 sprintf(alias, "dmi*");
104162
104163 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
104164 index 0663556..d9494f0 100644
104165 --- a/scripts/mod/modpost.c
104166 +++ b/scripts/mod/modpost.c
104167 @@ -949,6 +949,7 @@ enum mismatch {
104168 ANY_INIT_TO_ANY_EXIT,
104169 ANY_EXIT_TO_ANY_INIT,
104170 EXPORT_TO_INIT_EXIT,
104171 + DATA_TO_TEXT
104172 };
104173
104174 struct sectioncheck {
104175 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
104176 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
104177 .mismatch = EXPORT_TO_INIT_EXIT,
104178 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
104179 +},
104180 +/* Do not reference code from writable data */
104181 +{
104182 + .fromsec = { DATA_SECTIONS, NULL },
104183 + .tosec = { TEXT_SECTIONS, NULL },
104184 + .mismatch = DATA_TO_TEXT
104185 }
104186 };
104187
104188 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
104189 continue;
104190 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
104191 continue;
104192 - if (sym->st_value == addr)
104193 - return sym;
104194 /* Find a symbol nearby - addr are maybe negative */
104195 d = sym->st_value - addr;
104196 + if (d == 0)
104197 + return sym;
104198 if (d < 0)
104199 d = addr - sym->st_value;
104200 if (d < distance) {
104201 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
104202 tosym, prl_to, prl_to, tosym);
104203 free(prl_to);
104204 break;
104205 + case DATA_TO_TEXT:
104206 +#if 0
104207 + fprintf(stderr,
104208 + "The %s %s:%s references\n"
104209 + "the %s %s:%s%s\n",
104210 + from, fromsec, fromsym, to, tosec, tosym, to_p);
104211 +#endif
104212 + break;
104213 }
104214 fprintf(stderr, "\n");
104215 }
104216 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
104217 static void check_sec_ref(struct module *mod, const char *modname,
104218 struct elf_info *elf)
104219 {
104220 - int i;
104221 + unsigned int i;
104222 Elf_Shdr *sechdrs = elf->sechdrs;
104223
104224 /* Walk through all sections */
104225 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
104226 va_end(ap);
104227 }
104228
104229 -void buf_write(struct buffer *buf, const char *s, int len)
104230 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
104231 {
104232 if (buf->size - buf->pos < len) {
104233 buf->size += len + SZ;
104234 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
104235 if (fstat(fileno(file), &st) < 0)
104236 goto close_write;
104237
104238 - if (st.st_size != b->pos)
104239 + if (st.st_size != (off_t)b->pos)
104240 goto close_write;
104241
104242 tmp = NOFAIL(malloc(b->pos));
104243 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
104244 index 168b43d..77914bf 100644
104245 --- a/scripts/mod/modpost.h
104246 +++ b/scripts/mod/modpost.h
104247 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
104248
104249 struct buffer {
104250 char *p;
104251 - int pos;
104252 - int size;
104253 + unsigned int pos;
104254 + unsigned int size;
104255 };
104256
104257 void __attribute__((format(printf, 2, 3)))
104258 buf_printf(struct buffer *buf, const char *fmt, ...);
104259
104260 void
104261 -buf_write(struct buffer *buf, const char *s, int len);
104262 +buf_write(struct buffer *buf, const char *s, unsigned int len);
104263
104264 struct module {
104265 struct module *next;
104266 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
104267 index deb2994..af4f63e 100644
104268 --- a/scripts/mod/sumversion.c
104269 +++ b/scripts/mod/sumversion.c
104270 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
104271 goto out;
104272 }
104273
104274 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
104275 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
104276 warn("writing sum in %s failed: %s\n",
104277 filename, strerror(errno));
104278 goto out;
104279 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
104280 index 0865b3e..7235dd4 100644
104281 --- a/scripts/module-common.lds
104282 +++ b/scripts/module-common.lds
104283 @@ -6,6 +6,10 @@
104284 SECTIONS {
104285 /DISCARD/ : { *(.discard) }
104286
104287 + .rodata : {
104288 + *(.rodata) *(.rodata.*)
104289 + *(.data..read_only)
104290 + }
104291 __ksymtab : { *(SORT(___ksymtab+*)) }
104292 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104293 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104294 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104295 index 152d4d2..791684c 100644
104296 --- a/scripts/package/builddeb
104297 +++ b/scripts/package/builddeb
104298 @@ -291,6 +291,7 @@ fi
104299 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104300 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104301 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104302 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104303 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104304 mkdir -p "$destdir"
104305 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104306 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104307 index 68bb4ef..2f419e1 100644
104308 --- a/scripts/pnmtologo.c
104309 +++ b/scripts/pnmtologo.c
104310 @@ -244,14 +244,14 @@ static void write_header(void)
104311 fprintf(out, " * Linux logo %s\n", logoname);
104312 fputs(" */\n\n", out);
104313 fputs("#include <linux/linux_logo.h>\n\n", out);
104314 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104315 + fprintf(out, "static unsigned char %s_data[] = {\n",
104316 logoname);
104317 }
104318
104319 static void write_footer(void)
104320 {
104321 fputs("\n};\n\n", out);
104322 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104323 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104324 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104325 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104326 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104327 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104328 fputs("\n};\n\n", out);
104329
104330 /* write logo clut */
104331 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104332 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104333 logoname);
104334 write_hex_cnt = 0;
104335 for (i = 0; i < logo_clutsize; i++) {
104336 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104337 index 8fac3fd..32ff38d 100644
104338 --- a/scripts/sortextable.h
104339 +++ b/scripts/sortextable.h
104340 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104341 const char *secstrtab;
104342 const char *strtab;
104343 char *extab_image;
104344 - int extab_index = 0;
104345 - int i;
104346 - int idx;
104347 + unsigned int extab_index = 0;
104348 + unsigned int i;
104349 + unsigned int idx;
104350 unsigned int num_sections;
104351 unsigned int secindex_strings;
104352
104353 diff --git a/security/Kconfig b/security/Kconfig
104354 index beb86b5..40b1edb 100644
104355 --- a/security/Kconfig
104356 +++ b/security/Kconfig
104357 @@ -4,6 +4,957 @@
104358
104359 menu "Security options"
104360
104361 +menu "Grsecurity"
104362 +
104363 + config ARCH_TRACK_EXEC_LIMIT
104364 + bool
104365 +
104366 + config PAX_KERNEXEC_PLUGIN
104367 + bool
104368 +
104369 + config PAX_PER_CPU_PGD
104370 + bool
104371 +
104372 + config TASK_SIZE_MAX_SHIFT
104373 + int
104374 + depends on X86_64
104375 + default 47 if !PAX_PER_CPU_PGD
104376 + default 42 if PAX_PER_CPU_PGD
104377 +
104378 + config PAX_ENABLE_PAE
104379 + bool
104380 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
104381 +
104382 + config PAX_USERCOPY_SLABS
104383 + bool
104384 +
104385 +config GRKERNSEC
104386 + bool "Grsecurity"
104387 + select CRYPTO
104388 + select CRYPTO_SHA256
104389 + select PROC_FS
104390 + select STOP_MACHINE
104391 + select TTY
104392 + select DEBUG_KERNEL
104393 + select DEBUG_LIST
104394 + help
104395 + If you say Y here, you will be able to configure many features
104396 + that will enhance the security of your system. It is highly
104397 + recommended that you say Y here and read through the help
104398 + for each option so that you fully understand the features and
104399 + can evaluate their usefulness for your machine.
104400 +
104401 +choice
104402 + prompt "Configuration Method"
104403 + depends on GRKERNSEC
104404 + default GRKERNSEC_CONFIG_CUSTOM
104405 + help
104406 +
104407 +config GRKERNSEC_CONFIG_AUTO
104408 + bool "Automatic"
104409 + help
104410 + If you choose this configuration method, you'll be able to answer a small
104411 + number of simple questions about how you plan to use this kernel.
104412 + The settings of grsecurity and PaX will be automatically configured for
104413 + the highest commonly-used settings within the provided constraints.
104414 +
104415 + If you require additional configuration, custom changes can still be made
104416 + from the "custom configuration" menu.
104417 +
104418 +config GRKERNSEC_CONFIG_CUSTOM
104419 + bool "Custom"
104420 + help
104421 + If you choose this configuration method, you'll be able to configure all
104422 + grsecurity and PaX settings manually. Via this method, no options are
104423 + automatically enabled.
104424 +
104425 +endchoice
104426 +
104427 +choice
104428 + prompt "Usage Type"
104429 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104430 + default GRKERNSEC_CONFIG_SERVER
104431 + help
104432 +
104433 +config GRKERNSEC_CONFIG_SERVER
104434 + bool "Server"
104435 + help
104436 + Choose this option if you plan to use this kernel on a server.
104437 +
104438 +config GRKERNSEC_CONFIG_DESKTOP
104439 + bool "Desktop"
104440 + help
104441 + Choose this option if you plan to use this kernel on a desktop.
104442 +
104443 +endchoice
104444 +
104445 +choice
104446 + prompt "Virtualization Type"
104447 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
104448 + default GRKERNSEC_CONFIG_VIRT_NONE
104449 + help
104450 +
104451 +config GRKERNSEC_CONFIG_VIRT_NONE
104452 + bool "None"
104453 + help
104454 + Choose this option if this kernel will be run on bare metal.
104455 +
104456 +config GRKERNSEC_CONFIG_VIRT_GUEST
104457 + bool "Guest"
104458 + help
104459 + Choose this option if this kernel will be run as a VM guest.
104460 +
104461 +config GRKERNSEC_CONFIG_VIRT_HOST
104462 + bool "Host"
104463 + help
104464 + Choose this option if this kernel will be run as a VM host.
104465 +
104466 +endchoice
104467 +
104468 +choice
104469 + prompt "Virtualization Hardware"
104470 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104471 + help
104472 +
104473 +config GRKERNSEC_CONFIG_VIRT_EPT
104474 + bool "EPT/RVI Processor Support"
104475 + depends on X86
104476 + help
104477 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
104478 + hardware virtualization. This allows for additional kernel hardening protections
104479 + to operate without additional performance impact.
104480 +
104481 + To see if your Intel processor supports EPT, see:
104482 + http://ark.intel.com/Products/VirtualizationTechnology
104483 + (Most Core i3/5/7 support EPT)
104484 +
104485 + To see if your AMD processor supports RVI, see:
104486 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
104487 +
104488 +config GRKERNSEC_CONFIG_VIRT_SOFT
104489 + bool "First-gen/No Hardware Virtualization"
104490 + help
104491 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
104492 + support hardware virtualization or doesn't support the EPT/RVI extensions.
104493 +
104494 +endchoice
104495 +
104496 +choice
104497 + prompt "Virtualization Software"
104498 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104499 + help
104500 +
104501 +config GRKERNSEC_CONFIG_VIRT_XEN
104502 + bool "Xen"
104503 + help
104504 + Choose this option if this kernel is running as a Xen guest or host.
104505 +
104506 +config GRKERNSEC_CONFIG_VIRT_VMWARE
104507 + bool "VMWare"
104508 + help
104509 + Choose this option if this kernel is running as a VMWare guest or host.
104510 +
104511 +config GRKERNSEC_CONFIG_VIRT_KVM
104512 + bool "KVM"
104513 + help
104514 + Choose this option if this kernel is running as a KVM guest or host.
104515 +
104516 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
104517 + bool "VirtualBox"
104518 + help
104519 + Choose this option if this kernel is running as a VirtualBox guest or host.
104520 +
104521 +endchoice
104522 +
104523 +choice
104524 + prompt "Required Priorities"
104525 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104526 + default GRKERNSEC_CONFIG_PRIORITY_PERF
104527 + help
104528 +
104529 +config GRKERNSEC_CONFIG_PRIORITY_PERF
104530 + bool "Performance"
104531 + help
104532 + Choose this option if performance is of highest priority for this deployment
104533 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
104534 + clearing of structures intended for userland, and freed memory sanitizing will
104535 + be disabled.
104536 +
104537 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
104538 + bool "Security"
104539 + help
104540 + Choose this option if security is of highest priority for this deployment of
104541 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
104542 + for userland, and freed memory sanitizing will be enabled for this kernel.
104543 + In a worst-case scenario, these features can introduce a 20% performance hit
104544 + (UDEREF on x64 contributing half of this hit).
104545 +
104546 +endchoice
104547 +
104548 +menu "Default Special Groups"
104549 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104550 +
104551 +config GRKERNSEC_PROC_GID
104552 + int "GID exempted from /proc restrictions"
104553 + default 1001
104554 + help
104555 + Setting this GID determines which group will be exempted from
104556 + grsecurity's /proc restrictions, allowing users of the specified
104557 + group to view network statistics and the existence of other users'
104558 + processes on the system. This GID may also be chosen at boot time
104559 + via "grsec_proc_gid=" on the kernel commandline.
104560 +
104561 +config GRKERNSEC_TPE_UNTRUSTED_GID
104562 + int "GID for TPE-untrusted users"
104563 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
104564 + default 1005
104565 + help
104566 + Setting this GID determines which group untrusted users should
104567 + be added to. These users will be placed under grsecurity's Trusted Path
104568 + Execution mechanism, preventing them from executing their own binaries.
104569 + The users will only be able to execute binaries in directories owned and
104570 + writable only by the root user. If the sysctl option is enabled, a sysctl
104571 + option with name "tpe_gid" is created.
104572 +
104573 +config GRKERNSEC_TPE_TRUSTED_GID
104574 + int "GID for TPE-trusted users"
104575 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
104576 + default 1005
104577 + help
104578 + Setting this GID determines what group TPE restrictions will be
104579 + *disabled* for. If the sysctl option is enabled, a sysctl option
104580 + with name "tpe_gid" is created.
104581 +
104582 +config GRKERNSEC_SYMLINKOWN_GID
104583 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
104584 + depends on GRKERNSEC_CONFIG_SERVER
104585 + default 1006
104586 + help
104587 + Setting this GID determines what group kernel-enforced
104588 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
104589 + is enabled, a sysctl option with name "symlinkown_gid" is created.
104590 +
104591 +
104592 +endmenu
104593 +
104594 +menu "Customize Configuration"
104595 +depends on GRKERNSEC
104596 +
104597 +menu "PaX"
104598 +
104599 +config PAX
104600 + bool "Enable various PaX features"
104601 + default y if GRKERNSEC_CONFIG_AUTO
104602 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
104603 + help
104604 + This allows you to enable various PaX features. PaX adds
104605 + intrusion prevention mechanisms to the kernel that reduce
104606 + the risks posed by exploitable memory corruption bugs.
104607 +
104608 +menu "PaX Control"
104609 + depends on PAX
104610 +
104611 +config PAX_SOFTMODE
104612 + bool 'Support soft mode'
104613 + help
104614 + Enabling this option will allow you to run PaX in soft mode, that
104615 + is, PaX features will not be enforced by default, only on executables
104616 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
104617 + support as they are the only way to mark executables for soft mode use.
104618 +
104619 + Soft mode can be activated by using the "pax_softmode=1" kernel command
104620 + line option on boot. Furthermore you can control various PaX features
104621 + at runtime via the entries in /proc/sys/kernel/pax.
104622 +
104623 +config PAX_EI_PAX
104624 + bool 'Use legacy ELF header marking'
104625 + default y if GRKERNSEC_CONFIG_AUTO
104626 + help
104627 + Enabling this option will allow you to control PaX features on
104628 + a per executable basis via the 'chpax' utility available at
104629 + http://pax.grsecurity.net/. The control flags will be read from
104630 + an otherwise reserved part of the ELF header. This marking has
104631 + numerous drawbacks (no support for soft-mode, toolchain does not
104632 + know about the non-standard use of the ELF header) therefore it
104633 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
104634 + support.
104635 +
104636 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
104637 + support as well, they will override the legacy EI_PAX marks.
104638 +
104639 + If you enable none of the marking options then all applications
104640 + will run with PaX enabled on them by default.
104641 +
104642 +config PAX_PT_PAX_FLAGS
104643 + bool 'Use ELF program header marking'
104644 + default y if GRKERNSEC_CONFIG_AUTO
104645 + help
104646 + Enabling this option will allow you to control PaX features on
104647 + a per executable basis via the 'paxctl' utility available at
104648 + http://pax.grsecurity.net/. The control flags will be read from
104649 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
104650 + has the benefits of supporting both soft mode and being fully
104651 + integrated into the toolchain (the binutils patch is available
104652 + from http://pax.grsecurity.net).
104653 +
104654 + Note that if you enable the legacy EI_PAX marking support as well,
104655 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
104656 +
104657 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104658 + must make sure that the marks are the same if a binary has both marks.
104659 +
104660 + If you enable none of the marking options then all applications
104661 + will run with PaX enabled on them by default.
104662 +
104663 +config PAX_XATTR_PAX_FLAGS
104664 + bool 'Use filesystem extended attributes marking'
104665 + default y if GRKERNSEC_CONFIG_AUTO
104666 + select CIFS_XATTR if CIFS
104667 + select F2FS_FS_XATTR if F2FS_FS
104668 + select EXT2_FS_XATTR if EXT2_FS
104669 + select EXT3_FS_XATTR if EXT3_FS
104670 + select JFFS2_FS_XATTR if JFFS2_FS
104671 + select REISERFS_FS_XATTR if REISERFS_FS
104672 + select SQUASHFS_XATTR if SQUASHFS
104673 + select TMPFS_XATTR if TMPFS
104674 + help
104675 + Enabling this option will allow you to control PaX features on
104676 + a per executable basis via the 'setfattr' utility. The control
104677 + flags will be read from the user.pax.flags extended attribute of
104678 + the file. This marking has the benefit of supporting binary-only
104679 + applications that self-check themselves (e.g., skype) and would
104680 + not tolerate chpax/paxctl changes. The main drawback is that
104681 + extended attributes are not supported by some filesystems (e.g.,
104682 + isofs, udf, vfat) so copying files through such filesystems will
104683 + lose the extended attributes and these PaX markings.
104684 +
104685 + Note that if you enable the legacy EI_PAX marking support as well,
104686 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
104687 +
104688 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104689 + must make sure that the marks are the same if a binary has both marks.
104690 +
104691 + If you enable none of the marking options then all applications
104692 + will run with PaX enabled on them by default.
104693 +
104694 +choice
104695 + prompt 'MAC system integration'
104696 + default PAX_HAVE_ACL_FLAGS
104697 + help
104698 + Mandatory Access Control systems have the option of controlling
104699 + PaX flags on a per executable basis, choose the method supported
104700 + by your particular system.
104701 +
104702 + - "none": if your MAC system does not interact with PaX,
104703 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
104704 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
104705 +
104706 + NOTE: this option is for developers/integrators only.
104707 +
104708 + config PAX_NO_ACL_FLAGS
104709 + bool 'none'
104710 +
104711 + config PAX_HAVE_ACL_FLAGS
104712 + bool 'direct'
104713 +
104714 + config PAX_HOOK_ACL_FLAGS
104715 + bool 'hook'
104716 +endchoice
104717 +
104718 +endmenu
104719 +
104720 +menu "Non-executable pages"
104721 + depends on PAX
104722 +
104723 +config PAX_NOEXEC
104724 + bool "Enforce non-executable pages"
104725 + default y if GRKERNSEC_CONFIG_AUTO
104726 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
104727 + help
104728 + By design some architectures do not allow for protecting memory
104729 + pages against execution or even if they do, Linux does not make
104730 + use of this feature. In practice this means that if a page is
104731 + readable (such as the stack or heap) it is also executable.
104732 +
104733 + There is a well known exploit technique that makes use of this
104734 + fact and a common programming mistake where an attacker can
104735 + introduce code of his choice somewhere in the attacked program's
104736 + memory (typically the stack or the heap) and then execute it.
104737 +
104738 + If the attacked program was running with different (typically
104739 + higher) privileges than that of the attacker, then he can elevate
104740 + his own privilege level (e.g. get a root shell, write to files for
104741 + which he does not have write access to, etc).
104742 +
104743 + Enabling this option will let you choose from various features
104744 + that prevent the injection and execution of 'foreign' code in
104745 + a program.
104746 +
104747 + This will also break programs that rely on the old behaviour and
104748 + expect that dynamically allocated memory via the malloc() family
104749 + of functions is executable (which it is not). Notable examples
104750 + are the XFree86 4.x server, the java runtime and wine.
104751 +
104752 +config PAX_PAGEEXEC
104753 + bool "Paging based non-executable pages"
104754 + default y if GRKERNSEC_CONFIG_AUTO
104755 + 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)
104756 + select ARCH_TRACK_EXEC_LIMIT if X86_32
104757 + help
104758 + This implementation is based on the paging feature of the CPU.
104759 + On i386 without hardware non-executable bit support there is a
104760 + variable but usually low performance impact, however on Intel's
104761 + P4 core based CPUs it is very high so you should not enable this
104762 + for kernels meant to be used on such CPUs.
104763 +
104764 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
104765 + with hardware non-executable bit support there is no performance
104766 + impact, on ppc the impact is negligible.
104767 +
104768 + Note that several architectures require various emulations due to
104769 + badly designed userland ABIs, this will cause a performance impact
104770 + but will disappear as soon as userland is fixed. For example, ppc
104771 + userland MUST have been built with secure-plt by a recent toolchain.
104772 +
104773 +config PAX_SEGMEXEC
104774 + bool "Segmentation based non-executable pages"
104775 + default y if GRKERNSEC_CONFIG_AUTO
104776 + depends on PAX_NOEXEC && X86_32
104777 + help
104778 + This implementation is based on the segmentation feature of the
104779 + CPU and has a very small performance impact, however applications
104780 + will be limited to a 1.5 GB address space instead of the normal
104781 + 3 GB.
104782 +
104783 +config PAX_EMUTRAMP
104784 + bool "Emulate trampolines"
104785 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
104786 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
104787 + help
104788 + There are some programs and libraries that for one reason or
104789 + another attempt to execute special small code snippets from
104790 + non-executable memory pages. Most notable examples are the
104791 + signal handler return code generated by the kernel itself and
104792 + the GCC trampolines.
104793 +
104794 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
104795 + such programs will no longer work under your kernel.
104796 +
104797 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
104798 + utilities to enable trampoline emulation for the affected programs
104799 + yet still have the protection provided by the non-executable pages.
104800 +
104801 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
104802 + your system will not even boot.
104803 +
104804 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
104805 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
104806 + for the affected files.
104807 +
104808 + NOTE: enabling this feature *may* open up a loophole in the
104809 + protection provided by non-executable pages that an attacker
104810 + could abuse. Therefore the best solution is to not have any
104811 + files on your system that would require this option. This can
104812 + be achieved by not using libc5 (which relies on the kernel
104813 + signal handler return code) and not using or rewriting programs
104814 + that make use of the nested function implementation of GCC.
104815 + Skilled users can just fix GCC itself so that it implements
104816 + nested function calls in a way that does not interfere with PaX.
104817 +
104818 +config PAX_EMUSIGRT
104819 + bool "Automatically emulate sigreturn trampolines"
104820 + depends on PAX_EMUTRAMP && PARISC
104821 + default y
104822 + help
104823 + Enabling this option will have the kernel automatically detect
104824 + and emulate signal return trampolines executing on the stack
104825 + that would otherwise lead to task termination.
104826 +
104827 + This solution is intended as a temporary one for users with
104828 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
104829 + Modula-3 runtime, etc) or executables linked to such, basically
104830 + everything that does not specify its own SA_RESTORER function in
104831 + normal executable memory like glibc 2.1+ does.
104832 +
104833 + On parisc you MUST enable this option, otherwise your system will
104834 + not even boot.
104835 +
104836 + NOTE: this feature cannot be disabled on a per executable basis
104837 + and since it *does* open up a loophole in the protection provided
104838 + by non-executable pages, the best solution is to not have any
104839 + files on your system that would require this option.
104840 +
104841 +config PAX_MPROTECT
104842 + bool "Restrict mprotect()"
104843 + default y if GRKERNSEC_CONFIG_AUTO
104844 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
104845 + help
104846 + Enabling this option will prevent programs from
104847 + - changing the executable status of memory pages that were
104848 + not originally created as executable,
104849 + - making read-only executable pages writable again,
104850 + - creating executable pages from anonymous memory,
104851 + - making read-only-after-relocations (RELRO) data pages writable again.
104852 +
104853 + You should say Y here to complete the protection provided by
104854 + the enforcement of non-executable pages.
104855 +
104856 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
104857 + this feature on a per file basis.
104858 +
104859 +config PAX_MPROTECT_COMPAT
104860 + bool "Use legacy/compat protection demoting (read help)"
104861 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
104862 + depends on PAX_MPROTECT
104863 + help
104864 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
104865 + by sending the proper error code to the application. For some broken
104866 + userland, this can cause problems with Python or other applications. The
104867 + current implementation however allows for applications like clamav to
104868 + detect if JIT compilation/execution is allowed and to fall back gracefully
104869 + to an interpreter-based mode if it does not. While we encourage everyone
104870 + to use the current implementation as-is and push upstream to fix broken
104871 + userland (note that the RWX logging option can assist with this), in some
104872 + environments this may not be possible. Having to disable MPROTECT
104873 + completely on certain binaries reduces the security benefit of PaX,
104874 + so this option is provided for those environments to revert to the old
104875 + behavior.
104876 +
104877 +config PAX_ELFRELOCS
104878 + bool "Allow ELF text relocations (read help)"
104879 + depends on PAX_MPROTECT
104880 + default n
104881 + help
104882 + Non-executable pages and mprotect() restrictions are effective
104883 + in preventing the introduction of new executable code into an
104884 + attacked task's address space. There remain only two venues
104885 + for this kind of attack: if the attacker can execute already
104886 + existing code in the attacked task then he can either have it
104887 + create and mmap() a file containing his code or have it mmap()
104888 + an already existing ELF library that does not have position
104889 + independent code in it and use mprotect() on it to make it
104890 + writable and copy his code there. While protecting against
104891 + the former approach is beyond PaX, the latter can be prevented
104892 + by having only PIC ELF libraries on one's system (which do not
104893 + need to relocate their code). If you are sure this is your case,
104894 + as is the case with all modern Linux distributions, then leave
104895 + this option disabled. You should say 'n' here.
104896 +
104897 +config PAX_ETEXECRELOCS
104898 + bool "Allow ELF ET_EXEC text relocations"
104899 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
104900 + select PAX_ELFRELOCS
104901 + default y
104902 + help
104903 + On some architectures there are incorrectly created applications
104904 + that require text relocations and would not work without enabling
104905 + this option. If you are an alpha, ia64 or parisc user, you should
104906 + enable this option and disable it once you have made sure that
104907 + none of your applications need it.
104908 +
104909 +config PAX_EMUPLT
104910 + bool "Automatically emulate ELF PLT"
104911 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
104912 + default y
104913 + help
104914 + Enabling this option will have the kernel automatically detect
104915 + and emulate the Procedure Linkage Table entries in ELF files.
104916 + On some architectures such entries are in writable memory, and
104917 + become non-executable leading to task termination. Therefore
104918 + it is mandatory that you enable this option on alpha, parisc,
104919 + sparc and sparc64, otherwise your system would not even boot.
104920 +
104921 + NOTE: this feature *does* open up a loophole in the protection
104922 + provided by the non-executable pages, therefore the proper
104923 + solution is to modify the toolchain to produce a PLT that does
104924 + not need to be writable.
104925 +
104926 +config PAX_DLRESOLVE
104927 + bool 'Emulate old glibc resolver stub'
104928 + depends on PAX_EMUPLT && SPARC
104929 + default n
104930 + help
104931 + This option is needed if userland has an old glibc (before 2.4)
104932 + that puts a 'save' instruction into the runtime generated resolver
104933 + stub that needs special emulation.
104934 +
104935 +config PAX_KERNEXEC
104936 + bool "Enforce non-executable kernel pages"
104937 + 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))
104938 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
104939 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
104940 + select PAX_KERNEXEC_PLUGIN if X86_64
104941 + help
104942 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
104943 + that is, enabling this option will make it harder to inject
104944 + and execute 'foreign' code in kernel memory itself.
104945 +
104946 +choice
104947 + prompt "Return Address Instrumentation Method"
104948 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
104949 + depends on PAX_KERNEXEC_PLUGIN
104950 + help
104951 + Select the method used to instrument function pointer dereferences.
104952 + Note that binary modules cannot be instrumented by this approach.
104953 +
104954 + Note that the implementation requires a gcc with plugin support,
104955 + i.e., gcc 4.5 or newer. You may need to install the supporting
104956 + headers explicitly in addition to the normal gcc package.
104957 +
104958 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
104959 + bool "bts"
104960 + help
104961 + This method is compatible with binary only modules but has
104962 + a higher runtime overhead.
104963 +
104964 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
104965 + bool "or"
104966 + depends on !PARAVIRT
104967 + help
104968 + This method is incompatible with binary only modules but has
104969 + a lower runtime overhead.
104970 +endchoice
104971 +
104972 +config PAX_KERNEXEC_PLUGIN_METHOD
104973 + string
104974 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
104975 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
104976 + default ""
104977 +
104978 +config PAX_KERNEXEC_MODULE_TEXT
104979 + int "Minimum amount of memory reserved for module code"
104980 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
104981 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
104982 + depends on PAX_KERNEXEC && X86_32
104983 + help
104984 + Due to implementation details the kernel must reserve a fixed
104985 + amount of memory for runtime allocated code (such as modules)
104986 + at compile time that cannot be changed at runtime. Here you
104987 + can specify the minimum amount in MB that will be reserved.
104988 + Due to the same implementation details this size will always
104989 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
104990 + the actually available memory for runtime allocated code will
104991 + usually be more than this minimum.
104992 +
104993 + The default 4 MB should be enough for most users but if you have
104994 + an excessive number of modules (e.g., most distribution configs
104995 + compile many drivers as modules) or use huge modules such as
104996 + nvidia's kernel driver, you will need to adjust this amount.
104997 + A good rule of thumb is to look at your currently loaded kernel
104998 + modules and add up their sizes.
104999 +
105000 +endmenu
105001 +
105002 +menu "Address Space Layout Randomization"
105003 + depends on PAX
105004 +
105005 +config PAX_ASLR
105006 + bool "Address Space Layout Randomization"
105007 + default y if GRKERNSEC_CONFIG_AUTO
105008 + help
105009 + Many if not most exploit techniques rely on the knowledge of
105010 + certain addresses in the attacked program. The following options
105011 + will allow the kernel to apply a certain amount of randomization
105012 + to specific parts of the program thereby forcing an attacker to
105013 + guess them in most cases. Any failed guess will most likely crash
105014 + the attacked program which allows the kernel to detect such attempts
105015 + and react on them. PaX itself provides no reaction mechanisms,
105016 + instead it is strongly encouraged that you make use of grsecurity's
105017 + (http://www.grsecurity.net/) built-in crash detection features or
105018 + develop one yourself.
105019 +
105020 + By saying Y here you can choose to randomize the following areas:
105021 + - top of the task's kernel stack
105022 + - top of the task's userland stack
105023 + - base address for mmap() requests that do not specify one
105024 + (this includes all libraries)
105025 + - base address of the main executable
105026 +
105027 + It is strongly recommended to say Y here as address space layout
105028 + randomization has negligible impact on performance yet it provides
105029 + a very effective protection.
105030 +
105031 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105032 + this feature on a per file basis.
105033 +
105034 +config PAX_RANDKSTACK
105035 + bool "Randomize kernel stack base"
105036 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
105037 + depends on X86_TSC && X86
105038 + help
105039 + By saying Y here the kernel will randomize every task's kernel
105040 + stack on every system call. This will not only force an attacker
105041 + to guess it but also prevent him from making use of possible
105042 + leaked information about it.
105043 +
105044 + Since the kernel stack is a rather scarce resource, randomization
105045 + may cause unexpected stack overflows, therefore you should very
105046 + carefully test your system. Note that once enabled in the kernel
105047 + configuration, this feature cannot be disabled on a per file basis.
105048 +
105049 +config PAX_RANDUSTACK
105050 + bool
105051 +
105052 +config PAX_RANDMMAP
105053 + bool "Randomize user stack and mmap() bases"
105054 + default y if GRKERNSEC_CONFIG_AUTO
105055 + depends on PAX_ASLR
105056 + select PAX_RANDUSTACK
105057 + help
105058 + By saying Y here the kernel will randomize every task's userland
105059 + stack and use a randomized base address for mmap() requests that
105060 + do not specify one themselves.
105061 +
105062 + The stack randomization is done in two steps where the second
105063 + one may apply a big amount of shift to the top of the stack and
105064 + cause problems for programs that want to use lots of memory (more
105065 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
105066 +
105067 + As a result of mmap randomization all dynamically loaded libraries
105068 + will appear at random addresses and therefore be harder to exploit
105069 + by a technique where an attacker attempts to execute library code
105070 + for his purposes (e.g. spawn a shell from an exploited program that
105071 + is running at an elevated privilege level).
105072 +
105073 + Furthermore, if a program is relinked as a dynamic ELF file, its
105074 + base address will be randomized as well, completing the full
105075 + randomization of the address space layout. Attacking such programs
105076 + becomes a guess game. You can find an example of doing this at
105077 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
105078 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
105079 +
105080 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
105081 + feature on a per file basis.
105082 +
105083 +endmenu
105084 +
105085 +menu "Miscellaneous hardening features"
105086 +
105087 +config PAX_MEMORY_SANITIZE
105088 + bool "Sanitize all freed memory"
105089 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105090 + help
105091 + By saying Y here the kernel will erase memory pages and slab objects
105092 + as soon as they are freed. This in turn reduces the lifetime of data
105093 + stored in them, making it less likely that sensitive information such
105094 + as passwords, cryptographic secrets, etc stay in memory for too long.
105095 +
105096 + This is especially useful for programs whose runtime is short, long
105097 + lived processes and the kernel itself benefit from this as long as
105098 + they ensure timely freeing of memory that may hold sensitive
105099 + information.
105100 +
105101 + A nice side effect of the sanitization of slab objects is the
105102 + reduction of possible info leaks caused by padding bytes within the
105103 + leaky structures. Use-after-free bugs for structures containing
105104 + pointers can also be detected as dereferencing the sanitized pointer
105105 + will generate an access violation.
105106 +
105107 + The tradeoff is performance impact, on a single CPU system kernel
105108 + compilation sees a 3% slowdown, other systems and workloads may vary
105109 + and you are advised to test this feature on your expected workload
105110 + before deploying it.
105111 +
105112 + To reduce the performance penalty by sanitizing pages only, albeit
105113 + limiting the effectiveness of this feature at the same time, slab
105114 + sanitization can be disabled with the kernel commandline parameter
105115 + "pax_sanitize_slab=0".
105116 +
105117 + Note that this feature does not protect data stored in live pages,
105118 + e.g., process memory swapped to disk may stay there for a long time.
105119 +
105120 +config PAX_MEMORY_STACKLEAK
105121 + bool "Sanitize kernel stack"
105122 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105123 + depends on X86
105124 + help
105125 + By saying Y here the kernel will erase the kernel stack before it
105126 + returns from a system call. This in turn reduces the information
105127 + that a kernel stack leak bug can reveal.
105128 +
105129 + Note that such a bug can still leak information that was put on
105130 + the stack by the current system call (the one eventually triggering
105131 + the bug) but traces of earlier system calls on the kernel stack
105132 + cannot leak anymore.
105133 +
105134 + The tradeoff is performance impact: on a single CPU system kernel
105135 + compilation sees a 1% slowdown, other systems and workloads may vary
105136 + and you are advised to test this feature on your expected workload
105137 + before deploying it.
105138 +
105139 + Note that the full feature requires a gcc with plugin support,
105140 + i.e., gcc 4.5 or newer. You may need to install the supporting
105141 + headers explicitly in addition to the normal gcc package. Using
105142 + older gcc versions means that functions with large enough stack
105143 + frames may leave uninitialized memory behind that may be exposed
105144 + to a later syscall leaking the stack.
105145 +
105146 +config PAX_MEMORY_STRUCTLEAK
105147 + bool "Forcibly initialize local variables copied to userland"
105148 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105149 + help
105150 + By saying Y here the kernel will zero initialize some local
105151 + variables that are going to be copied to userland. This in
105152 + turn prevents unintended information leakage from the kernel
105153 + stack should later code forget to explicitly set all parts of
105154 + the copied variable.
105155 +
105156 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
105157 + at a much smaller coverage.
105158 +
105159 + Note that the implementation requires a gcc with plugin support,
105160 + i.e., gcc 4.5 or newer. You may need to install the supporting
105161 + headers explicitly in addition to the normal gcc package.
105162 +
105163 +config PAX_MEMORY_UDEREF
105164 + bool "Prevent invalid userland pointer dereference"
105165 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
105166 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
105167 + select PAX_PER_CPU_PGD if X86_64
105168 + help
105169 + By saying Y here the kernel will be prevented from dereferencing
105170 + userland pointers in contexts where the kernel expects only kernel
105171 + pointers. This is both a useful runtime debugging feature and a
105172 + security measure that prevents exploiting a class of kernel bugs.
105173 +
105174 + The tradeoff is that some virtualization solutions may experience
105175 + a huge slowdown and therefore you should not enable this feature
105176 + for kernels meant to run in such environments. Whether a given VM
105177 + solution is affected or not is best determined by simply trying it
105178 + out, the performance impact will be obvious right on boot as this
105179 + mechanism engages from very early on. A good rule of thumb is that
105180 + VMs running on CPUs without hardware virtualization support (i.e.,
105181 + the majority of IA-32 CPUs) will likely experience the slowdown.
105182 +
105183 + On X86_64 the kernel will make use of PCID support when available
105184 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
105185 + or performance impact. Pass pax_weakuderef on the kernel command
105186 + line to choose the latter.
105187 +
105188 +config PAX_REFCOUNT
105189 + bool "Prevent various kernel object reference counter overflows"
105190 + default y if GRKERNSEC_CONFIG_AUTO
105191 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
105192 + help
105193 + By saying Y here the kernel will detect and prevent overflowing
105194 + various (but not all) kinds of object reference counters. Such
105195 + overflows can normally occur due to bugs only and are often, if
105196 + not always, exploitable.
105197 +
105198 + The tradeoff is that data structures protected by an overflowed
105199 + refcount will never be freed and therefore will leak memory. Note
105200 + that this leak also happens even without this protection but in
105201 + that case the overflow can eventually trigger the freeing of the
105202 + data structure while it is still being used elsewhere, resulting
105203 + in the exploitable situation that this feature prevents.
105204 +
105205 + Since this has a negligible performance impact, you should enable
105206 + this feature.
105207 +
105208 +config PAX_CONSTIFY_PLUGIN
105209 + bool "Automatically constify eligible structures"
105210 + default y
105211 + depends on !UML && PAX_KERNEXEC
105212 + help
105213 + By saying Y here the compiler will automatically constify a class
105214 + of types that contain only function pointers. This reduces the
105215 + kernel's attack surface and also produces a better memory layout.
105216 +
105217 + Note that the implementation requires a gcc with plugin support,
105218 + i.e., gcc 4.5 or newer. You may need to install the supporting
105219 + headers explicitly in addition to the normal gcc package.
105220 +
105221 + Note that if some code really has to modify constified variables
105222 + then the source code will have to be patched to allow it. Examples
105223 + can be found in PaX itself (the no_const attribute) and for some
105224 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
105225 +
105226 +config PAX_USERCOPY
105227 + bool "Harden heap object copies between kernel and userland"
105228 + default y if GRKERNSEC_CONFIG_AUTO
105229 + depends on ARM || IA64 || PPC || SPARC || X86
105230 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
105231 + select PAX_USERCOPY_SLABS
105232 + help
105233 + By saying Y here the kernel will enforce the size of heap objects
105234 + when they are copied in either direction between the kernel and
105235 + userland, even if only a part of the heap object is copied.
105236 +
105237 + Specifically, this checking prevents information leaking from the
105238 + kernel heap during kernel to userland copies (if the kernel heap
105239 + object is otherwise fully initialized) and prevents kernel heap
105240 + overflows during userland to kernel copies.
105241 +
105242 + Note that the current implementation provides the strictest bounds
105243 + checks for the SLUB allocator.
105244 +
105245 + Enabling this option also enables per-slab cache protection against
105246 + data in a given cache being copied into/out of via userland
105247 + accessors. Though the whitelist of regions will be reduced over
105248 + time, it notably protects important data structures like task structs.
105249 +
105250 + If frame pointers are enabled on x86, this option will also restrict
105251 + copies into and out of the kernel stack to local variables within a
105252 + single frame.
105253 +
105254 + Since this has a negligible performance impact, you should enable
105255 + this feature.
105256 +
105257 +config PAX_USERCOPY_DEBUG
105258 + bool
105259 + depends on X86 && PAX_USERCOPY
105260 + default n
105261 +
105262 +config PAX_SIZE_OVERFLOW
105263 + bool "Prevent various integer overflows in function size parameters"
105264 + default y if GRKERNSEC_CONFIG_AUTO
105265 + depends on X86
105266 + help
105267 + By saying Y here the kernel recomputes expressions of function
105268 + arguments marked by a size_overflow attribute with double integer
105269 + precision (DImode/TImode for 32/64 bit integer types).
105270 +
105271 + The recomputed argument is checked against TYPE_MAX and an event
105272 + is logged on overflow and the triggering process is killed.
105273 +
105274 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
105275 +
105276 + Note that the implementation requires a gcc with plugin support,
105277 + i.e., gcc 4.5 or newer. You may need to install the supporting
105278 + headers explicitly in addition to the normal gcc package.
105279 +
105280 +config PAX_LATENT_ENTROPY
105281 + bool "Generate some entropy during boot and runtime"
105282 + default y if GRKERNSEC_CONFIG_AUTO
105283 + help
105284 + By saying Y here the kernel will instrument some kernel code to
105285 + extract some entropy from both original and artificially created
105286 + program state. This will help especially embedded systems where
105287 + there is little 'natural' source of entropy normally. The cost
105288 + is some slowdown of the boot process and fork and irq processing.
105289 +
105290 + When pax_extra_latent_entropy is passed on the kernel command line,
105291 + entropy will be extracted from up to the first 4GB of RAM while the
105292 + runtime memory allocator is being initialized. This costs even more
105293 + slowdown of the boot process.
105294 +
105295 + Note that the implementation requires a gcc with plugin support,
105296 + i.e., gcc 4.5 or newer. You may need to install the supporting
105297 + headers explicitly in addition to the normal gcc package.
105298 +
105299 + Note that entropy extracted this way is not cryptographically
105300 + secure!
105301 +
105302 +endmenu
105303 +
105304 +endmenu
105305 +
105306 +source grsecurity/Kconfig
105307 +
105308 +endmenu
105309 +
105310 +endmenu
105311 +
105312 source security/keys/Kconfig
105313
105314 config SECURITY_DMESG_RESTRICT
105315 @@ -103,7 +1054,7 @@ config INTEL_TXT
105316 config LSM_MMAP_MIN_ADDR
105317 int "Low address space for LSM to protect from user allocation"
105318 depends on SECURITY && SECURITY_SELINUX
105319 - default 32768 if ARM || (ARM64 && COMPAT)
105320 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105321 default 65536
105322 help
105323 This is the portion of low virtual memory which should be protected
105324 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105325 index fdaa50c..2761dcb 100644
105326 --- a/security/apparmor/file.c
105327 +++ b/security/apparmor/file.c
105328 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105329 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105330 struct path *new_dir, struct dentry *new_dentry)
105331 {
105332 - struct path link = { new_dir->mnt, new_dentry };
105333 - struct path target = { new_dir->mnt, old_dentry };
105334 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105335 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105336 struct path_cond cond = {
105337 old_dentry->d_inode->i_uid,
105338 old_dentry->d_inode->i_mode
105339 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105340 index 9981000..eb21356 100644
105341 --- a/security/apparmor/lsm.c
105342 +++ b/security/apparmor/lsm.c
105343 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105344 struct dentry *dentry, u32 mask,
105345 struct path_cond *cond)
105346 {
105347 - struct path path = { dir->mnt, dentry };
105348 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
105349
105350 return common_perm(op, &path, mask, cond);
105351 }
105352 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105353 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
105354 struct dentry *dentry, u32 mask)
105355 {
105356 - struct path path = { mnt, dentry };
105357 + struct path path = { .mnt = mnt, .dentry = dentry };
105358 struct path_cond cond = { dentry->d_inode->i_uid,
105359 dentry->d_inode->i_mode
105360 };
105361 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
105362
105363 profile = aa_current_profile();
105364 if (!unconfined(profile)) {
105365 - struct path old_path = { old_dir->mnt, old_dentry };
105366 - struct path new_path = { new_dir->mnt, new_dentry };
105367 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
105368 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
105369 struct path_cond cond = { old_dentry->d_inode->i_uid,
105370 old_dentry->d_inode->i_mode
105371 };
105372 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
105373 return error;
105374 }
105375
105376 -static struct security_operations apparmor_ops = {
105377 +static struct security_operations apparmor_ops __read_only = {
105378 .name = "apparmor",
105379
105380 .ptrace_access_check = apparmor_ptrace_access_check,
105381 diff --git a/security/commoncap.c b/security/commoncap.c
105382 index b9d613e..f68305c 100644
105383 --- a/security/commoncap.c
105384 +++ b/security/commoncap.c
105385 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
105386 return 0;
105387 }
105388
105389 +/* returns:
105390 + 1 for suid privilege
105391 + 2 for sgid privilege
105392 + 3 for fscap privilege
105393 +*/
105394 +int is_privileged_binary(const struct dentry *dentry)
105395 +{
105396 + struct cpu_vfs_cap_data capdata;
105397 + struct inode *inode = dentry->d_inode;
105398 +
105399 + if (!inode || S_ISDIR(inode->i_mode))
105400 + return 0;
105401 +
105402 + if (inode->i_mode & S_ISUID)
105403 + return 1;
105404 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
105405 + return 2;
105406 +
105407 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
105408 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
105409 + return 3;
105410 + }
105411 +
105412 + return 0;
105413 +}
105414 +
105415 /*
105416 * Attempt to get the on-exec apply capability sets for an executable file from
105417 * its xattrs and, if present, apply them to the proposed credentials being
105418 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
105419 const struct cred *cred = current_cred();
105420 kuid_t root_uid = make_kuid(cred->user_ns, 0);
105421
105422 + if (gr_acl_enable_at_secure())
105423 + return 1;
105424 +
105425 if (!uid_eq(cred->uid, root_uid)) {
105426 if (bprm->cap_effective)
105427 return 1;
105428 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
105429 index f79fa8b..6161868 100644
105430 --- a/security/integrity/ima/ima.h
105431 +++ b/security/integrity/ima/ima.h
105432 @@ -118,8 +118,8 @@ int ima_init_template(void);
105433 extern spinlock_t ima_queue_lock;
105434
105435 struct ima_h_table {
105436 - atomic_long_t len; /* number of stored measurements in the list */
105437 - atomic_long_t violations;
105438 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
105439 + atomic_long_unchecked_t violations;
105440 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
105441 };
105442 extern struct ima_h_table ima_htable;
105443 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
105444 index d9cd5ce..c5c29ac 100644
105445 --- a/security/integrity/ima/ima_api.c
105446 +++ b/security/integrity/ima/ima_api.c
105447 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
105448 int result;
105449
105450 /* can overflow, only indicator */
105451 - atomic_long_inc(&ima_htable.violations);
105452 + atomic_long_inc_unchecked(&ima_htable.violations);
105453
105454 result = ima_alloc_init_template(NULL, file, filename,
105455 NULL, 0, &entry);
105456 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
105457 index da92fcc..8a5d390 100644
105458 --- a/security/integrity/ima/ima_fs.c
105459 +++ b/security/integrity/ima/ima_fs.c
105460 @@ -28,12 +28,12 @@
105461 static int valid_policy = 1;
105462 #define TMPBUFLEN 12
105463 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
105464 - loff_t *ppos, atomic_long_t *val)
105465 + loff_t *ppos, atomic_long_unchecked_t *val)
105466 {
105467 char tmpbuf[TMPBUFLEN];
105468 ssize_t len;
105469
105470 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
105471 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
105472 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
105473 }
105474
105475 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
105476 index 552705d..9920f4fb 100644
105477 --- a/security/integrity/ima/ima_queue.c
105478 +++ b/security/integrity/ima/ima_queue.c
105479 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
105480 INIT_LIST_HEAD(&qe->later);
105481 list_add_tail_rcu(&qe->later, &ima_measurements);
105482
105483 - atomic_long_inc(&ima_htable.len);
105484 + atomic_long_inc_unchecked(&ima_htable.len);
105485 key = ima_hash_key(entry->digest);
105486 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
105487 return 0;
105488 diff --git a/security/keys/compat.c b/security/keys/compat.c
105489 index 3478965..ec7bb9e 100644
105490 --- a/security/keys/compat.c
105491 +++ b/security/keys/compat.c
105492 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
105493 if (ret == 0)
105494 goto no_payload_free;
105495
105496 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105497 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105498 err:
105499 if (iov != iovstack)
105500 kfree(iov);
105501 diff --git a/security/keys/internal.h b/security/keys/internal.h
105502 index 80b2aac..bb7ee65 100644
105503 --- a/security/keys/internal.h
105504 +++ b/security/keys/internal.h
105505 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
105506 extern long keyctl_invalidate_key(key_serial_t);
105507
105508 extern long keyctl_instantiate_key_common(key_serial_t,
105509 - const struct iovec *,
105510 + const struct iovec __user *,
105511 unsigned, size_t, key_serial_t);
105512 #ifdef CONFIG_PERSISTENT_KEYRINGS
105513 extern long keyctl_get_persistent(uid_t, key_serial_t);
105514 diff --git a/security/keys/key.c b/security/keys/key.c
105515 index 6e21c11..9ed67ca 100644
105516 --- a/security/keys/key.c
105517 +++ b/security/keys/key.c
105518 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
105519
105520 atomic_set(&key->usage, 1);
105521 init_rwsem(&key->sem);
105522 - lockdep_set_class(&key->sem, &type->lock_class);
105523 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
105524 key->index_key.type = type;
105525 key->user = user;
105526 key->quotalen = quotalen;
105527 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
105528 struct key_type *p;
105529 int ret;
105530
105531 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
105532 + pax_open_kernel();
105533 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
105534 + pax_close_kernel();
105535
105536 ret = -EEXIST;
105537 down_write(&key_types_sem);
105538 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
105539 }
105540
105541 /* store the type */
105542 - list_add(&ktype->link, &key_types_list);
105543 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
105544
105545 pr_notice("Key type %s registered\n", ktype->name);
105546 ret = 0;
105547 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
105548 void unregister_key_type(struct key_type *ktype)
105549 {
105550 down_write(&key_types_sem);
105551 - list_del_init(&ktype->link);
105552 + pax_list_del_init((struct list_head *)&ktype->link);
105553 downgrade_write(&key_types_sem);
105554 key_gc_keytype(ktype);
105555 pr_notice("Key type %s unregistered\n", ktype->name);
105556 @@ -1088,10 +1090,10 @@ void __init key_init(void)
105557 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
105558
105559 /* add the special key types */
105560 - list_add_tail(&key_type_keyring.link, &key_types_list);
105561 - list_add_tail(&key_type_dead.link, &key_types_list);
105562 - list_add_tail(&key_type_user.link, &key_types_list);
105563 - list_add_tail(&key_type_logon.link, &key_types_list);
105564 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
105565 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
105566 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
105567 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
105568
105569 /* record the root user tracking */
105570 rb_link_node(&root_key_user.node,
105571 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
105572 index cee72ce..e46074a 100644
105573 --- a/security/keys/keyctl.c
105574 +++ b/security/keys/keyctl.c
105575 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
105576 /*
105577 * Copy the iovec data from userspace
105578 */
105579 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105580 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
105581 unsigned ioc)
105582 {
105583 for (; ioc > 0; ioc--) {
105584 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105585 * If successful, 0 will be returned.
105586 */
105587 long keyctl_instantiate_key_common(key_serial_t id,
105588 - const struct iovec *payload_iov,
105589 + const struct iovec __user *payload_iov,
105590 unsigned ioc,
105591 size_t plen,
105592 key_serial_t ringid)
105593 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
105594 [0].iov_len = plen
105595 };
105596
105597 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
105598 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
105599 }
105600
105601 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
105602 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
105603 if (ret == 0)
105604 goto no_payload_free;
105605
105606 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105607 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105608 err:
105609 if (iov != iovstack)
105610 kfree(iov);
105611 diff --git a/security/min_addr.c b/security/min_addr.c
105612 index f728728..6457a0c 100644
105613 --- a/security/min_addr.c
105614 +++ b/security/min_addr.c
105615 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
105616 */
105617 static void update_mmap_min_addr(void)
105618 {
105619 +#ifndef SPARC
105620 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
105621 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
105622 mmap_min_addr = dac_mmap_min_addr;
105623 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
105624 #else
105625 mmap_min_addr = dac_mmap_min_addr;
105626 #endif
105627 +#endif
105628 }
105629
105630 /*
105631 diff --git a/security/security.c b/security/security.c
105632 index 8b774f3..a396233 100644
105633 --- a/security/security.c
105634 +++ b/security/security.c
105635 @@ -33,8 +33,8 @@
105636 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
105637 CONFIG_DEFAULT_SECURITY;
105638
105639 -static struct security_operations *security_ops;
105640 -static struct security_operations default_security_ops = {
105641 +struct security_operations *security_ops __read_only;
105642 +struct security_operations default_security_ops __read_only = {
105643 .name = "default",
105644 };
105645
105646 @@ -73,11 +73,6 @@ int __init security_init(void)
105647 return 0;
105648 }
105649
105650 -void reset_security_ops(void)
105651 -{
105652 - security_ops = &default_security_ops;
105653 -}
105654 -
105655 /* Save user chosen LSM */
105656 static int __init choose_lsm(char *str)
105657 {
105658 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
105659 index fc3e662..7844c60 100644
105660 --- a/security/selinux/avc.c
105661 +++ b/security/selinux/avc.c
105662 @@ -59,7 +59,7 @@ struct avc_node {
105663 struct avc_cache {
105664 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
105665 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
105666 - atomic_t lru_hint; /* LRU hint for reclaim scan */
105667 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
105668 atomic_t active_nodes;
105669 u32 latest_notif; /* latest revocation notification */
105670 };
105671 @@ -167,7 +167,7 @@ void __init avc_init(void)
105672 spin_lock_init(&avc_cache.slots_lock[i]);
105673 }
105674 atomic_set(&avc_cache.active_nodes, 0);
105675 - atomic_set(&avc_cache.lru_hint, 0);
105676 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
105677
105678 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
105679 0, SLAB_PANIC, NULL);
105680 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
105681 spinlock_t *lock;
105682
105683 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
105684 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105685 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105686 head = &avc_cache.slots[hvalue];
105687 lock = &avc_cache.slots_lock[hvalue];
105688
105689 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
105690 index 2c7341d..1da068e 100644
105691 --- a/security/selinux/hooks.c
105692 +++ b/security/selinux/hooks.c
105693 @@ -95,8 +95,6 @@
105694 #include "audit.h"
105695 #include "avc_ss.h"
105696
105697 -extern struct security_operations *security_ops;
105698 -
105699 /* SECMARK reference count */
105700 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
105701
105702 @@ -5758,7 +5756,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
105703
105704 #endif
105705
105706 -static struct security_operations selinux_ops = {
105707 +static struct security_operations selinux_ops __read_only = {
105708 .name = "selinux",
105709
105710 .ptrace_access_check = selinux_ptrace_access_check,
105711 @@ -6111,6 +6109,9 @@ static void selinux_nf_ip_exit(void)
105712 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
105713 static int selinux_disabled;
105714
105715 +extern struct security_operations *security_ops;
105716 +extern struct security_operations default_security_ops;
105717 +
105718 int selinux_disable(void)
105719 {
105720 if (ss_initialized) {
105721 @@ -6128,7 +6129,9 @@ int selinux_disable(void)
105722 selinux_disabled = 1;
105723 selinux_enabled = 0;
105724
105725 - reset_security_ops();
105726 + pax_open_kernel();
105727 + security_ops = &default_security_ops;
105728 + pax_close_kernel();
105729
105730 /* Try to destroy the avc node cache */
105731 avc_disable();
105732 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
105733 index 1450f85..a91e0bc 100644
105734 --- a/security/selinux/include/xfrm.h
105735 +++ b/security/selinux/include/xfrm.h
105736 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
105737
105738 rtnl_lock();
105739 for_each_net(net) {
105740 - atomic_inc(&net->xfrm.flow_cache_genid);
105741 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
105742 rt_genid_bump_all(net);
105743 }
105744 rtnl_unlock();
105745 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
105746 index 14f52be..7352368 100644
105747 --- a/security/smack/smack_lsm.c
105748 +++ b/security/smack/smack_lsm.c
105749 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
105750 return 0;
105751 }
105752
105753 -struct security_operations smack_ops = {
105754 +struct security_operations smack_ops __read_only = {
105755 .name = "smack",
105756
105757 .ptrace_access_check = smack_ptrace_access_check,
105758 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
105759 index 4003907..13a2b55 100644
105760 --- a/security/tomoyo/file.c
105761 +++ b/security/tomoyo/file.c
105762 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
105763 {
105764 struct tomoyo_request_info r;
105765 struct tomoyo_obj_info obj = {
105766 - .path1 = *path,
105767 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105768 };
105769 int error = -ENOMEM;
105770 struct tomoyo_path_info buf;
105771 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
105772 struct tomoyo_path_info buf;
105773 struct tomoyo_request_info r;
105774 struct tomoyo_obj_info obj = {
105775 - .path1 = *path,
105776 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105777 };
105778 int idx;
105779
105780 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
105781 {
105782 struct tomoyo_request_info r;
105783 struct tomoyo_obj_info obj = {
105784 - .path1 = *path,
105785 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105786 };
105787 int error;
105788 struct tomoyo_path_info buf;
105789 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
105790 {
105791 struct tomoyo_request_info r;
105792 struct tomoyo_obj_info obj = {
105793 - .path1 = *path,
105794 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105795 };
105796 int error = -ENOMEM;
105797 struct tomoyo_path_info buf;
105798 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
105799 struct tomoyo_path_info buf2;
105800 struct tomoyo_request_info r;
105801 struct tomoyo_obj_info obj = {
105802 - .path1 = *path1,
105803 - .path2 = *path2,
105804 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
105805 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
105806 };
105807 int idx;
105808
105809 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
105810 index 390c646..f2f8db3 100644
105811 --- a/security/tomoyo/mount.c
105812 +++ b/security/tomoyo/mount.c
105813 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
105814 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
105815 need_dev = -1; /* dev_name is a directory */
105816 } else {
105817 + if (!capable(CAP_SYS_ADMIN)) {
105818 + error = -EPERM;
105819 + goto out;
105820 + }
105821 fstype = get_fs_type(type);
105822 if (!fstype) {
105823 error = -ENODEV;
105824 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
105825 index f0b756e..8aa497b 100644
105826 --- a/security/tomoyo/tomoyo.c
105827 +++ b/security/tomoyo/tomoyo.c
105828 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
105829 */
105830 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
105831 {
105832 - struct path path = { mnt, dentry };
105833 + struct path path = { .mnt = mnt, .dentry = dentry };
105834 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
105835 }
105836
105837 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
105838 */
105839 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
105840 {
105841 - struct path path = { parent->mnt, dentry };
105842 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105843 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
105844 }
105845
105846 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
105847 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
105848 umode_t mode)
105849 {
105850 - struct path path = { parent->mnt, dentry };
105851 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105852 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
105853 mode & S_IALLUGO);
105854 }
105855 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
105856 */
105857 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
105858 {
105859 - struct path path = { parent->mnt, dentry };
105860 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105861 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
105862 }
105863
105864 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
105865 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
105866 const char *old_name)
105867 {
105868 - struct path path = { parent->mnt, dentry };
105869 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105870 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
105871 }
105872
105873 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
105874 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
105875 umode_t mode, unsigned int dev)
105876 {
105877 - struct path path = { parent->mnt, dentry };
105878 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105879 int type = TOMOYO_TYPE_CREATE;
105880 const unsigned int perm = mode & S_IALLUGO;
105881
105882 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
105883 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
105884 struct dentry *new_dentry)
105885 {
105886 - struct path path1 = { new_dir->mnt, old_dentry };
105887 - struct path path2 = { new_dir->mnt, new_dentry };
105888 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
105889 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
105890 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
105891 }
105892
105893 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
105894 struct path *new_parent,
105895 struct dentry *new_dentry)
105896 {
105897 - struct path path1 = { old_parent->mnt, old_dentry };
105898 - struct path path2 = { new_parent->mnt, new_dentry };
105899 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
105900 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
105901 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
105902 }
105903
105904 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
105905 */
105906 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
105907 {
105908 - struct path path = { mnt, mnt->mnt_root };
105909 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
105910 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
105911 }
105912
105913 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
105914 * tomoyo_security_ops is a "struct security_operations" which is used for
105915 * registering TOMOYO.
105916 */
105917 -static struct security_operations tomoyo_security_ops = {
105918 +static struct security_operations tomoyo_security_ops __read_only = {
105919 .name = "tomoyo",
105920 .cred_alloc_blank = tomoyo_cred_alloc_blank,
105921 .cred_prepare = tomoyo_cred_prepare,
105922 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
105923 index 20ef514..4182bed 100644
105924 --- a/security/yama/Kconfig
105925 +++ b/security/yama/Kconfig
105926 @@ -1,6 +1,6 @@
105927 config SECURITY_YAMA
105928 bool "Yama support"
105929 - depends on SECURITY
105930 + depends on SECURITY && !GRKERNSEC
105931 select SECURITYFS
105932 select SECURITY_PATH
105933 default n
105934 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
105935 index 13c88fbc..f8c115e 100644
105936 --- a/security/yama/yama_lsm.c
105937 +++ b/security/yama/yama_lsm.c
105938 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
105939 }
105940
105941 #ifndef CONFIG_SECURITY_YAMA_STACKED
105942 -static struct security_operations yama_ops = {
105943 +static struct security_operations yama_ops __read_only = {
105944 .name = "yama",
105945
105946 .ptrace_access_check = yama_ptrace_access_check,
105947 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
105948 #endif
105949
105950 #ifdef CONFIG_SYSCTL
105951 +static int zero __read_only;
105952 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
105953 +
105954 static int yama_dointvec_minmax(struct ctl_table *table, int write,
105955 void __user *buffer, size_t *lenp, loff_t *ppos)
105956 {
105957 - int rc;
105958 + ctl_table_no_const yama_table;
105959
105960 if (write && !capable(CAP_SYS_PTRACE))
105961 return -EPERM;
105962
105963 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
105964 - if (rc)
105965 - return rc;
105966 -
105967 + yama_table = *table;
105968 /* Lock the max value if it ever gets set. */
105969 - if (write && *(int *)table->data == *(int *)table->extra2)
105970 - table->extra1 = table->extra2;
105971 -
105972 - return rc;
105973 + if (ptrace_scope == max_scope)
105974 + yama_table.extra1 = &max_scope;
105975 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
105976 }
105977
105978 -static int zero;
105979 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
105980 -
105981 struct ctl_path yama_sysctl_path[] = {
105982 { .procname = "kernel", },
105983 { .procname = "yama", },
105984 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
105985 index f01bffb..bdda392 100644
105986 --- a/sound/aoa/codecs/onyx.c
105987 +++ b/sound/aoa/codecs/onyx.c
105988 @@ -54,7 +54,7 @@ struct onyx {
105989 spdif_locked:1,
105990 analog_locked:1,
105991 original_mute:2;
105992 - int open_count;
105993 + local_t open_count;
105994 struct codec_info *codec_info;
105995
105996 /* mutex serializes concurrent access to the device
105997 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
105998 struct onyx *onyx = cii->codec_data;
105999
106000 mutex_lock(&onyx->mutex);
106001 - onyx->open_count++;
106002 + local_inc(&onyx->open_count);
106003 mutex_unlock(&onyx->mutex);
106004
106005 return 0;
106006 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
106007 struct onyx *onyx = cii->codec_data;
106008
106009 mutex_lock(&onyx->mutex);
106010 - onyx->open_count--;
106011 - if (!onyx->open_count)
106012 + if (local_dec_and_test(&onyx->open_count))
106013 onyx->spdif_locked = onyx->analog_locked = 0;
106014 mutex_unlock(&onyx->mutex);
106015
106016 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
106017 index ffd2025..df062c9 100644
106018 --- a/sound/aoa/codecs/onyx.h
106019 +++ b/sound/aoa/codecs/onyx.h
106020 @@ -11,6 +11,7 @@
106021 #include <linux/i2c.h>
106022 #include <asm/pmac_low_i2c.h>
106023 #include <asm/prom.h>
106024 +#include <asm/local.h>
106025
106026 /* PCM3052 register definitions */
106027
106028 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
106029 index ada69d7..5f65386 100644
106030 --- a/sound/core/oss/pcm_oss.c
106031 +++ b/sound/core/oss/pcm_oss.c
106032 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
106033 if (in_kernel) {
106034 mm_segment_t fs;
106035 fs = snd_enter_user();
106036 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106037 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106038 snd_leave_user(fs);
106039 } else {
106040 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106041 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106042 }
106043 if (ret != -EPIPE && ret != -ESTRPIPE)
106044 break;
106045 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
106046 if (in_kernel) {
106047 mm_segment_t fs;
106048 fs = snd_enter_user();
106049 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106050 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106051 snd_leave_user(fs);
106052 } else {
106053 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106054 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106055 }
106056 if (ret == -EPIPE) {
106057 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
106058 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
106059 struct snd_pcm_plugin_channel *channels;
106060 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
106061 if (!in_kernel) {
106062 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
106063 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
106064 return -EFAULT;
106065 buf = runtime->oss.buffer;
106066 }
106067 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
106068 }
106069 } else {
106070 tmp = snd_pcm_oss_write2(substream,
106071 - (const char __force *)buf,
106072 + (const char __force_kernel *)buf,
106073 runtime->oss.period_bytes, 0);
106074 if (tmp <= 0)
106075 goto err;
106076 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
106077 struct snd_pcm_runtime *runtime = substream->runtime;
106078 snd_pcm_sframes_t frames, frames1;
106079 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
106080 - char __user *final_dst = (char __force __user *)buf;
106081 + char __user *final_dst = (char __force_user *)buf;
106082 if (runtime->oss.plugin_first) {
106083 struct snd_pcm_plugin_channel *channels;
106084 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
106085 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
106086 xfer += tmp;
106087 runtime->oss.buffer_used -= tmp;
106088 } else {
106089 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
106090 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
106091 runtime->oss.period_bytes, 0);
106092 if (tmp <= 0)
106093 goto err;
106094 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
106095 size1);
106096 size1 /= runtime->channels; /* frames */
106097 fs = snd_enter_user();
106098 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
106099 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
106100 snd_leave_user(fs);
106101 }
106102 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
106103 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
106104 index af49721..e85058e 100644
106105 --- a/sound/core/pcm_compat.c
106106 +++ b/sound/core/pcm_compat.c
106107 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
106108 int err;
106109
106110 fs = snd_enter_user();
106111 - err = snd_pcm_delay(substream, &delay);
106112 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
106113 snd_leave_user(fs);
106114 if (err < 0)
106115 return err;
106116 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
106117 index b653ab0..a4738e3 100644
106118 --- a/sound/core/pcm_native.c
106119 +++ b/sound/core/pcm_native.c
106120 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
106121 switch (substream->stream) {
106122 case SNDRV_PCM_STREAM_PLAYBACK:
106123 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
106124 - (void __user *)arg);
106125 + (void __force_user *)arg);
106126 break;
106127 case SNDRV_PCM_STREAM_CAPTURE:
106128 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
106129 - (void __user *)arg);
106130 + (void __force_user *)arg);
106131 break;
106132 default:
106133 result = -EINVAL;
106134 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
106135 index 16d4267..fe8b49b 100644
106136 --- a/sound/core/seq/oss/seq_oss.c
106137 +++ b/sound/core/seq/oss/seq_oss.c
106138 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
106139 {
106140 int rc;
106141 static struct snd_seq_dev_ops ops = {
106142 - snd_seq_oss_synth_register,
106143 - snd_seq_oss_synth_unregister,
106144 + .init_device = snd_seq_oss_synth_register,
106145 + .free_device = snd_seq_oss_synth_unregister,
106146 };
106147
106148 snd_seq_autoload_lock();
106149 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
106150 index 91a786a..4c07ed4 100644
106151 --- a/sound/core/seq/seq_device.c
106152 +++ b/sound/core/seq/seq_device.c
106153 @@ -64,7 +64,7 @@ struct ops_list {
106154 int argsize; /* argument size */
106155
106156 /* operators */
106157 - struct snd_seq_dev_ops ops;
106158 + struct snd_seq_dev_ops *ops;
106159
106160 /* registered devices */
106161 struct list_head dev_list; /* list of devices */
106162 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
106163
106164 mutex_lock(&ops->reg_mutex);
106165 /* copy driver operators */
106166 - ops->ops = *entry;
106167 + ops->ops = entry;
106168 ops->driver |= DRIVER_LOADED;
106169 ops->argsize = argsize;
106170
106171 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
106172 dev->name, ops->id, ops->argsize, dev->argsize);
106173 return -EINVAL;
106174 }
106175 - if (ops->ops.init_device(dev) >= 0) {
106176 + if (ops->ops->init_device(dev) >= 0) {
106177 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
106178 ops->num_init_devices++;
106179 } else {
106180 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
106181 dev->name, ops->id, ops->argsize, dev->argsize);
106182 return -EINVAL;
106183 }
106184 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
106185 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
106186 dev->status = SNDRV_SEQ_DEVICE_FREE;
106187 dev->driver_data = NULL;
106188 ops->num_init_devices--;
106189 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
106190 index 3e05c55..0f02efc 100644
106191 --- a/sound/core/seq/seq_midi.c
106192 +++ b/sound/core/seq/seq_midi.c
106193 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
106194 static int __init alsa_seq_midi_init(void)
106195 {
106196 static struct snd_seq_dev_ops ops = {
106197 - snd_seq_midisynth_register_port,
106198 - snd_seq_midisynth_unregister_port,
106199 + .init_device = snd_seq_midisynth_register_port,
106200 + .free_device = snd_seq_midisynth_unregister_port,
106201 };
106202 memset(&synths, 0, sizeof(synths));
106203 snd_seq_autoload_lock();
106204 diff --git a/sound/core/sound.c b/sound/core/sound.c
106205 index 38ad1a0..5010a40 100644
106206 --- a/sound/core/sound.c
106207 +++ b/sound/core/sound.c
106208 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
106209 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
106210 default: return;
106211 }
106212 - request_module(str);
106213 + request_module("%s", str);
106214 }
106215
106216 #endif /* modular kernel */
106217 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
106218 index f5fd448..6ae276da 100644
106219 --- a/sound/drivers/mts64.c
106220 +++ b/sound/drivers/mts64.c
106221 @@ -29,6 +29,7 @@
106222 #include <sound/initval.h>
106223 #include <sound/rawmidi.h>
106224 #include <sound/control.h>
106225 +#include <asm/local.h>
106226
106227 #define CARD_NAME "Miditerminal 4140"
106228 #define DRIVER_NAME "MTS64"
106229 @@ -67,7 +68,7 @@ struct mts64 {
106230 struct pardevice *pardev;
106231 int pardev_claimed;
106232
106233 - int open_count;
106234 + local_t open_count;
106235 int current_midi_output_port;
106236 int current_midi_input_port;
106237 u8 mode[MTS64_NUM_INPUT_PORTS];
106238 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106239 {
106240 struct mts64 *mts = substream->rmidi->private_data;
106241
106242 - if (mts->open_count == 0) {
106243 + if (local_read(&mts->open_count) == 0) {
106244 /* We don't need a spinlock here, because this is just called
106245 if the device has not been opened before.
106246 So there aren't any IRQs from the device */
106247 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106248
106249 msleep(50);
106250 }
106251 - ++(mts->open_count);
106252 + local_inc(&mts->open_count);
106253
106254 return 0;
106255 }
106256 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106257 struct mts64 *mts = substream->rmidi->private_data;
106258 unsigned long flags;
106259
106260 - --(mts->open_count);
106261 - if (mts->open_count == 0) {
106262 + if (local_dec_return(&mts->open_count) == 0) {
106263 /* We need the spinlock_irqsave here because we can still
106264 have IRQs at this point */
106265 spin_lock_irqsave(&mts->lock, flags);
106266 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106267
106268 msleep(500);
106269
106270 - } else if (mts->open_count < 0)
106271 - mts->open_count = 0;
106272 + } else if (local_read(&mts->open_count) < 0)
106273 + local_set(&mts->open_count, 0);
106274
106275 return 0;
106276 }
106277 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
106278 index 6839953..7a0f4b9 100644
106279 --- a/sound/drivers/opl3/opl3_seq.c
106280 +++ b/sound/drivers/opl3/opl3_seq.c
106281 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
106282 {
106283 static struct snd_seq_dev_ops ops =
106284 {
106285 - snd_opl3_seq_new_device,
106286 - snd_opl3_seq_delete_device
106287 + .init_device = snd_opl3_seq_new_device,
106288 + .free_device = snd_opl3_seq_delete_device
106289 };
106290
106291 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106292 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106293 index b953fb4..1999c01 100644
106294 --- a/sound/drivers/opl4/opl4_lib.c
106295 +++ b/sound/drivers/opl4/opl4_lib.c
106296 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106297 MODULE_DESCRIPTION("OPL4 driver");
106298 MODULE_LICENSE("GPL");
106299
106300 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106301 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106302 {
106303 int timeout = 10;
106304 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106305 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106306 index 9919769..d7de36c 100644
106307 --- a/sound/drivers/opl4/opl4_seq.c
106308 +++ b/sound/drivers/opl4/opl4_seq.c
106309 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106310 static int __init alsa_opl4_synth_init(void)
106311 {
106312 static struct snd_seq_dev_ops ops = {
106313 - snd_opl4_seq_new_device,
106314 - snd_opl4_seq_delete_device
106315 + .init_device = snd_opl4_seq_new_device,
106316 + .free_device = snd_opl4_seq_delete_device
106317 };
106318
106319 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106320 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106321 index 78ccfa4..7a0857b 100644
106322 --- a/sound/drivers/portman2x4.c
106323 +++ b/sound/drivers/portman2x4.c
106324 @@ -48,6 +48,7 @@
106325 #include <sound/initval.h>
106326 #include <sound/rawmidi.h>
106327 #include <sound/control.h>
106328 +#include <asm/local.h>
106329
106330 #define CARD_NAME "Portman 2x4"
106331 #define DRIVER_NAME "portman"
106332 @@ -85,7 +86,7 @@ struct portman {
106333 struct pardevice *pardev;
106334 int pardev_claimed;
106335
106336 - int open_count;
106337 + local_t open_count;
106338 int mode[PORTMAN_NUM_INPUT_PORTS];
106339 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106340 };
106341 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106342 index 9048777..2d8b1fc 100644
106343 --- a/sound/firewire/amdtp.c
106344 +++ b/sound/firewire/amdtp.c
106345 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
106346 ptr = s->pcm_buffer_pointer + data_blocks;
106347 if (ptr >= pcm->runtime->buffer_size)
106348 ptr -= pcm->runtime->buffer_size;
106349 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
106350 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
106351
106352 s->pcm_period_pointer += data_blocks;
106353 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
106354 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
106355 */
106356 void amdtp_out_stream_update(struct amdtp_out_stream *s)
106357 {
106358 - ACCESS_ONCE(s->source_node_id_field) =
106359 + ACCESS_ONCE_RW(s->source_node_id_field) =
106360 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
106361 }
106362 EXPORT_SYMBOL(amdtp_out_stream_update);
106363 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
106364 index 2746ecd..c35dedd 100644
106365 --- a/sound/firewire/amdtp.h
106366 +++ b/sound/firewire/amdtp.h
106367 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
106368 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
106369 struct snd_pcm_substream *pcm)
106370 {
106371 - ACCESS_ONCE(s->pcm) = pcm;
106372 + ACCESS_ONCE_RW(s->pcm) = pcm;
106373 }
106374
106375 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
106376 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
106377 index 7ac9443..0ec6274 100644
106378 --- a/sound/firewire/isight.c
106379 +++ b/sound/firewire/isight.c
106380 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
106381 ptr += count;
106382 if (ptr >= runtime->buffer_size)
106383 ptr -= runtime->buffer_size;
106384 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
106385 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
106386
106387 isight->period_counter += count;
106388 if (isight->period_counter >= runtime->period_size) {
106389 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
106390 if (err < 0)
106391 return err;
106392
106393 - ACCESS_ONCE(isight->pcm_active) = true;
106394 + ACCESS_ONCE_RW(isight->pcm_active) = true;
106395
106396 return 0;
106397 }
106398 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
106399 {
106400 struct isight *isight = substream->private_data;
106401
106402 - ACCESS_ONCE(isight->pcm_active) = false;
106403 + ACCESS_ONCE_RW(isight->pcm_active) = false;
106404
106405 mutex_lock(&isight->mutex);
106406 isight_stop_streaming(isight);
106407 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
106408
106409 switch (cmd) {
106410 case SNDRV_PCM_TRIGGER_START:
106411 - ACCESS_ONCE(isight->pcm_running) = true;
106412 + ACCESS_ONCE_RW(isight->pcm_running) = true;
106413 break;
106414 case SNDRV_PCM_TRIGGER_STOP:
106415 - ACCESS_ONCE(isight->pcm_running) = false;
106416 + ACCESS_ONCE_RW(isight->pcm_running) = false;
106417 break;
106418 default:
106419 return -EINVAL;
106420 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
106421 index 2dba848..c682aef 100644
106422 --- a/sound/firewire/scs1x.c
106423 +++ b/sound/firewire/scs1x.c
106424 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
106425 {
106426 struct scs *scs = stream->rmidi->private_data;
106427
106428 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
106429 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
106430 if (up) {
106431 scs->output_idle = false;
106432 tasklet_schedule(&scs->tasklet);
106433 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
106434 {
106435 struct scs *scs = stream->rmidi->private_data;
106436
106437 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
106438 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
106439 }
106440
106441 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
106442 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
106443
106444 snd_card_disconnect(scs->card);
106445
106446 - ACCESS_ONCE(scs->output) = NULL;
106447 - ACCESS_ONCE(scs->input) = NULL;
106448 + ACCESS_ONCE_RW(scs->output) = NULL;
106449 + ACCESS_ONCE_RW(scs->input) = NULL;
106450
106451 wait_event(scs->idle_wait, scs->output_idle);
106452
106453 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
106454 index 4e3fcfb..ab45a9d 100644
106455 --- a/sound/isa/sb/emu8000_synth.c
106456 +++ b/sound/isa/sb/emu8000_synth.c
106457 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
106458 {
106459
106460 static struct snd_seq_dev_ops ops = {
106461 - snd_emu8000_new_device,
106462 - snd_emu8000_delete_device,
106463 + .init_device = snd_emu8000_new_device,
106464 + .free_device = snd_emu8000_delete_device,
106465 };
106466 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
106467 sizeof(struct snd_emu8000*));
106468 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
106469 index 048439a..3be9f6f 100644
106470 --- a/sound/oss/sb_audio.c
106471 +++ b/sound/oss/sb_audio.c
106472 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
106473 buf16 = (signed short *)(localbuf + localoffs);
106474 while (c)
106475 {
106476 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106477 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106478 if (copy_from_user(lbuf8,
106479 userbuf+useroffs + p,
106480 locallen))
106481 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
106482 index f851fd0..92576fb 100644
106483 --- a/sound/oss/swarm_cs4297a.c
106484 +++ b/sound/oss/swarm_cs4297a.c
106485 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
106486 {
106487 struct cs4297a_state *s;
106488 u32 pwr, id;
106489 - mm_segment_t fs;
106490 int rval;
106491 #ifndef CONFIG_BCM_CS4297A_CSWARM
106492 u64 cfg;
106493 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
106494 if (!rval) {
106495 char *sb1250_duart_present;
106496
106497 +#if 0
106498 + mm_segment_t fs;
106499 fs = get_fs();
106500 set_fs(KERNEL_DS);
106501 -#if 0
106502 val = SOUND_MASK_LINE;
106503 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
106504 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
106505 val = initvol[i].vol;
106506 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
106507 }
106508 + set_fs(fs);
106509 // cs4297a_write_ac97(s, 0x18, 0x0808);
106510 #else
106511 // cs4297a_write_ac97(s, 0x5e, 0x180);
106512 cs4297a_write_ac97(s, 0x02, 0x0808);
106513 cs4297a_write_ac97(s, 0x18, 0x0808);
106514 #endif
106515 - set_fs(fs);
106516
106517 list_add(&s->list, &cs4297a_devs);
106518
106519 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
106520 index 4c41c90..37f3631 100644
106521 --- a/sound/pci/emu10k1/emu10k1_synth.c
106522 +++ b/sound/pci/emu10k1/emu10k1_synth.c
106523 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
106524 {
106525
106526 static struct snd_seq_dev_ops ops = {
106527 - snd_emu10k1_synth_new_device,
106528 - snd_emu10k1_synth_delete_device,
106529 + .init_device = snd_emu10k1_synth_new_device,
106530 + .free_device = snd_emu10k1_synth_delete_device,
106531 };
106532 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
106533 sizeof(struct snd_emu10k1_synth_arg));
106534 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
106535 index 4c20277..91abdce 100644
106536 --- a/sound/pci/hda/hda_codec.c
106537 +++ b/sound/pci/hda/hda_codec.c
106538 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
106539 mutex_unlock(&preset_mutex);
106540
106541 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
106542 - char name[32];
106543 if (!mod_requested)
106544 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
106545 - codec->vendor_id);
106546 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
106547 else
106548 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
106549 - (codec->vendor_id >> 16) & 0xffff);
106550 - request_module(name);
106551 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
106552 mod_requested++;
106553 goto again;
106554 }
106555 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
106556 /* FIXME: set_fs() hack for obtaining user-space TLV data */
106557 mm_segment_t fs = get_fs();
106558 set_fs(get_ds());
106559 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
106560 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
106561 tlv = _tlv;
106562 set_fs(fs);
106563 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
106564 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
106565 index 4631a23..001ae57 100644
106566 --- a/sound/pci/ymfpci/ymfpci.h
106567 +++ b/sound/pci/ymfpci/ymfpci.h
106568 @@ -358,7 +358,7 @@ struct snd_ymfpci {
106569 spinlock_t reg_lock;
106570 spinlock_t voice_lock;
106571 wait_queue_head_t interrupt_sleep;
106572 - atomic_t interrupt_sleep_count;
106573 + atomic_unchecked_t interrupt_sleep_count;
106574 struct snd_info_entry *proc_entry;
106575 const struct firmware *dsp_microcode;
106576 const struct firmware *controller_microcode;
106577 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
106578 index 81c916a..516f0bf 100644
106579 --- a/sound/pci/ymfpci/ymfpci_main.c
106580 +++ b/sound/pci/ymfpci/ymfpci_main.c
106581 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
106582 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
106583 break;
106584 }
106585 - if (atomic_read(&chip->interrupt_sleep_count)) {
106586 - atomic_set(&chip->interrupt_sleep_count, 0);
106587 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106588 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106589 wake_up(&chip->interrupt_sleep);
106590 }
106591 __end:
106592 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
106593 continue;
106594 init_waitqueue_entry(&wait, current);
106595 add_wait_queue(&chip->interrupt_sleep, &wait);
106596 - atomic_inc(&chip->interrupt_sleep_count);
106597 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
106598 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
106599 remove_wait_queue(&chip->interrupt_sleep, &wait);
106600 }
106601 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
106602 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
106603 spin_unlock(&chip->reg_lock);
106604
106605 - if (atomic_read(&chip->interrupt_sleep_count)) {
106606 - atomic_set(&chip->interrupt_sleep_count, 0);
106607 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106608 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106609 wake_up(&chip->interrupt_sleep);
106610 }
106611 }
106612 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
106613 spin_lock_init(&chip->reg_lock);
106614 spin_lock_init(&chip->voice_lock);
106615 init_waitqueue_head(&chip->interrupt_sleep);
106616 - atomic_set(&chip->interrupt_sleep_count, 0);
106617 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106618 chip->card = card;
106619 chip->pci = pci;
106620 chip->irq = -1;
106621 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
106622 index 5428a1f..474f651 100644
106623 --- a/sound/soc/fsl/fsl_ssi.c
106624 +++ b/sound/soc/fsl/fsl_ssi.c
106625 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106626 {
106627 struct fsl_ssi_private *ssi_private;
106628 int ret = 0;
106629 - struct device_attribute *dev_attr = NULL;
106630 struct device_node *np = pdev->dev.of_node;
106631 const struct of_device_id *of_id;
106632 enum fsl_ssi_type hw_type;
106633 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106634 &ssi_private->cpu_dai_drv, 1);
106635 if (ret) {
106636 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
106637 - goto error_dev;
106638 + goto error_clk;
106639 }
106640
106641 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
106642 @@ -1562,9 +1561,6 @@ error_pcm:
106643 error_dbgfs:
106644 snd_soc_unregister_component(&pdev->dev);
106645
106646 -error_dev:
106647 - device_remove_file(&pdev->dev, dev_attr);
106648 -
106649 error_clk:
106650 if (ssi_private->ssi_on_imx) {
106651 if (!IS_ERR(ssi_private->baudclk))
106652 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
106653 index 051c006..70598e8 100644
106654 --- a/sound/soc/soc-core.c
106655 +++ b/sound/soc/soc-core.c
106656 @@ -2255,8 +2255,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
106657 if (ret)
106658 return ret;
106659
106660 - ops->warm_reset = snd_soc_ac97_warm_reset;
106661 - ops->reset = snd_soc_ac97_reset;
106662 + pax_open_kernel();
106663 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
106664 + *(void **)&ops->reset = snd_soc_ac97_reset;
106665 + pax_close_kernel();
106666
106667 snd_ac97_rst_cfg = cfg;
106668 return 0;
106669 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
106670 index 7778b8e..3d619fc 100644
106671 --- a/sound/synth/emux/emux_seq.c
106672 +++ b/sound/synth/emux/emux_seq.c
106673 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
106674 * MIDI emulation operators
106675 */
106676 static struct snd_midi_op emux_ops = {
106677 - snd_emux_note_on,
106678 - snd_emux_note_off,
106679 - snd_emux_key_press,
106680 - snd_emux_terminate_note,
106681 - snd_emux_control,
106682 - snd_emux_nrpn,
106683 - snd_emux_sysex,
106684 + .note_on = snd_emux_note_on,
106685 + .note_off = snd_emux_note_off,
106686 + .key_press = snd_emux_key_press,
106687 + .note_terminate = snd_emux_terminate_note,
106688 + .control = snd_emux_control,
106689 + .nrpn = snd_emux_nrpn,
106690 + .sysex = snd_emux_sysex,
106691 };
106692
106693
106694 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
106695 new file mode 100644
106696 index 0000000..7b8921f
106697 --- /dev/null
106698 +++ b/tools/gcc/Makefile
106699 @@ -0,0 +1,52 @@
106700 +#CC := gcc
106701 +#PLUGIN_SOURCE_FILES := pax_plugin.c
106702 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
106703 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
106704 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
106705 +
106706 +ifeq ($(PLUGINCC),$(HOSTCC))
106707 +HOSTLIBS := hostlibs
106708 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
106709 +export HOST_EXTRACFLAGS
106710 +else
106711 +HOSTLIBS := hostcxxlibs
106712 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
106713 +export HOST_EXTRACXXFLAGS
106714 +endif
106715 +
106716 +export GCCPLUGINS_DIR HOSTLIBS
106717 +
106718 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
106719 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
106720 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
106721 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
106722 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
106723 +$(HOSTLIBS)-y += colorize_plugin.so
106724 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
106725 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
106726 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
106727 +
106728 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
106729 +subdir- += size_overflow_plugin
106730 +
106731 +always := $($(HOSTLIBS)-y)
106732 +
106733 +constify_plugin-objs := constify_plugin.o
106734 +stackleak_plugin-objs := stackleak_plugin.o
106735 +kallocstat_plugin-objs := kallocstat_plugin.o
106736 +kernexec_plugin-objs := kernexec_plugin.o
106737 +checker_plugin-objs := checker_plugin.o
106738 +colorize_plugin-objs := colorize_plugin.o
106739 +latent_entropy_plugin-objs := latent_entropy_plugin.o
106740 +structleak_plugin-objs := structleak_plugin.o
106741 +randomize_layout_plugin-objs := randomize_layout_plugin.o
106742 +
106743 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
106744 +
106745 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
106746 + cmd_create_randomize_layout_seed = \
106747 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
106748 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
106749 + $(call if_changed,create_randomize_layout_seed)
106750 +
106751 +targets += randomize_layout_seed.h randomize_layout_hash.h
106752 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
106753 new file mode 100644
106754 index 0000000..5452feea
106755 --- /dev/null
106756 +++ b/tools/gcc/checker_plugin.c
106757 @@ -0,0 +1,150 @@
106758 +/*
106759 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106760 + * Licensed under the GPL v2
106761 + *
106762 + * Note: the choice of the license means that the compilation process is
106763 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106764 + * but for the kernel it doesn't matter since it doesn't link against
106765 + * any of the gcc libraries
106766 + *
106767 + * gcc plugin to implement various sparse (source code checker) features
106768 + *
106769 + * TODO:
106770 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
106771 + *
106772 + * BUGS:
106773 + * - none known
106774 + */
106775 +
106776 +#include "gcc-common.h"
106777 +
106778 +extern void c_register_addr_space (const char *str, addr_space_t as);
106779 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
106780 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
106781 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
106782 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
106783 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
106784 +
106785 +int plugin_is_GPL_compatible;
106786 +
106787 +static struct plugin_info checker_plugin_info = {
106788 + .version = "201304082245",
106789 + .help = NULL,
106790 +};
106791 +
106792 +#define ADDR_SPACE_KERNEL 0
106793 +#define ADDR_SPACE_FORCE_KERNEL 1
106794 +#define ADDR_SPACE_USER 2
106795 +#define ADDR_SPACE_FORCE_USER 3
106796 +#define ADDR_SPACE_IOMEM 0
106797 +#define ADDR_SPACE_FORCE_IOMEM 0
106798 +#define ADDR_SPACE_PERCPU 0
106799 +#define ADDR_SPACE_FORCE_PERCPU 0
106800 +#define ADDR_SPACE_RCU 0
106801 +#define ADDR_SPACE_FORCE_RCU 0
106802 +
106803 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
106804 +{
106805 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
106806 +}
106807 +
106808 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
106809 +{
106810 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
106811 +}
106812 +
106813 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
106814 +{
106815 + return default_addr_space_valid_pointer_mode(mode, as);
106816 +}
106817 +
106818 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
106819 +{
106820 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
106821 +}
106822 +
106823 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
106824 +{
106825 + return default_addr_space_legitimize_address(x, oldx, mode, as);
106826 +}
106827 +
106828 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
106829 +{
106830 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
106831 + return true;
106832 +
106833 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
106834 + return true;
106835 +
106836 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
106837 + return true;
106838 +
106839 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
106840 + return true;
106841 +
106842 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
106843 + return true;
106844 +
106845 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
106846 + return true;
106847 +
106848 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
106849 + return true;
106850 +
106851 + return subset == superset;
106852 +}
106853 +
106854 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
106855 +{
106856 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
106857 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
106858 +
106859 + return op;
106860 +}
106861 +
106862 +static void register_checker_address_spaces(void *event_data, void *data)
106863 +{
106864 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
106865 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
106866 + c_register_addr_space("__user", ADDR_SPACE_USER);
106867 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
106868 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
106869 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
106870 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
106871 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
106872 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
106873 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
106874 +
106875 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
106876 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
106877 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
106878 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
106879 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
106880 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
106881 + targetm.addr_space.convert = checker_addr_space_convert;
106882 +}
106883 +
106884 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106885 +{
106886 + const char * const plugin_name = plugin_info->base_name;
106887 + const int argc = plugin_info->argc;
106888 + const struct plugin_argument * const argv = plugin_info->argv;
106889 + int i;
106890 +
106891 + if (!plugin_default_version_check(version, &gcc_version)) {
106892 + error(G_("incompatible gcc/plugin versions"));
106893 + return 1;
106894 + }
106895 +
106896 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
106897 +
106898 + for (i = 0; i < argc; ++i)
106899 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106900 +
106901 + if (TARGET_64BIT == 0)
106902 + return 0;
106903 +
106904 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
106905 +
106906 + return 0;
106907 +}
106908 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
106909 new file mode 100644
106910 index 0000000..54461af
106911 --- /dev/null
106912 +++ b/tools/gcc/colorize_plugin.c
106913 @@ -0,0 +1,210 @@
106914 +/*
106915 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
106916 + * Licensed under the GPL v2
106917 + *
106918 + * Note: the choice of the license means that the compilation process is
106919 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106920 + * but for the kernel it doesn't matter since it doesn't link against
106921 + * any of the gcc libraries
106922 + *
106923 + * gcc plugin to colorize diagnostic output
106924 + *
106925 + */
106926 +
106927 +#include "gcc-common.h"
106928 +
106929 +int plugin_is_GPL_compatible;
106930 +
106931 +static struct plugin_info colorize_plugin_info = {
106932 + .version = "201404202350",
106933 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
106934 +};
106935 +
106936 +#define GREEN "\033[32m\033[K"
106937 +#define LIGHTGREEN "\033[1;32m\033[K"
106938 +#define YELLOW "\033[33m\033[K"
106939 +#define LIGHTYELLOW "\033[1;33m\033[K"
106940 +#define RED "\033[31m\033[K"
106941 +#define LIGHTRED "\033[1;31m\033[K"
106942 +#define BLUE "\033[34m\033[K"
106943 +#define LIGHTBLUE "\033[1;34m\033[K"
106944 +#define BRIGHT "\033[1;m\033[K"
106945 +#define NORMAL "\033[m\033[K"
106946 +
106947 +static diagnostic_starter_fn old_starter;
106948 +static diagnostic_finalizer_fn old_finalizer;
106949 +
106950 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
106951 +{
106952 + const char *color;
106953 + char *newprefix;
106954 +
106955 + switch (diagnostic->kind) {
106956 + case DK_NOTE:
106957 + color = LIGHTBLUE;
106958 + break;
106959 +
106960 + case DK_PEDWARN:
106961 + case DK_WARNING:
106962 + color = LIGHTYELLOW;
106963 + break;
106964 +
106965 + case DK_ERROR:
106966 + case DK_FATAL:
106967 + case DK_ICE:
106968 + case DK_PERMERROR:
106969 + case DK_SORRY:
106970 + color = LIGHTRED;
106971 + break;
106972 +
106973 + default:
106974 + color = NORMAL;
106975 + }
106976 +
106977 + old_starter(context, diagnostic);
106978 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
106979 + return;
106980 + pp_destroy_prefix(context->printer);
106981 + pp_set_prefix(context->printer, newprefix);
106982 +}
106983 +
106984 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
106985 +{
106986 + old_finalizer(context, diagnostic);
106987 +}
106988 +
106989 +static void colorize_arm(void)
106990 +{
106991 + old_starter = diagnostic_starter(global_dc);
106992 + old_finalizer = diagnostic_finalizer(global_dc);
106993 +
106994 + diagnostic_starter(global_dc) = start_colorize;
106995 + diagnostic_finalizer(global_dc) = finalize_colorize;
106996 +}
106997 +
106998 +static unsigned int execute_colorize_rearm(void)
106999 +{
107000 + if (diagnostic_starter(global_dc) == start_colorize)
107001 + return 0;
107002 +
107003 + colorize_arm();
107004 + return 0;
107005 +}
107006 +
107007 +#if BUILDING_GCC_VERSION >= 4009
107008 +static const struct pass_data colorize_rearm_pass_data = {
107009 +#else
107010 +struct simple_ipa_opt_pass colorize_rearm_pass = {
107011 + .pass = {
107012 +#endif
107013 + .type = SIMPLE_IPA_PASS,
107014 + .name = "colorize_rearm",
107015 +#if BUILDING_GCC_VERSION >= 4008
107016 + .optinfo_flags = OPTGROUP_NONE,
107017 +#endif
107018 +#if BUILDING_GCC_VERSION >= 4009
107019 + .has_gate = false,
107020 + .has_execute = true,
107021 +#else
107022 + .gate = NULL,
107023 + .execute = execute_colorize_rearm,
107024 + .sub = NULL,
107025 + .next = NULL,
107026 + .static_pass_number = 0,
107027 +#endif
107028 + .tv_id = TV_NONE,
107029 + .properties_required = 0,
107030 + .properties_provided = 0,
107031 + .properties_destroyed = 0,
107032 + .todo_flags_start = 0,
107033 + .todo_flags_finish = 0
107034 +#if BUILDING_GCC_VERSION < 4009
107035 + }
107036 +#endif
107037 +};
107038 +
107039 +#if BUILDING_GCC_VERSION >= 4009
107040 +namespace {
107041 +class colorize_rearm_pass : public simple_ipa_opt_pass {
107042 +public:
107043 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
107044 + unsigned int execute() { return execute_colorize_rearm(); }
107045 +};
107046 +}
107047 +
107048 +static opt_pass *make_colorize_rearm_pass(void)
107049 +{
107050 + return new colorize_rearm_pass();
107051 +}
107052 +#else
107053 +static struct opt_pass *make_colorize_rearm_pass(void)
107054 +{
107055 + return &colorize_rearm_pass.pass;
107056 +}
107057 +#endif
107058 +
107059 +static void colorize_start_unit(void *gcc_data, void *user_data)
107060 +{
107061 + colorize_arm();
107062 +}
107063 +
107064 +static bool should_colorize(void)
107065 +{
107066 +#if BUILDING_GCC_VERSION >= 4009
107067 + return false;
107068 +#else
107069 + char const *t = getenv("TERM");
107070 +
107071 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
107072 +#endif
107073 +}
107074 +
107075 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107076 +{
107077 + const char * const plugin_name = plugin_info->base_name;
107078 + const int argc = plugin_info->argc;
107079 + const struct plugin_argument * const argv = plugin_info->argv;
107080 + int i;
107081 + struct register_pass_info colorize_rearm_pass_info;
107082 + bool colorize;
107083 +
107084 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
107085 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
107086 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
107087 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107088 +
107089 + if (!plugin_default_version_check(version, &gcc_version)) {
107090 + error(G_("incompatible gcc/plugin versions"));
107091 + return 1;
107092 + }
107093 +
107094 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
107095 +
107096 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
107097 +
107098 + for (i = 0; i < argc; ++i) {
107099 + if (!strcmp(argv[i].key, "color")) {
107100 + if (!argv[i].value) {
107101 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107102 + continue;
107103 + }
107104 + if (!strcmp(argv[i].value, "always"))
107105 + colorize = true;
107106 + else if (!strcmp(argv[i].value, "never"))
107107 + colorize = false;
107108 + else if (!strcmp(argv[i].value, "auto"))
107109 + colorize = should_colorize();
107110 + else
107111 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107112 + continue;
107113 + }
107114 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107115 + }
107116 +
107117 + if (colorize) {
107118 + // TODO: parse GCC_COLORS as used by gcc 4.9+
107119 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
107120 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
107121 + }
107122 + return 0;
107123 +}
107124 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
107125 new file mode 100644
107126 index 0000000..82bc5a8
107127 --- /dev/null
107128 +++ b/tools/gcc/constify_plugin.c
107129 @@ -0,0 +1,557 @@
107130 +/*
107131 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
107132 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
107133 + * Licensed under the GPL v2, or (at your option) v3
107134 + *
107135 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
107136 + *
107137 + * Homepage:
107138 + * http://www.grsecurity.net/~ephox/const_plugin/
107139 + *
107140 + * Usage:
107141 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
107142 + * $ gcc -fplugin=constify_plugin.so test.c -O2
107143 + */
107144 +
107145 +#include "gcc-common.h"
107146 +
107147 +// unused C type flag in all versions 4.5-4.9
107148 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
107149 +
107150 +int plugin_is_GPL_compatible;
107151 +
107152 +static struct plugin_info const_plugin_info = {
107153 + .version = "201401270210",
107154 + .help = "no-constify\tturn off constification\n",
107155 +};
107156 +
107157 +typedef struct {
107158 + bool has_fptr_field;
107159 + bool has_writable_field;
107160 + bool has_do_const_field;
107161 + bool has_no_const_field;
107162 +} constify_info;
107163 +
107164 +static const_tree get_field_type(const_tree field)
107165 +{
107166 + return strip_array_types(TREE_TYPE(field));
107167 +}
107168 +
107169 +static bool is_fptr(const_tree field)
107170 +{
107171 + const_tree ptr = get_field_type(field);
107172 +
107173 + if (TREE_CODE(ptr) != POINTER_TYPE)
107174 + return false;
107175 +
107176 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
107177 +}
107178 +
107179 +/*
107180 + * determine whether the given structure type meets the requirements for automatic constification,
107181 + * including the constification attributes on nested structure types
107182 + */
107183 +static void constifiable(const_tree node, constify_info *cinfo)
107184 +{
107185 + const_tree field;
107186 +
107187 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107188 +
107189 + // e.g., pointer to structure fields while still constructing the structure type
107190 + if (TYPE_FIELDS(node) == NULL_TREE)
107191 + return;
107192 +
107193 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107194 + const_tree type = get_field_type(field);
107195 + enum tree_code code = TREE_CODE(type);
107196 +
107197 + if (node == type)
107198 + continue;
107199 +
107200 + if (is_fptr(field))
107201 + cinfo->has_fptr_field = true;
107202 + else if (!TREE_READONLY(field))
107203 + cinfo->has_writable_field = true;
107204 +
107205 + if (code == RECORD_TYPE || code == UNION_TYPE) {
107206 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107207 + cinfo->has_do_const_field = true;
107208 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
107209 + cinfo->has_no_const_field = true;
107210 + else
107211 + constifiable(type, cinfo);
107212 + }
107213 + }
107214 +}
107215 +
107216 +static bool constified(const_tree node)
107217 +{
107218 + constify_info cinfo = {
107219 + .has_fptr_field = false,
107220 + .has_writable_field = false,
107221 + .has_do_const_field = false,
107222 + .has_no_const_field = false
107223 + };
107224 +
107225 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107226 +
107227 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
107228 +// gcc_assert(!TYPE_READONLY(node));
107229 + return false;
107230 + }
107231 +
107232 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
107233 + gcc_assert(TYPE_READONLY(node));
107234 + return true;
107235 + }
107236 +
107237 + constifiable(node, &cinfo);
107238 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
107239 + return false;
107240 +
107241 + return TYPE_READONLY(node);
107242 +}
107243 +
107244 +static void deconstify_tree(tree node);
107245 +
107246 +static void deconstify_type(tree type)
107247 +{
107248 + tree field;
107249 +
107250 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
107251 +
107252 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107253 + const_tree fieldtype = get_field_type(field);
107254 +
107255 + // special case handling of simple ptr-to-same-array-type members
107256 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
107257 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
107258 +
107259 + if (TREE_TYPE(TREE_TYPE(field)) == type)
107260 + continue;
107261 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
107262 + continue;
107263 + if (!constified(ptrtype))
107264 + continue;
107265 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
107266 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
107267 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
107268 + }
107269 + continue;
107270 + }
107271 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
107272 + continue;
107273 + if (!constified(fieldtype))
107274 + continue;
107275 +
107276 + deconstify_tree(field);
107277 + TREE_READONLY(field) = 0;
107278 + }
107279 + TYPE_READONLY(type) = 0;
107280 + C_TYPE_FIELDS_READONLY(type) = 0;
107281 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107282 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107283 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107284 + }
107285 +}
107286 +
107287 +static void deconstify_tree(tree node)
107288 +{
107289 + tree old_type, new_type, field;
107290 +
107291 + old_type = TREE_TYPE(node);
107292 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107293 + node = TREE_TYPE(node) = copy_node(old_type);
107294 + old_type = TREE_TYPE(old_type);
107295 + }
107296 +
107297 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107298 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107299 +
107300 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107301 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107302 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107303 + DECL_FIELD_CONTEXT(field) = new_type;
107304 +
107305 + deconstify_type(new_type);
107306 +
107307 + TREE_TYPE(node) = new_type;
107308 +}
107309 +
107310 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107311 +{
107312 + tree type;
107313 + constify_info cinfo = {
107314 + .has_fptr_field = false,
107315 + .has_writable_field = false,
107316 + .has_do_const_field = false,
107317 + .has_no_const_field = false
107318 + };
107319 +
107320 + *no_add_attrs = true;
107321 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107322 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107323 + return NULL_TREE;
107324 + }
107325 +
107326 + if (TREE_CODE(*node) == PARM_DECL) {
107327 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107328 + return NULL_TREE;
107329 + }
107330 +
107331 + if (TREE_CODE(*node) == VAR_DECL) {
107332 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107333 + return NULL_TREE;
107334 + }
107335 +
107336 + if (TYPE_P(*node)) {
107337 + type = *node;
107338 + } else {
107339 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107340 + type = TREE_TYPE(*node);
107341 + }
107342 +
107343 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
107344 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
107345 + return NULL_TREE;
107346 + }
107347 +
107348 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107349 + error("%qE attribute is already applied to the type %qT", name, type);
107350 + return NULL_TREE;
107351 + }
107352 +
107353 + if (TYPE_P(*node)) {
107354 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107355 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
107356 + else
107357 + *no_add_attrs = false;
107358 + return NULL_TREE;
107359 + }
107360 +
107361 + constifiable(type, &cinfo);
107362 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107363 + deconstify_tree(*node);
107364 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
107365 + return NULL_TREE;
107366 + }
107367 +
107368 + error("%qE attribute used on type %qT that is not constified", name, type);
107369 + return NULL_TREE;
107370 +}
107371 +
107372 +static void constify_type(tree type)
107373 +{
107374 + TYPE_READONLY(type) = 1;
107375 + C_TYPE_FIELDS_READONLY(type) = 1;
107376 + TYPE_CONSTIFY_VISITED(type) = 1;
107377 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107378 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
107379 +}
107380 +
107381 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107382 +{
107383 + *no_add_attrs = true;
107384 + if (!TYPE_P(*node)) {
107385 + error("%qE attribute applies to types only (%qD)", name, *node);
107386 + return NULL_TREE;
107387 + }
107388 +
107389 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
107390 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
107391 + return NULL_TREE;
107392 + }
107393 +
107394 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
107395 + error("%qE attribute used on %qT is already applied to the type", name, *node);
107396 + return NULL_TREE;
107397 + }
107398 +
107399 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
107400 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
107401 + return NULL_TREE;
107402 + }
107403 +
107404 + *no_add_attrs = false;
107405 + return NULL_TREE;
107406 +}
107407 +
107408 +static struct attribute_spec no_const_attr = {
107409 + .name = "no_const",
107410 + .min_length = 0,
107411 + .max_length = 0,
107412 + .decl_required = false,
107413 + .type_required = false,
107414 + .function_type_required = false,
107415 + .handler = handle_no_const_attribute,
107416 +#if BUILDING_GCC_VERSION >= 4007
107417 + .affects_type_identity = true
107418 +#endif
107419 +};
107420 +
107421 +static struct attribute_spec do_const_attr = {
107422 + .name = "do_const",
107423 + .min_length = 0,
107424 + .max_length = 0,
107425 + .decl_required = false,
107426 + .type_required = false,
107427 + .function_type_required = false,
107428 + .handler = handle_do_const_attribute,
107429 +#if BUILDING_GCC_VERSION >= 4007
107430 + .affects_type_identity = true
107431 +#endif
107432 +};
107433 +
107434 +static void register_attributes(void *event_data, void *data)
107435 +{
107436 + register_attribute(&no_const_attr);
107437 + register_attribute(&do_const_attr);
107438 +}
107439 +
107440 +static void finish_type(void *event_data, void *data)
107441 +{
107442 + tree type = (tree)event_data;
107443 + constify_info cinfo = {
107444 + .has_fptr_field = false,
107445 + .has_writable_field = false,
107446 + .has_do_const_field = false,
107447 + .has_no_const_field = false
107448 + };
107449 +
107450 + if (type == NULL_TREE || type == error_mark_node)
107451 + return;
107452 +
107453 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
107454 + return;
107455 +
107456 + constifiable(type, &cinfo);
107457 +
107458 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
107459 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
107460 + deconstify_type(type);
107461 + TYPE_CONSTIFY_VISITED(type) = 1;
107462 + } else
107463 + error("'no_const' attribute used on type %qT that is not constified", type);
107464 + return;
107465 + }
107466 +
107467 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107468 + if (!cinfo.has_writable_field) {
107469 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
107470 + return;
107471 + }
107472 + constify_type(type);
107473 + return;
107474 + }
107475 +
107476 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
107477 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107478 + error("'do_const' attribute used on type %qT that is constified", type);
107479 + return;
107480 + }
107481 + constify_type(type);
107482 + return;
107483 + }
107484 +
107485 + deconstify_type(type);
107486 + TYPE_CONSTIFY_VISITED(type) = 1;
107487 +}
107488 +
107489 +static void check_global_variables(void *event_data, void *data)
107490 +{
107491 +#if BUILDING_GCC_VERSION >= 4009
107492 + varpool_node *node;
107493 +#else
107494 + struct varpool_node *node;
107495 +#endif
107496 +
107497 + FOR_EACH_VARIABLE(node) {
107498 + tree var = NODE_DECL(node);
107499 + tree type = TREE_TYPE(var);
107500 +
107501 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107502 + continue;
107503 +
107504 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107505 + continue;
107506 +
107507 + if (!TYPE_CONSTIFY_VISITED(type))
107508 + continue;
107509 +
107510 + if (DECL_EXTERNAL(var))
107511 + continue;
107512 +
107513 + if (DECL_INITIAL(var))
107514 + continue;
107515 +
107516 + // this works around a gcc bug/feature where uninitialized globals
107517 + // are moved into the .bss section regardless of any constification
107518 + DECL_INITIAL(var) = build_constructor(type, NULL);
107519 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
107520 + }
107521 +}
107522 +
107523 +static unsigned int check_local_variables(void)
107524 +{
107525 + unsigned int ret = 0;
107526 + tree var;
107527 +
107528 + unsigned int i;
107529 +
107530 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
107531 + tree type = TREE_TYPE(var);
107532 +
107533 + gcc_assert(DECL_P(var));
107534 + if (is_global_var(var))
107535 + continue;
107536 +
107537 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107538 + continue;
107539 +
107540 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107541 + continue;
107542 +
107543 + if (!TYPE_CONSTIFY_VISITED(type))
107544 + continue;
107545 +
107546 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
107547 + ret = 1;
107548 + }
107549 + return ret;
107550 +}
107551 +
107552 +#if BUILDING_GCC_VERSION >= 4009
107553 +static const struct pass_data check_local_variables_pass_data = {
107554 +#else
107555 +static struct gimple_opt_pass check_local_variables_pass = {
107556 + .pass = {
107557 +#endif
107558 + .type = GIMPLE_PASS,
107559 + .name = "check_local_variables",
107560 +#if BUILDING_GCC_VERSION >= 4008
107561 + .optinfo_flags = OPTGROUP_NONE,
107562 +#endif
107563 +#if BUILDING_GCC_VERSION >= 4009
107564 + .has_gate = false,
107565 + .has_execute = true,
107566 +#else
107567 + .gate = NULL,
107568 + .execute = check_local_variables,
107569 + .sub = NULL,
107570 + .next = NULL,
107571 + .static_pass_number = 0,
107572 +#endif
107573 + .tv_id = TV_NONE,
107574 + .properties_required = 0,
107575 + .properties_provided = 0,
107576 + .properties_destroyed = 0,
107577 + .todo_flags_start = 0,
107578 + .todo_flags_finish = 0
107579 +#if BUILDING_GCC_VERSION < 4009
107580 + }
107581 +#endif
107582 +};
107583 +
107584 +#if BUILDING_GCC_VERSION >= 4009
107585 +namespace {
107586 +class check_local_variables_pass : public gimple_opt_pass {
107587 +public:
107588 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
107589 + unsigned int execute() { return check_local_variables(); }
107590 +};
107591 +}
107592 +
107593 +static opt_pass *make_check_local_variables_pass(void)
107594 +{
107595 + return new check_local_variables_pass();
107596 +}
107597 +#else
107598 +static struct opt_pass *make_check_local_variables_pass(void)
107599 +{
107600 + return &check_local_variables_pass.pass;
107601 +}
107602 +#endif
107603 +
107604 +static struct {
107605 + const char *name;
107606 + const char *asm_op;
107607 +} sections[] = {
107608 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
107609 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
107610 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
107611 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
107612 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
107613 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
107614 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
107615 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
107616 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
107617 +};
107618 +
107619 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
107620 +
107621 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
107622 +{
107623 + size_t i;
107624 +
107625 + for (i = 0; i < ARRAY_SIZE(sections); i++)
107626 + if (!strcmp(sections[i].name, name))
107627 + return 0;
107628 + return old_section_type_flags(decl, name, reloc);
107629 +}
107630 +
107631 +static void constify_start_unit(void *gcc_data, void *user_data)
107632 +{
107633 +// size_t i;
107634 +
107635 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
107636 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
107637 +// sections[i].section = get_section(sections[i].name, 0, NULL);
107638 +
107639 + old_section_type_flags = targetm.section_type_flags;
107640 + targetm.section_type_flags = constify_section_type_flags;
107641 +}
107642 +
107643 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107644 +{
107645 + const char * const plugin_name = plugin_info->base_name;
107646 + const int argc = plugin_info->argc;
107647 + const struct plugin_argument * const argv = plugin_info->argv;
107648 + int i;
107649 + bool constify = true;
107650 +
107651 + struct register_pass_info check_local_variables_pass_info;
107652 +
107653 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
107654 + check_local_variables_pass_info.reference_pass_name = "ssa";
107655 + check_local_variables_pass_info.ref_pass_instance_number = 1;
107656 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107657 +
107658 + if (!plugin_default_version_check(version, &gcc_version)) {
107659 + error(G_("incompatible gcc/plugin versions"));
107660 + return 1;
107661 + }
107662 +
107663 + for (i = 0; i < argc; ++i) {
107664 + if (!(strcmp(argv[i].key, "no-constify"))) {
107665 + constify = false;
107666 + continue;
107667 + }
107668 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107669 + }
107670 +
107671 + if (strcmp(lang_hooks.name, "GNU C")) {
107672 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
107673 + constify = false;
107674 + }
107675 +
107676 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
107677 + if (constify) {
107678 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
107679 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
107680 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
107681 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
107682 + }
107683 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107684 +
107685 + return 0;
107686 +}
107687 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
107688 new file mode 100644
107689 index 0000000..e90c205
107690 --- /dev/null
107691 +++ b/tools/gcc/gcc-common.h
107692 @@ -0,0 +1,295 @@
107693 +#ifndef GCC_COMMON_H_INCLUDED
107694 +#define GCC_COMMON_H_INCLUDED
107695 +
107696 +#include "plugin.h"
107697 +#include "bversion.h"
107698 +#include "plugin-version.h"
107699 +#include "config.h"
107700 +#include "system.h"
107701 +#include "coretypes.h"
107702 +#include "tm.h"
107703 +#include "line-map.h"
107704 +#include "input.h"
107705 +#include "tree.h"
107706 +
107707 +#include "tree-inline.h"
107708 +#include "version.h"
107709 +#include "rtl.h"
107710 +#include "tm_p.h"
107711 +#include "flags.h"
107712 +//#include "insn-attr.h"
107713 +//#include "insn-config.h"
107714 +//#include "insn-flags.h"
107715 +#include "hard-reg-set.h"
107716 +//#include "recog.h"
107717 +#include "output.h"
107718 +#include "except.h"
107719 +#include "function.h"
107720 +#include "toplev.h"
107721 +//#include "expr.h"
107722 +#include "basic-block.h"
107723 +#include "intl.h"
107724 +#include "ggc.h"
107725 +//#include "regs.h"
107726 +#include "timevar.h"
107727 +
107728 +#include "params.h"
107729 +#include "pointer-set.h"
107730 +#include "emit-rtl.h"
107731 +//#include "reload.h"
107732 +//#include "ira.h"
107733 +//#include "dwarf2asm.h"
107734 +#include "debug.h"
107735 +#include "target.h"
107736 +#include "langhooks.h"
107737 +#include "cfgloop.h"
107738 +//#include "hosthooks.h"
107739 +#include "cgraph.h"
107740 +#include "opts.h"
107741 +//#include "coverage.h"
107742 +//#include "value-prof.h"
107743 +
107744 +#if BUILDING_GCC_VERSION >= 4007
107745 +#include "tree-pretty-print.h"
107746 +#include "gimple-pretty-print.h"
107747 +#include "c-tree.h"
107748 +//#include "alloc-pool.h"
107749 +#endif
107750 +
107751 +#if BUILDING_GCC_VERSION <= 4008
107752 +#include "tree-flow.h"
107753 +#else
107754 +#include "tree-cfgcleanup.h"
107755 +#endif
107756 +
107757 +#include "diagnostic.h"
107758 +//#include "tree-diagnostic.h"
107759 +#include "tree-dump.h"
107760 +#include "tree-pass.h"
107761 +//#include "df.h"
107762 +#include "predict.h"
107763 +#include "ipa-utils.h"
107764 +
107765 +#if BUILDING_GCC_VERSION >= 4009
107766 +#include "varasm.h"
107767 +#include "stor-layout.h"
107768 +#include "internal-fn.h"
107769 +#include "gimple-expr.h"
107770 +//#include "diagnostic-color.h"
107771 +#include "context.h"
107772 +#include "tree-ssa-alias.h"
107773 +#include "stringpool.h"
107774 +#include "tree-ssanames.h"
107775 +#include "print-tree.h"
107776 +#include "tree-eh.h"
107777 +#include "stmt.h"
107778 +#endif
107779 +
107780 +#include "gimple.h"
107781 +
107782 +#if BUILDING_GCC_VERSION >= 4009
107783 +#include "tree-ssa-operands.h"
107784 +#include "tree-phinodes.h"
107785 +#include "tree-cfg.h"
107786 +#include "gimple-iterator.h"
107787 +#include "gimple-ssa.h"
107788 +#include "ssa-iterators.h"
107789 +#endif
107790 +
107791 +//#include "lto/lto.h"
107792 +//#include "data-streamer.h"
107793 +//#include "lto-compress.h"
107794 +
107795 +//#include "expr.h" where are you...
107796 +extern rtx emit_move_insn(rtx x, rtx y);
107797 +
107798 +// missing from basic_block.h...
107799 +extern void debug_dominance_info(enum cdi_direction dir);
107800 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
107801 +
107802 +#define __unused __attribute__((__unused__))
107803 +
107804 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
107805 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
107806 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
107807 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
107808 +
107809 +#if BUILDING_GCC_VERSION == 4005
107810 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
107811 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
107812 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
107813 +#define TODO_rebuild_cgraph_edges 0
107814 +
107815 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
107816 +{
107817 + tree fndecl;
107818 +
107819 + if (!is_gimple_call(stmt))
107820 + return false;
107821 + fndecl = gimple_call_fndecl(stmt);
107822 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
107823 + return false;
107824 +// print_node(stderr, "pax", fndecl, 4);
107825 + return DECL_FUNCTION_CODE(fndecl) == code;
107826 +}
107827 +
107828 +static inline bool is_simple_builtin(tree decl)
107829 +{
107830 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
107831 + return false;
107832 +
107833 + switch (DECL_FUNCTION_CODE(decl)) {
107834 + /* Builtins that expand to constants. */
107835 + case BUILT_IN_CONSTANT_P:
107836 + case BUILT_IN_EXPECT:
107837 + case BUILT_IN_OBJECT_SIZE:
107838 + case BUILT_IN_UNREACHABLE:
107839 + /* Simple register moves or loads from stack. */
107840 + case BUILT_IN_RETURN_ADDRESS:
107841 + case BUILT_IN_EXTRACT_RETURN_ADDR:
107842 + case BUILT_IN_FROB_RETURN_ADDR:
107843 + case BUILT_IN_RETURN:
107844 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
107845 + case BUILT_IN_FRAME_ADDRESS:
107846 + case BUILT_IN_VA_END:
107847 + case BUILT_IN_STACK_SAVE:
107848 + case BUILT_IN_STACK_RESTORE:
107849 + /* Exception state returns or moves registers around. */
107850 + case BUILT_IN_EH_FILTER:
107851 + case BUILT_IN_EH_POINTER:
107852 + case BUILT_IN_EH_COPY_VALUES:
107853 + return true;
107854 +
107855 + default:
107856 + return false;
107857 + }
107858 +}
107859 +#endif
107860 +
107861 +#if BUILDING_GCC_VERSION <= 4006
107862 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
107863 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
107864 +
107865 +// should come from c-tree.h if only it were installed for gcc 4.5...
107866 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
107867 +
107868 +#define get_random_seed(noinit) ({ \
107869 + unsigned HOST_WIDE_INT seed; \
107870 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
107871 + seed * seed; })
107872 +
107873 +static inline bool gimple_clobber_p(gimple s)
107874 +{
107875 + return false;
107876 +}
107877 +
107878 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
107879 +{
107880 + return implicit_built_in_decls[fncode];
107881 +}
107882 +
107883 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
107884 +{
107885 + struct cgraph_node *node = cgraph_get_node(decl);
107886 +
107887 + return node ? node : cgraph_node(decl);
107888 +}
107889 +
107890 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
107891 +{
107892 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
107893 +}
107894 +
107895 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
107896 +{
107897 + struct cgraph_node *node;
107898 +
107899 + for (node = cgraph_nodes; node; node = node->next)
107900 + if (cgraph_function_with_gimple_body_p(node))
107901 + return node;
107902 + return NULL;
107903 +}
107904 +
107905 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
107906 +{
107907 + for (node = node->next; node; node = node->next)
107908 + if (cgraph_function_with_gimple_body_p(node))
107909 + return node;
107910 + return NULL;
107911 +}
107912 +
107913 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
107914 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
107915 + (node) = cgraph_next_function_with_gimple_body(node))
107916 +#endif
107917 +
107918 +#if BUILDING_GCC_VERSION == 4006
107919 +extern void debug_gimple_stmt(gimple);
107920 +extern void debug_gimple_seq(gimple_seq);
107921 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
107922 +extern void print_gimple_stmt(FILE *, gimple, int, int);
107923 +extern void print_gimple_expr(FILE *, gimple, int, int);
107924 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
107925 +#endif
107926 +
107927 +#if BUILDING_GCC_VERSION <= 4007
107928 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
107929 +#define PROP_loops 0
107930 +
107931 +static inline int bb_loop_depth(const_basic_block bb)
107932 +{
107933 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
107934 +}
107935 +
107936 +static inline bool gimple_store_p(gimple gs)
107937 +{
107938 + tree lhs = gimple_get_lhs(gs);
107939 + return lhs && !is_gimple_reg(lhs);
107940 +}
107941 +#endif
107942 +
107943 +#if BUILDING_GCC_VERSION >= 4007
107944 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
107945 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
107946 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
107947 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
107948 +#endif
107949 +
107950 +#if BUILDING_GCC_VERSION <= 4008
107951 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
107952 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
107953 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
107954 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
107955 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
107956 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
107957 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
107958 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
107959 +
107960 +static inline const char *get_tree_code_name(enum tree_code code)
107961 +{
107962 + gcc_assert(code < MAX_TREE_CODES);
107963 + return tree_code_name[code];
107964 +}
107965 +
107966 +#define ipa_remove_stmt_references(cnode, stmt)
107967 +#endif
107968 +
107969 +#if BUILDING_GCC_VERSION == 4008
107970 +#define NODE_DECL(node) node->symbol.decl
107971 +#else
107972 +#define NODE_DECL(node) node->decl
107973 +#endif
107974 +
107975 +#if BUILDING_GCC_VERSION >= 4008
107976 +#define add_referenced_var(var)
107977 +#define mark_sym_for_renaming(var)
107978 +#define varpool_mark_needed_node(node)
107979 +#define TODO_dump_func 0
107980 +#define TODO_dump_cgraph 0
107981 +#endif
107982 +
107983 +#if BUILDING_GCC_VERSION >= 4009
107984 +#define TODO_ggc_collect 0
107985 +#endif
107986 +
107987 +#endif
107988 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
107989 new file mode 100644
107990 index 0000000..7514850
107991 --- /dev/null
107992 +++ b/tools/gcc/gen-random-seed.sh
107993 @@ -0,0 +1,8 @@
107994 +#!/bin/sh
107995 +
107996 +if [ ! -f "$1" ]; then
107997 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
107998 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
107999 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
108000 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
108001 +fi
108002 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
108003 new file mode 100644
108004 index 0000000..d81c094
108005 --- /dev/null
108006 +++ b/tools/gcc/kallocstat_plugin.c
108007 @@ -0,0 +1,183 @@
108008 +/*
108009 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108010 + * Licensed under the GPL v2
108011 + *
108012 + * Note: the choice of the license means that the compilation process is
108013 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108014 + * but for the kernel it doesn't matter since it doesn't link against
108015 + * any of the gcc libraries
108016 + *
108017 + * gcc plugin to find the distribution of k*alloc sizes
108018 + *
108019 + * TODO:
108020 + *
108021 + * BUGS:
108022 + * - none known
108023 + */
108024 +
108025 +#include "gcc-common.h"
108026 +
108027 +int plugin_is_GPL_compatible;
108028 +
108029 +static struct plugin_info kallocstat_plugin_info = {
108030 + .version = "201401260140",
108031 + .help = NULL
108032 +};
108033 +
108034 +static const char * const kalloc_functions[] = {
108035 + "__kmalloc",
108036 + "kmalloc",
108037 + "kmalloc_large",
108038 + "kmalloc_node",
108039 + "kmalloc_order",
108040 + "kmalloc_order_trace",
108041 + "kmalloc_slab",
108042 + "kzalloc",
108043 + "kzalloc_node",
108044 +};
108045 +
108046 +static bool is_kalloc(const char *fnname)
108047 +{
108048 + size_t i;
108049 +
108050 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
108051 + if (!strcmp(fnname, kalloc_functions[i]))
108052 + return true;
108053 + return false;
108054 +}
108055 +
108056 +static unsigned int execute_kallocstat(void)
108057 +{
108058 + basic_block bb;
108059 +
108060 + // 1. loop through BBs and GIMPLE statements
108061 + FOR_EACH_BB_FN(bb, cfun) {
108062 + gimple_stmt_iterator gsi;
108063 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108064 + // gimple match:
108065 + tree fndecl, size;
108066 + gimple stmt;
108067 + const char *fnname;
108068 +
108069 + // is it a call
108070 + stmt = gsi_stmt(gsi);
108071 + if (!is_gimple_call(stmt))
108072 + continue;
108073 + fndecl = gimple_call_fndecl(stmt);
108074 + if (fndecl == NULL_TREE)
108075 + continue;
108076 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
108077 + continue;
108078 +
108079 + // is it a call to k*alloc
108080 + fnname = DECL_NAME_POINTER(fndecl);
108081 + if (!is_kalloc(fnname))
108082 + continue;
108083 +
108084 + // is the size arg const or the result of a simple const assignment
108085 + size = gimple_call_arg(stmt, 0);
108086 + while (true) {
108087 + expanded_location xloc;
108088 + size_t size_val;
108089 +
108090 + if (TREE_CONSTANT(size)) {
108091 + xloc = expand_location(gimple_location(stmt));
108092 + if (!xloc.file)
108093 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
108094 + size_val = TREE_INT_CST_LOW(size);
108095 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
108096 + break;
108097 + }
108098 +
108099 + if (TREE_CODE(size) != SSA_NAME)
108100 + break;
108101 + stmt = SSA_NAME_DEF_STMT(size);
108102 +//debug_gimple_stmt(stmt);
108103 +//debug_tree(size);
108104 + if (!stmt || !is_gimple_assign(stmt))
108105 + break;
108106 + if (gimple_num_ops(stmt) != 2)
108107 + break;
108108 + size = gimple_assign_rhs1(stmt);
108109 + }
108110 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108111 +//debug_tree(gimple_call_fn(call_stmt));
108112 +//print_node(stderr, "pax", fndecl, 4);
108113 + }
108114 + }
108115 +
108116 + return 0;
108117 +}
108118 +
108119 +#if BUILDING_GCC_VERSION >= 4009
108120 +static const struct pass_data kallocstat_pass_data = {
108121 +#else
108122 +static struct gimple_opt_pass kallocstat_pass = {
108123 + .pass = {
108124 +#endif
108125 + .type = GIMPLE_PASS,
108126 + .name = "kallocstat",
108127 +#if BUILDING_GCC_VERSION >= 4008
108128 + .optinfo_flags = OPTGROUP_NONE,
108129 +#endif
108130 +#if BUILDING_GCC_VERSION >= 4009
108131 + .has_gate = false,
108132 + .has_execute = true,
108133 +#else
108134 + .gate = NULL,
108135 + .execute = execute_kallocstat,
108136 + .sub = NULL,
108137 + .next = NULL,
108138 + .static_pass_number = 0,
108139 +#endif
108140 + .tv_id = TV_NONE,
108141 + .properties_required = 0,
108142 + .properties_provided = 0,
108143 + .properties_destroyed = 0,
108144 + .todo_flags_start = 0,
108145 + .todo_flags_finish = 0
108146 +#if BUILDING_GCC_VERSION < 4009
108147 + }
108148 +#endif
108149 +};
108150 +
108151 +#if BUILDING_GCC_VERSION >= 4009
108152 +namespace {
108153 +class kallocstat_pass : public gimple_opt_pass {
108154 +public:
108155 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
108156 + unsigned int execute() { return execute_kallocstat(); }
108157 +};
108158 +}
108159 +
108160 +static opt_pass *make_kallocstat_pass(void)
108161 +{
108162 + return new kallocstat_pass();
108163 +}
108164 +#else
108165 +static struct opt_pass *make_kallocstat_pass(void)
108166 +{
108167 + return &kallocstat_pass.pass;
108168 +}
108169 +#endif
108170 +
108171 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108172 +{
108173 + const char * const plugin_name = plugin_info->base_name;
108174 + struct register_pass_info kallocstat_pass_info;
108175 +
108176 + kallocstat_pass_info.pass = make_kallocstat_pass();
108177 + kallocstat_pass_info.reference_pass_name = "ssa";
108178 + kallocstat_pass_info.ref_pass_instance_number = 1;
108179 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108180 +
108181 + if (!plugin_default_version_check(version, &gcc_version)) {
108182 + error(G_("incompatible gcc/plugin versions"));
108183 + return 1;
108184 + }
108185 +
108186 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
108187 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
108188 +
108189 + return 0;
108190 +}
108191 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
108192 new file mode 100644
108193 index 0000000..89f256d
108194 --- /dev/null
108195 +++ b/tools/gcc/kernexec_plugin.c
108196 @@ -0,0 +1,522 @@
108197 +/*
108198 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108199 + * Licensed under the GPL v2
108200 + *
108201 + * Note: the choice of the license means that the compilation process is
108202 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108203 + * but for the kernel it doesn't matter since it doesn't link against
108204 + * any of the gcc libraries
108205 + *
108206 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
108207 + *
108208 + * TODO:
108209 + *
108210 + * BUGS:
108211 + * - none known
108212 + */
108213 +
108214 +#include "gcc-common.h"
108215 +
108216 +int plugin_is_GPL_compatible;
108217 +
108218 +static struct plugin_info kernexec_plugin_info = {
108219 + .version = "201401260140",
108220 + .help = "method=[bts|or]\tinstrumentation method\n"
108221 +};
108222 +
108223 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
108224 +static void (*kernexec_instrument_retaddr)(rtx);
108225 +
108226 +/*
108227 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
108228 + */
108229 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
108230 +{
108231 + gimple asm_movabs_stmt;
108232 +
108233 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
108234 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
108235 + gimple_asm_set_volatile(asm_movabs_stmt, true);
108236 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
108237 + update_stmt(asm_movabs_stmt);
108238 +}
108239 +
108240 +/*
108241 + * find all asm() stmts that clobber r12 and add a reload of r12
108242 + */
108243 +static unsigned int execute_kernexec_reload(void)
108244 +{
108245 + basic_block bb;
108246 +
108247 + // 1. loop through BBs and GIMPLE statements
108248 + FOR_EACH_BB_FN(bb, cfun) {
108249 + gimple_stmt_iterator gsi;
108250 +
108251 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108252 + // gimple match: __asm__ ("" : : : "r12");
108253 + gimple asm_stmt;
108254 + size_t nclobbers;
108255 +
108256 + // is it an asm ...
108257 + asm_stmt = gsi_stmt(gsi);
108258 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
108259 + continue;
108260 +
108261 + // ... clobbering r12
108262 + nclobbers = gimple_asm_nclobbers(asm_stmt);
108263 + while (nclobbers--) {
108264 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
108265 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
108266 + continue;
108267 + kernexec_reload_fptr_mask(&gsi);
108268 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
108269 + break;
108270 + }
108271 + }
108272 + }
108273 +
108274 + return 0;
108275 +}
108276 +
108277 +/*
108278 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
108279 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
108280 + */
108281 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
108282 +{
108283 + gimple assign_intptr, assign_new_fptr, call_stmt;
108284 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
108285 +
108286 + call_stmt = gsi_stmt(*gsi);
108287 + old_fptr = gimple_call_fn(call_stmt);
108288 +
108289 + // create temporary unsigned long variable used for bitops and cast fptr to it
108290 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108291 + add_referenced_var(intptr);
108292 + intptr = make_ssa_name(intptr, NULL);
108293 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108294 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108295 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108296 + update_stmt(assign_intptr);
108297 +
108298 + // apply logical or to temporary unsigned long and bitmask
108299 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108300 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108301 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108302 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108303 + assign_intptr = gimple_build_assign(intptr, orptr);
108304 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108305 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108306 + update_stmt(assign_intptr);
108307 +
108308 + // cast temporary unsigned long back to a temporary fptr variable
108309 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108310 + add_referenced_var(new_fptr);
108311 + new_fptr = make_ssa_name(new_fptr, NULL);
108312 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108313 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108314 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108315 + update_stmt(assign_new_fptr);
108316 +
108317 + // replace call stmt fn with the new fptr
108318 + gimple_call_set_fn(call_stmt, new_fptr);
108319 + update_stmt(call_stmt);
108320 +}
108321 +
108322 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108323 +{
108324 + gimple asm_or_stmt, call_stmt;
108325 + tree old_fptr, new_fptr, input, output;
108326 +#if BUILDING_GCC_VERSION <= 4007
108327 + VEC(tree, gc) *inputs = NULL;
108328 + VEC(tree, gc) *outputs = NULL;
108329 +#else
108330 + vec<tree, va_gc> *inputs = NULL;
108331 + vec<tree, va_gc> *outputs = NULL;
108332 +#endif
108333 +
108334 + call_stmt = gsi_stmt(*gsi);
108335 + old_fptr = gimple_call_fn(call_stmt);
108336 +
108337 + // create temporary fptr variable
108338 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
108339 + add_referenced_var(new_fptr);
108340 + new_fptr = make_ssa_name(new_fptr, NULL);
108341 +
108342 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
108343 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
108344 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
108345 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
108346 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
108347 +#if BUILDING_GCC_VERSION <= 4007
108348 + VEC_safe_push(tree, gc, inputs, input);
108349 + VEC_safe_push(tree, gc, outputs, output);
108350 +#else
108351 + vec_safe_push(inputs, input);
108352 + vec_safe_push(outputs, output);
108353 +#endif
108354 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
108355 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
108356 + gimple_asm_set_volatile(asm_or_stmt, true);
108357 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
108358 + update_stmt(asm_or_stmt);
108359 +
108360 + // replace call stmt fn with the new fptr
108361 + gimple_call_set_fn(call_stmt, new_fptr);
108362 + update_stmt(call_stmt);
108363 +}
108364 +
108365 +/*
108366 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
108367 + */
108368 +static unsigned int execute_kernexec_fptr(void)
108369 +{
108370 + basic_block bb;
108371 +
108372 + // 1. loop through BBs and GIMPLE statements
108373 + FOR_EACH_BB_FN(bb, cfun) {
108374 + gimple_stmt_iterator gsi;
108375 +
108376 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108377 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
108378 + tree fn;
108379 + gimple call_stmt;
108380 +
108381 + // is it a call ...
108382 + call_stmt = gsi_stmt(gsi);
108383 + if (!is_gimple_call(call_stmt))
108384 + continue;
108385 + fn = gimple_call_fn(call_stmt);
108386 + if (TREE_CODE(fn) == ADDR_EXPR)
108387 + continue;
108388 + if (TREE_CODE(fn) != SSA_NAME)
108389 + gcc_unreachable();
108390 +
108391 + // ... through a function pointer
108392 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
108393 + fn = SSA_NAME_VAR(fn);
108394 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
108395 + debug_tree(fn);
108396 + gcc_unreachable();
108397 + }
108398 + }
108399 + fn = TREE_TYPE(fn);
108400 + if (TREE_CODE(fn) != POINTER_TYPE)
108401 + continue;
108402 + fn = TREE_TYPE(fn);
108403 + if (TREE_CODE(fn) != FUNCTION_TYPE)
108404 + continue;
108405 +
108406 + kernexec_instrument_fptr(&gsi);
108407 +
108408 +//debug_tree(gimple_call_fn(call_stmt));
108409 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108410 + }
108411 + }
108412 +
108413 + return 0;
108414 +}
108415 +
108416 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
108417 +static void kernexec_instrument_retaddr_bts(rtx insn)
108418 +{
108419 + rtx btsq;
108420 + rtvec argvec, constraintvec, labelvec;
108421 + int line;
108422 +
108423 + // create asm volatile("btsq $63,(%%rsp)":::)
108424 + argvec = rtvec_alloc(0);
108425 + constraintvec = rtvec_alloc(0);
108426 + labelvec = rtvec_alloc(0);
108427 + line = expand_location(RTL_LOCATION(insn)).line;
108428 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108429 + MEM_VOLATILE_P(btsq) = 1;
108430 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
108431 + emit_insn_before(btsq, insn);
108432 +}
108433 +
108434 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
108435 +static void kernexec_instrument_retaddr_or(rtx insn)
108436 +{
108437 + rtx orq;
108438 + rtvec argvec, constraintvec, labelvec;
108439 + int line;
108440 +
108441 + // create asm volatile("orq %%r12,(%%rsp)":::)
108442 + argvec = rtvec_alloc(0);
108443 + constraintvec = rtvec_alloc(0);
108444 + labelvec = rtvec_alloc(0);
108445 + line = expand_location(RTL_LOCATION(insn)).line;
108446 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108447 + MEM_VOLATILE_P(orq) = 1;
108448 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
108449 + emit_insn_before(orq, insn);
108450 +}
108451 +
108452 +/*
108453 + * find all asm level function returns and forcibly set the highest bit of the return address
108454 + */
108455 +static unsigned int execute_kernexec_retaddr(void)
108456 +{
108457 + rtx insn;
108458 +
108459 +// if (stack_realign_drap)
108460 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
108461 +
108462 + // 1. find function returns
108463 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
108464 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
108465 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
108466 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
108467 + rtx body;
108468 +
108469 + // is it a retn
108470 + if (!JUMP_P(insn))
108471 + continue;
108472 + body = PATTERN(insn);
108473 + if (GET_CODE(body) == PARALLEL)
108474 + body = XVECEXP(body, 0, 0);
108475 + if (!ANY_RETURN_P(body))
108476 + continue;
108477 + kernexec_instrument_retaddr(insn);
108478 + }
108479 +
108480 +// print_simple_rtl(stderr, get_insns());
108481 +// print_rtl(stderr, get_insns());
108482 +
108483 + return 0;
108484 +}
108485 +
108486 +static bool kernexec_cmodel_check(void)
108487 +{
108488 + tree section;
108489 +
108490 + if (ix86_cmodel != CM_KERNEL)
108491 + return false;
108492 +
108493 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
108494 + if (!section || !TREE_VALUE(section))
108495 + return true;
108496 +
108497 + section = TREE_VALUE(TREE_VALUE(section));
108498 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
108499 + return true;
108500 +
108501 + return false;
108502 +}
108503 +
108504 +#if BUILDING_GCC_VERSION >= 4009
108505 +static const struct pass_data kernexec_reload_pass_data = {
108506 +#else
108507 +static struct gimple_opt_pass kernexec_reload_pass = {
108508 + .pass = {
108509 +#endif
108510 + .type = GIMPLE_PASS,
108511 + .name = "kernexec_reload",
108512 +#if BUILDING_GCC_VERSION >= 4008
108513 + .optinfo_flags = OPTGROUP_NONE,
108514 +#endif
108515 +#if BUILDING_GCC_VERSION >= 4009
108516 + .has_gate = true,
108517 + .has_execute = true,
108518 +#else
108519 + .gate = kernexec_cmodel_check,
108520 + .execute = execute_kernexec_reload,
108521 + .sub = NULL,
108522 + .next = NULL,
108523 + .static_pass_number = 0,
108524 +#endif
108525 + .tv_id = TV_NONE,
108526 + .properties_required = 0,
108527 + .properties_provided = 0,
108528 + .properties_destroyed = 0,
108529 + .todo_flags_start = 0,
108530 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108531 +#if BUILDING_GCC_VERSION < 4009
108532 + }
108533 +#endif
108534 +};
108535 +
108536 +#if BUILDING_GCC_VERSION >= 4009
108537 +static const struct pass_data kernexec_fptr_pass_data = {
108538 +#else
108539 +static struct gimple_opt_pass kernexec_fptr_pass = {
108540 + .pass = {
108541 +#endif
108542 + .type = GIMPLE_PASS,
108543 + .name = "kernexec_fptr",
108544 +#if BUILDING_GCC_VERSION >= 4008
108545 + .optinfo_flags = OPTGROUP_NONE,
108546 +#endif
108547 +#if BUILDING_GCC_VERSION >= 4009
108548 + .has_gate = true,
108549 + .has_execute = true,
108550 +#else
108551 + .gate = kernexec_cmodel_check,
108552 + .execute = execute_kernexec_fptr,
108553 + .sub = NULL,
108554 + .next = NULL,
108555 + .static_pass_number = 0,
108556 +#endif
108557 + .tv_id = TV_NONE,
108558 + .properties_required = 0,
108559 + .properties_provided = 0,
108560 + .properties_destroyed = 0,
108561 + .todo_flags_start = 0,
108562 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108563 +#if BUILDING_GCC_VERSION < 4009
108564 + }
108565 +#endif
108566 +};
108567 +
108568 +#if BUILDING_GCC_VERSION >= 4009
108569 +static const struct pass_data kernexec_retaddr_pass_data = {
108570 +#else
108571 +static struct rtl_opt_pass kernexec_retaddr_pass = {
108572 + .pass = {
108573 +#endif
108574 + .type = RTL_PASS,
108575 + .name = "kernexec_retaddr",
108576 +#if BUILDING_GCC_VERSION >= 4008
108577 + .optinfo_flags = OPTGROUP_NONE,
108578 +#endif
108579 +#if BUILDING_GCC_VERSION >= 4009
108580 + .has_gate = true,
108581 + .has_execute = true,
108582 +#else
108583 + .gate = kernexec_cmodel_check,
108584 + .execute = execute_kernexec_retaddr,
108585 + .sub = NULL,
108586 + .next = NULL,
108587 + .static_pass_number = 0,
108588 +#endif
108589 + .tv_id = TV_NONE,
108590 + .properties_required = 0,
108591 + .properties_provided = 0,
108592 + .properties_destroyed = 0,
108593 + .todo_flags_start = 0,
108594 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
108595 +#if BUILDING_GCC_VERSION < 4009
108596 + }
108597 +#endif
108598 +};
108599 +
108600 +#if BUILDING_GCC_VERSION >= 4009
108601 +namespace {
108602 +class kernexec_reload_pass : public gimple_opt_pass {
108603 +public:
108604 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
108605 + bool gate() { return kernexec_cmodel_check(); }
108606 + unsigned int execute() { return execute_kernexec_reload(); }
108607 +};
108608 +
108609 +class kernexec_fptr_pass : public gimple_opt_pass {
108610 +public:
108611 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
108612 + bool gate() { return kernexec_cmodel_check(); }
108613 + unsigned int execute() { return execute_kernexec_fptr(); }
108614 +};
108615 +
108616 +class kernexec_retaddr_pass : public rtl_opt_pass {
108617 +public:
108618 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
108619 + bool gate() { return kernexec_cmodel_check(); }
108620 + unsigned int execute() { return execute_kernexec_retaddr(); }
108621 +};
108622 +}
108623 +
108624 +static opt_pass *make_kernexec_reload_pass(void)
108625 +{
108626 + return new kernexec_reload_pass();
108627 +}
108628 +
108629 +static opt_pass *make_kernexec_fptr_pass(void)
108630 +{
108631 + return new kernexec_fptr_pass();
108632 +}
108633 +
108634 +static opt_pass *make_kernexec_retaddr_pass(void)
108635 +{
108636 + return new kernexec_retaddr_pass();
108637 +}
108638 +#else
108639 +static struct opt_pass *make_kernexec_reload_pass(void)
108640 +{
108641 + return &kernexec_reload_pass.pass;
108642 +}
108643 +
108644 +static struct opt_pass *make_kernexec_fptr_pass(void)
108645 +{
108646 + return &kernexec_fptr_pass.pass;
108647 +}
108648 +
108649 +static struct opt_pass *make_kernexec_retaddr_pass(void)
108650 +{
108651 + return &kernexec_retaddr_pass.pass;
108652 +}
108653 +#endif
108654 +
108655 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108656 +{
108657 + const char * const plugin_name = plugin_info->base_name;
108658 + const int argc = plugin_info->argc;
108659 + const struct plugin_argument * const argv = plugin_info->argv;
108660 + int i;
108661 + struct register_pass_info kernexec_reload_pass_info;
108662 + struct register_pass_info kernexec_fptr_pass_info;
108663 + struct register_pass_info kernexec_retaddr_pass_info;
108664 +
108665 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
108666 + kernexec_reload_pass_info.reference_pass_name = "ssa";
108667 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
108668 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108669 +
108670 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
108671 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
108672 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
108673 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108674 +
108675 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
108676 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
108677 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
108678 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108679 +
108680 + if (!plugin_default_version_check(version, &gcc_version)) {
108681 + error(G_("incompatible gcc/plugin versions"));
108682 + return 1;
108683 + }
108684 +
108685 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
108686 +
108687 + if (TARGET_64BIT == 0)
108688 + return 0;
108689 +
108690 + for (i = 0; i < argc; ++i) {
108691 + if (!strcmp(argv[i].key, "method")) {
108692 + if (!argv[i].value) {
108693 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108694 + continue;
108695 + }
108696 + if (!strcmp(argv[i].value, "bts")) {
108697 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
108698 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
108699 + } else if (!strcmp(argv[i].value, "or")) {
108700 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
108701 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
108702 + fix_register("r12", 1, 1);
108703 + } else
108704 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
108705 + continue;
108706 + }
108707 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108708 + }
108709 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
108710 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
108711 +
108712 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
108713 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
108714 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
108715 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
108716 +
108717 + return 0;
108718 +}
108719 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
108720 new file mode 100644
108721 index 0000000..39d7cc7
108722 --- /dev/null
108723 +++ b/tools/gcc/latent_entropy_plugin.c
108724 @@ -0,0 +1,462 @@
108725 +/*
108726 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
108727 + * Licensed under the GPL v2
108728 + *
108729 + * Note: the choice of the license means that the compilation process is
108730 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108731 + * but for the kernel it doesn't matter since it doesn't link against
108732 + * any of the gcc libraries
108733 + *
108734 + * gcc plugin to help generate a little bit of entropy from program state,
108735 + * used throughout the uptime of the kernel
108736 + *
108737 + * TODO:
108738 + * - add ipa pass to identify not explicitly marked candidate functions
108739 + * - mix in more program state (function arguments/return values, loop variables, etc)
108740 + * - more instrumentation control via attribute parameters
108741 + *
108742 + * BUGS:
108743 + * - LTO needs -flto-partition=none for now
108744 + */
108745 +
108746 +#include "gcc-common.h"
108747 +
108748 +int plugin_is_GPL_compatible;
108749 +
108750 +static tree latent_entropy_decl;
108751 +
108752 +static struct plugin_info latent_entropy_plugin_info = {
108753 + .version = "201403280150",
108754 + .help = NULL
108755 +};
108756 +
108757 +static unsigned HOST_WIDE_INT seed;
108758 +static unsigned HOST_WIDE_INT get_random_const(void)
108759 +{
108760 + unsigned int i;
108761 + unsigned HOST_WIDE_INT ret = 0;
108762 +
108763 + for (i = 0; i < 8 * sizeof ret; i++) {
108764 + ret = (ret << 1) | (seed & 1);
108765 + seed >>= 1;
108766 + if (ret & 1)
108767 + seed ^= 0xD800000000000000ULL;
108768 + }
108769 +
108770 + return ret;
108771 +}
108772 +
108773 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108774 +{
108775 + tree type;
108776 + unsigned long long mask;
108777 +#if BUILDING_GCC_VERSION <= 4007
108778 + VEC(constructor_elt, gc) *vals;
108779 +#else
108780 + vec<constructor_elt, va_gc> *vals;
108781 +#endif
108782 +
108783 + switch (TREE_CODE(*node)) {
108784 + default:
108785 + *no_add_attrs = true;
108786 + error("%qE attribute only applies to functions and variables", name);
108787 + break;
108788 +
108789 + case VAR_DECL:
108790 + if (DECL_INITIAL(*node)) {
108791 + *no_add_attrs = true;
108792 + error("variable %qD with %qE attribute must not be initialized", *node, name);
108793 + break;
108794 + }
108795 +
108796 + if (!TREE_STATIC(*node)) {
108797 + *no_add_attrs = true;
108798 + error("variable %qD with %qE attribute must not be local", *node, name);
108799 + break;
108800 + }
108801 +
108802 + type = TREE_TYPE(*node);
108803 + switch (TREE_CODE(type)) {
108804 + default:
108805 + *no_add_attrs = true;
108806 + 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);
108807 + break;
108808 +
108809 + case RECORD_TYPE: {
108810 + tree field;
108811 + unsigned int nelt = 0;
108812 +
108813 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
108814 + tree fieldtype;
108815 +
108816 + fieldtype = TREE_TYPE(field);
108817 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
108818 + *no_add_attrs = true;
108819 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
108820 + break;
108821 + }
108822 + }
108823 +
108824 + if (field)
108825 + break;
108826 +
108827 +#if BUILDING_GCC_VERSION <= 4007
108828 + vals = VEC_alloc(constructor_elt, gc, nelt);
108829 +#else
108830 + vec_alloc(vals, nelt);
108831 +#endif
108832 +
108833 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
108834 + tree fieldtype;
108835 +
108836 + fieldtype = TREE_TYPE(field);
108837 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
108838 + mask = 2 * (mask - 1) + 1;
108839 +
108840 + if (TYPE_UNSIGNED(fieldtype))
108841 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
108842 + else
108843 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
108844 + }
108845 +
108846 + DECL_INITIAL(*node) = build_constructor(type, vals);
108847 +//debug_tree(DECL_INITIAL(*node));
108848 + break;
108849 + }
108850 +
108851 + case INTEGER_TYPE:
108852 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
108853 + mask = 2 * (mask - 1) + 1;
108854 +
108855 + if (TYPE_UNSIGNED(type))
108856 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
108857 + else
108858 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
108859 + break;
108860 +
108861 + case ARRAY_TYPE: {
108862 + tree elt_type, array_size, elt_size;
108863 + unsigned int i, nelt;
108864 +
108865 + elt_type = TREE_TYPE(type);
108866 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
108867 + array_size = TYPE_SIZE_UNIT(type);
108868 +
108869 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
108870 + *no_add_attrs = true;
108871 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
108872 + break;
108873 + }
108874 +
108875 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
108876 +#if BUILDING_GCC_VERSION <= 4007
108877 + vals = VEC_alloc(constructor_elt, gc, nelt);
108878 +#else
108879 + vec_alloc(vals, nelt);
108880 +#endif
108881 +
108882 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
108883 + mask = 2 * (mask - 1) + 1;
108884 +
108885 + for (i = 0; i < nelt; i++)
108886 + if (TYPE_UNSIGNED(elt_type))
108887 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
108888 + else
108889 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
108890 +
108891 + DECL_INITIAL(*node) = build_constructor(type, vals);
108892 +//debug_tree(DECL_INITIAL(*node));
108893 + break;
108894 + }
108895 + }
108896 + break;
108897 +
108898 + case FUNCTION_DECL:
108899 + break;
108900 + }
108901 +
108902 + return NULL_TREE;
108903 +}
108904 +
108905 +static struct attribute_spec latent_entropy_attr = {
108906 + .name = "latent_entropy",
108907 + .min_length = 0,
108908 + .max_length = 0,
108909 + .decl_required = true,
108910 + .type_required = false,
108911 + .function_type_required = false,
108912 + .handler = handle_latent_entropy_attribute,
108913 +#if BUILDING_GCC_VERSION >= 4007
108914 + .affects_type_identity = false
108915 +#endif
108916 +};
108917 +
108918 +static void register_attributes(void *event_data, void *data)
108919 +{
108920 + register_attribute(&latent_entropy_attr);
108921 +}
108922 +
108923 +static bool gate_latent_entropy(void)
108924 +{
108925 + // don't bother with noreturn functions for now
108926 + if (TREE_THIS_VOLATILE(current_function_decl))
108927 + return false;
108928 +
108929 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
108930 +}
108931 +
108932 +static enum tree_code get_op(tree *rhs)
108933 +{
108934 + static enum tree_code op;
108935 + unsigned HOST_WIDE_INT random_const;
108936 +
108937 + random_const = get_random_const();
108938 +
108939 + switch (op) {
108940 + case BIT_XOR_EXPR:
108941 + op = PLUS_EXPR;
108942 + break;
108943 +
108944 + case PLUS_EXPR:
108945 + if (rhs) {
108946 + op = LROTATE_EXPR;
108947 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
108948 + break;
108949 + }
108950 +
108951 + case LROTATE_EXPR:
108952 + default:
108953 + op = BIT_XOR_EXPR;
108954 + break;
108955 + }
108956 + if (rhs)
108957 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
108958 + return op;
108959 +}
108960 +
108961 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
108962 +{
108963 + gimple_stmt_iterator gsi;
108964 + gimple assign;
108965 + tree addxorrol, rhs;
108966 + enum tree_code op;
108967 +
108968 + op = get_op(&rhs);
108969 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
108970 + assign = gimple_build_assign(local_entropy, addxorrol);
108971 + gsi = gsi_after_labels(bb);
108972 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
108973 + update_stmt(assign);
108974 +//debug_bb(bb);
108975 +}
108976 +
108977 +static void perturb_latent_entropy(basic_block bb, tree rhs)
108978 +{
108979 + gimple_stmt_iterator gsi;
108980 + gimple assign;
108981 + tree addxorrol, temp;
108982 +
108983 + // 1. create temporary copy of latent_entropy
108984 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
108985 + add_referenced_var(temp);
108986 +
108987 + // 2. read...
108988 + temp = make_ssa_name(temp, NULL);
108989 + assign = gimple_build_assign(temp, latent_entropy_decl);
108990 + SSA_NAME_DEF_STMT(temp) = assign;
108991 + add_referenced_var(latent_entropy_decl);
108992 + gsi = gsi_after_labels(bb);
108993 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
108994 + update_stmt(assign);
108995 +
108996 + // 3. ...modify...
108997 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
108998 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
108999 + assign = gimple_build_assign(temp, addxorrol);
109000 + SSA_NAME_DEF_STMT(temp) = assign;
109001 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109002 + update_stmt(assign);
109003 +
109004 + // 4. ...write latent_entropy
109005 + assign = gimple_build_assign(latent_entropy_decl, temp);
109006 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109007 + update_stmt(assign);
109008 +}
109009 +
109010 +static unsigned int execute_latent_entropy(void)
109011 +{
109012 + basic_block bb;
109013 + gimple assign;
109014 + gimple_stmt_iterator gsi;
109015 + tree local_entropy;
109016 +
109017 + if (!latent_entropy_decl) {
109018 +#if BUILDING_GCC_VERSION >= 4009
109019 + varpool_node *node;
109020 +#else
109021 + struct varpool_node *node;
109022 +#endif
109023 +
109024 + FOR_EACH_VARIABLE(node) {
109025 + tree var = NODE_DECL(node);
109026 +
109027 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
109028 + continue;
109029 + latent_entropy_decl = var;
109030 +// debug_tree(var);
109031 + break;
109032 + }
109033 + if (!latent_entropy_decl) {
109034 +// debug_tree(current_function_decl);
109035 + return 0;
109036 + }
109037 + }
109038 +
109039 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109040 +
109041 + // 1. create local entropy variable
109042 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
109043 + add_referenced_var(local_entropy);
109044 + mark_sym_for_renaming(local_entropy);
109045 +
109046 + // 2. initialize local entropy variable
109047 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
109048 + if (dom_info_available_p(CDI_DOMINATORS))
109049 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
109050 + gsi = gsi_start_bb(bb);
109051 +
109052 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
109053 +// gimple_set_location(assign, loc);
109054 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109055 + update_stmt(assign);
109056 +//debug_bb(bb);
109057 + gcc_assert(single_succ_p(bb));
109058 + bb = single_succ(bb);
109059 +
109060 + // 3. instrument each BB with an operation on the local entropy variable
109061 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
109062 + perturb_local_entropy(bb, local_entropy);
109063 +//debug_bb(bb);
109064 + bb = bb->next_bb;
109065 + };
109066 +
109067 + // 4. mix local entropy into the global entropy variable
109068 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109069 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
109070 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109071 + return 0;
109072 +}
109073 +
109074 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
109075 +{
109076 + tree latent_entropy_type;
109077 +
109078 + seed = get_random_seed(false);
109079 +
109080 + if (in_lto_p)
109081 + return;
109082 +
109083 + // extern volatile u64 latent_entropy
109084 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
109085 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
109086 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
109087 +
109088 + TREE_STATIC(latent_entropy_decl) = 1;
109089 + TREE_PUBLIC(latent_entropy_decl) = 1;
109090 + TREE_USED(latent_entropy_decl) = 1;
109091 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
109092 + DECL_EXTERNAL(latent_entropy_decl) = 1;
109093 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
109094 + lang_hooks.decls.pushdecl(latent_entropy_decl);
109095 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
109096 +// varpool_finalize_decl(latent_entropy_decl);
109097 +// varpool_mark_needed_node(latent_entropy_decl);
109098 +}
109099 +
109100 +#if BUILDING_GCC_VERSION >= 4009
109101 +static const struct pass_data latent_entropy_pass_data = {
109102 +#else
109103 +static struct gimple_opt_pass latent_entropy_pass = {
109104 + .pass = {
109105 +#endif
109106 + .type = GIMPLE_PASS,
109107 + .name = "latent_entropy",
109108 +#if BUILDING_GCC_VERSION >= 4008
109109 + .optinfo_flags = OPTGROUP_NONE,
109110 +#endif
109111 +#if BUILDING_GCC_VERSION >= 4009
109112 + .has_gate = true,
109113 + .has_execute = true,
109114 +#else
109115 + .gate = gate_latent_entropy,
109116 + .execute = execute_latent_entropy,
109117 + .sub = NULL,
109118 + .next = NULL,
109119 + .static_pass_number = 0,
109120 +#endif
109121 + .tv_id = TV_NONE,
109122 + .properties_required = PROP_gimple_leh | PROP_cfg,
109123 + .properties_provided = 0,
109124 + .properties_destroyed = 0,
109125 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
109126 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
109127 +#if BUILDING_GCC_VERSION < 4009
109128 + }
109129 +#endif
109130 +};
109131 +
109132 +#if BUILDING_GCC_VERSION >= 4009
109133 +namespace {
109134 +class latent_entropy_pass : public gimple_opt_pass {
109135 +public:
109136 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
109137 + bool gate() { return gate_latent_entropy(); }
109138 + unsigned int execute() { return execute_latent_entropy(); }
109139 +};
109140 +}
109141 +
109142 +static opt_pass *make_latent_entropy_pass(void)
109143 +{
109144 + return new latent_entropy_pass();
109145 +}
109146 +#else
109147 +static struct opt_pass *make_latent_entropy_pass(void)
109148 +{
109149 + return &latent_entropy_pass.pass;
109150 +}
109151 +#endif
109152 +
109153 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109154 +{
109155 + const char * const plugin_name = plugin_info->base_name;
109156 + struct register_pass_info latent_entropy_pass_info;
109157 +
109158 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
109159 + latent_entropy_pass_info.reference_pass_name = "optimized";
109160 + latent_entropy_pass_info.ref_pass_instance_number = 1;
109161 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
109162 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
109163 + {
109164 + .base = &latent_entropy_decl,
109165 + .nelt = 1,
109166 + .stride = sizeof(latent_entropy_decl),
109167 + .cb = &gt_ggc_mx_tree_node,
109168 + .pchw = &gt_pch_nx_tree_node
109169 + },
109170 + LAST_GGC_ROOT_TAB
109171 + };
109172 +
109173 + if (!plugin_default_version_check(version, &gcc_version)) {
109174 + error(G_("incompatible gcc/plugin versions"));
109175 + return 1;
109176 + }
109177 +
109178 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
109179 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
109180 + if (!in_lto_p)
109181 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
109182 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
109183 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109184 +
109185 + return 0;
109186 +}
109187 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
109188 new file mode 100644
109189 index 0000000..8dafb22
109190 --- /dev/null
109191 +++ b/tools/gcc/randomize_layout_plugin.c
109192 @@ -0,0 +1,910 @@
109193 +/*
109194 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
109195 + * and PaX Team <pageexec@freemail.hu>
109196 + * Licensed under the GPL v2
109197 + *
109198 + * Usage:
109199 + * $ # for 4.5/4.6/C based 4.7
109200 + * $ 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
109201 + * $ # for C++ based 4.7/4.8+
109202 + * $ 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
109203 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
109204 + */
109205 +
109206 +#include "gcc-common.h"
109207 +#include "randomize_layout_seed.h"
109208 +
109209 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
109210 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
109211 +#endif
109212 +
109213 +#define ORIG_TYPE_NAME(node) \
109214 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
109215 +
109216 +int plugin_is_GPL_compatible;
109217 +
109218 +static int performance_mode;
109219 +
109220 +static struct plugin_info randomize_layout_plugin_info = {
109221 + .version = "201402201816",
109222 + .help = "disable\t\t\tdo not activate plugin\n"
109223 + "performance-mode\tenable cacheline-aware layout randomization\n"
109224 +};
109225 +
109226 +/* from old Linux dcache.h */
109227 +static inline unsigned long
109228 +partial_name_hash(unsigned long c, unsigned long prevhash)
109229 +{
109230 + return (prevhash + (c << 4) + (c >> 4)) * 11;
109231 +}
109232 +static inline unsigned int
109233 +name_hash(const unsigned char *name)
109234 +{
109235 + unsigned long hash = 0;
109236 + unsigned int len = strlen((const char *)name);
109237 + while (len--)
109238 + hash = partial_name_hash(*name++, hash);
109239 + return (unsigned int)hash;
109240 +}
109241 +
109242 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109243 +{
109244 + tree type;
109245 +
109246 + *no_add_attrs = true;
109247 + if (TREE_CODE(*node) == FUNCTION_DECL) {
109248 + error("%qE attribute does not apply to functions (%qF)", name, *node);
109249 + return NULL_TREE;
109250 + }
109251 +
109252 + if (TREE_CODE(*node) == PARM_DECL) {
109253 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
109254 + return NULL_TREE;
109255 + }
109256 +
109257 + if (TREE_CODE(*node) == VAR_DECL) {
109258 + error("%qE attribute does not apply to variables (%qD)", name, *node);
109259 + return NULL_TREE;
109260 + }
109261 +
109262 + if (TYPE_P(*node)) {
109263 + type = *node;
109264 + } else {
109265 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
109266 + type = TREE_TYPE(*node);
109267 + }
109268 +
109269 + if (TREE_CODE(type) != RECORD_TYPE) {
109270 + error("%qE attribute used on %qT applies to struct types only", name, type);
109271 + return NULL_TREE;
109272 + }
109273 +
109274 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
109275 + error("%qE attribute is already applied to the type %qT", name, type);
109276 + return NULL_TREE;
109277 + }
109278 +
109279 + *no_add_attrs = false;
109280 +
109281 + return NULL_TREE;
109282 +}
109283 +
109284 +/* set on complete types that we don't need to inspect further at all */
109285 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109286 +{
109287 + *no_add_attrs = false;
109288 + return NULL_TREE;
109289 +}
109290 +
109291 +/*
109292 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109293 + * this does not preclude us from inspecting its fields for potential shuffles
109294 + */
109295 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109296 +{
109297 + *no_add_attrs = false;
109298 + return NULL_TREE;
109299 +}
109300 +
109301 +/*
109302 + * 64bit variant of Bob Jenkins' public domain PRNG
109303 + * 256 bits of internal state
109304 + */
109305 +
109306 +typedef unsigned long long u64;
109307 +
109308 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109309 +
109310 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109311 +static u64 ranval(ranctx *x) {
109312 + u64 e = x->a - rot(x->b, 7);
109313 + x->a = x->b ^ rot(x->c, 13);
109314 + x->b = x->c + rot(x->d, 37);
109315 + x->c = x->d + e;
109316 + x->d = e + x->a;
109317 + return x->d;
109318 +}
109319 +
109320 +static void raninit(ranctx *x, u64 *seed) {
109321 + int i;
109322 +
109323 + x->a = seed[0];
109324 + x->b = seed[1];
109325 + x->c = seed[2];
109326 + x->d = seed[3];
109327 +
109328 + for (i=0; i < 30; ++i)
109329 + (void)ranval(x);
109330 +}
109331 +
109332 +static u64 shuffle_seed[4];
109333 +
109334 +struct partition_group {
109335 + tree tree_start;
109336 + unsigned long start;
109337 + unsigned long length;
109338 +};
109339 +
109340 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
109341 +{
109342 + unsigned long i;
109343 + unsigned long accum_size = 0;
109344 + unsigned long accum_length = 0;
109345 + unsigned long group_idx = 0;
109346 +
109347 + gcc_assert(length < INT_MAX);
109348 +
109349 + memset(size_groups, 0, sizeof(struct partition_group) * length);
109350 +
109351 + for (i = 0; i < length; i++) {
109352 + if (size_groups[group_idx].tree_start == NULL_TREE) {
109353 + size_groups[group_idx].tree_start = fields[i];
109354 + size_groups[group_idx].start = i;
109355 + accum_length = 0;
109356 + accum_size = 0;
109357 + }
109358 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
109359 + accum_length++;
109360 + if (accum_size >= 64) {
109361 + size_groups[group_idx].length = accum_length;
109362 + accum_length = 0;
109363 + group_idx++;
109364 + }
109365 + }
109366 +
109367 + if (size_groups[group_idx].tree_start != NULL_TREE &&
109368 + !size_groups[group_idx].length) {
109369 + size_groups[group_idx].length = accum_length;
109370 + group_idx++;
109371 + }
109372 +
109373 + *num_groups = group_idx;
109374 +}
109375 +
109376 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109377 +{
109378 + unsigned long i, x;
109379 + struct partition_group size_group[length];
109380 + unsigned long num_groups = 0;
109381 + unsigned long randnum;
109382 +
109383 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
109384 + for (i = num_groups - 1; i > 0; i--) {
109385 + struct partition_group tmp;
109386 + randnum = ranval(prng_state) % (i + 1);
109387 + tmp = size_group[i];
109388 + size_group[i] = size_group[randnum];
109389 + size_group[randnum] = tmp;
109390 + }
109391 +
109392 + for (x = 0; x < num_groups; x++) {
109393 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
109394 + tree tmp;
109395 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
109396 + continue;
109397 + randnum = ranval(prng_state) % (i + 1);
109398 + // we could handle this case differently if desired
109399 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
109400 + continue;
109401 + tmp = newtree[i];
109402 + newtree[i] = newtree[randnum];
109403 + newtree[randnum] = tmp;
109404 + }
109405 + }
109406 +}
109407 +
109408 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109409 +{
109410 + unsigned long i, randnum;
109411 +
109412 + for (i = length - 1; i > 0; i--) {
109413 + tree tmp;
109414 + randnum = ranval(prng_state) % (i + 1);
109415 + tmp = newtree[i];
109416 + newtree[i] = newtree[randnum];
109417 + newtree[randnum] = tmp;
109418 + }
109419 +}
109420 +
109421 +/* modern in-place Fisher-Yates shuffle */
109422 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
109423 +{
109424 + unsigned long i;
109425 + u64 seed[4];
109426 + ranctx prng_state;
109427 + const unsigned char *structname;
109428 +
109429 + if (length == 0)
109430 + return;
109431 +
109432 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109433 +
109434 + structname = ORIG_TYPE_NAME(type);
109435 +
109436 +#ifdef __DEBUG_PLUGIN
109437 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
109438 +#ifdef __DEBUG_VERBOSE
109439 + debug_tree((tree)type);
109440 +#endif
109441 +#endif
109442 +
109443 + for (i = 0; i < 4; i++) {
109444 + seed[i] = shuffle_seed[i];
109445 + seed[i] ^= name_hash(structname);
109446 + }
109447 +
109448 + raninit(&prng_state, (u64 *)&seed);
109449 +
109450 + if (performance_mode)
109451 + performance_shuffle(newtree, length, &prng_state);
109452 + else
109453 + full_shuffle(newtree, length, &prng_state);
109454 +}
109455 +
109456 +static bool is_flexible_array(const_tree field)
109457 +{
109458 + const_tree fieldtype;
109459 + const_tree typesize;
109460 + const_tree elemtype;
109461 + const_tree elemsize;
109462 +
109463 + fieldtype = TREE_TYPE(field);
109464 + typesize = TYPE_SIZE(fieldtype);
109465 +
109466 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
109467 + return false;
109468 +
109469 + elemtype = TREE_TYPE(fieldtype);
109470 + elemsize = TYPE_SIZE(elemtype);
109471 +
109472 + /* size of type is represented in bits */
109473 +
109474 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
109475 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
109476 + return true;
109477 +
109478 + if (typesize != NULL_TREE &&
109479 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
109480 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
109481 + return true;
109482 +
109483 + return false;
109484 +}
109485 +
109486 +static int relayout_struct(tree type)
109487 +{
109488 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
109489 + unsigned long shuffle_length = num_fields;
109490 + tree field;
109491 + tree newtree[num_fields];
109492 + unsigned long i;
109493 + tree list;
109494 + tree variant;
109495 + expanded_location xloc;
109496 +
109497 + if (TYPE_FIELDS(type) == NULL_TREE)
109498 + return 0;
109499 +
109500 + if (num_fields < 2)
109501 + return 0;
109502 +
109503 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109504 +
109505 + gcc_assert(num_fields < INT_MAX);
109506 +
109507 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
109508 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
109509 + return 0;
109510 +
109511 + /* throw out any structs in uapi */
109512 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
109513 +
109514 + if (strstr(xloc.file, "/uapi/"))
109515 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
109516 +
109517 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
109518 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
109519 + newtree[i] = field;
109520 + }
109521 +
109522 + /*
109523 + * enforce that we don't randomize the layout of the last
109524 + * element of a struct if it's a 0 or 1-length array
109525 + * or a proper flexible array
109526 + */
109527 + if (is_flexible_array(newtree[num_fields - 1]))
109528 + shuffle_length--;
109529 +
109530 + shuffle(type, (tree *)newtree, shuffle_length);
109531 +
109532 + /*
109533 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
109534 + * as gcc provides no other way to detect such code
109535 + */
109536 + list = make_node(FIELD_DECL);
109537 + TREE_CHAIN(list) = newtree[0];
109538 + TREE_TYPE(list) = void_type_node;
109539 + DECL_SIZE(list) = bitsize_zero_node;
109540 + DECL_NONADDRESSABLE_P(list) = 1;
109541 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
109542 + DECL_SIZE_UNIT(list) = size_zero_node;
109543 + DECL_FIELD_OFFSET(list) = size_zero_node;
109544 + // to satisfy the constify plugin
109545 + TREE_READONLY(list) = 1;
109546 +
109547 + for (i = 0; i < num_fields - 1; i++)
109548 + TREE_CHAIN(newtree[i]) = newtree[i+1];
109549 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
109550 +
109551 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109552 + TYPE_FIELDS(variant) = list;
109553 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
109554 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
109555 + // force a re-layout
109556 + TYPE_SIZE(variant) = NULL_TREE;
109557 + layout_type(variant);
109558 + }
109559 +
109560 + return 1;
109561 +}
109562 +
109563 +/* from constify plugin */
109564 +static const_tree get_field_type(const_tree field)
109565 +{
109566 + return strip_array_types(TREE_TYPE(field));
109567 +}
109568 +
109569 +/* from constify plugin */
109570 +static bool is_fptr(const_tree fieldtype)
109571 +{
109572 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
109573 + return false;
109574 +
109575 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
109576 +}
109577 +
109578 +/* derived from constify plugin */
109579 +static int is_pure_ops_struct(const_tree node)
109580 +{
109581 + const_tree field;
109582 +
109583 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109584 +
109585 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
109586 + const_tree fieldtype = get_field_type(field);
109587 + enum tree_code code = TREE_CODE(fieldtype);
109588 +
109589 + if (node == fieldtype)
109590 + continue;
109591 +
109592 + if (!is_fptr(fieldtype))
109593 + return 0;
109594 +
109595 + if (code != RECORD_TYPE && code != UNION_TYPE)
109596 + continue;
109597 +
109598 + if (!is_pure_ops_struct(fieldtype))
109599 + return 0;
109600 + }
109601 +
109602 + return 1;
109603 +}
109604 +
109605 +static void randomize_type(tree type)
109606 +{
109607 + tree variant;
109608 +
109609 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109610 +
109611 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109612 + return;
109613 +
109614 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
109615 + relayout_struct(type);
109616 +
109617 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109618 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
109619 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
109620 + }
109621 +#ifdef __DEBUG_PLUGIN
109622 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
109623 +#ifdef __DEBUG_VERBOSE
109624 + debug_tree(type);
109625 +#endif
109626 +#endif
109627 +}
109628 +
109629 +static void randomize_layout_finish_decl(void *event_data, void *data)
109630 +{
109631 + tree decl = (tree)event_data;
109632 + tree type;
109633 +
109634 + if (decl == NULL_TREE || decl == error_mark_node)
109635 + return;
109636 +
109637 + type = TREE_TYPE(decl);
109638 +
109639 + if (TREE_CODE(decl) != VAR_DECL)
109640 + return;
109641 +
109642 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
109643 + return;
109644 +
109645 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
109646 + return;
109647 +
109648 + relayout_decl(decl);
109649 +}
109650 +
109651 +static void finish_type(void *event_data, void *data)
109652 +{
109653 + tree type = (tree)event_data;
109654 +
109655 + if (type == NULL_TREE || type == error_mark_node)
109656 + return;
109657 +
109658 + if (TREE_CODE(type) != RECORD_TYPE)
109659 + return;
109660 +
109661 + if (TYPE_FIELDS(type) == NULL_TREE)
109662 + return;
109663 +
109664 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109665 + return;
109666 +
109667 +#ifdef __DEBUG_PLUGIN
109668 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
109669 +#endif
109670 +#ifdef __DEBUG_VERBOSE
109671 + debug_tree(type);
109672 +#endif
109673 + randomize_type(type);
109674 +
109675 + return;
109676 +}
109677 +
109678 +static struct attribute_spec randomize_layout_attr = {
109679 + .name = "randomize_layout",
109680 + // related to args
109681 + .min_length = 0,
109682 + .max_length = 0,
109683 + .decl_required = false,
109684 + // need type declaration
109685 + .type_required = true,
109686 + .function_type_required = false,
109687 + .handler = handle_randomize_layout_attr,
109688 +#if BUILDING_GCC_VERSION >= 4007
109689 + .affects_type_identity = true
109690 +#endif
109691 +};
109692 +
109693 +static struct attribute_spec no_randomize_layout_attr = {
109694 + .name = "no_randomize_layout",
109695 + // related to args
109696 + .min_length = 0,
109697 + .max_length = 0,
109698 + .decl_required = false,
109699 + // need type declaration
109700 + .type_required = true,
109701 + .function_type_required = false,
109702 + .handler = handle_randomize_layout_attr,
109703 +#if BUILDING_GCC_VERSION >= 4007
109704 + .affects_type_identity = true
109705 +#endif
109706 +};
109707 +
109708 +static struct attribute_spec randomize_considered_attr = {
109709 + .name = "randomize_considered",
109710 + // related to args
109711 + .min_length = 0,
109712 + .max_length = 0,
109713 + .decl_required = false,
109714 + // need type declaration
109715 + .type_required = true,
109716 + .function_type_required = false,
109717 + .handler = handle_randomize_considered_attr,
109718 +#if BUILDING_GCC_VERSION >= 4007
109719 + .affects_type_identity = false
109720 +#endif
109721 +};
109722 +
109723 +static struct attribute_spec randomize_performed_attr = {
109724 + .name = "randomize_performed",
109725 + // related to args
109726 + .min_length = 0,
109727 + .max_length = 0,
109728 + .decl_required = false,
109729 + // need type declaration
109730 + .type_required = true,
109731 + .function_type_required = false,
109732 + .handler = handle_randomize_performed_attr,
109733 +#if BUILDING_GCC_VERSION >= 4007
109734 + .affects_type_identity = false
109735 +#endif
109736 +};
109737 +
109738 +static void register_attributes(void *event_data, void *data)
109739 +{
109740 + register_attribute(&randomize_layout_attr);
109741 + register_attribute(&no_randomize_layout_attr);
109742 + register_attribute(&randomize_considered_attr);
109743 + register_attribute(&randomize_performed_attr);
109744 +}
109745 +
109746 +static void check_bad_casts_in_constructor(tree var, tree init)
109747 +{
109748 + unsigned HOST_WIDE_INT idx;
109749 + tree field, val;
109750 + tree field_type, val_type;
109751 +
109752 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
109753 + if (TREE_CODE(val) == CONSTRUCTOR) {
109754 + check_bad_casts_in_constructor(var, val);
109755 + continue;
109756 + }
109757 +
109758 + /* pipacs' plugin creates franken-arrays that differ from those produced by
109759 + normal code which all have valid 'field' trees. work around this */
109760 + if (field == NULL_TREE)
109761 + continue;
109762 + field_type = TREE_TYPE(field);
109763 + val_type = TREE_TYPE(val);
109764 +
109765 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
109766 + continue;
109767 +
109768 + if (field_type == val_type)
109769 + continue;
109770 +
109771 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
109772 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
109773 +
109774 + if (field_type == void_type_node)
109775 + continue;
109776 + if (field_type == val_type)
109777 + continue;
109778 + if (TREE_CODE(val_type) != RECORD_TYPE)
109779 + continue;
109780 +
109781 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
109782 + continue;
109783 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
109784 + }
109785 +}
109786 +
109787 +/* derived from the constify plugin */
109788 +static void check_global_variables(void *event_data, void *data)
109789 +{
109790 + struct varpool_node *node;
109791 + tree init;
109792 +
109793 + FOR_EACH_VARIABLE(node) {
109794 + tree var = NODE_DECL(node);
109795 + init = DECL_INITIAL(var);
109796 + if (init == NULL_TREE)
109797 + continue;
109798 +
109799 + if (TREE_CODE(init) != CONSTRUCTOR)
109800 + continue;
109801 +
109802 + check_bad_casts_in_constructor(var, init);
109803 + }
109804 +}
109805 +
109806 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
109807 +{
109808 + basic_block dom;
109809 + gimple dom_stmt;
109810 + gimple call_stmt;
109811 + const_tree dom_lhs;
109812 + const_tree poss_is_err_cond;
109813 + const_tree poss_is_err_func;
109814 + const_tree is_err_arg;
109815 +
109816 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
109817 + if (!dom)
109818 + return false;
109819 +
109820 + dom_stmt = last_stmt(dom);
109821 + if (!dom_stmt)
109822 + return false;
109823 +
109824 + if (gimple_code(dom_stmt) != GIMPLE_COND)
109825 + return false;
109826 +
109827 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
109828 + return false;
109829 +
109830 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
109831 + return false;
109832 +
109833 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
109834 +
109835 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
109836 + return false;
109837 +
109838 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
109839 +
109840 + if (gimple_code(call_stmt) != GIMPLE_CALL)
109841 + return false;
109842 +
109843 + dom_lhs = gimple_get_lhs(call_stmt);
109844 + poss_is_err_func = gimple_call_fndecl(call_stmt);
109845 + if (!poss_is_err_func)
109846 + return false;
109847 + if (dom_lhs != poss_is_err_cond)
109848 + return false;
109849 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
109850 + return false;
109851 +
109852 + is_err_arg = gimple_call_arg(call_stmt, 0);
109853 + if (!is_err_arg)
109854 + return false;
109855 +
109856 + if (is_err_arg != rhs)
109857 + return false;
109858 +
109859 + return true;
109860 +}
109861 +
109862 +static void handle_local_var_initializers(void)
109863 +{
109864 + tree var;
109865 + unsigned int i;
109866 +
109867 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
109868 + tree init = DECL_INITIAL(var);
109869 + if (!init)
109870 + continue;
109871 + if (TREE_CODE(init) != CONSTRUCTOR)
109872 + continue;
109873 + check_bad_casts_in_constructor(var, init);
109874 + }
109875 +}
109876 +
109877 +/*
109878 + * iterate over all statements to find "bad" casts:
109879 + * those where the address of the start of a structure is cast
109880 + * to a pointer of a structure of a different type, or a
109881 + * structure pointer type is cast to a different structure pointer type
109882 + */
109883 +static unsigned int find_bad_casts(void)
109884 +{
109885 + basic_block bb;
109886 +
109887 + handle_local_var_initializers();
109888 +
109889 + FOR_ALL_BB_FN(bb, cfun) {
109890 + gimple_stmt_iterator gsi;
109891 +
109892 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
109893 + gimple stmt;
109894 + const_tree lhs;
109895 + const_tree lhs_type;
109896 + const_tree rhs1;
109897 + const_tree rhs_type;
109898 + const_tree ptr_lhs_type;
109899 + const_tree ptr_rhs_type;
109900 + const_tree op0;
109901 + const_tree op0_type;
109902 + enum tree_code rhs_code;
109903 +
109904 + stmt = gsi_stmt(gsi);
109905 +
109906 +#ifdef __DEBUG_PLUGIN
109907 +#ifdef __DEBUG_VERBOSE
109908 + debug_gimple_stmt(stmt);
109909 + debug_tree(gimple_get_lhs(stmt));
109910 +#endif
109911 +#endif
109912 +
109913 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
109914 + continue;
109915 +
109916 +#ifdef __DEBUG_PLUGIN
109917 +#ifdef __DEBUG_VERBOSE
109918 + debug_tree(gimple_assign_rhs1(stmt));
109919 +#endif
109920 +#endif
109921 +
109922 + rhs_code = gimple_assign_rhs_code(stmt);
109923 +
109924 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
109925 + continue;
109926 +
109927 + lhs = gimple_get_lhs(stmt);
109928 + lhs_type = TREE_TYPE(lhs);
109929 + rhs1 = gimple_assign_rhs1(stmt);
109930 + rhs_type = TREE_TYPE(rhs1);
109931 +
109932 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
109933 + TREE_CODE(lhs_type) != POINTER_TYPE)
109934 + continue;
109935 +
109936 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
109937 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
109938 +
109939 + if (ptr_rhs_type == void_type_node)
109940 + continue;
109941 +
109942 + if (ptr_lhs_type == void_type_node)
109943 + continue;
109944 +
109945 + if (dominated_by_is_err(rhs1, bb))
109946 + continue;
109947 +
109948 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
109949 +#ifndef __DEBUG_PLUGIN
109950 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
109951 +#endif
109952 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
109953 + continue;
109954 + }
109955 +
109956 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
109957 + continue;
109958 +
109959 + if (rhs_code == ADDR_EXPR) {
109960 + op0 = TREE_OPERAND(rhs1, 0);
109961 +
109962 + if (op0 == NULL_TREE)
109963 + continue;
109964 +
109965 + if (TREE_CODE(op0) != VAR_DECL)
109966 + continue;
109967 +
109968 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
109969 + if (op0_type == ptr_lhs_type)
109970 + continue;
109971 +
109972 +#ifndef __DEBUG_PLUGIN
109973 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
109974 +#endif
109975 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
109976 + } else {
109977 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
109978 + /* skip bogus type casts introduced by container_of */
109979 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
109980 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
109981 + continue;
109982 +#ifndef __DEBUG_PLUGIN
109983 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
109984 +#endif
109985 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
109986 + }
109987 +
109988 + }
109989 + }
109990 + return 0;
109991 +}
109992 +
109993 +#if BUILDING_GCC_VERSION >= 4009
109994 +static const struct pass_data randomize_layout_bad_cast_data = {
109995 +#else
109996 +static struct gimple_opt_pass randomize_layout_bad_cast = {
109997 + .pass = {
109998 +#endif
109999 + .type = GIMPLE_PASS,
110000 + .name = "randomize_layout_bad_cast",
110001 +#if BUILDING_GCC_VERSION >= 4008
110002 + .optinfo_flags = OPTGROUP_NONE,
110003 +#endif
110004 +#if BUILDING_GCC_VERSION >= 4009
110005 + .has_gate = false,
110006 + .has_execute = true,
110007 +#else
110008 + .gate = NULL,
110009 + .execute = find_bad_casts,
110010 + .sub = NULL,
110011 + .next = NULL,
110012 + .static_pass_number = 0,
110013 +#endif
110014 + .tv_id = TV_NONE,
110015 + .properties_required = PROP_cfg,
110016 + .properties_provided = 0,
110017 + .properties_destroyed = 0,
110018 + .todo_flags_start = 0,
110019 + .todo_flags_finish = TODO_dump_func
110020 +#if BUILDING_GCC_VERSION < 4009
110021 + }
110022 +#endif
110023 +};
110024 +
110025 +#if BUILDING_GCC_VERSION >= 4009
110026 +namespace {
110027 +class randomize_layout_bad_cast : public gimple_opt_pass {
110028 +public:
110029 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
110030 + unsigned int execute() { return find_bad_casts(); }
110031 +};
110032 +}
110033 +#endif
110034 +
110035 +static struct opt_pass *make_randomize_layout_bad_cast(void)
110036 +{
110037 +#if BUILDING_GCC_VERSION >= 4009
110038 + return new randomize_layout_bad_cast();
110039 +#else
110040 + return &randomize_layout_bad_cast.pass;
110041 +#endif
110042 +}
110043 +
110044 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110045 +{
110046 + int i;
110047 + const char * const plugin_name = plugin_info->base_name;
110048 + const int argc = plugin_info->argc;
110049 + const struct plugin_argument * const argv = plugin_info->argv;
110050 + bool enable = true;
110051 + int obtained_seed = 0;
110052 + struct register_pass_info randomize_layout_bad_cast_info;
110053 +
110054 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
110055 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
110056 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
110057 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
110058 +
110059 + if (!plugin_default_version_check(version, &gcc_version)) {
110060 + error(G_("incompatible gcc/plugin versions"));
110061 + return 1;
110062 + }
110063 +
110064 + if (strcmp(lang_hooks.name, "GNU C")) {
110065 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110066 + enable = false;
110067 + }
110068 +
110069 + for (i = 0; i < argc; ++i) {
110070 + if (!strcmp(argv[i].key, "disable")) {
110071 + enable = false;
110072 + continue;
110073 + }
110074 + if (!strcmp(argv[i].key, "performance-mode")) {
110075 + performance_mode = 1;
110076 + continue;
110077 + }
110078 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110079 + }
110080 +
110081 + if (strlen(randstruct_seed) != 64) {
110082 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
110083 + return 1;
110084 + }
110085 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
110086 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
110087 + if (obtained_seed != 4) {
110088 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
110089 + return 1;
110090 + }
110091 +
110092 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
110093 + if (enable) {
110094 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110095 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
110096 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110097 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
110098 + }
110099 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110100 +
110101 + return 0;
110102 +}
110103 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
110104 new file mode 100644
110105 index 0000000..1f0214f
110106 --- /dev/null
110107 +++ b/tools/gcc/size_overflow_plugin/.gitignore
110108 @@ -0,0 +1,3 @@
110109 +randomize_layout_seed.h
110110 +size_overflow_hash.h
110111 +size_overflow_hash_aux.h
110112 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
110113 new file mode 100644
110114 index 0000000..1ae2ed5
110115 --- /dev/null
110116 +++ b/tools/gcc/size_overflow_plugin/Makefile
110117 @@ -0,0 +1,20 @@
110118 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
110119 +always := $($(HOSTLIBS)-y)
110120 +
110121 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
110122 +
110123 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
110124 +
110125 +quiet_cmd_build_size_overflow_hash = GENHASH $@
110126 + cmd_build_size_overflow_hash = \
110127 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
110128 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
110129 + $(call if_changed,build_size_overflow_hash)
110130 +
110131 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
110132 + cmd_build_size_overflow_hash_aux = \
110133 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
110134 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
110135 + $(call if_changed,build_size_overflow_hash_aux)
110136 +
110137 +targets += size_overflow_hash.h size_overflow_hash_aux.h
110138 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110139 new file mode 100644
110140 index 0000000..12b1e3b
110141 --- /dev/null
110142 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110143 @@ -0,0 +1,102 @@
110144 +#!/bin/bash
110145 +
110146 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
110147 +
110148 +header1="size_overflow_hash.h"
110149 +database="size_overflow_hash.data"
110150 +n=65536
110151 +hashtable_name="size_overflow_hash"
110152 +
110153 +usage() {
110154 +cat <<EOF
110155 +usage: $0 options
110156 +OPTIONS:
110157 + -h|--help help
110158 + -o header file
110159 + -d database file
110160 + -n hash array size
110161 + -s name of the hash table
110162 +EOF
110163 + return 0
110164 +}
110165 +
110166 +while true
110167 +do
110168 + case "$1" in
110169 + -h|--help) usage && exit 0;;
110170 + -n) n=$2; shift 2;;
110171 + -o) header1="$2"; shift 2;;
110172 + -d) database="$2"; shift 2;;
110173 + -s) hashtable_name="$2"; shift 2;;
110174 + --) shift 1; break ;;
110175 + *) break ;;
110176 + esac
110177 +done
110178 +
110179 +create_defines() {
110180 + for i in `seq 0 31`
110181 + do
110182 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
110183 + done
110184 + echo >> "$header1"
110185 +}
110186 +
110187 +create_structs() {
110188 + rm -f "$header1"
110189 +
110190 + create_defines
110191 +
110192 + cat "$database" | while read data
110193 + do
110194 + data_array=($data)
110195 + struct_hash_name="${data_array[0]}"
110196 + funcn="${data_array[1]}"
110197 + params="${data_array[2]}"
110198 + next="${data_array[4]}"
110199 +
110200 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
110201 +
110202 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
110203 + echo -en "\t.param\t= " >> "$header1"
110204 + line=
110205 + for param_num in ${params//-/ };
110206 + do
110207 + line="${line}PARAM"$param_num"|"
110208 + done
110209 +
110210 + echo -e "${line%?},\n};\n" >> "$header1"
110211 + done
110212 +}
110213 +
110214 +create_headers() {
110215 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
110216 +}
110217 +
110218 +create_array_elements() {
110219 + index=0
110220 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
110221 + do
110222 + data_array=($data)
110223 + i="${data_array[3]}"
110224 + hash="${data_array[0]}"
110225 + while [[ $index -lt $i ]]
110226 + do
110227 + echo -e "\t["$index"]\t= NULL," >> "$header1"
110228 + index=$(($index + 1))
110229 + done
110230 + index=$(($index + 1))
110231 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
110232 + done
110233 + echo '};' >> $header1
110234 +}
110235 +
110236 +size_overflow_plugin_dir=`dirname $header1`
110237 +if [ "$size_overflow_plugin_dir" != '.' ]; then
110238 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
110239 +fi
110240 +
110241 +create_structs
110242 +create_headers
110243 +create_array_elements
110244 +
110245 +exit 0
110246 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110247 new file mode 100644
110248 index 0000000..3e8148c
110249 --- /dev/null
110250 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110251 @@ -0,0 +1,790 @@
110252 +/*
110253 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110254 + * Licensed under the GPL v2, or (at your option) v3
110255 + *
110256 + * Homepage:
110257 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110258 + *
110259 + * Documentation:
110260 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110261 + *
110262 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110263 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110264 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110265 + *
110266 + * Usage:
110267 + * $ make
110268 + * $ make run
110269 + */
110270 +
110271 +#include "gcc-common.h"
110272 +#include "size_overflow.h"
110273 +
110274 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
110275 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
110276 +
110277 +// data for the size_overflow asm stmt
110278 +struct asm_data {
110279 + gimple def_stmt;
110280 + tree input;
110281 + tree output;
110282 +};
110283 +
110284 +#if BUILDING_GCC_VERSION <= 4007
110285 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
110286 +#else
110287 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
110288 +#endif
110289 +{
110290 + tree list;
110291 +#if BUILDING_GCC_VERSION <= 4007
110292 + VEC(tree, gc) *vec_list = NULL;
110293 +#else
110294 + vec<tree, va_gc> *vec_list = NULL;
110295 +#endif
110296 +
110297 + list = build_tree_list(NULL_TREE, string);
110298 + list = chainon(NULL_TREE, build_tree_list(list, io));
110299 +#if BUILDING_GCC_VERSION <= 4007
110300 + VEC_safe_push(tree, gc, vec_list, list);
110301 +#else
110302 + vec_safe_push(vec_list, list);
110303 +#endif
110304 + return vec_list;
110305 +}
110306 +
110307 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110308 +{
110309 + gimple asm_stmt;
110310 + gimple_stmt_iterator gsi;
110311 +#if BUILDING_GCC_VERSION <= 4007
110312 + VEC(tree, gc) *input, *output = NULL;
110313 +#else
110314 + vec<tree, va_gc> *input, *output = NULL;
110315 +#endif
110316 +
110317 + input = create_asm_io_list(str_input, asm_data->input);
110318 +
110319 + if (asm_data->output)
110320 + output = create_asm_io_list(str_output, asm_data->output);
110321 +
110322 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110323 + gsi = gsi_for_stmt(asm_data->def_stmt);
110324 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110325 +
110326 + if (asm_data->output)
110327 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110328 +}
110329 +
110330 +static void replace_call_lhs(const struct asm_data *asm_data)
110331 +{
110332 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
110333 + update_stmt(asm_data->def_stmt);
110334 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
110335 +}
110336 +
110337 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
110338 +{
110339 + enum mark cur_fndecl_attr;
110340 + gimple phi = get_def_stmt(result);
110341 + unsigned int i, n = gimple_phi_num_args(phi);
110342 +
110343 + pointer_set_insert(visited, phi);
110344 + for (i = 0; i < n; i++) {
110345 + tree arg = gimple_phi_arg_def(phi, i);
110346 +
110347 + cur_fndecl_attr = search_intentional(visited, arg);
110348 + if (cur_fndecl_attr != MARK_NO)
110349 + return cur_fndecl_attr;
110350 + }
110351 + return MARK_NO;
110352 +}
110353 +
110354 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
110355 +{
110356 + enum mark cur_fndecl_attr;
110357 + const_tree rhs1, rhs2;
110358 + gimple def_stmt = get_def_stmt(lhs);
110359 +
110360 + rhs1 = gimple_assign_rhs1(def_stmt);
110361 + rhs2 = gimple_assign_rhs2(def_stmt);
110362 +
110363 + cur_fndecl_attr = search_intentional(visited, rhs1);
110364 + if (cur_fndecl_attr != MARK_NO)
110365 + return cur_fndecl_attr;
110366 + return search_intentional(visited, rhs2);
110367 +}
110368 +
110369 +// Look up the intentional_overflow attribute on the caller and the callee functions.
110370 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
110371 +{
110372 + const_gimple def_stmt;
110373 +
110374 + if (TREE_CODE(lhs) != SSA_NAME)
110375 + return get_intentional_attr_type(lhs);
110376 +
110377 + def_stmt = get_def_stmt(lhs);
110378 + if (!def_stmt)
110379 + return MARK_NO;
110380 +
110381 + if (pointer_set_contains(visited, def_stmt))
110382 + return MARK_NO;
110383 +
110384 + switch (gimple_code(def_stmt)) {
110385 + case GIMPLE_NOP:
110386 + return search_intentional(visited, SSA_NAME_VAR(lhs));
110387 + case GIMPLE_ASM:
110388 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
110389 + return MARK_TURN_OFF;
110390 + return MARK_NO;
110391 + case GIMPLE_CALL:
110392 + return MARK_NO;
110393 + case GIMPLE_PHI:
110394 + return search_intentional_phi(visited, lhs);
110395 + case GIMPLE_ASSIGN:
110396 + switch (gimple_num_ops(def_stmt)) {
110397 + case 2:
110398 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
110399 + case 3:
110400 + return search_intentional_binary(visited, lhs);
110401 + }
110402 + case GIMPLE_RETURN:
110403 + return MARK_NO;
110404 + default:
110405 + debug_gimple_stmt((gimple)def_stmt);
110406 + error("%s: unknown gimple code", __func__);
110407 + gcc_unreachable();
110408 + }
110409 +}
110410 +
110411 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
110412 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
110413 +{
110414 + const_tree fndecl;
110415 + struct pointer_set_t *visited;
110416 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
110417 +
110418 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
110419 + if (is_end_intentional_intentional_attr(fndecl, argnum))
110420 + decl_attr = MARK_NOT_INTENTIONAL;
110421 + else if (is_yes_intentional_attr(fndecl, argnum))
110422 + decl_attr = MARK_YES;
110423 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
110424 + return MARK_TURN_OFF;
110425 + }
110426 +
110427 + visited = pointer_set_create();
110428 + cur_fndecl_attr = search_intentional(visited, arg);
110429 + pointer_set_destroy(visited);
110430 +
110431 + switch (cur_fndecl_attr) {
110432 + case MARK_NO:
110433 + case MARK_TURN_OFF:
110434 + return cur_fndecl_attr;
110435 + default:
110436 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
110437 + return MARK_YES;
110438 + }
110439 +}
110440 +
110441 +static void check_missing_size_overflow_attribute(tree var)
110442 +{
110443 + tree orig_fndecl;
110444 + unsigned int num;
110445 +
110446 + if (is_a_return_check(var))
110447 + orig_fndecl = DECL_ORIGIN(var);
110448 + else
110449 + orig_fndecl = DECL_ORIGIN(current_function_decl);
110450 +
110451 + num = get_function_num(var, orig_fndecl);
110452 + if (num == CANNOT_FIND_ARG)
110453 + return;
110454 +
110455 + is_missing_function(orig_fndecl, num);
110456 +}
110457 +
110458 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
110459 +{
110460 + gimple phi = get_def_stmt(result);
110461 + unsigned int i, n = gimple_phi_num_args(phi);
110462 +
110463 + pointer_set_insert(visited, phi);
110464 + for (i = 0; i < n; i++) {
110465 + tree arg = gimple_phi_arg_def(phi, i);
110466 +
110467 + search_size_overflow_attribute(visited, arg);
110468 + }
110469 +}
110470 +
110471 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
110472 +{
110473 + const_gimple def_stmt = get_def_stmt(lhs);
110474 + tree rhs1, rhs2;
110475 +
110476 + rhs1 = gimple_assign_rhs1(def_stmt);
110477 + rhs2 = gimple_assign_rhs2(def_stmt);
110478 +
110479 + search_size_overflow_attribute(visited, rhs1);
110480 + search_size_overflow_attribute(visited, rhs2);
110481 +}
110482 +
110483 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
110484 +{
110485 + const_gimple def_stmt;
110486 +
110487 + if (TREE_CODE(lhs) == PARM_DECL) {
110488 + check_missing_size_overflow_attribute(lhs);
110489 + return;
110490 + }
110491 +
110492 + def_stmt = get_def_stmt(lhs);
110493 + if (!def_stmt)
110494 + return;
110495 +
110496 + if (pointer_set_insert(visited, def_stmt))
110497 + return;
110498 +
110499 + switch (gimple_code(def_stmt)) {
110500 + case GIMPLE_NOP:
110501 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
110502 + case GIMPLE_ASM:
110503 + return;
110504 + case GIMPLE_CALL: {
110505 + tree fndecl = gimple_call_fndecl(def_stmt);
110506 +
110507 + if (fndecl == NULL_TREE)
110508 + return;
110509 + check_missing_size_overflow_attribute(fndecl);
110510 + return;
110511 + }
110512 + case GIMPLE_PHI:
110513 + return search_size_overflow_attribute_phi(visited, lhs);
110514 + case GIMPLE_ASSIGN:
110515 + switch (gimple_num_ops(def_stmt)) {
110516 + case 2:
110517 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
110518 + case 3:
110519 + return search_size_overflow_attribute_binary(visited, lhs);
110520 + }
110521 + default:
110522 + debug_gimple_stmt((gimple)def_stmt);
110523 + error("%s: unknown gimple code", __func__);
110524 + gcc_unreachable();
110525 + }
110526 +}
110527 +
110528 +// Search missing entries in the hash table (invoked from the gimple pass)
110529 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
110530 +{
110531 + tree fndecl = NULL_TREE;
110532 + tree lhs;
110533 + struct pointer_set_t *visited;
110534 +
110535 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
110536 + return;
110537 +
110538 + if (num == 0) {
110539 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
110540 + lhs = gimple_return_retval(stmt);
110541 + } else {
110542 + gcc_assert(is_gimple_call(stmt));
110543 + lhs = gimple_call_arg(stmt, num - 1);
110544 + fndecl = gimple_call_fndecl(stmt);
110545 + }
110546 +
110547 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
110548 + return;
110549 +
110550 + visited = pointer_set_create();
110551 + search_size_overflow_attribute(visited, lhs);
110552 + pointer_set_destroy(visited);
110553 +}
110554 +
110555 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110556 +{
110557 + gimple_stmt_iterator gsi;
110558 + gimple assign;
110559 +
110560 + assign = gimple_build_assign(asm_data->input, asm_data->output);
110561 + gsi = gsi_for_stmt(stmt);
110562 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
110563 + asm_data->def_stmt = assign;
110564 +
110565 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
110566 + asm_data->output = make_ssa_name(asm_data->output, stmt);
110567 + if (gimple_code(stmt) == GIMPLE_RETURN)
110568 + gimple_return_set_retval(stmt, asm_data->output);
110569 + else
110570 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
110571 + update_stmt(stmt);
110572 +}
110573 +
110574 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
110575 +{
110576 + const char *fn_name;
110577 + char *asm_comment;
110578 + unsigned int len;
110579 +
110580 + if (argnum == 0)
110581 + fn_name = DECL_NAME_POINTER(current_function_decl);
110582 + else
110583 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
110584 +
110585 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
110586 + gcc_assert(len > 0);
110587 +
110588 + return asm_comment;
110589 +}
110590 +
110591 +static const char *convert_mark_to_str(enum mark mark)
110592 +{
110593 + switch (mark) {
110594 + case MARK_NO:
110595 + return OK_ASM_STR;
110596 + case MARK_YES:
110597 + case MARK_NOT_INTENTIONAL:
110598 + return YES_ASM_STR;
110599 + case MARK_TURN_OFF:
110600 + return TURN_OFF_ASM_STR;
110601 + }
110602 +
110603 + gcc_unreachable();
110604 +}
110605 +
110606 +/* Create the input of the size_overflow asm stmt.
110607 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
110608 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110609 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
110610 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
110611 + */
110612 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110613 +{
110614 + if (!asm_data->def_stmt) {
110615 + asm_data->input = NULL_TREE;
110616 + return;
110617 + }
110618 +
110619 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
110620 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
110621 +
110622 + switch (gimple_code(asm_data->def_stmt)) {
110623 + case GIMPLE_ASSIGN:
110624 + case GIMPLE_CALL:
110625 + replace_call_lhs(asm_data);
110626 + break;
110627 + case GIMPLE_PHI:
110628 + create_output_from_phi(stmt, argnum, asm_data);
110629 + break;
110630 + case GIMPLE_NOP: {
110631 + enum mark mark;
110632 + const char *mark_str;
110633 + char *asm_comment;
110634 +
110635 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
110636 +
110637 + asm_data->input = asm_data->output;
110638 + asm_data->output = NULL;
110639 + asm_data->def_stmt = stmt;
110640 +
110641 + mark_str = convert_mark_to_str(mark);
110642 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110643 +
110644 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
110645 + free(asm_comment);
110646 + asm_data->input = NULL_TREE;
110647 + break;
110648 + }
110649 + case GIMPLE_ASM:
110650 + if (is_size_overflow_asm(asm_data->def_stmt)) {
110651 + asm_data->input = NULL_TREE;
110652 + break;
110653 + }
110654 + default:
110655 + debug_gimple_stmt(asm_data->def_stmt);
110656 + gcc_unreachable();
110657 + }
110658 +}
110659 +
110660 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
110661 + * is of the right kind create the appropriate size_overflow asm stmts:
110662 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
110663 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110664 + */
110665 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
110666 +{
110667 + struct asm_data asm_data;
110668 + const char *mark_str;
110669 + char *asm_comment;
110670 + enum mark mark;
110671 +
110672 + if (is_gimple_constant(output_node))
110673 + return;
110674 +
110675 + asm_data.output = output_node;
110676 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
110677 + if (mark != MARK_TURN_OFF)
110678 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
110679 +
110680 + asm_data.def_stmt = get_def_stmt(asm_data.output);
110681 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
110682 + return;
110683 +
110684 + create_asm_input(stmt, argnum, &asm_data);
110685 + if (asm_data.input == NULL_TREE)
110686 + return;
110687 +
110688 + mark_str = convert_mark_to_str(mark);
110689 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110690 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110691 + free(asm_comment);
110692 +}
110693 +
110694 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
110695 +static bool create_mark_asm(gimple stmt, enum mark mark)
110696 +{
110697 + struct asm_data asm_data;
110698 + const char *asm_str;
110699 +
110700 + switch (mark) {
110701 + case MARK_TURN_OFF:
110702 + asm_str = TURN_OFF_ASM_STR;
110703 + break;
110704 + case MARK_NOT_INTENTIONAL:
110705 + case MARK_YES:
110706 + asm_str = YES_ASM_STR;
110707 + break;
110708 + default:
110709 + gcc_unreachable();
110710 + }
110711 +
110712 + asm_data.def_stmt = stmt;
110713 + asm_data.output = gimple_call_lhs(stmt);
110714 +
110715 + if (asm_data.output == NULL_TREE) {
110716 + asm_data.input = gimple_call_arg(stmt, 0);
110717 + if (is_gimple_constant(asm_data.input))
110718 + return false;
110719 + asm_data.output = NULL;
110720 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
110721 + return true;
110722 + }
110723 +
110724 + create_asm_input(stmt, 0, &asm_data);
110725 + gcc_assert(asm_data.input != NULL_TREE);
110726 +
110727 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110728 + return true;
110729 +}
110730 +
110731 +static bool is_from_cast(const_tree node)
110732 +{
110733 + gimple def_stmt = get_def_stmt(node);
110734 +
110735 + if (!def_stmt)
110736 + return false;
110737 +
110738 + if (gimple_assign_cast_p(def_stmt))
110739 + return true;
110740 +
110741 + return false;
110742 +}
110743 +
110744 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
110745 +static bool skip_ptr_minus(gimple stmt)
110746 +{
110747 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
110748 +
110749 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
110750 + return false;
110751 +
110752 + rhs1 = gimple_assign_rhs1(stmt);
110753 + if (!is_from_cast(rhs1))
110754 + return false;
110755 +
110756 + rhs2 = gimple_assign_rhs2(stmt);
110757 + if (!is_from_cast(rhs2))
110758 + return false;
110759 +
110760 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
110761 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
110762 +
110763 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
110764 + return false;
110765 +
110766 + create_mark_asm(stmt, MARK_YES);
110767 + return true;
110768 +}
110769 +
110770 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
110771 +{
110772 + gimple def_stmt;
110773 +
110774 + def_stmt = get_def_stmt(lhs);
110775 + if (!def_stmt)
110776 + return;
110777 +
110778 + if (pointer_set_insert(visited, def_stmt))
110779 + return;
110780 +
110781 + switch (gimple_code(def_stmt)) {
110782 + case GIMPLE_NOP:
110783 + case GIMPLE_ASM:
110784 + case GIMPLE_CALL:
110785 + break;
110786 + case GIMPLE_PHI: {
110787 + unsigned int i, n = gimple_phi_num_args(def_stmt);
110788 +
110789 + pointer_set_insert(visited, def_stmt);
110790 +
110791 + for (i = 0; i < n; i++) {
110792 + tree arg = gimple_phi_arg_def(def_stmt, i);
110793 +
110794 + walk_use_def_ptr(visited, arg);
110795 + }
110796 + }
110797 + case GIMPLE_ASSIGN:
110798 + switch (gimple_num_ops(def_stmt)) {
110799 + case 2:
110800 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
110801 + return;
110802 + case 3:
110803 + if (skip_ptr_minus(def_stmt))
110804 + return;
110805 +
110806 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
110807 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
110808 + return;
110809 + default:
110810 + return;
110811 + }
110812 + default:
110813 + debug_gimple_stmt((gimple)def_stmt);
110814 + error("%s: unknown gimple code", __func__);
110815 + gcc_unreachable();
110816 + }
110817 +}
110818 +
110819 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
110820 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
110821 +{
110822 + struct pointer_set_t *visited;
110823 +
110824 + visited = pointer_set_create();
110825 + walk_use_def_ptr(visited, arg);
110826 + pointer_set_destroy(visited);
110827 +}
110828 +
110829 +// Determine the return value and insert the asm stmt to mark the return stmt.
110830 +static void insert_asm_ret(gimple stmt)
110831 +{
110832 + tree ret;
110833 +
110834 + ret = gimple_return_retval(stmt);
110835 + create_size_overflow_asm(stmt, ret, 0);
110836 +}
110837 +
110838 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
110839 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
110840 +{
110841 + tree arg;
110842 + unsigned int argnum;
110843 +
110844 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
110845 + gcc_assert(argnum != 0);
110846 + if (argnum == CANNOT_FIND_ARG)
110847 + return;
110848 +
110849 + arg = gimple_call_arg(stmt, argnum - 1);
110850 + gcc_assert(arg != NULL_TREE);
110851 +
110852 + // skip all ptr - ptr expressions
110853 + insert_mark_not_intentional_asm_at_ptr(arg);
110854 +
110855 + create_size_overflow_asm(stmt, arg, argnum);
110856 +}
110857 +
110858 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
110859 +static void set_argnum_attribute(const_tree attr, bool *argnums)
110860 +{
110861 + unsigned int argnum;
110862 + tree attr_value;
110863 +
110864 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
110865 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
110866 + argnums[argnum] = true;
110867 + }
110868 +}
110869 +
110870 +// If a function arg or the return value is in the hash table then set its index in the array.
110871 +static void set_argnum_hash(tree fndecl, bool *argnums)
110872 +{
110873 + unsigned int num;
110874 + const struct size_overflow_hash *hash;
110875 +
110876 + hash = get_function_hash(DECL_ORIGIN(fndecl));
110877 + if (!hash)
110878 + return;
110879 +
110880 + for (num = 0; num <= MAX_PARAM; num++) {
110881 + if (!(hash->param & (1U << num)))
110882 + continue;
110883 +
110884 + argnums[num] = true;
110885 + }
110886 +}
110887 +
110888 +static bool is_all_the_argnums_empty(bool *argnums)
110889 +{
110890 + unsigned int i;
110891 +
110892 + for (i = 0; i <= MAX_PARAM; i++)
110893 + if (argnums[i])
110894 + return false;
110895 + return true;
110896 +}
110897 +
110898 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
110899 +static void search_interesting_args(tree fndecl, bool *argnums)
110900 +{
110901 + const_tree attr;
110902 +
110903 + set_argnum_hash(fndecl, argnums);
110904 + if (!is_all_the_argnums_empty(argnums))
110905 + return;
110906 +
110907 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
110908 + if (attr && TREE_VALUE(attr))
110909 + set_argnum_attribute(attr, argnums);
110910 +}
110911 +
110912 +/*
110913 + * Look up the intentional_overflow attribute that turns off ipa based duplication
110914 + * on the callee function.
110915 + */
110916 +static bool is_mark_turn_off_attribute(gimple stmt)
110917 +{
110918 + enum mark mark;
110919 + const_tree fndecl = gimple_call_fndecl(stmt);
110920 +
110921 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
110922 + if (mark == MARK_TURN_OFF)
110923 + return true;
110924 + return false;
110925 +}
110926 +
110927 +// 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
110928 +static void handle_interesting_function(gimple stmt)
110929 +{
110930 + unsigned int argnum;
110931 + tree fndecl;
110932 + bool orig_argnums[MAX_PARAM + 1] = {false};
110933 +
110934 + if (gimple_call_num_args(stmt) == 0)
110935 + return;
110936 + fndecl = gimple_call_fndecl(stmt);
110937 + if (fndecl == NULL_TREE)
110938 + return;
110939 + fndecl = DECL_ORIGIN(fndecl);
110940 +
110941 + if (is_mark_turn_off_attribute(stmt)) {
110942 + create_mark_asm(stmt, MARK_TURN_OFF);
110943 + return;
110944 + }
110945 +
110946 + search_interesting_args(fndecl, orig_argnums);
110947 +
110948 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
110949 + if (orig_argnums[argnum])
110950 + insert_asm_arg(stmt, argnum);
110951 +}
110952 +
110953 +// 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
110954 +static void handle_interesting_ret(gimple stmt)
110955 +{
110956 + bool orig_argnums[MAX_PARAM + 1] = {false};
110957 +
110958 + search_interesting_args(current_function_decl, orig_argnums);
110959 +
110960 + if (orig_argnums[0])
110961 + insert_asm_ret(stmt);
110962 +}
110963 +
110964 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
110965 +static unsigned int search_interesting_functions(void)
110966 +{
110967 + basic_block bb;
110968 +
110969 + FOR_ALL_BB_FN(bb, cfun) {
110970 + gimple_stmt_iterator gsi;
110971 +
110972 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110973 + gimple stmt = gsi_stmt(gsi);
110974 +
110975 + if (is_size_overflow_asm(stmt))
110976 + continue;
110977 +
110978 + if (is_gimple_call(stmt))
110979 + handle_interesting_function(stmt);
110980 + else if (gimple_code(stmt) == GIMPLE_RETURN)
110981 + handle_interesting_ret(stmt);
110982 + }
110983 + }
110984 + return 0;
110985 +}
110986 +
110987 +/*
110988 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
110989 + * this pass inserts asm stmts to mark the interesting args
110990 + * that the ipa pass will detect and insert the size overflow checks for.
110991 + */
110992 +#if BUILDING_GCC_VERSION >= 4009
110993 +static const struct pass_data insert_size_overflow_asm_pass_data = {
110994 +#else
110995 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
110996 + .pass = {
110997 +#endif
110998 + .type = GIMPLE_PASS,
110999 + .name = "insert_size_overflow_asm",
111000 +#if BUILDING_GCC_VERSION >= 4008
111001 + .optinfo_flags = OPTGROUP_NONE,
111002 +#endif
111003 +#if BUILDING_GCC_VERSION >= 4009
111004 + .has_gate = false,
111005 + .has_execute = true,
111006 +#else
111007 + .gate = NULL,
111008 + .execute = search_interesting_functions,
111009 + .sub = NULL,
111010 + .next = NULL,
111011 + .static_pass_number = 0,
111012 +#endif
111013 + .tv_id = TV_NONE,
111014 + .properties_required = PROP_cfg,
111015 + .properties_provided = 0,
111016 + .properties_destroyed = 0,
111017 + .todo_flags_start = 0,
111018 + .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
111019 +#if BUILDING_GCC_VERSION < 4009
111020 + }
111021 +#endif
111022 +};
111023 +
111024 +#if BUILDING_GCC_VERSION >= 4009
111025 +namespace {
111026 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
111027 +public:
111028 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
111029 + unsigned int execute() { return search_interesting_functions(); }
111030 +};
111031 +}
111032 +#endif
111033 +
111034 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
111035 +{
111036 +#if BUILDING_GCC_VERSION >= 4009
111037 + return new insert_size_overflow_asm_pass();
111038 +#else
111039 + return &insert_size_overflow_asm_pass.pass;
111040 +#endif
111041 +}
111042 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
111043 new file mode 100644
111044 index 0000000..88469e9
111045 --- /dev/null
111046 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
111047 @@ -0,0 +1,902 @@
111048 +/*
111049 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111050 + * Licensed under the GPL v2, or (at your option) v3
111051 + *
111052 + * Homepage:
111053 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111054 + *
111055 + * Documentation:
111056 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111057 + *
111058 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111059 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111060 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111061 + *
111062 + * Usage:
111063 + * $ make
111064 + * $ make run
111065 + */
111066 +
111067 +#include "gcc-common.h"
111068 +#include "size_overflow.h"
111069 +
111070 +#define MIN_CHECK true
111071 +#define MAX_CHECK false
111072 +
111073 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
111074 +{
111075 + const_tree type;
111076 + tree new_type;
111077 +
111078 + gcc_assert(node != NULL_TREE);
111079 +
111080 + type = TREE_TYPE(node);
111081 +
111082 + if (pointer_set_contains(visited->my_stmts, stmt))
111083 + return TREE_TYPE(node);
111084 +
111085 + switch (TYPE_MODE(type)) {
111086 + case QImode:
111087 + new_type = size_overflow_type_HI;
111088 + break;
111089 + case HImode:
111090 + new_type = size_overflow_type_SI;
111091 + break;
111092 + case SImode:
111093 + new_type = size_overflow_type_DI;
111094 + break;
111095 + case DImode:
111096 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
111097 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
111098 + else
111099 + new_type = size_overflow_type_TI;
111100 + break;
111101 + case TImode:
111102 + gcc_assert(!TYPE_UNSIGNED(type));
111103 + new_type = size_overflow_type_TI;
111104 + break;
111105 + default:
111106 + debug_tree((tree)node);
111107 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
111108 + gcc_unreachable();
111109 + }
111110 +
111111 + if (TYPE_QUALS(type) != 0)
111112 + return build_qualified_type(new_type, TYPE_QUALS(type));
111113 + return new_type;
111114 +}
111115 +
111116 +static tree get_lhs(const_gimple stmt)
111117 +{
111118 + switch (gimple_code(stmt)) {
111119 + case GIMPLE_ASSIGN:
111120 + case GIMPLE_CALL:
111121 + return gimple_get_lhs(stmt);
111122 + case GIMPLE_PHI:
111123 + return gimple_phi_result(stmt);
111124 + default:
111125 + return NULL_TREE;
111126 + }
111127 +}
111128 +
111129 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
111130 +{
111131 + gimple_stmt_iterator gsi;
111132 + tree lhs;
111133 + gimple new_stmt;
111134 +
111135 + if (rhs == NULL_TREE)
111136 + return NULL_TREE;
111137 +
111138 + gsi = gsi_for_stmt(stmt);
111139 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
111140 + pointer_set_insert(visited->my_stmts, new_stmt);
111141 +
111142 + lhs = get_lhs(new_stmt);
111143 + gcc_assert(lhs != NULL_TREE);
111144 + return lhs;
111145 +}
111146 +
111147 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
111148 +{
111149 + tree lhs, dst_type;
111150 + gimple_stmt_iterator gsi;
111151 +
111152 + if (rhs1 == NULL_TREE) {
111153 + debug_gimple_stmt(oldstmt);
111154 + error("%s: rhs1 is NULL_TREE", __func__);
111155 + gcc_unreachable();
111156 + }
111157 +
111158 + switch (gimple_code(oldstmt)) {
111159 + case GIMPLE_ASM:
111160 + lhs = rhs1;
111161 + break;
111162 + case GIMPLE_CALL:
111163 + case GIMPLE_ASSIGN:
111164 + lhs = gimple_get_lhs(oldstmt);
111165 + break;
111166 + default:
111167 + debug_gimple_stmt(oldstmt);
111168 + gcc_unreachable();
111169 + }
111170 +
111171 + gsi = gsi_for_stmt(oldstmt);
111172 + pointer_set_insert(visited->stmts, oldstmt);
111173 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
111174 + basic_block next_bb, cur_bb;
111175 + const_edge e;
111176 +
111177 + gcc_assert(before == false);
111178 + gcc_assert(stmt_can_throw_internal(oldstmt));
111179 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
111180 + gcc_assert(!gsi_end_p(gsi));
111181 +
111182 + cur_bb = gimple_bb(oldstmt);
111183 + next_bb = cur_bb->next_bb;
111184 + e = find_edge(cur_bb, next_bb);
111185 + gcc_assert(e != NULL);
111186 + gcc_assert(e->flags & EDGE_FALLTHRU);
111187 +
111188 + gsi = gsi_after_labels(next_bb);
111189 + gcc_assert(!gsi_end_p(gsi));
111190 +
111191 + before = true;
111192 + oldstmt = gsi_stmt(gsi);
111193 + }
111194 +
111195 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
111196 +
111197 + if (is_gimple_constant(rhs1))
111198 + return cast_a_tree(dst_type, rhs1);
111199 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
111200 +}
111201 +
111202 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
111203 +{
111204 + gimple stmt;
111205 + gimple_stmt_iterator gsi;
111206 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
111207 +
111208 + if (pointer_set_contains(visited->my_stmts, oldstmt))
111209 + return lhs;
111210 +
111211 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
111212 + rhs1 = gimple_assign_rhs1(oldstmt);
111213 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
111214 + }
111215 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
111216 + rhs2 = gimple_assign_rhs2(oldstmt);
111217 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
111218 + }
111219 +
111220 + stmt = gimple_copy(oldstmt);
111221 + gimple_set_location(stmt, gimple_location(oldstmt));
111222 + pointer_set_insert(visited->my_stmts, stmt);
111223 +
111224 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
111225 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
111226 +
111227 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
111228 +
111229 + new_var = create_new_var(size_overflow_type);
111230 + new_var = make_ssa_name(new_var, stmt);
111231 + gimple_assign_set_lhs(stmt, new_var);
111232 +
111233 + if (rhs1 != NULL_TREE)
111234 + gimple_assign_set_rhs1(stmt, rhs1);
111235 +
111236 + if (rhs2 != NULL_TREE)
111237 + gimple_assign_set_rhs2(stmt, rhs2);
111238 +#if BUILDING_GCC_VERSION >= 4006
111239 + if (rhs3 != NULL_TREE)
111240 + gimple_assign_set_rhs3(stmt, rhs3);
111241 +#endif
111242 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
111243 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
111244 +
111245 + gsi = gsi_for_stmt(oldstmt);
111246 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
111247 + update_stmt(stmt);
111248 + pointer_set_insert(visited->stmts, oldstmt);
111249 + return gimple_assign_lhs(stmt);
111250 +}
111251 +
111252 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
111253 +{
111254 + gimple assign;
111255 + gimple_stmt_iterator gsi;
111256 + basic_block first_bb;
111257 +
111258 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
111259 +
111260 + if (bb->index == 0) {
111261 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111262 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111263 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111264 + bb = first_bb;
111265 + }
111266 +
111267 + gsi = gsi_after_labels(bb);
111268 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
111269 + pointer_set_insert(visited->my_stmts, assign);
111270 +
111271 + return gimple_assign_lhs(assign);
111272 +}
111273 +
111274 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
111275 +{
111276 + gimple_stmt_iterator gsi;
111277 + gimple assign, def_stmt = get_def_stmt(new_arg);
111278 +
111279 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
111280 + gsi = gsi_after_labels(gimple_bb(def_stmt));
111281 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
111282 + } else {
111283 + gsi = gsi_for_stmt(def_stmt);
111284 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
111285 + }
111286 +
111287 + pointer_set_insert(visited->my_stmts, assign);
111288 + return gimple_assign_lhs(assign);
111289 +}
111290 +
111291 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111292 +{
111293 + basic_block bb;
111294 + gimple_stmt_iterator gsi;
111295 + const_gimple def_stmt;
111296 + gimple assign;
111297 +
111298 + def_stmt = get_def_stmt(arg);
111299 + bb = gimple_bb(def_stmt);
111300 + gcc_assert(bb->index != 0);
111301 + gsi = gsi_after_labels(bb);
111302 +
111303 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111304 + pointer_set_insert(visited->my_stmts, assign);
111305 + return gimple_assign_lhs(assign);
111306 +}
111307 +
111308 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111309 +{
111310 + tree size_overflow_type;
111311 + tree arg;
111312 + const_gimple def_stmt;
111313 +
111314 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111315 + return new_arg;
111316 +
111317 + arg = gimple_phi_arg_def(oldstmt, i);
111318 + def_stmt = get_def_stmt(arg);
111319 + gcc_assert(def_stmt != NULL);
111320 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111321 +
111322 + switch (gimple_code(def_stmt)) {
111323 + case GIMPLE_PHI:
111324 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111325 + case GIMPLE_NOP: {
111326 + basic_block bb;
111327 +
111328 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111329 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111330 + }
111331 + case GIMPLE_ASM: {
111332 + gimple_stmt_iterator gsi;
111333 + gimple assign, stmt = get_def_stmt(arg);
111334 +
111335 + gsi = gsi_for_stmt(stmt);
111336 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111337 + pointer_set_insert(visited->my_stmts, assign);
111338 + return gimple_assign_lhs(assign);
111339 + }
111340 + default:
111341 + gcc_assert(new_arg != NULL_TREE);
111342 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111343 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111344 + }
111345 +}
111346 +
111347 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111348 +{
111349 + basic_block bb;
111350 + gimple phi;
111351 + gimple_seq seq;
111352 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111353 +
111354 + bb = gsi_bb(gsi);
111355 +
111356 + if (result == NULL_TREE) {
111357 + tree old_result = gimple_phi_result(oldstmt);
111358 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111359 +
111360 + result = create_new_var(size_overflow_type);
111361 + }
111362 +
111363 + phi = create_phi_node(result, bb);
111364 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111365 + seq = phi_nodes(bb);
111366 + gsi = gsi_last(seq);
111367 + gsi_remove(&gsi, false);
111368 +
111369 + gsi = gsi_for_stmt(oldstmt);
111370 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111371 + gimple_set_bb(phi, bb);
111372 + return phi;
111373 +}
111374 +
111375 +#if BUILDING_GCC_VERSION <= 4007
111376 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
111377 +#else
111378 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
111379 +#endif
111380 +{
111381 + gimple new_phi;
111382 + unsigned int i;
111383 + tree arg, result;
111384 + location_t loc = gimple_location(oldstmt);
111385 +
111386 +#if BUILDING_GCC_VERSION <= 4007
111387 + gcc_assert(!VEC_empty(tree, *args));
111388 +#else
111389 + gcc_assert(!args->is_empty());
111390 +#endif
111391 +
111392 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
111393 + result = gimple_phi_result(new_phi);
111394 + ssa_name_var = SSA_NAME_VAR(result);
111395 +
111396 +#if BUILDING_GCC_VERSION <= 4007
111397 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
111398 +#else
111399 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
111400 +#endif
111401 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
111402 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
111403 + }
111404 +
111405 +#if BUILDING_GCC_VERSION <= 4007
111406 + VEC_free(tree, heap, *args);
111407 +#else
111408 + vec_free(args);
111409 +#endif
111410 + update_stmt(new_phi);
111411 + pointer_set_insert(visited->my_stmts, new_phi);
111412 + return result;
111413 +}
111414 +
111415 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
111416 +{
111417 + tree ssa_name_var = NULL_TREE;
111418 +#if BUILDING_GCC_VERSION <= 4007
111419 + VEC(tree, heap) *args = NULL;
111420 +#else
111421 + vec<tree, va_heap, vl_embed> *args = NULL;
111422 +#endif
111423 + gimple oldstmt = get_def_stmt(orig_result);
111424 + unsigned int i, len = gimple_phi_num_args(oldstmt);
111425 +
111426 + pointer_set_insert(visited->stmts, oldstmt);
111427 + for (i = 0; i < len; i++) {
111428 + tree arg, new_arg;
111429 +
111430 + arg = gimple_phi_arg_def(oldstmt, i);
111431 + new_arg = expand(visited, caller_node, arg);
111432 +
111433 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
111434 + ssa_name_var = SSA_NAME_VAR(new_arg);
111435 +
111436 + if (is_gimple_constant(arg)) {
111437 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111438 +
111439 + new_arg = cast_a_tree(size_overflow_type, arg);
111440 + }
111441 +
111442 +#if BUILDING_GCC_VERSION <= 4007
111443 + VEC_safe_push(tree, heap, args, new_arg);
111444 +#else
111445 + vec_safe_push(args, new_arg);
111446 +#endif
111447 + }
111448 +
111449 +#if BUILDING_GCC_VERSION <= 4007
111450 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
111451 +#else
111452 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
111453 +#endif
111454 +}
111455 +
111456 +static tree create_cast_assign(struct visited *visited, gimple stmt)
111457 +{
111458 + tree rhs1 = gimple_assign_rhs1(stmt);
111459 + tree lhs = gimple_assign_lhs(stmt);
111460 + const_tree rhs1_type = TREE_TYPE(rhs1);
111461 + const_tree lhs_type = TREE_TYPE(lhs);
111462 +
111463 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
111464 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111465 +
111466 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
111467 +}
111468 +
111469 +static bool skip_lhs_cast_check(const_gimple stmt)
111470 +{
111471 + const_tree rhs = gimple_assign_rhs1(stmt);
111472 + const_gimple def_stmt = get_def_stmt(rhs);
111473 +
111474 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
111475 + if (gimple_code(def_stmt) == GIMPLE_ASM)
111476 + return true;
111477 +
111478 + if (is_const_plus_unsigned_signed_truncation(rhs))
111479 + return true;
111480 +
111481 + return false;
111482 +}
111483 +
111484 +static tree create_string_param(tree string)
111485 +{
111486 + tree i_type, a_type;
111487 + const int length = TREE_STRING_LENGTH(string);
111488 +
111489 + gcc_assert(length > 0);
111490 +
111491 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
111492 + a_type = build_array_type(char_type_node, i_type);
111493 +
111494 + TREE_TYPE(string) = a_type;
111495 + TREE_CONSTANT(string) = 1;
111496 + TREE_READONLY(string) = 1;
111497 +
111498 + return build1(ADDR_EXPR, ptr_type_node, string);
111499 +}
111500 +
111501 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
111502 +{
111503 + gimple cond_stmt;
111504 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
111505 +
111506 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
111507 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
111508 + update_stmt(cond_stmt);
111509 +}
111510 +
111511 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
111512 +{
111513 + gimple func_stmt;
111514 + const_gimple def_stmt;
111515 + const_tree loc_line;
111516 + tree loc_file, ssa_name, current_func;
111517 + expanded_location xloc;
111518 + char *ssa_name_buf;
111519 + int len;
111520 + struct cgraph_edge *edge;
111521 + struct cgraph_node *callee_node;
111522 + int frequency;
111523 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
111524 +
111525 + def_stmt = get_def_stmt(arg);
111526 + xloc = expand_location(gimple_location(def_stmt));
111527 +
111528 + if (!gimple_has_location(def_stmt)) {
111529 + xloc = expand_location(gimple_location(stmt));
111530 + if (!gimple_has_location(stmt))
111531 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111532 + }
111533 +
111534 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
111535 +
111536 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
111537 + loc_file = create_string_param(loc_file);
111538 +
111539 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
111540 + current_func = create_string_param(current_func);
111541 +
111542 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
111543 + call_count++;
111544 + 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);
111545 + gcc_assert(len > 0);
111546 + ssa_name = build_string(len + 1, ssa_name_buf);
111547 + free(ssa_name_buf);
111548 + ssa_name = create_string_param(ssa_name);
111549 +
111550 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
111551 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
111552 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
111553 +
111554 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
111555 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
111556 +
111557 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
111558 + gcc_assert(edge != NULL);
111559 +}
111560 +
111561 +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)
111562 +{
111563 + basic_block cond_bb, join_bb, bb_true;
111564 + edge e;
111565 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
111566 +
111567 + cond_bb = gimple_bb(stmt);
111568 + if (before)
111569 + gsi_prev(&gsi);
111570 + if (gsi_end_p(gsi))
111571 + e = split_block_after_labels(cond_bb);
111572 + else
111573 + e = split_block(cond_bb, gsi_stmt(gsi));
111574 + cond_bb = e->src;
111575 + join_bb = e->dest;
111576 + e->flags = EDGE_FALSE_VALUE;
111577 + e->probability = REG_BR_PROB_BASE;
111578 +
111579 + bb_true = create_empty_bb(cond_bb);
111580 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
111581 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
111582 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
111583 +
111584 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111585 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
111586 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
111587 +
111588 + if (current_loops != NULL) {
111589 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
111590 + add_bb_to_loop(bb_true, cond_bb->loop_father);
111591 + }
111592 +
111593 + insert_cond(cond_bb, arg, cond_code, type_value);
111594 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
111595 +
111596 +// print_the_code_insertions(stmt);
111597 +}
111598 +
111599 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
111600 +{
111601 + const_tree rhs_type = TREE_TYPE(rhs);
111602 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
111603 +
111604 + gcc_assert(rhs_type != NULL_TREE);
111605 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
111606 + return;
111607 +
111608 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
111609 +
111610 + if (is_const_plus_unsigned_signed_truncation(rhs))
111611 + return;
111612 +
111613 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
111614 + // typemax (-1) < typemin (0)
111615 + if (TREE_OVERFLOW(type_max))
111616 + return;
111617 +
111618 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
111619 +
111620 + cast_rhs_type = TREE_TYPE(cast_rhs);
111621 + type_max_type = TREE_TYPE(type_max);
111622 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
111623 +
111624 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
111625 +
111626 + // special case: get_size_overflow_type(), 32, u64->s
111627 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
111628 + return;
111629 +
111630 + type_min_type = TREE_TYPE(type_min);
111631 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
111632 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
111633 +}
111634 +
111635 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
111636 +{
111637 + bool cast_lhs, cast_rhs;
111638 + tree lhs = gimple_assign_lhs(stmt);
111639 + tree rhs = gimple_assign_rhs1(stmt);
111640 + const_tree lhs_type = TREE_TYPE(lhs);
111641 + const_tree rhs_type = TREE_TYPE(rhs);
111642 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
111643 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
111644 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
111645 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
111646 +
111647 + static bool check_lhs[3][4] = {
111648 + // ss su us uu
111649 + { false, true, true, false }, // lhs > rhs
111650 + { false, false, false, false }, // lhs = rhs
111651 + { true, true, true, true }, // lhs < rhs
111652 + };
111653 +
111654 + static bool check_rhs[3][4] = {
111655 + // ss su us uu
111656 + { true, false, true, true }, // lhs > rhs
111657 + { true, false, true, true }, // lhs = rhs
111658 + { true, false, true, true }, // lhs < rhs
111659 + };
111660 +
111661 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
111662 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
111663 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111664 +
111665 + if (lhs_size > rhs_size) {
111666 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111667 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111668 + } else if (lhs_size == rhs_size) {
111669 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111670 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111671 + } else {
111672 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111673 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111674 + }
111675 +
111676 + if (!cast_lhs && !cast_rhs)
111677 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111678 +
111679 + if (cast_lhs && !skip_lhs_cast_check(stmt))
111680 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
111681 +
111682 + if (cast_rhs)
111683 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
111684 +
111685 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111686 +}
111687 +
111688 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111689 +{
111690 + enum tree_code rhs_code;
111691 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
111692 +
111693 + if (pointer_set_contains(visited->my_stmts, stmt))
111694 + return lhs;
111695 +
111696 + rhs1 = gimple_assign_rhs1(stmt);
111697 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
111698 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111699 +
111700 + new_rhs1 = expand(visited, caller_node, rhs1);
111701 +
111702 + if (new_rhs1 == NULL_TREE)
111703 + return create_cast_assign(visited, stmt);
111704 +
111705 + if (pointer_set_contains(visited->no_cast_check, stmt))
111706 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111707 +
111708 + rhs_code = gimple_assign_rhs_code(stmt);
111709 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
111710 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
111711 +
111712 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
111713 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
111714 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111715 + }
111716 +
111717 + if (!gimple_assign_cast_p(stmt))
111718 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111719 +
111720 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
111721 +}
111722 +
111723 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111724 +{
111725 + tree rhs1, lhs = gimple_assign_lhs(stmt);
111726 + gimple def_stmt = get_def_stmt(lhs);
111727 +
111728 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
111729 + rhs1 = gimple_assign_rhs1(def_stmt);
111730 +
111731 + if (is_gimple_constant(rhs1))
111732 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111733 +
111734 + switch (TREE_CODE(rhs1)) {
111735 + case SSA_NAME: {
111736 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
111737 +
111738 + if (gimple_assign_cast_p(stmt))
111739 + unsigned_signed_cast_intentional_overflow(visited, stmt);
111740 + return ret;
111741 + }
111742 + case ARRAY_REF:
111743 + case BIT_FIELD_REF:
111744 + case ADDR_EXPR:
111745 + case COMPONENT_REF:
111746 + case INDIRECT_REF:
111747 +#if BUILDING_GCC_VERSION >= 4006
111748 + case MEM_REF:
111749 +#endif
111750 + case TARGET_MEM_REF:
111751 + case VIEW_CONVERT_EXPR:
111752 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111753 + case PARM_DECL:
111754 + case VAR_DECL:
111755 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111756 +
111757 + default:
111758 + debug_gimple_stmt(def_stmt);
111759 + debug_tree(rhs1);
111760 + gcc_unreachable();
111761 + }
111762 +}
111763 +
111764 +static void __unused print_the_code_insertions(const_gimple stmt)
111765 +{
111766 + location_t loc = gimple_location(stmt);
111767 +
111768 + inform(loc, "Integer size_overflow check applied here.");
111769 +}
111770 +
111771 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111772 +{
111773 + enum intentional_overflow_type res;
111774 + tree rhs1, rhs2, new_lhs;
111775 + gimple def_stmt = get_def_stmt(lhs);
111776 + tree new_rhs1 = NULL_TREE;
111777 + tree new_rhs2 = NULL_TREE;
111778 +
111779 + rhs1 = gimple_assign_rhs1(def_stmt);
111780 + rhs2 = gimple_assign_rhs2(def_stmt);
111781 +
111782 + /* no DImode/TImode division in the 32/64 bit kernel */
111783 + switch (gimple_assign_rhs_code(def_stmt)) {
111784 + case RDIV_EXPR:
111785 + case TRUNC_DIV_EXPR:
111786 + case CEIL_DIV_EXPR:
111787 + case FLOOR_DIV_EXPR:
111788 + case ROUND_DIV_EXPR:
111789 + case TRUNC_MOD_EXPR:
111790 + case CEIL_MOD_EXPR:
111791 + case FLOOR_MOD_EXPR:
111792 + case ROUND_MOD_EXPR:
111793 + case EXACT_DIV_EXPR:
111794 + case POINTER_PLUS_EXPR:
111795 + case BIT_AND_EXPR:
111796 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111797 + default:
111798 + break;
111799 + }
111800 +
111801 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
111802 + if (new_lhs != NULL_TREE)
111803 + return new_lhs;
111804 +
111805 + if (TREE_CODE(rhs1) == SSA_NAME)
111806 + new_rhs1 = expand(visited, caller_node, rhs1);
111807 + if (TREE_CODE(rhs2) == SSA_NAME)
111808 + new_rhs2 = expand(visited, caller_node, rhs2);
111809 +
111810 + res = add_mul_intentional_overflow(def_stmt);
111811 + if (res != NO_INTENTIONAL_OVERFLOW) {
111812 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111813 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
111814 + return new_lhs;
111815 + }
111816 +
111817 + if (skip_expr_on_double_type(def_stmt)) {
111818 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111819 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
111820 + return new_lhs;
111821 + }
111822 +
111823 + if (is_a_neg_overflow(def_stmt, rhs2))
111824 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
111825 + if (is_a_neg_overflow(def_stmt, rhs1))
111826 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
111827 +
111828 +
111829 + if (is_a_constant_overflow(def_stmt, rhs2))
111830 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
111831 + if (is_a_constant_overflow(def_stmt, rhs1))
111832 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
111833 +
111834 + // the const is between 0 and (signed) MAX
111835 + if (is_gimple_constant(rhs1))
111836 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
111837 + if (is_gimple_constant(rhs2))
111838 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
111839 +
111840 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111841 +}
111842 +
111843 +#if BUILDING_GCC_VERSION >= 4006
111844 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
111845 +{
111846 + if (is_gimple_constant(rhs))
111847 + return cast_a_tree(size_overflow_type, rhs);
111848 + if (TREE_CODE(rhs) != SSA_NAME)
111849 + return NULL_TREE;
111850 + return expand(visited, caller_node, rhs);
111851 +}
111852 +
111853 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111854 +{
111855 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
111856 + gimple def_stmt = get_def_stmt(lhs);
111857 +
111858 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
111859 +
111860 + rhs1 = gimple_assign_rhs1(def_stmt);
111861 + rhs2 = gimple_assign_rhs2(def_stmt);
111862 + rhs3 = gimple_assign_rhs3(def_stmt);
111863 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
111864 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
111865 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
111866 +
111867 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
111868 +}
111869 +#endif
111870 +
111871 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
111872 +{
111873 + gimple_stmt_iterator gsi;
111874 + gimple next_stmt = NULL;
111875 +
111876 + gsi = gsi_for_stmt(stmt);
111877 +
111878 + do {
111879 + gsi_next(&gsi);
111880 + next_stmt = gsi_stmt(gsi);
111881 +
111882 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
111883 + return NULL_TREE;
111884 +
111885 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
111886 + break;
111887 +
111888 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
111889 + } while (!gsi_end_p(gsi));
111890 +
111891 + gcc_assert(next_stmt);
111892 + return get_lhs(next_stmt);
111893 +}
111894 +
111895 +static tree expand_visited(struct visited *visited, gimple def_stmt)
111896 +{
111897 + gimple_stmt_iterator gsi;
111898 + enum gimple_code code = gimple_code(def_stmt);
111899 +
111900 + if (code == GIMPLE_ASM)
111901 + return NULL_TREE;
111902 +
111903 + gsi = gsi_for_stmt(def_stmt);
111904 + gsi_next(&gsi);
111905 +
111906 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
111907 + return NULL_TREE;
111908 + return get_my_stmt_lhs(visited, def_stmt);
111909 +}
111910 +
111911 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111912 +{
111913 + gimple def_stmt;
111914 +
111915 + def_stmt = get_def_stmt(lhs);
111916 +
111917 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
111918 + return NULL_TREE;
111919 +
111920 + if (pointer_set_contains(visited->my_stmts, def_stmt))
111921 + return lhs;
111922 +
111923 + if (pointer_set_contains(visited->stmts, def_stmt))
111924 + return expand_visited(visited, def_stmt);
111925 +
111926 + switch (gimple_code(def_stmt)) {
111927 + case GIMPLE_PHI:
111928 + return handle_phi(visited, caller_node, lhs);
111929 + case GIMPLE_CALL:
111930 + case GIMPLE_ASM:
111931 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111932 + case GIMPLE_ASSIGN:
111933 + switch (gimple_num_ops(def_stmt)) {
111934 + case 2:
111935 + return handle_unary_ops(visited, caller_node, def_stmt);
111936 + case 3:
111937 + return handle_binary_ops(visited, caller_node, lhs);
111938 +#if BUILDING_GCC_VERSION >= 4006
111939 + case 4:
111940 + return handle_ternary_ops(visited, caller_node, lhs);
111941 +#endif
111942 + }
111943 + default:
111944 + debug_gimple_stmt(def_stmt);
111945 + error("%s: unknown gimple code", __func__);
111946 + gcc_unreachable();
111947 + }
111948 +}
111949 +
111950 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
111951 new file mode 100644
111952 index 0000000..f8f5dd5
111953 --- /dev/null
111954 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
111955 @@ -0,0 +1,1133 @@
111956 +/*
111957 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111958 + * Licensed under the GPL v2, or (at your option) v3
111959 + *
111960 + * Homepage:
111961 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111962 + *
111963 + * Documentation:
111964 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111965 + *
111966 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111967 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111968 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111969 + *
111970 + * Usage:
111971 + * $ make
111972 + * $ make run
111973 + */
111974 +
111975 +#include "gcc-common.h"
111976 +#include "size_overflow.h"
111977 +
111978 +#define VEC_LEN 128
111979 +#define RET_CHECK NULL_TREE
111980 +#define WRONG_NODE 32
111981 +#define NOT_INTENTIONAL_ASM NULL
111982 +
111983 +unsigned int call_count;
111984 +
111985 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
111986 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
111987 +
111988 +struct visited_fns {
111989 + struct visited_fns *next;
111990 + const_tree fndecl;
111991 + unsigned int num;
111992 + const_gimple first_stmt;
111993 +};
111994 +
111995 +struct next_cgraph_node {
111996 + struct next_cgraph_node *next;
111997 + struct cgraph_node *current_function;
111998 + tree callee_fndecl;
111999 + unsigned int num;
112000 +};
112001 +
112002 +// Don't want to duplicate entries in next_cgraph_node
112003 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
112004 +{
112005 + const_tree new_callee_fndecl;
112006 + struct next_cgraph_node *cur_node;
112007 +
112008 + if (fndecl == RET_CHECK)
112009 + new_callee_fndecl = NODE_DECL(node);
112010 + else
112011 + new_callee_fndecl = fndecl;
112012 +
112013 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112014 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
112015 + continue;
112016 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
112017 + continue;
112018 + if (num == cur_node->num)
112019 + return true;
112020 + }
112021 + return false;
112022 +}
112023 +
112024 +/* Add a next_cgraph_node into the list for handle_function().
112025 + * handle_function() iterates over all the next cgraph nodes and
112026 + * starts the overflow check insertion process.
112027 + */
112028 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
112029 +{
112030 + struct next_cgraph_node *new_node;
112031 +
112032 + if (is_in_next_cgraph_node(head, node, fndecl, num))
112033 + return head;
112034 +
112035 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
112036 + new_node->current_function = node;
112037 + new_node->next = NULL;
112038 + new_node->num = num;
112039 + if (fndecl == RET_CHECK)
112040 + new_node->callee_fndecl = NODE_DECL(node);
112041 + else
112042 + new_node->callee_fndecl = fndecl;
112043 +
112044 + if (!head)
112045 + return new_node;
112046 +
112047 + new_node->next = head;
112048 + return new_node;
112049 +}
112050 +
112051 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
112052 +{
112053 + struct cgraph_edge *e;
112054 +
112055 + if (num == 0)
112056 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
112057 +
112058 + for (e = node->callers; e; e = e->next_caller) {
112059 + tree fndecl = gimple_call_fndecl(e->call_stmt);
112060 +
112061 + gcc_assert(fndecl != NULL_TREE);
112062 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
112063 + }
112064 +
112065 + return head;
112066 +}
112067 +
112068 +struct missing_functions {
112069 + struct missing_functions *next;
112070 + const_tree node;
112071 + tree fndecl;
112072 +};
112073 +
112074 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
112075 +{
112076 + struct missing_functions *new_function;
112077 +
112078 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
112079 + new_function->node = node;
112080 + new_function->next = NULL;
112081 +
112082 + if (TREE_CODE(node) == FUNCTION_DECL)
112083 + new_function->fndecl = node;
112084 + else
112085 + new_function->fndecl = current_function_decl;
112086 + gcc_assert(new_function->fndecl);
112087 +
112088 + if (!missing_fn_head)
112089 + return new_function;
112090 +
112091 + new_function->next = missing_fn_head;
112092 + return new_function;
112093 +}
112094 +
112095 +/* If the function is missing from the hash table and it is a static function
112096 + * then create a next_cgraph_node from it for handle_function()
112097 + */
112098 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
112099 +{
112100 + unsigned int num;
112101 + const_tree orig_fndecl;
112102 + struct cgraph_node *next_node = NULL;
112103 +
112104 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
112105 +
112106 + num = get_function_num(missing_fn_head->node, orig_fndecl);
112107 + if (num == CANNOT_FIND_ARG)
112108 + return cnodes;
112109 +
112110 + if (!is_missing_function(orig_fndecl, num))
112111 + return cnodes;
112112 +
112113 + next_node = cgraph_get_node(missing_fn_head->fndecl);
112114 + if (next_node && next_node->local.local)
112115 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
112116 + return cnodes;
112117 +}
112118 +
112119 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
112120 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
112121 + */
112122 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
112123 +{
112124 + unsigned int i;
112125 + tree node;
112126 + struct missing_functions *cur, *missing_fn_head = NULL;
112127 +
112128 +#if BUILDING_GCC_VERSION <= 4007
112129 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
112130 +#else
112131 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
112132 +#endif
112133 + switch (TREE_CODE(node)) {
112134 + case PARM_DECL:
112135 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
112136 + break;
112137 + case FUNCTION_DECL:
112138 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
112139 + break;
112140 + default:
112141 + break;
112142 + }
112143 + }
112144 +
112145 + while (missing_fn_head) {
112146 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
112147 +
112148 + cur = missing_fn_head->next;
112149 + free(missing_fn_head);
112150 + missing_fn_head = cur;
112151 + }
112152 +
112153 + return cnodes;
112154 +}
112155 +
112156 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
112157 +{
112158 + gimple phi = get_def_stmt(result);
112159 + unsigned int i, n = gimple_phi_num_args(phi);
112160 +
112161 + pointer_set_insert(visited, phi);
112162 + for (i = 0; i < n; i++) {
112163 + const_tree arg = gimple_phi_arg_def(phi, i);
112164 +
112165 + set_conditions(visited, interesting_conditions, arg);
112166 + }
112167 +}
112168 +
112169 +enum conditions {
112170 + FROM_CONST, NOT_UNARY, CAST
112171 +};
112172 +
112173 +// Search for constants, cast assignments and binary/ternary assignments
112174 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
112175 +{
112176 + gimple def_stmt = get_def_stmt(lhs);
112177 +
112178 + if (is_gimple_constant(lhs)) {
112179 + interesting_conditions[FROM_CONST] = true;
112180 + return;
112181 + }
112182 +
112183 + if (!def_stmt)
112184 + return;
112185 +
112186 + if (pointer_set_contains(visited, def_stmt))
112187 + return;
112188 +
112189 + switch (gimple_code(def_stmt)) {
112190 + case GIMPLE_NOP:
112191 + case GIMPLE_CALL:
112192 + case GIMPLE_ASM:
112193 + return;
112194 + case GIMPLE_PHI:
112195 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
112196 + case GIMPLE_ASSIGN:
112197 + if (gimple_num_ops(def_stmt) == 2) {
112198 + const_tree rhs = gimple_assign_rhs1(def_stmt);
112199 +
112200 + if (gimple_assign_cast_p(def_stmt))
112201 + interesting_conditions[CAST] = true;
112202 +
112203 + return set_conditions(visited, interesting_conditions, rhs);
112204 + } else {
112205 + interesting_conditions[NOT_UNARY] = true;
112206 + return;
112207 + }
112208 + default:
112209 + debug_gimple_stmt(def_stmt);
112210 + gcc_unreachable();
112211 + }
112212 +}
112213 +
112214 +// determine whether duplication will be necessary or not.
112215 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
112216 +{
112217 + struct pointer_set_t *visited;
112218 +
112219 + if (gimple_assign_cast_p(cur_node->first_stmt))
112220 + interesting_conditions[CAST] = true;
112221 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
112222 + interesting_conditions[NOT_UNARY] = true;
112223 +
112224 + visited = pointer_set_create();
112225 + set_conditions(visited, interesting_conditions, cur_node->node);
112226 + pointer_set_destroy(visited);
112227 +}
112228 +
112229 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
112230 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
112231 +{
112232 + gimple assign;
112233 + gimple_stmt_iterator gsi;
112234 +
112235 + // already removed
112236 + if (gimple_bb(asm_stmt) == NULL)
112237 + return;
112238 + gsi = gsi_for_stmt(asm_stmt);
112239 +
112240 + assign = gimple_build_assign(lhs, rhs);
112241 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
112242 + SSA_NAME_DEF_STMT(lhs) = assign;
112243 +
112244 + gsi_remove(&gsi, true);
112245 +}
112246 +
112247 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
112248 + * stmt is a return otherwise it is the callee function.
112249 + */
112250 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
112251 +{
112252 + const_tree fndecl;
112253 +
112254 + if (argnum == 0)
112255 + fndecl = current_function_decl;
112256 + else
112257 + fndecl = gimple_call_fndecl(stmt);
112258 +
112259 + if (fndecl == NULL_TREE)
112260 + return NULL_TREE;
112261 +
112262 + return DECL_ORIGIN(fndecl);
112263 +}
112264 +
112265 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
112266 +static bool skip_asm(const_tree arg)
112267 +{
112268 + gimple def_stmt = get_def_stmt(arg);
112269 +
112270 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
112271 + return false;
112272 +
112273 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
112274 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
112275 +}
112276 +
112277 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
112278 +{
112279 + gimple phi = get_def_stmt(result);
112280 + unsigned int i, n = gimple_phi_num_args(phi);
112281 +
112282 + pointer_set_insert(visited, phi);
112283 + for (i = 0; i < n; i++) {
112284 + tree arg = gimple_phi_arg_def(phi, i);
112285 +
112286 + walk_use_def(visited, cur_node, arg);
112287 + }
112288 +}
112289 +
112290 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112291 +{
112292 + gimple def_stmt = get_def_stmt(lhs);
112293 + tree rhs1, rhs2;
112294 +
112295 + rhs1 = gimple_assign_rhs1(def_stmt);
112296 + rhs2 = gimple_assign_rhs2(def_stmt);
112297 +
112298 + walk_use_def(visited, cur_node, rhs1);
112299 + walk_use_def(visited, cur_node, rhs2);
112300 +}
112301 +
112302 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112303 +{
112304 + unsigned int i;
112305 + tree element;
112306 + enum tree_code code;
112307 +
112308 + gcc_assert(node != NULL_TREE);
112309 +
112310 + if (is_gimple_constant(node))
112311 + return;
112312 +
112313 + code = TREE_CODE(node);
112314 + if (code == VAR_DECL) {
112315 + node = DECL_ORIGIN(node);
112316 + code = TREE_CODE(node);
112317 + }
112318 +
112319 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112320 + return;
112321 +
112322 +#if BUILDING_GCC_VERSION <= 4007
112323 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112324 +#else
112325 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112326 +#endif
112327 + if (operand_equal_p(node, element, 0))
112328 + return;
112329 + }
112330 +
112331 +#if BUILDING_GCC_VERSION <= 4007
112332 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
112333 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
112334 +#else
112335 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
112336 + vec_safe_push(cur_node->last_nodes, node);
112337 +#endif
112338 +}
112339 +
112340 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
112341 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
112342 +{
112343 + if (!is_size_overflow_asm(stmt))
112344 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112345 +}
112346 +
112347 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
112348 + * and component refs (for checking the intentional_overflow attribute).
112349 + */
112350 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112351 +{
112352 + const_gimple def_stmt;
112353 +
112354 + if (TREE_CODE(lhs) != SSA_NAME) {
112355 + insert_last_node(cur_node, lhs);
112356 + return;
112357 + }
112358 +
112359 + def_stmt = get_def_stmt(lhs);
112360 + if (!def_stmt)
112361 + return;
112362 +
112363 + if (pointer_set_insert(visited, def_stmt))
112364 + return;
112365 +
112366 + switch (gimple_code(def_stmt)) {
112367 + case GIMPLE_NOP:
112368 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112369 + case GIMPLE_ASM:
112370 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
112371 + case GIMPLE_CALL: {
112372 + tree fndecl = gimple_call_fndecl(def_stmt);
112373 +
112374 + if (fndecl == NULL_TREE)
112375 + return;
112376 + insert_last_node(cur_node, fndecl);
112377 + return;
112378 + }
112379 + case GIMPLE_PHI:
112380 + return walk_use_def_phi(visited, cur_node, lhs);
112381 + case GIMPLE_ASSIGN:
112382 + switch (gimple_num_ops(def_stmt)) {
112383 + case 2:
112384 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
112385 + case 3:
112386 + return walk_use_def_binary(visited, cur_node, lhs);
112387 + }
112388 + default:
112389 + debug_gimple_stmt((gimple)def_stmt);
112390 + error("%s: unknown gimple code", __func__);
112391 + gcc_unreachable();
112392 + }
112393 +}
112394 +
112395 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
112396 +static void set_last_nodes(struct interesting_node *cur_node)
112397 +{
112398 + struct pointer_set_t *visited;
112399 +
112400 + visited = pointer_set_create();
112401 + walk_use_def(visited, cur_node, cur_node->node);
112402 + pointer_set_destroy(visited);
112403 +}
112404 +
112405 +enum precond {
112406 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
112407 +};
112408 +
112409 +/* 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.
112410 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
112411 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
112412 + * It skips the possible error codes too. If the def_stmts trace back to a constant and there are no binary/ternary assigments then we assume that it is some kind of error code.
112413 + */
112414 +static enum precond check_preconditions(struct interesting_node *cur_node)
112415 +{
112416 + bool interesting_conditions[3] = {false, false, false};
112417 +
112418 + set_last_nodes(cur_node);
112419 +
112420 + check_intentional_attribute_ipa(cur_node);
112421 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
112422 + return NO_ATTRIBUTE_SEARCH;
112423 +
112424 + search_interesting_conditions(cur_node, interesting_conditions);
112425 +
112426 + // error code
112427 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
112428 + return NO_ATTRIBUTE_SEARCH;
112429 +
112430 + // unnecessary overflow check
112431 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
112432 + return NO_CHECK_INSERT;
112433 +
112434 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
112435 + return NO_CHECK_INSERT;
112436 +
112437 + return NONE;
112438 +}
112439 +
112440 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
112441 +{
112442 + const_gimple assign;
112443 + tree orig_type = TREE_TYPE(orig_node);
112444 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112445 +
112446 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
112447 + return gimple_assign_lhs(assign);
112448 +}
112449 +
112450 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
112451 +{
112452 + void (*set_rhs)(gimple, tree);
112453 + gimple stmt = cur_node->first_stmt;
112454 + const_tree orig_node = cur_node->node;
112455 +
112456 + switch (gimple_code(stmt)) {
112457 + case GIMPLE_RETURN:
112458 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112459 + break;
112460 + case GIMPLE_CALL:
112461 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
112462 + break;
112463 + case GIMPLE_ASSIGN:
112464 + switch (cur_node->num) {
112465 + case 1:
112466 + set_rhs = &gimple_assign_set_rhs1;
112467 + break;
112468 + case 2:
112469 + set_rhs = &gimple_assign_set_rhs2;
112470 + break;
112471 +#if BUILDING_GCC_VERSION >= 4006
112472 + case 3:
112473 + set_rhs = &gimple_assign_set_rhs3;
112474 + break;
112475 +#endif
112476 + default:
112477 + gcc_unreachable();
112478 + }
112479 +
112480 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112481 + break;
112482 + default:
112483 + debug_gimple_stmt(stmt);
112484 + gcc_unreachable();
112485 + }
112486 +
112487 + update_stmt(stmt);
112488 +}
112489 +
112490 +static struct visited *create_visited(void)
112491 +{
112492 + struct visited *new_node;
112493 +
112494 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
112495 + new_node->stmts = pointer_set_create();
112496 + new_node->my_stmts = pointer_set_create();
112497 + new_node->skip_expr_casts = pointer_set_create();
112498 + new_node->no_cast_check = pointer_set_create();
112499 + return new_node;
112500 +}
112501 +
112502 +static void free_visited(struct visited *visited)
112503 +{
112504 + pointer_set_destroy(visited->stmts);
112505 + pointer_set_destroy(visited->my_stmts);
112506 + pointer_set_destroy(visited->skip_expr_casts);
112507 + pointer_set_destroy(visited->no_cast_check);
112508 +
112509 + free(visited);
112510 +}
112511 +
112512 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
112513 + * 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
112514 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
112515 + */
112516 +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)
112517 +{
112518 + enum precond ret;
112519 + tree new_node, orig_node = cur_node->node;
112520 +
112521 + ret = check_preconditions(cur_node);
112522 + if (ret == NO_ATTRIBUTE_SEARCH)
112523 + return cnodes;
112524 +
112525 + cnodes = search_overflow_attribute(cnodes, cur_node);
112526 +
112527 + if (ret == NO_CHECK_INSERT)
112528 + return cnodes;
112529 +
112530 + new_node = expand(visited, caller_node, orig_node);
112531 + if (new_node == NULL_TREE)
112532 + return cnodes;
112533 +
112534 + change_orig_node(visited, cur_node, new_node);
112535 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
112536 +
112537 + return cnodes;
112538 +}
112539 +
112540 +// Check visited_fns interesting nodes.
112541 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
112542 +{
112543 + struct interesting_node *cur;
112544 +
112545 + for (cur = head; cur; cur = cur->next) {
112546 + if (!operand_equal_p(node, cur->node, 0))
112547 + continue;
112548 + if (num != cur->num)
112549 + continue;
112550 + if (first_stmt == cur->first_stmt)
112551 + return true;
112552 + }
112553 + return false;
112554 +}
112555 +
112556 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
112557 + 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
112558 + 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
112559 + the intentional_overflow attribute check. They are collected by set_last_nodes().
112560 + num: arg count of a call stmt or 0 when it is a ret
112561 + node: the recursion starts from here, it is a call arg or a return value
112562 + 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.
112563 + intentional_attr_decl: intentional_overflow attribute of the callee function
112564 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
112565 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
112566 + */
112567 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
112568 +{
112569 + struct interesting_node *new_node;
112570 + tree fndecl;
112571 + enum gimple_code code;
112572 +
112573 + gcc_assert(node != NULL_TREE);
112574 + code = gimple_code(first_stmt);
112575 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
112576 +
112577 + if (num == CANNOT_FIND_ARG)
112578 + return head;
112579 +
112580 + if (skip_types(node))
112581 + return head;
112582 +
112583 + if (skip_asm(node))
112584 + return head;
112585 +
112586 + if (is_gimple_call(first_stmt))
112587 + fndecl = gimple_call_fndecl(first_stmt);
112588 + else
112589 + fndecl = current_function_decl;
112590 +
112591 + if (fndecl == NULL_TREE)
112592 + return head;
112593 +
112594 + if (is_in_interesting_node(head, first_stmt, node, num))
112595 + return head;
112596 +
112597 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
112598 +
112599 + new_node->next = NULL;
112600 + new_node->first_stmt = first_stmt;
112601 +#if BUILDING_GCC_VERSION <= 4007
112602 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
112603 +#else
112604 + vec_alloc(new_node->last_nodes, VEC_LEN);
112605 +#endif
112606 + new_node->num = num;
112607 + new_node->node = node;
112608 + new_node->fndecl = fndecl;
112609 + new_node->intentional_attr_decl = MARK_NO;
112610 + new_node->intentional_attr_cur_fndecl = MARK_NO;
112611 + new_node->intentional_mark_from_gimple = asm_stmt;
112612 +
112613 + if (!head)
112614 + return new_node;
112615 +
112616 + new_node->next = head;
112617 + return new_node;
112618 +}
112619 +
112620 +/* 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).
112621 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
112622 + */
112623 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112624 +{
112625 + struct next_cgraph_node *cur_node;
112626 + tree ret = gimple_return_retval(stmt);
112627 +
112628 + if (ret == NULL_TREE)
112629 + return head;
112630 +
112631 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112632 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
112633 + continue;
112634 + if (cur_node->num == 0)
112635 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
112636 + }
112637 +
112638 + return head;
112639 +}
112640 +
112641 +/* 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).
112642 + * If the call stmt is in the next cgraph node list then it's an interesting call.
112643 + */
112644 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112645 +{
112646 + unsigned int argnum;
112647 + tree arg;
112648 + const_tree fndecl;
112649 + struct next_cgraph_node *cur_node;
112650 +
112651 + fndecl = gimple_call_fndecl(stmt);
112652 + if (fndecl == NULL_TREE)
112653 + return head;
112654 +
112655 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112656 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
112657 + continue;
112658 + argnum = get_correct_arg_count(cur_node->num, fndecl);
112659 + gcc_assert(argnum != CANNOT_FIND_ARG);
112660 + if (argnum == 0)
112661 + continue;
112662 +
112663 + arg = gimple_call_arg(stmt, argnum - 1);
112664 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
112665 + }
112666 +
112667 + return head;
112668 +}
112669 +
112670 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
112671 +{
112672 + if (!operand_equal_p(orig_node, node, 0))
112673 + return WRONG_NODE;
112674 + if (skip_types(node))
112675 + return WRONG_NODE;
112676 + return ret_count;
112677 +}
112678 +
112679 +// Get the index of the rhs node in an assignment
112680 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
112681 +{
112682 + const_tree rhs1, rhs2;
112683 + unsigned int ret;
112684 +
112685 + gcc_assert(stmt);
112686 + gcc_assert(is_gimple_assign(stmt));
112687 +
112688 + rhs1 = gimple_assign_rhs1(stmt);
112689 + gcc_assert(rhs1 != NULL_TREE);
112690 +
112691 + switch (gimple_num_ops(stmt)) {
112692 + case 2:
112693 + return check_ops(node, rhs1, 1);
112694 + case 3:
112695 + ret = check_ops(node, rhs1, 1);
112696 + if (ret != WRONG_NODE)
112697 + return ret;
112698 +
112699 + rhs2 = gimple_assign_rhs2(stmt);
112700 + gcc_assert(rhs2 != NULL_TREE);
112701 + return check_ops(node, rhs2, 2);
112702 + default:
112703 + gcc_unreachable();
112704 + }
112705 +}
112706 +
112707 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
112708 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
112709 +{
112710 + unsigned int i;
112711 +
112712 + if (gimple_call_fndecl(stmt) == NULL_TREE)
112713 + return CANNOT_FIND_ARG;
112714 +
112715 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
112716 + tree node;
112717 +
112718 + node = gimple_call_arg(stmt, i);
112719 + if (!operand_equal_p(arg, node, 0))
112720 + continue;
112721 + if (!skip_types(node))
112722 + return i + 1;
112723 + }
112724 +
112725 + return CANNOT_FIND_ARG;
112726 +}
112727 +
112728 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
112729 + * any of return, call or assignment stmts (because of inlining).
112730 + */
112731 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
112732 +{
112733 + use_operand_p use_p;
112734 + imm_use_iterator imm_iter;
112735 + unsigned int argnum;
112736 +
112737 + gcc_assert(TREE_CODE(node) == SSA_NAME);
112738 +
112739 + if (pointer_set_insert(visited, node))
112740 + return head;
112741 +
112742 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
112743 + gimple stmt = USE_STMT(use_p);
112744 +
112745 + if (stmt == NULL)
112746 + return head;
112747 + if (is_gimple_debug(stmt))
112748 + continue;
112749 +
112750 + switch (gimple_code(stmt)) {
112751 + case GIMPLE_CALL:
112752 + argnum = find_arg_number_gimple(node, stmt);
112753 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112754 + break;
112755 + case GIMPLE_RETURN:
112756 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
112757 + break;
112758 + case GIMPLE_ASSIGN:
112759 + argnum = get_assign_ops_count(stmt, node);
112760 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112761 + break;
112762 + case GIMPLE_PHI: {
112763 + tree result = gimple_phi_result(stmt);
112764 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
112765 + break;
112766 + }
112767 + case GIMPLE_ASM:
112768 + if (gimple_asm_noutputs(stmt) != 0)
112769 + break;
112770 + if (!is_size_overflow_asm(stmt))
112771 + break;
112772 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
112773 + break;
112774 + case GIMPLE_COND:
112775 + case GIMPLE_SWITCH:
112776 + break;
112777 + default:
112778 + debug_gimple_stmt(stmt);
112779 + gcc_unreachable();
112780 + break;
112781 + }
112782 + }
112783 + return head;
112784 +}
112785 +
112786 +static void remove_size_overflow_asm(gimple stmt)
112787 +{
112788 + gimple_stmt_iterator gsi;
112789 + tree input, output;
112790 +
112791 + if (!is_size_overflow_asm(stmt))
112792 + return;
112793 +
112794 + if (gimple_asm_noutputs(stmt) == 0) {
112795 + gsi = gsi_for_stmt(stmt);
112796 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
112797 + gsi_remove(&gsi, true);
112798 + return;
112799 + }
112800 +
112801 + input = gimple_asm_input_op(stmt, 0);
112802 + output = gimple_asm_output_op(stmt, 0);
112803 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
112804 +}
112805 +
112806 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
112807 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
112808 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
112809 + */
112810 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
112811 +{
112812 + const_tree output;
112813 + struct pointer_set_t *visited;
112814 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
112815 +
112816 + if (!is_size_overflow_asm(stmt))
112817 + return head;
112818 +
112819 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
112820 + intentional_asm = stmt;
112821 +
112822 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
112823 +
112824 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
112825 + return head;
112826 +
112827 + if (gimple_asm_noutputs(stmt) == 0) {
112828 + const_tree input;
112829 +
112830 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
112831 + return head;
112832 +
112833 + input = gimple_asm_input_op(stmt, 0);
112834 + remove_size_overflow_asm(stmt);
112835 + if (is_gimple_constant(TREE_VALUE(input)))
112836 + return head;
112837 + visited = pointer_set_create();
112838 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
112839 + pointer_set_destroy(visited);
112840 + return head;
112841 + }
112842 +
112843 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
112844 + remove_size_overflow_asm(stmt);
112845 +
112846 + visited = pointer_set_create();
112847 + output = gimple_asm_output_op(stmt, 0);
112848 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
112849 + pointer_set_destroy(visited);
112850 + return head;
112851 +}
112852 +
112853 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
112854 + * or a call stmt or a return stmt and store them in the interesting_node list
112855 + */
112856 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
112857 +{
112858 + basic_block bb;
112859 + struct interesting_node *head = NULL;
112860 +
112861 + FOR_ALL_BB_FN(bb, cfun) {
112862 + gimple_stmt_iterator gsi;
112863 +
112864 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112865 + enum gimple_code code;
112866 + gimple stmt = gsi_stmt(gsi);
112867 +
112868 + code = gimple_code(stmt);
112869 +
112870 + if (code == GIMPLE_ASM)
112871 + head = handle_stmt_by_size_overflow_asm(stmt, head);
112872 +
112873 + if (!next_node)
112874 + continue;
112875 + if (code == GIMPLE_CALL)
112876 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
112877 + if (code == GIMPLE_RETURN)
112878 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
112879 + }
112880 + }
112881 + return head;
112882 +}
112883 +
112884 +static void free_interesting_node(struct interesting_node *head)
112885 +{
112886 + struct interesting_node *cur;
112887 +
112888 + while (head) {
112889 + cur = head->next;
112890 +#if BUILDING_GCC_VERSION <= 4007
112891 + VEC_free(tree, gc, head->last_nodes);
112892 +#else
112893 + vec_free(head->last_nodes);
112894 +#endif
112895 + free(head);
112896 + head = cur;
112897 + }
112898 +}
112899 +
112900 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
112901 +{
112902 + struct visited_fns *new_visited_fns;
112903 +
112904 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
112905 + new_visited_fns->fndecl = cur_node->fndecl;
112906 + new_visited_fns->num = cur_node->num;
112907 + new_visited_fns->first_stmt = cur_node->first_stmt;
112908 + new_visited_fns->next = NULL;
112909 +
112910 + if (!head)
112911 + return new_visited_fns;
112912 +
112913 + new_visited_fns->next = head;
112914 + return new_visited_fns;
112915 +}
112916 +
112917 +/* 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
112918 + * it is a visited_fns function.
112919 + */
112920 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
112921 +{
112922 + struct visited_fns *cur;
112923 +
112924 + if (!head)
112925 + return false;
112926 +
112927 + for (cur = head; cur; cur = cur->next) {
112928 + if (cur_node->first_stmt != cur->first_stmt)
112929 + continue;
112930 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
112931 + continue;
112932 + if (cur_node->num == cur->num)
112933 + return true;
112934 + }
112935 + return false;
112936 +}
112937 +
112938 +static void free_next_cgraph_node(struct next_cgraph_node *head)
112939 +{
112940 + struct next_cgraph_node *cur;
112941 +
112942 + while (head) {
112943 + cur = head->next;
112944 + free(head);
112945 + head = cur;
112946 + }
112947 +}
112948 +
112949 +static void remove_all_size_overflow_asm(void)
112950 +{
112951 + basic_block bb;
112952 +
112953 + FOR_ALL_BB_FN(bb, cfun) {
112954 + gimple_stmt_iterator si;
112955 +
112956 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
112957 + remove_size_overflow_asm(gsi_stmt(si));
112958 + }
112959 +}
112960 +
112961 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
112962 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
112963 + * the newly collected interesting functions (they are interesting if there is control flow between
112964 + * the interesting stmts and them).
112965 + */
112966 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
112967 +{
112968 + struct visited *visited;
112969 + struct interesting_node *head, *cur_node;
112970 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
112971 +
112972 + set_current_function_decl(NODE_DECL(node));
112973 + call_count = 0;
112974 +
112975 + head = collect_interesting_stmts(next_node);
112976 +
112977 + visited = create_visited();
112978 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112979 + if (is_visited_fns_function(visited_fns, cur_node))
112980 + continue;
112981 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
112982 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
112983 + }
112984 +
112985 + free_visited(visited);
112986 + free_interesting_node(head);
112987 + remove_all_size_overflow_asm();
112988 + unset_current_function_decl();
112989 +
112990 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
112991 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
112992 +
112993 + free_next_cgraph_node(cnodes_head);
112994 + return visited_fns;
112995 +}
112996 +
112997 +static void free_visited_fns(struct visited_fns *head)
112998 +{
112999 + struct visited_fns *cur;
113000 +
113001 + while (head) {
113002 + cur = head->next;
113003 + free(head);
113004 + head = cur;
113005 + }
113006 +}
113007 +
113008 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
113009 +unsigned int search_function(void)
113010 +{
113011 + struct cgraph_node *node;
113012 + struct visited_fns *visited_fns = NULL;
113013 +
113014 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
113015 + gcc_assert(cgraph_function_flags_ready);
113016 +#if BUILDING_GCC_VERSION <= 4007
113017 + gcc_assert(node->reachable);
113018 +#endif
113019 +
113020 + visited_fns = handle_function(node, NULL, visited_fns);
113021 + }
113022 +
113023 + free_visited_fns(visited_fns);
113024 + return 0;
113025 +}
113026 +
113027 +#if BUILDING_GCC_VERSION >= 4009
113028 +static const struct pass_data insert_size_overflow_check_data = {
113029 +#else
113030 +static struct ipa_opt_pass_d insert_size_overflow_check = {
113031 + .pass = {
113032 +#endif
113033 + .type = SIMPLE_IPA_PASS,
113034 + .name = "size_overflow",
113035 +#if BUILDING_GCC_VERSION >= 4008
113036 + .optinfo_flags = OPTGROUP_NONE,
113037 +#endif
113038 +#if BUILDING_GCC_VERSION >= 4009
113039 + .has_gate = false,
113040 + .has_execute = true,
113041 +#else
113042 + .gate = NULL,
113043 + .execute = search_function,
113044 + .sub = NULL,
113045 + .next = NULL,
113046 + .static_pass_number = 0,
113047 +#endif
113048 + .tv_id = TV_NONE,
113049 + .properties_required = 0,
113050 + .properties_provided = 0,
113051 + .properties_destroyed = 0,
113052 + .todo_flags_start = 0,
113053 + .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,
113054 +#if BUILDING_GCC_VERSION < 4009
113055 + },
113056 + .generate_summary = NULL,
113057 + .write_summary = NULL,
113058 + .read_summary = NULL,
113059 +#if BUILDING_GCC_VERSION >= 4006
113060 + .write_optimization_summary = NULL,
113061 + .read_optimization_summary = NULL,
113062 +#endif
113063 + .stmt_fixup = NULL,
113064 + .function_transform_todo_flags_start = 0,
113065 + .function_transform = NULL,
113066 + .variable_transform = NULL,
113067 +#endif
113068 +};
113069 +
113070 +#if BUILDING_GCC_VERSION >= 4009
113071 +namespace {
113072 +class insert_size_overflow_check : public ipa_opt_pass_d {
113073 +public:
113074 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
113075 + unsigned int execute() { return search_function(); }
113076 +};
113077 +}
113078 +#endif
113079 +
113080 +struct opt_pass *make_insert_size_overflow_check(void)
113081 +{
113082 +#if BUILDING_GCC_VERSION >= 4009
113083 + return new insert_size_overflow_check();
113084 +#else
113085 + return &insert_size_overflow_check.pass;
113086 +#endif
113087 +}
113088 +
113089 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113090 new file mode 100644
113091 index 0000000..38904bc
113092 --- /dev/null
113093 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113094 @@ -0,0 +1,733 @@
113095 +/*
113096 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113097 + * Licensed under the GPL v2, or (at your option) v3
113098 + *
113099 + * Homepage:
113100 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113101 + *
113102 + * Documentation:
113103 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113104 + *
113105 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113106 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113107 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113108 + *
113109 + * Usage:
113110 + * $ make
113111 + * $ make run
113112 + */
113113 +
113114 +#include "gcc-common.h"
113115 +#include "size_overflow.h"
113116 +
113117 +/* Get the param of the intentional_overflow attribute.
113118 + * * 0: MARK_NOT_INTENTIONAL
113119 + * * 1..MAX_PARAM: MARK_YES
113120 + * * -1: MARK_TURN_OFF
113121 + */
113122 +static tree get_attribute_param(const_tree decl)
113123 +{
113124 + const_tree attr;
113125 +
113126 + if (decl == NULL_TREE)
113127 + return NULL_TREE;
113128 +
113129 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
113130 + if (!attr || !TREE_VALUE(attr))
113131 + return NULL_TREE;
113132 +
113133 + return TREE_VALUE(attr);
113134 +}
113135 +
113136 +// MARK_TURN_OFF
113137 +bool is_turn_off_intentional_attr(const_tree decl)
113138 +{
113139 + const_tree param_head;
113140 +
113141 + param_head = get_attribute_param(decl);
113142 + if (param_head == NULL_TREE)
113143 + return false;
113144 +
113145 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
113146 + return true;
113147 + return false;
113148 +}
113149 +
113150 +// MARK_NOT_INTENTIONAL
113151 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
113152 +{
113153 + const_tree param_head;
113154 +
113155 + if (argnum == 0)
113156 + return false;
113157 +
113158 + param_head = get_attribute_param(decl);
113159 + if (param_head == NULL_TREE)
113160 + return false;
113161 +
113162 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
113163 + return true;
113164 + return false;
113165 +}
113166 +
113167 +// MARK_YES
113168 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
113169 +{
113170 + tree param, param_head;
113171 +
113172 + if (argnum == 0)
113173 + return false;
113174 +
113175 + param_head = get_attribute_param(decl);
113176 + for (param = param_head; param; param = TREE_CHAIN(param))
113177 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
113178 + return true;
113179 + return false;
113180 +}
113181 +
113182 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
113183 +{
113184 + location_t loc;
113185 +
113186 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
113187 + return;
113188 +
113189 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
113190 + return;
113191 +
113192 + loc = DECL_SOURCE_LOCATION(decl);
113193 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
113194 +}
113195 +
113196 +// Get the field decl of a component ref for intentional_overflow checking
113197 +static const_tree search_field_decl(const_tree comp_ref)
113198 +{
113199 + const_tree field = NULL_TREE;
113200 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
113201 +
113202 + for (i = 0; i < len; i++) {
113203 + field = TREE_OPERAND(comp_ref, i);
113204 + if (TREE_CODE(field) == FIELD_DECL)
113205 + break;
113206 + }
113207 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113208 + return field;
113209 +}
113210 +
113211 +/* Get the type of the intentional_overflow attribute of a node
113212 + * * MARK_TURN_OFF
113213 + * * MARK_YES
113214 + * * MARK_NO
113215 + * * MARK_NOT_INTENTIONAL
113216 + */
113217 +enum mark get_intentional_attr_type(const_tree node)
113218 +{
113219 + const_tree cur_decl;
113220 +
113221 + if (node == NULL_TREE)
113222 + return MARK_NO;
113223 +
113224 + switch (TREE_CODE(node)) {
113225 + case COMPONENT_REF:
113226 + cur_decl = search_field_decl(node);
113227 + if (is_turn_off_intentional_attr(cur_decl))
113228 + return MARK_TURN_OFF;
113229 + if (is_end_intentional_intentional_attr(cur_decl, 1))
113230 + return MARK_YES;
113231 + break;
113232 + case PARM_DECL: {
113233 + unsigned int argnum;
113234 +
113235 + cur_decl = DECL_ORIGIN(current_function_decl);
113236 + argnum = find_arg_number_tree(node, cur_decl);
113237 + if (argnum == CANNOT_FIND_ARG)
113238 + return MARK_NO;
113239 + if (is_yes_intentional_attr(cur_decl, argnum))
113240 + return MARK_YES;
113241 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
113242 + return MARK_NOT_INTENTIONAL;
113243 + break;
113244 + }
113245 + case FUNCTION_DECL:
113246 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
113247 + return MARK_TURN_OFF;
113248 + break;
113249 + default:
113250 + break;
113251 + }
113252 + return MARK_NO;
113253 +}
113254 +
113255 +// Search for the intentional_overflow attribute on the last nodes
113256 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
113257 +{
113258 + unsigned int i;
113259 + tree last_node;
113260 + enum mark mark = MARK_NO;
113261 +
113262 +#if BUILDING_GCC_VERSION <= 4007
113263 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
113264 +#else
113265 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
113266 +#endif
113267 + mark = get_intentional_attr_type(last_node);
113268 + if (mark != MARK_NO)
113269 + break;
113270 + }
113271 + return mark;
113272 +}
113273 +
113274 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
113275 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
113276 + */
113277 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
113278 +{
113279 + if (!cur_node->intentional_mark_from_gimple)
113280 + return false;
113281 +
113282 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
113283 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
113284 + else
113285 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113286 +
113287 + // skip param decls
113288 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
113289 + return true;
113290 + return true;
113291 +}
113292 +
113293 +/* Search intentional_overflow attribute on caller and on callee too.
113294 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113295 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113296 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113297 +*/
113298 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113299 +{
113300 + const_tree fndecl;
113301 +
113302 + if (is_intentional_attribute_from_gimple(cur_node))
113303 + return;
113304 +
113305 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113306 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113307 + return;
113308 + }
113309 +
113310 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113311 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113312 + return;
113313 + }
113314 +
113315 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113316 + return;
113317 +
113318 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113319 + if (is_turn_off_intentional_attr(fndecl)) {
113320 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113321 + return;
113322 + }
113323 +
113324 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113325 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
113326 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
113327 + cur_node->intentional_attr_decl = MARK_YES;
113328 +
113329 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
113330 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
113331 +}
113332 +
113333 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113334 +{
113335 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113336 + enum machine_mode lhs_mode, rhs_mode;
113337 + gimple def_stmt = get_def_stmt(no_const_rhs);
113338 +
113339 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113340 + return false;
113341 +
113342 + rhs1 = gimple_assign_rhs1(def_stmt);
113343 + lhs = gimple_assign_lhs(def_stmt);
113344 + rhs1_type = TREE_TYPE(rhs1);
113345 + lhs_type = TREE_TYPE(lhs);
113346 + rhs_mode = TYPE_MODE(rhs1_type);
113347 + lhs_mode = TYPE_MODE(lhs_type);
113348 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113349 + return false;
113350 +
113351 + return true;
113352 +}
113353 +
113354 +static unsigned int uses_num(tree node)
113355 +{
113356 + imm_use_iterator imm_iter;
113357 + use_operand_p use_p;
113358 + unsigned int num = 0;
113359 +
113360 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113361 + gimple use_stmt = USE_STMT(use_p);
113362 +
113363 + if (use_stmt == NULL)
113364 + return num;
113365 + if (is_gimple_debug(use_stmt))
113366 + continue;
113367 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
113368 + continue;
113369 + num++;
113370 + }
113371 + return num;
113372 +}
113373 +
113374 +static bool no_uses(tree node)
113375 +{
113376 + return !uses_num(node);
113377 +}
113378 +
113379 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113380 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113381 +{
113382 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113383 + gimple def_stmt = get_def_stmt(lhs);
113384 +
113385 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113386 + return false;
113387 +
113388 + rhs1 = gimple_assign_rhs1(def_stmt);
113389 + rhs_type = TREE_TYPE(rhs1);
113390 + lhs_type = TREE_TYPE(lhs);
113391 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113392 + return false;
113393 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113394 + return false;
113395 +
113396 + def_stmt = get_def_stmt(rhs1);
113397 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113398 + return false;
113399 +
113400 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113401 + return false;
113402 +
113403 + rhs1 = gimple_assign_rhs1(def_stmt);
113404 + rhs2 = gimple_assign_rhs2(def_stmt);
113405 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113406 + return false;
113407 +
113408 + if (is_gimple_constant(rhs2))
113409 + not_const_rhs = rhs1;
113410 + else
113411 + not_const_rhs = rhs2;
113412 +
113413 + return no_uses(not_const_rhs);
113414 +}
113415 +
113416 +static bool is_lt_signed_type_max(const_tree rhs)
113417 +{
113418 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
113419 +
113420 + if (!TYPE_UNSIGNED(type))
113421 + return true;
113422 +
113423 + switch (TYPE_MODE(type)) {
113424 + case QImode:
113425 + new_type = intQI_type_node;
113426 + break;
113427 + case HImode:
113428 + new_type = intHI_type_node;
113429 + break;
113430 + case SImode:
113431 + new_type = intSI_type_node;
113432 + break;
113433 + case DImode:
113434 + new_type = intDI_type_node;
113435 + break;
113436 + default:
113437 + debug_tree((tree)type);
113438 + gcc_unreachable();
113439 + }
113440 +
113441 + type_max = TYPE_MAX_VALUE(new_type);
113442 + if (!tree_int_cst_lt(type_max, rhs))
113443 + return true;
113444 +
113445 + return false;
113446 +}
113447 +
113448 +static bool is_gt_zero(const_tree rhs)
113449 +{
113450 + const_tree type = TREE_TYPE(rhs);
113451 +
113452 + if (TYPE_UNSIGNED(type))
113453 + return true;
113454 +
113455 + if (!tree_int_cst_lt(rhs, integer_zero_node))
113456 + return true;
113457 +
113458 + return false;
113459 +}
113460 +
113461 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113462 +{
113463 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113464 + return false;
113465 + if (!is_gimple_constant(rhs))
113466 + return false;
113467 +
113468 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
113469 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
113470 + return false;
113471 +
113472 + return true;
113473 +}
113474 +
113475 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
113476 +{
113477 + gimple assign;
113478 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113479 + tree origtype = TREE_TYPE(orig_rhs);
113480 +
113481 + gcc_assert(is_gimple_assign(stmt));
113482 +
113483 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113484 + pointer_set_insert(visited->my_stmts, assign);
113485 + return gimple_assign_lhs(assign);
113486 +}
113487 +
113488 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
113489 +{
113490 + tree new_rhs, orig_rhs;
113491 + void (*gimple_assign_set_rhs)(gimple, tree);
113492 + tree rhs1 = gimple_assign_rhs1(stmt);
113493 + tree rhs2 = gimple_assign_rhs2(stmt);
113494 + tree lhs = gimple_assign_lhs(stmt);
113495 +
113496 + if (!check_overflow)
113497 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113498 +
113499 + if (change_rhs == NULL_TREE)
113500 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113501 +
113502 + if (new_rhs2 == NULL_TREE) {
113503 + orig_rhs = rhs1;
113504 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113505 + } else {
113506 + orig_rhs = rhs2;
113507 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
113508 + }
113509 +
113510 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
113511 +
113512 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
113513 + gimple_assign_set_rhs(stmt, new_rhs);
113514 + update_stmt(stmt);
113515 +
113516 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113517 +}
113518 +
113519 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
113520 +{
113521 + gimple rhs1_def_stmt, rhs2_def_stmt;
113522 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
113523 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
113524 + const_tree rhs1 = gimple_assign_rhs1(stmt);
113525 + const_tree rhs2 = gimple_assign_rhs2(stmt);
113526 +
113527 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
113528 + return false;
113529 +
113530 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
113531 +
113532 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
113533 + return false;
113534 +
113535 + rhs1_def_stmt = get_def_stmt(rhs1);
113536 + rhs2_def_stmt = get_def_stmt(rhs2);
113537 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
113538 + return false;
113539 +
113540 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113541 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
113542 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
113543 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
113544 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
113545 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
113546 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
113547 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
113548 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
113549 + return false;
113550 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
113551 + return false;
113552 +
113553 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
113554 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
113555 + return true;
113556 +}
113557 +
113558 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113559 +{
113560 + gimple assign;
113561 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113562 + tree type = TREE_TYPE(rhs1);
113563 + tree lhs = create_new_var(type);
113564 +
113565 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113566 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113567 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113568 +
113569 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113570 + update_stmt(assign);
113571 + pointer_set_insert(visited->my_stmts, assign);
113572 + return assign;
113573 +}
113574 +
113575 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
113576 +{
113577 + gimple_stmt_iterator gsi;
113578 + gimple cast_stmt;
113579 + tree type = TREE_TYPE(node);
113580 +
113581 + if (types_compatible_p(type, intTI_type_node))
113582 + return node;
113583 +
113584 + gsi = gsi_for_stmt(stmt);
113585 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113586 + pointer_set_insert(visited->my_stmts, cast_stmt);
113587 + return gimple_assign_lhs(cast_stmt);
113588 +}
113589 +
113590 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
113591 +{
113592 + tree rhs1, def_stmt_rhs1;
113593 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113594 +
113595 + def_stmt = get_def_stmt(var);
113596 + if (!gimple_assign_cast_p(def_stmt))
113597 + return NULL_TREE;
113598 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
113599 +
113600 + rhs1 = gimple_assign_rhs1(def_stmt);
113601 + rhs1_def_stmt = get_def_stmt(rhs1);
113602 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113603 + return rhs1;
113604 +
113605 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113606 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113607 +
113608 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113609 + case GIMPLE_CALL:
113610 + case GIMPLE_NOP:
113611 + case GIMPLE_ASM:
113612 + case GIMPLE_PHI:
113613 + return def_stmt_rhs1;
113614 + case GIMPLE_ASSIGN:
113615 + return rhs1;
113616 + default:
113617 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113618 + gcc_unreachable();
113619 + }
113620 +}
113621 +
113622 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
113623 +{
113624 + tree new_rhs1, new_rhs2;
113625 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
113626 + gimple assign, stmt = get_def_stmt(lhs);
113627 + tree rhs1 = gimple_assign_rhs1(stmt);
113628 + tree rhs2 = gimple_assign_rhs2(stmt);
113629 +
113630 + if (!is_subtraction_special(visited, stmt))
113631 + return NULL_TREE;
113632 +
113633 + new_rhs1 = expand(visited, caller_node, rhs1);
113634 + new_rhs2 = expand(visited, caller_node, rhs2);
113635 +
113636 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
113637 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
113638 +
113639 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
113640 + return NULL_TREE;
113641 +
113642 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
113643 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
113644 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
113645 + }
113646 +
113647 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
113648 + new_lhs = gimple_assign_lhs(assign);
113649 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
113650 +
113651 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113652 +}
113653 +
113654 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
113655 +{
113656 + const_gimple def_stmt;
113657 +
113658 + if (TREE_CODE(rhs) != SSA_NAME)
113659 + return false;
113660 +
113661 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
113662 + return false;
113663 +
113664 + def_stmt = get_def_stmt(rhs);
113665 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
113666 + return false;
113667 +
113668 + return true;
113669 +}
113670 +
113671 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
113672 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
113673 + * fffffff * 16 > signed max -> truncate
113674 + */
113675 +static bool look_for_mult_and_add(const_gimple stmt)
113676 +{
113677 + const_tree res;
113678 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
113679 + const_gimple def_stmt;
113680 +
113681 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
113682 + return false;
113683 + if (!is_gimple_assign(stmt))
113684 + return false;
113685 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
113686 + return false;
113687 +
113688 + rhs1 = gimple_assign_rhs1(stmt);
113689 + rhs2 = gimple_assign_rhs2(stmt);
113690 + if (is_gimple_constant(rhs1)) {
113691 + const_rhs = rhs1;
113692 + def_stmt = get_def_stmt(rhs2);
113693 + } else if (is_gimple_constant(rhs2)) {
113694 + const_rhs = rhs2;
113695 + def_stmt = get_def_stmt(rhs1);
113696 + } else
113697 + return false;
113698 +
113699 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
113700 + return false;
113701 +
113702 + def_rhs1 = gimple_assign_rhs1(def_stmt);
113703 + def_rhs2 = gimple_assign_rhs2(def_stmt);
113704 + if (is_gimple_constant(def_rhs1))
113705 + def_const_rhs = def_rhs1;
113706 + else if (is_gimple_constant(def_rhs2))
113707 + def_const_rhs = def_rhs2;
113708 + else
113709 + return false;
113710 +
113711 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
113712 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
113713 + return false;
113714 + return true;
113715 +}
113716 +
113717 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
113718 +{
113719 + const_gimple def_stmt_1, def_stmt_2;
113720 + const_tree rhs1, rhs2;
113721 + bool add_mul_rhs1, add_mul_rhs2;
113722 +
113723 + rhs1 = gimple_assign_rhs1(stmt);
113724 + def_stmt_1 = get_def_stmt(rhs1);
113725 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
113726 +
113727 + rhs2 = gimple_assign_rhs2(stmt);
113728 + def_stmt_2 = get_def_stmt(rhs2);
113729 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
113730 +
113731 + if (add_mul_rhs1)
113732 + return RHS1_INTENTIONAL_OVERFLOW;
113733 + if (add_mul_rhs2)
113734 + return RHS2_INTENTIONAL_OVERFLOW;
113735 + return NO_INTENTIONAL_OVERFLOW;
113736 +}
113737 +
113738 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
113739 +{
113740 + gimple my_stmt;
113741 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113742 +
113743 + gsi_next(&gsi);
113744 + my_stmt = gsi_stmt(gsi);
113745 +
113746 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
113747 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
113748 +
113749 + return my_stmt;
113750 +}
113751 +
113752 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
113753 + * unsigned type cast to signed type, unsigned type: no more uses
113754 + * e.g., lib/vsprintf.c:simple_strtol()
113755 + * _10 = (unsigned long int) _9
113756 + * _11 = -_10;
113757 + * _12 = (long int) _11; (_11_ no more uses)
113758 + */
113759 +static bool is_call_or_cast(gimple stmt)
113760 +{
113761 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
113762 +}
113763 +
113764 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
113765 +{
113766 + const_tree rhs;
113767 + gimple def_stmt;
113768 +
113769 + if (node == NULL_TREE)
113770 + return true;
113771 + if (is_gimple_constant(node))
113772 + return true;
113773 +
113774 + def_stmt = get_def_stmt(node);
113775 + if (!def_stmt)
113776 + return false;
113777 +
113778 + if (is_call_or_cast(def_stmt))
113779 + return true;
113780 +
113781 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
113782 + return false;
113783 + rhs = gimple_assign_rhs1(def_stmt);
113784 + def_stmt = get_def_stmt(rhs);
113785 + if (!def_stmt)
113786 + return false;
113787 + return is_call_or_cast(def_stmt);
113788 +}
113789 +
113790 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
113791 +{
113792 + unsigned int use_num;
113793 + gimple so_stmt;
113794 + const_gimple def_stmt;
113795 + const_tree rhs1, rhs2;
113796 + tree rhs = gimple_assign_rhs1(stmt);
113797 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
113798 + const_tree rhs_type = TREE_TYPE(rhs);
113799 +
113800 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
113801 + return;
113802 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
113803 + return;
113804 + use_num = uses_num(rhs);
113805 + if (use_num != 1)
113806 + return;
113807 +
113808 + def_stmt = get_def_stmt(rhs);
113809 + if (!def_stmt)
113810 + return;
113811 + if (!is_gimple_assign(def_stmt))
113812 + return;
113813 +
113814 + rhs1 = gimple_assign_rhs1(def_stmt);
113815 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
113816 + return;
113817 +
113818 + rhs2 = gimple_assign_rhs2(def_stmt);
113819 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
113820 + return;
113821 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113822 + return;
113823 +
113824 + so_stmt = get_dup_stmt(visited, stmt);
113825 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
113826 +}
113827 +
113828 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
113829 new file mode 100644
113830 index 0000000..4bddad2
113831 --- /dev/null
113832 +++ b/tools/gcc/size_overflow_plugin/misc.c
113833 @@ -0,0 +1,203 @@
113834 +/*
113835 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113836 + * Licensed under the GPL v2, or (at your option) v3
113837 + *
113838 + * Homepage:
113839 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113840 + *
113841 + * Documentation:
113842 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113843 + *
113844 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113845 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113846 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113847 + *
113848 + * Usage:
113849 + * $ make
113850 + * $ make run
113851 + */
113852 +
113853 +#include "gcc-common.h"
113854 +#include "size_overflow.h"
113855 +
113856 +void set_current_function_decl(tree fndecl)
113857 +{
113858 + gcc_assert(fndecl != NULL_TREE);
113859 +
113860 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
113861 + calculate_dominance_info(CDI_DOMINATORS);
113862 + current_function_decl = fndecl;
113863 +}
113864 +
113865 +void unset_current_function_decl(void)
113866 +{
113867 + free_dominance_info(CDI_DOMINATORS);
113868 + pop_cfun();
113869 + current_function_decl = NULL_TREE;
113870 +}
113871 +
113872 +static bool is_bool(const_tree node)
113873 +{
113874 + const_tree type;
113875 +
113876 + if (node == NULL_TREE)
113877 + return false;
113878 +
113879 + type = TREE_TYPE(node);
113880 + if (!INTEGRAL_TYPE_P(type))
113881 + return false;
113882 + if (TREE_CODE(type) == BOOLEAN_TYPE)
113883 + return true;
113884 + if (TYPE_PRECISION(type) == 1)
113885 + return true;
113886 + return false;
113887 +}
113888 +
113889 +bool skip_types(const_tree var)
113890 +{
113891 + tree type;
113892 + enum tree_code code;
113893 +
113894 + if (is_gimple_constant(var))
113895 + return true;
113896 +
113897 + switch (TREE_CODE(var)) {
113898 + case ADDR_EXPR:
113899 +#if BUILDING_GCC_VERSION >= 4006
113900 + case MEM_REF:
113901 +#endif
113902 + case ARRAY_REF:
113903 + case BIT_FIELD_REF:
113904 + case INDIRECT_REF:
113905 + case TARGET_MEM_REF:
113906 + case COMPONENT_REF:
113907 + case VAR_DECL:
113908 + case VIEW_CONVERT_EXPR:
113909 + return true;
113910 + default:
113911 + break;
113912 + }
113913 +
113914 + code = TREE_CODE(var);
113915 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
113916 +
113917 + type = TREE_TYPE(var);
113918 + switch (TREE_CODE(type)) {
113919 + case INTEGER_TYPE:
113920 + case ENUMERAL_TYPE:
113921 + return false;
113922 + case BOOLEAN_TYPE:
113923 + return is_bool(var);
113924 + default:
113925 + return true;
113926 + }
113927 +}
113928 +
113929 +gimple get_def_stmt(const_tree node)
113930 +{
113931 + gcc_assert(node != NULL_TREE);
113932 +
113933 + if (skip_types(node))
113934 + return NULL;
113935 +
113936 + if (TREE_CODE(node) != SSA_NAME)
113937 + return NULL;
113938 + return SSA_NAME_DEF_STMT(node);
113939 +}
113940 +
113941 +tree create_new_var(tree type)
113942 +{
113943 + tree new_var = create_tmp_var(type, "cicus");
113944 +
113945 + add_referenced_var(new_var);
113946 + return new_var;
113947 +}
113948 +
113949 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
113950 +{
113951 + const_gimple def_stmt = get_def_stmt(rhs);
113952 +
113953 + if (force)
113954 + return false;
113955 +
113956 + if (is_gimple_constant(rhs))
113957 + return false;
113958 +
113959 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113960 + return false;
113961 +
113962 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113963 + return false;
113964 +
113965 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113966 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113967 + return false;
113968 +
113969 + return true;
113970 +}
113971 +
113972 +tree cast_a_tree(tree type, tree var)
113973 +{
113974 + gcc_assert(type != NULL_TREE);
113975 + gcc_assert(var != NULL_TREE);
113976 + gcc_assert(fold_convertible_p(type, var));
113977 +
113978 + return fold_convert(type, var);
113979 +}
113980 +
113981 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113982 +{
113983 + gimple assign, def_stmt;
113984 +
113985 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113986 + gcc_assert(!is_gimple_constant(rhs));
113987 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113988 + gcc_unreachable();
113989 +
113990 + def_stmt = get_def_stmt(rhs);
113991 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
113992 + return def_stmt;
113993 +
113994 + if (lhs == CREATE_NEW_VAR)
113995 + lhs = create_new_var(dst_type);
113996 +
113997 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113998 +
113999 + if (!gsi_end_p(*gsi)) {
114000 + location_t loc = gimple_location(gsi_stmt(*gsi));
114001 + gimple_set_location(assign, loc);
114002 + }
114003 +
114004 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114005 +
114006 + if (before)
114007 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114008 + else
114009 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114010 + update_stmt(assign);
114011 + return assign;
114012 +}
114013 +
114014 +bool is_size_overflow_type(const_tree var)
114015 +{
114016 + const char *name;
114017 + const_tree type_name, type;
114018 +
114019 + if (var == NULL_TREE)
114020 + return false;
114021 +
114022 + type = TREE_TYPE(var);
114023 + type_name = TYPE_NAME(type);
114024 + if (type_name == NULL_TREE)
114025 + return false;
114026 +
114027 + if (DECL_P(type_name))
114028 + name = DECL_NAME_POINTER(type_name);
114029 + else
114030 + name = IDENTIFIER_POINTER(type_name);
114031 +
114032 + if (!strncmp(name, "size_overflow_type", 18))
114033 + return true;
114034 + return false;
114035 +}
114036 +
114037 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114038 new file mode 100644
114039 index 0000000..7c9e6d1
114040 --- /dev/null
114041 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114042 @@ -0,0 +1,138 @@
114043 +/*
114044 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114045 + * Licensed under the GPL v2, or (at your option) v3
114046 + *
114047 + * Homepage:
114048 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114049 + *
114050 + * Documentation:
114051 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114052 + *
114053 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114054 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114055 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114056 + *
114057 + * Usage:
114058 + * $ make
114059 + * $ make run
114060 + */
114061 +
114062 +#include "gcc-common.h"
114063 +#include "size_overflow.h"
114064 +
114065 +bool skip_expr_on_double_type(const_gimple stmt)
114066 +{
114067 + enum tree_code code = gimple_assign_rhs_code(stmt);
114068 +
114069 + switch (code) {
114070 + case RSHIFT_EXPR:
114071 + case TRUNC_DIV_EXPR:
114072 + case CEIL_DIV_EXPR:
114073 + case FLOOR_DIV_EXPR:
114074 + case ROUND_DIV_EXPR:
114075 + case EXACT_DIV_EXPR:
114076 + case RDIV_EXPR:
114077 + case TRUNC_MOD_EXPR:
114078 + case CEIL_MOD_EXPR:
114079 + case FLOOR_MOD_EXPR:
114080 + case ROUND_MOD_EXPR:
114081 + return true;
114082 + default:
114083 + return false;
114084 + }
114085 +}
114086 +
114087 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
114088 +{
114089 + const_tree orig_rhs1;
114090 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
114091 + gimple down_cast, up_cast;
114092 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
114093 +
114094 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114095 + down_lhs = gimple_assign_lhs(down_cast);
114096 +
114097 + gsi = gsi_for_stmt(use_stmt);
114098 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114099 + new_lhs = gimple_assign_lhs(up_cast);
114100 +
114101 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
114102 + if (operand_equal_p(orig_rhs1, rhs, 0))
114103 + gimple_assign_set_rhs1(use_stmt, new_lhs);
114104 + else
114105 + gimple_assign_set_rhs2(use_stmt, new_lhs);
114106 + update_stmt(use_stmt);
114107 +
114108 + pointer_set_insert(visited->my_stmts, up_cast);
114109 + pointer_set_insert(visited->my_stmts, down_cast);
114110 + pointer_set_insert(visited->skip_expr_casts, up_cast);
114111 + pointer_set_insert(visited->skip_expr_casts, down_cast);
114112 +}
114113 +
114114 +static tree get_proper_unsigned_half_type(const_tree node)
114115 +{
114116 + tree new_type, type;
114117 +
114118 + gcc_assert(is_size_overflow_type(node));
114119 +
114120 + type = TREE_TYPE(node);
114121 + switch (TYPE_MODE(type)) {
114122 + case HImode:
114123 + new_type = unsigned_intQI_type_node;
114124 + break;
114125 + case SImode:
114126 + new_type = unsigned_intHI_type_node;
114127 + break;
114128 + case DImode:
114129 + new_type = unsigned_intSI_type_node;
114130 + break;
114131 + case TImode:
114132 + new_type = unsigned_intDI_type_node;
114133 + break;
114134 + default:
114135 + gcc_unreachable();
114136 + }
114137 +
114138 + if (TYPE_QUALS(type) != 0)
114139 + return build_qualified_type(new_type, TYPE_QUALS(type));
114140 + return new_type;
114141 +}
114142 +
114143 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
114144 +{
114145 + tree type;
114146 +
114147 + if (rhs == NULL_TREE)
114148 + return;
114149 + if (!is_size_overflow_type(rhs))
114150 + return;
114151 +
114152 + type = get_proper_unsigned_half_type(rhs);
114153 + if (is_gimple_constant(rhs))
114154 + return;
114155 + create_up_and_down_cast(visited, stmt, type, rhs);
114156 +}
114157 +
114158 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
114159 +{
114160 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
114161 + return;
114162 + gcc_assert(is_size_overflow_type(rhs));
114163 + insert_cast_rhs(visited, stmt, rhs);
114164 +}
114165 +
114166 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
114167 +{
114168 + tree rhs1, rhs2;
114169 +
114170 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
114171 + rhs1 = gimple_assign_rhs1(stmt);
114172 + insert_cast(visited, stmt, rhs1);
114173 + }
114174 +
114175 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
114176 + rhs2 = gimple_assign_rhs2(stmt);
114177 + insert_cast(visited, stmt, rhs2);
114178 + }
114179 +}
114180 +
114181 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
114182 new file mode 100644
114183 index 0000000..e5b4e50
114184 --- /dev/null
114185 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
114186 @@ -0,0 +1,127 @@
114187 +#ifndef SIZE_OVERFLOW_H
114188 +#define SIZE_OVERFLOW_H
114189 +
114190 +#define CREATE_NEW_VAR NULL_TREE
114191 +#define CANNOT_FIND_ARG 32
114192 +#define MAX_PARAM 31
114193 +#define BEFORE_STMT true
114194 +#define AFTER_STMT false
114195 +
114196 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114197 +#define YES_ASM_STR "# size_overflow MARK_YES "
114198 +#define OK_ASM_STR "# size_overflow "
114199 +
114200 +enum mark {
114201 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114202 +};
114203 +
114204 +enum intentional_overflow_type {
114205 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
114206 +};
114207 +
114208 +struct visited {
114209 + struct pointer_set_t *stmts;
114210 + struct pointer_set_t *my_stmts;
114211 + struct pointer_set_t *skip_expr_casts;
114212 + struct pointer_set_t *no_cast_check;
114213 +};
114214 +
114215 +// size_overflow_plugin.c
114216 +extern tree report_size_overflow_decl;
114217 +extern tree size_overflow_type_HI;
114218 +extern tree size_overflow_type_SI;
114219 +extern tree size_overflow_type_DI;
114220 +extern tree size_overflow_type_TI;
114221 +
114222 +
114223 +// size_overflow_plugin_hash.c
114224 +struct size_overflow_hash {
114225 + const struct size_overflow_hash * const next;
114226 + const char * const name;
114227 + const unsigned int param;
114228 +};
114229 +
114230 +struct interesting_node {
114231 + struct interesting_node *next;
114232 + gimple first_stmt;
114233 + const_tree fndecl;
114234 + tree node;
114235 +#if BUILDING_GCC_VERSION <= 4007
114236 + VEC(tree, gc) *last_nodes;
114237 +#else
114238 + vec<tree, va_gc> *last_nodes;
114239 +#endif
114240 + unsigned int num;
114241 + enum mark intentional_attr_decl;
114242 + enum mark intentional_attr_cur_fndecl;
114243 + gimple intentional_mark_from_gimple;
114244 +};
114245 +
114246 +extern bool is_size_overflow_asm(const_gimple stmt);
114247 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
114248 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
114249 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
114250 +extern bool is_a_return_check(const_tree node);
114251 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
114252 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
114253 +
114254 +
114255 +// size_overflow_debug.c
114256 +extern struct opt_pass *make_dump_pass(void);
114257 +
114258 +
114259 +// intentional_overflow.c
114260 +extern enum mark get_intentional_attr_type(const_tree node);
114261 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
114262 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
114263 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
114264 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
114265 +extern bool is_turn_off_intentional_attr(const_tree decl);
114266 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
114267 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
114268 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
114269 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
114270 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
114271 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
114272 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
114273 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
114274 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
114275 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
114276 +
114277 +
114278 +// insert_size_overflow_check_ipa.c
114279 +extern unsigned int search_function(void);
114280 +extern unsigned int call_count;
114281 +extern struct opt_pass *make_insert_size_overflow_check(void);
114282 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
114283 +
114284 +
114285 +// insert_size_overflow_asm.c
114286 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
114287 +
114288 +
114289 +// misc.c
114290 +extern void set_current_function_decl(tree fndecl);
114291 +extern void unset_current_function_decl(void);
114292 +extern gimple get_def_stmt(const_tree node);
114293 +extern tree create_new_var(tree type);
114294 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114295 +extern bool skip_types(const_tree var);
114296 +extern tree cast_a_tree(tree type, tree var);
114297 +extern bool is_size_overflow_type(const_tree var);
114298 +
114299 +
114300 +// insert_size_overflow_check_core.c
114301 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114302 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114303 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114304 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114305 +
114306 +
114307 +// remove_unnecessary_dup.c
114308 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114309 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114310 +extern bool skip_expr_on_double_type(const_gimple stmt);
114311 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114312 +
114313 +#endif
114314 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114315 new file mode 100644
114316 index 0000000..4378111
114317 --- /dev/null
114318 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114319 @@ -0,0 +1,116 @@
114320 +/*
114321 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114322 + * Licensed under the GPL v2, or (at your option) v3
114323 + *
114324 + * Homepage:
114325 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114326 + *
114327 + * Documentation:
114328 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114329 + *
114330 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114331 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114332 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114333 + *
114334 + * Usage:
114335 + * $ make
114336 + * $ make run
114337 + */
114338 +
114339 +#include "gcc-common.h"
114340 +
114341 +static unsigned int dump_functions(void)
114342 +{
114343 + struct cgraph_node *node;
114344 +
114345 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
114346 + basic_block bb;
114347 +
114348 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
114349 + current_function_decl = NODE_DECL(node);
114350 +
114351 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
114352 +
114353 + FOR_ALL_BB_FN(bb, cfun) {
114354 + gimple_stmt_iterator si;
114355 +
114356 + fprintf(stderr, "<bb %u>:\n", bb->index);
114357 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
114358 + debug_gimple_stmt(gsi_stmt(si));
114359 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
114360 + debug_gimple_stmt(gsi_stmt(si));
114361 + fprintf(stderr, "\n");
114362 + }
114363 +
114364 + fprintf(stderr, "-------------------------------------------------------------------------\n");
114365 +
114366 + pop_cfun();
114367 + current_function_decl = NULL_TREE;
114368 + }
114369 +
114370 + fprintf(stderr, "###############################################################################\n");
114371 +
114372 + return 0;
114373 +}
114374 +
114375 +#if BUILDING_GCC_VERSION >= 4009
114376 +static const struct pass_data dump_pass_data = {
114377 +#else
114378 +static struct ipa_opt_pass_d dump_pass = {
114379 + .pass = {
114380 +#endif
114381 + .type = SIMPLE_IPA_PASS,
114382 + .name = "dump",
114383 +#if BUILDING_GCC_VERSION >= 4008
114384 + .optinfo_flags = OPTGROUP_NONE,
114385 +#endif
114386 +#if BUILDING_GCC_VERSION >= 4009
114387 + .has_gate = false,
114388 + .has_execute = true,
114389 +#else
114390 + .gate = NULL,
114391 + .execute = dump_functions,
114392 + .sub = NULL,
114393 + .next = NULL,
114394 + .static_pass_number = 0,
114395 +#endif
114396 + .tv_id = TV_NONE,
114397 + .properties_required = 0,
114398 + .properties_provided = 0,
114399 + .properties_destroyed = 0,
114400 + .todo_flags_start = 0,
114401 + .todo_flags_finish = 0,
114402 +#if BUILDING_GCC_VERSION < 4009
114403 + },
114404 + .generate_summary = NULL,
114405 + .write_summary = NULL,
114406 + .read_summary = NULL,
114407 +#if BUILDING_GCC_VERSION >= 4006
114408 + .write_optimization_summary = NULL,
114409 + .read_optimization_summary = NULL,
114410 +#endif
114411 + .stmt_fixup = NULL,
114412 + .function_transform_todo_flags_start = 0,
114413 + .function_transform = NULL,
114414 + .variable_transform = NULL,
114415 +#endif
114416 +};
114417 +
114418 +#if BUILDING_GCC_VERSION >= 4009
114419 +namespace {
114420 +class dump_pass : public ipa_opt_pass_d {
114421 +public:
114422 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
114423 + unsigned int execute() { return dump_functions(); }
114424 +};
114425 +}
114426 +#endif
114427 +
114428 +struct opt_pass *make_dump_pass(void)
114429 +{
114430 +#if BUILDING_GCC_VERSION >= 4009
114431 + return new dump_pass();
114432 +#else
114433 + return &dump_pass.pass;
114434 +#endif
114435 +}
114436 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114437 new file mode 100644
114438 index 0000000..2393acc
114439 --- /dev/null
114440 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114441 @@ -0,0 +1,5800 @@
114442 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
114443 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
114444 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
114445 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
114446 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
114447 +padzero_55 padzero 1 55 &sel_read_policyvers_55
114448 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
114449 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
114450 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
114451 +load_msg_95 load_msg 2 95 NULL
114452 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
114453 +init_q_132 init_q 4 132 NULL
114454 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
114455 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
114456 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
114457 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
114458 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
114459 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
114460 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
114461 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
114462 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
114463 +br_port_info_size_268 br_port_info_size 0 268 NULL
114464 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
114465 +SYSC_connect_304 SYSC_connect 3 304 NULL
114466 +syslog_print_307 syslog_print 2 307 NULL
114467 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
114468 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
114469 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
114470 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
114471 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
114472 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
114473 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
114474 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
114475 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
114476 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
114477 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
114478 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
114479 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
114480 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
114481 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
114482 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
114483 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
114484 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
114485 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
114486 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
114487 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
114488 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
114489 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
114490 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
114491 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
114492 +unlink_queued_645 unlink_queued 4 645 NULL
114493 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
114494 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
114495 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
114496 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
114497 +dvb_video_write_754 dvb_video_write 3 754 NULL
114498 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
114499 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
114500 +snd_pcm_drain_811 snd_pcm_drain 0 811 NULL
114501 +if_writecmd_815 if_writecmd 2 815 NULL
114502 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
114503 +error_state_read_859 error_state_read 6 859 NULL
114504 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
114505 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
114506 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
114507 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
114508 +__nodes_weight_956 __nodes_weight 0 956 NULL
114509 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
114510 +mnt_want_write_975 mnt_want_write 0 975 NULL
114511 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
114512 +memcmp_990 memcmp 0 990 NULL
114513 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
114514 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
114515 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
114516 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
114517 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
114518 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
114519 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
114520 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
114521 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
114522 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
114523 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
114524 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
114525 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
114526 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
114527 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
114528 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
114529 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
114530 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
114531 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
114532 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
114533 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
114534 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
114535 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
114536 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
114537 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
114538 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
114539 +ffs_1322 ffs 0 1322 NULL
114540 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
114541 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
114542 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
114543 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
114544 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
114545 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
114546 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
114547 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
114548 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
114549 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
114550 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
114551 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
114552 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
114553 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
114554 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
114555 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
114556 +fpregs_set_1497 fpregs_set 4 1497 NULL
114557 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
114558 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
114559 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
114560 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
114561 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
114562 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
114563 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
114564 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
114565 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
114566 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
114567 +rmap_add_1677 rmap_add 3 1677 NULL
114568 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
114569 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
114570 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
114571 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
114572 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
114573 +internal_create_group_1733 internal_create_group 0 1733 NULL
114574 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
114575 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
114576 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
114577 +cosa_write_1774 cosa_write 3 1774 NULL
114578 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
114579 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
114580 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
114581 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
114582 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
114583 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
114584 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
114585 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
114586 +bdev_erase_1933 bdev_erase 3 1933 NULL
114587 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
114588 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
114589 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
114590 +__assign_irq_vector_1961 __assign_irq_vector 0 1961 NULL
114591 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
114592 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
114593 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
114594 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
114595 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
114596 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
114597 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
114598 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
114599 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
114600 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
114601 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
114602 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
114603 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
114604 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
114605 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
114606 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
114607 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
114608 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
114609 +enable_read_2117 enable_read 3 2117 NULL
114610 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
114611 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
114612 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
114613 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
114614 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
114615 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
114616 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
114617 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
114618 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
114619 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
114620 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
114621 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
114622 +do_update_counters_2259 do_update_counters 4 2259 NULL
114623 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
114624 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
114625 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
114626 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
114627 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
114628 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL nohasharray
114629 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 &picolcd_fb_write_2318
114630 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
114631 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
114632 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
114633 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
114634 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
114635 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
114636 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
114637 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
114638 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
114639 +raid1_size_2419 raid1_size 0-2 2419 NULL
114640 +arch_msi_check_device_2449 arch_msi_check_device 0 2449 NULL
114641 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
114642 +wiphy_new_2482 wiphy_new 2 2482 NULL
114643 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
114644 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
114645 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
114646 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
114647 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
114648 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
114649 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
114650 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
114651 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
114652 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
114653 +slot_bytes_2609 slot_bytes 0 2609 NULL
114654 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
114655 +switch_status_2629 switch_status 5 2629 NULL
114656 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
114657 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
114658 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
114659 +oti6858_write_2692 oti6858_write 4 2692 NULL
114660 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
114661 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
114662 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
114663 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
114664 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
114665 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
114666 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
114667 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
114668 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
114669 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
114670 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL nohasharray
114671 +snd_pcm_reset_2829 snd_pcm_reset 0 2829 &vb2_dc_get_userptr_2829
114672 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
114673 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
114674 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
114675 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
114676 +nla_padlen_2883 nla_padlen 1 2883 NULL
114677 +cmm_write_2896 cmm_write 3 2896 NULL
114678 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
114679 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
114680 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
114681 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
114682 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
114683 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
114684 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
114685 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
114686 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
114687 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
114688 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
114689 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
114690 +depth_write_3021 depth_write 3 3021 NULL
114691 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
114692 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
114693 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
114694 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
114695 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
114696 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
114697 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
114698 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
114699 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
114700 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
114701 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
114702 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
114703 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
114704 +rb_alloc_3102 rb_alloc 1 3102 NULL
114705 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
114706 +print_time_3132 print_time 0 3132 NULL
114707 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
114708 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
114709 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
114710 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
114711 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
114712 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
114713 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
114714 +alloc_context_3194 alloc_context 1 3194 NULL
114715 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
114716 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
114717 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
114718 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
114719 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
114720 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
114721 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
114722 +key_key_read_3241 key_key_read 3 3241 NULL
114723 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
114724 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
114725 +cgroup_name_3300 cgroup_name 3 3300 NULL
114726 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
114727 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 4-3-0 3314 NULL
114728 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
114729 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
114730 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
114731 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
114732 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
114733 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
114734 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
114735 +scnprintf_3360 scnprintf 0-2 3360 NULL
114736 +sr_read_3366 sr_read 3 3366 NULL
114737 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
114738 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
114739 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
114740 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
114741 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
114742 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
114743 +softsynth_write_3455 softsynth_write 3 3455 NULL
114744 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
114745 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
114746 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
114747 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
114748 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
114749 +SyS_readv_3539 SyS_readv 3 3539 NULL
114750 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
114751 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
114752 +evtchn_read_3569 evtchn_read 3 3569 NULL
114753 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
114754 +vc_resize_3585 vc_resize 3-2 3585 NULL
114755 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
114756 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
114757 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
114758 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
114759 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
114760 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
114761 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
114762 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
114763 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
114764 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
114765 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
114766 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
114767 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
114768 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
114769 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
114770 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
114771 +get_fd_set_3866 get_fd_set 1 3866 NULL
114772 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
114773 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
114774 +nvram_write_3894 nvram_write 3 3894 NULL
114775 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
114776 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
114777 +vcs_write_3910 vcs_write 3 3910 NULL
114778 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
114779 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
114780 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
114781 +do_add_counters_3992 do_add_counters 3 3992 NULL
114782 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
114783 +userspace_status_4004 userspace_status 4 4004 NULL
114784 +mei_write_4005 mei_write 3 4005 NULL nohasharray
114785 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
114786 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
114787 +blk_end_request_4024 blk_end_request 3 4024 NULL
114788 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
114789 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
114790 +read_file_queues_4078 read_file_queues 3 4078 NULL
114791 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
114792 +tm6000_read_4151 tm6000_read 3 4151 NULL
114793 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
114794 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
114795 +get_alua_req_4166 get_alua_req 3 4166 NULL
114796 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
114797 +read_file_bool_4180 read_file_bool 3 4180 NULL
114798 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
114799 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
114800 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
114801 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
114802 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
114803 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
114804 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
114805 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
114806 +count_strings_4315 count_strings 0 4315 NULL
114807 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
114808 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
114809 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
114810 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3-0 4365 NULL
114811 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
114812 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL nohasharray
114813 +access_process_vm_4412 access_process_vm 0 4412 &cxacru_cm_get_array_4412
114814 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
114815 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
114816 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
114817 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
114818 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
114819 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
114820 +set_link_security_4502 set_link_security 4 4502 NULL
114821 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
114822 +tty_register_device_4544 tty_register_device 2 4544 NULL
114823 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
114824 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
114825 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
114826 +bch_alloc_4593 bch_alloc 1 4593 NULL
114827 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
114828 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
114829 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
114830 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
114831 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
114832 +kone_receive_4690 kone_receive 4 4690 NULL
114833 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
114834 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
114835 +show_header_4722 show_header 3 4722 NULL nohasharray
114836 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
114837 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
114838 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
114839 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
114840 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
114841 +create_subvol_4791 create_subvol 4 4791 NULL
114842 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
114843 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
114844 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
114845 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
114846 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
114847 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
114848 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
114849 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
114850 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
114851 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
114852 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
114853 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
114854 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
114855 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
114856 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
114857 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
114858 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
114859 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
114860 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
114861 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
114862 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
114863 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
114864 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
114865 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
114866 +sound_write_5102 sound_write 3 5102 NULL
114867 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
114868 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
114869 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
114870 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
114871 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
114872 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
114873 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
114874 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
114875 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
114876 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
114877 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
114878 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
114879 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
114880 +cq_free_res_5355 cq_free_res 5 5355 NULL
114881 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
114882 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
114883 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
114884 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
114885 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
114886 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
114887 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3-0 5482 NULL
114888 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
114889 +tty_write_5494 tty_write 3 5494 NULL
114890 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
114891 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
114892 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
114893 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
114894 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
114895 +le_readq_5557 le_readq 0 5557 NULL
114896 +inw_5558 inw 0 5558 NULL
114897 +bioset_create_5580 bioset_create 1 5580 NULL
114898 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
114899 +__remove_suid_5618 __remove_suid 0 5618 NULL
114900 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
114901 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
114902 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
114903 +get_arg_5694 get_arg 3 5694 NULL
114904 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
114905 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
114906 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
114907 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
114908 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
114909 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
114910 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
114911 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
114912 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
114913 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
114914 +setup_req_5848 setup_req 3 5848 NULL
114915 +ria_page_count_5849 ria_page_count 0 5849 NULL
114916 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
114917 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
114918 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
114919 +port_show_regs_5904 port_show_regs 3 5904 NULL
114920 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
114921 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
114922 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
114923 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
114924 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
114925 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
114926 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
114927 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
114928 +SyS_semop_5980 SyS_semop 3 5980 NULL
114929 +alloc_msg_6072 alloc_msg 1 6072 NULL
114930 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
114931 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
114932 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
114933 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
114934 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
114935 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
114936 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
114937 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
114938 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
114939 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
114940 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
114941 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
114942 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
114943 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
114944 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
114945 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
114946 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
114947 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
114948 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
114949 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
114950 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
114951 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
114952 +serial_port_in_6291 serial_port_in 0 6291 NULL
114953 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
114954 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
114955 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
114956 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
114957 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
114958 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
114959 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
114960 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
114961 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
114962 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
114963 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
114964 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
114965 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
114966 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
114967 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
114968 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
114969 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
114970 +mei_read_6507 mei_read 3 6507 NULL
114971 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
114972 +wdm_read_6549 wdm_read 3 6549 NULL
114973 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
114974 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
114975 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
114976 +snd_pcm_hw_refine_old_user_6586 snd_pcm_hw_refine_old_user 0 6586 NULL
114977 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
114978 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
114979 +pvscsi_allocate_rings_6689 pvscsi_allocate_rings 0 6689 NULL
114980 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
114981 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
114982 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
114983 +mpeg_read_6708 mpeg_read 3 6708 NULL
114984 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
114985 +video_proc_write_6724 video_proc_write 3 6724 NULL
114986 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
114987 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
114988 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
114989 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
114990 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
114991 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
114992 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
114993 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
114994 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
114995 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
114996 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
114997 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
114998 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
114999 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
115000 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
115001 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
115002 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
115003 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
115004 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
115005 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
115006 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
115007 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
115008 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
115009 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
115010 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
115011 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
115012 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
115013 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
115014 +request_key_async_6990 request_key_async 4 6990 NULL
115015 +tpl_write_6998 tpl_write 3 6998 NULL
115016 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
115017 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
115018 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
115019 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
115020 +wimax_msg_7030 wimax_msg 4 7030 NULL
115021 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
115022 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
115023 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
115024 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
115025 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
115026 +event_enable_read_7074 event_enable_read 3 7074 NULL
115027 +tipc_send_packet_7091 tipc_send_packet 4 7091 NULL nohasharray
115028 +beacon_interval_read_7091 beacon_interval_read 3 7091 &tipc_send_packet_7091
115029 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
115030 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
115031 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
115032 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
115033 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
115034 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
115035 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
115036 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
115037 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
115038 +mgmt_control_7349 mgmt_control 3 7349 NULL
115039 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
115040 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
115041 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
115042 +hweight_long_7388 hweight_long 0 7388 NULL
115043 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
115044 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
115045 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
115046 +readb_7401 readb 0 7401 NULL
115047 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
115048 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
115049 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
115050 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
115051 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
115052 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
115053 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
115054 +garp_request_join_7471 garp_request_join 4 7471 NULL
115055 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
115056 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
115057 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
115058 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
115059 +sk_convert_filter_7541 sk_convert_filter 2 7541 NULL
115060 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
115061 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
115062 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
115063 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
115064 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
115065 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
115066 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
115067 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
115068 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
115069 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
115070 +dev_write_7708 dev_write 3 7708 NULL
115071 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
115072 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
115073 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
115074 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
115075 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
115076 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
115077 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
115078 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 NULL nohasharray
115079 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 &lustre_packed_msg_size_7792
115080 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
115081 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
115082 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
115083 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
115084 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
115085 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
115086 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
115087 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
115088 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
115089 +vcs_read_8017 vcs_read 3 8017 NULL
115090 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
115091 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
115092 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
115093 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
115094 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
115095 +venus_lookup_8121 venus_lookup 4 8121 NULL
115096 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
115097 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
115098 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
115099 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
115100 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
115101 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
115102 +play_iframe_8219 play_iframe 3 8219 NULL
115103 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
115104 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
115105 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
115106 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
115107 +init_cdev_8274 init_cdev 1 8274 NULL
115108 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
115109 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
115110 +snd_pcm_update_state_8320 snd_pcm_update_state 0 8320 NULL
115111 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
115112 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
115113 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
115114 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
115115 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
115116 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
115117 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
115118 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
115119 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
115120 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
115121 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
115122 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
115123 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
115124 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
115125 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
115126 +dev_config_8506 dev_config 3 8506 NULL
115127 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
115128 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
115129 +user_on_off_8552 user_on_off 2 8552 NULL
115130 +profile_remove_8556 profile_remove 3 8556 NULL
115131 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL nohasharray
115132 +pci_msi_check_device_8570 pci_msi_check_device 0 8570 &cache_slow_downcall_8570
115133 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
115134 +tower_write_8580 tower_write 3 8580 NULL
115135 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
115136 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
115137 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
115138 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
115139 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
115140 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
115141 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
115142 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
115143 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
115144 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
115145 +arcfb_write_8702 arcfb_write 3 8702 NULL
115146 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
115147 +init_header_8703 init_header 0 8703 &i_size_read_8703
115148 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
115149 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
115150 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
115151 +__create_irqs_8733 __create_irqs 2 8733 NULL
115152 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
115153 +compound_order_8750 compound_order 0 8750 NULL
115154 +yurex_write_8761 yurex_write 3 8761 NULL
115155 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
115156 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
115157 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
115158 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
115159 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
115160 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
115161 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
115162 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
115163 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
115164 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
115165 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
115166 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
115167 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
115168 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
115169 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
115170 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
115171 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
115172 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
115173 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
115174 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
115175 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
115176 +write_file_ani_8918 write_file_ani 3 8918 NULL
115177 +layout_commit_8926 layout_commit 3 8926 NULL
115178 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
115179 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
115180 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
115181 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
115182 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
115183 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
115184 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
115185 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
115186 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
115187 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
115188 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
115189 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
115190 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
115191 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
115192 +nla_put_9042 nla_put 3 9042 NULL
115193 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
115194 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
115195 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
115196 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
115197 +create_queues_9088 create_queues 2-3 9088 NULL
115198 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
115199 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
115200 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
115201 +gfn_to_rmap_9110 gfn_to_rmap 2-3 9110 &caif_stream_sendmsg_9110
115202 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
115203 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
115204 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
115205 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
115206 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
115207 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
115208 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
115209 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
115210 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
115211 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
115212 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
115213 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
115214 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
115215 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
115216 +flakey_status_9274 flakey_status 5 9274 NULL
115217 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
115218 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
115219 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
115220 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
115221 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
115222 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
115223 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
115224 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
115225 +read_9397 read 3 9397 NULL
115226 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
115227 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
115228 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
115229 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
115230 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
115231 +get_registers_9470 get_registers 4 9470 NULL nohasharray
115232 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
115233 +crypt_status_9492 crypt_status 5 9492 NULL
115234 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
115235 +lp_write_9511 lp_write 3 9511 NULL
115236 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
115237 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
115238 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
115239 +read_file_dma_9530 read_file_dma 3 9530 NULL
115240 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
115241 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
115242 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
115243 +fw_node_create_9559 fw_node_create 2 9559 NULL
115244 +kobj_map_9566 kobj_map 2-3 9566 NULL
115245 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
115246 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
115247 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
115248 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
115249 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
115250 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115251 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115252 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115253 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115254 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
115255 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115256 +dns_query_9676 dns_query 3 9676 NULL
115257 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115258 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115259 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115260 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115261 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115262 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115263 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
115264 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115265 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115266 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115267 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115268 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115269 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
115270 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
115271 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115272 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115273 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115274 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
115275 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
115276 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115277 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115278 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115279 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115280 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115281 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
115282 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115283 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
115284 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115285 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115286 +read_file_misc_9948 read_file_misc 3 9948 NULL
115287 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115288 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115289 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115290 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115291 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115292 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115293 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115294 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115295 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115296 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115297 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115298 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115299 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115300 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115301 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115302 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115303 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115304 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115305 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115306 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115307 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115308 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
115309 +read_emulate_10310 read_emulate 2-4 10310 NULL
115310 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115311 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115312 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115313 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115314 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115315 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115316 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115317 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115318 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115319 +led_classdev_register_10384 led_classdev_register 0 10384 NULL
115320 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115321 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115322 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
115323 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
115324 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
115325 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
115326 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
115327 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
115328 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
115329 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
115330 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
115331 +snd_pcm_hw_params_user_10520 snd_pcm_hw_params_user 0 10520 NULL
115332 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
115333 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
115334 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
115335 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
115336 +otp_read_10594 otp_read 2-4-5 10594 NULL
115337 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
115338 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
115339 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
115340 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
115341 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
115342 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
115343 +parport_write_10669 parport_write 0 10669 NULL
115344 +edge_write_10692 edge_write 4 10692 NULL
115345 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
115346 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
115347 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
115348 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
115349 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
115350 +spi_sync_10731 spi_sync 0 10731 NULL
115351 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
115352 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
115353 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
115354 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
115355 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
115356 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
115357 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
115358 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
115359 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
115360 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
115361 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
115362 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
115363 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
115364 +get_scq_10897 get_scq 2 10897 NULL
115365 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
115366 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
115367 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
115368 +kobject_add_10919 kobject_add 0 10919 NULL
115369 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
115370 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
115371 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
115372 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
115373 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
115374 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
115375 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
115376 +pci_msi_vec_count_11046 pci_msi_vec_count 0 11046 NULL
115377 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
115378 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 NULL nohasharray
115379 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 &qlcnic_83xx_calculate_msix_vector_11063
115380 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
115381 +snd_pcm_delay_11081 snd_pcm_delay 0 11081 NULL
115382 +count_argc_11083 count_argc 0 11083 NULL
115383 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
115384 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
115385 +page_offset_11120 page_offset 0 11120 NULL
115386 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
115387 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
115388 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
115389 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
115390 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
115391 +of_irq_count_11253 of_irq_count 0 11253 NULL
115392 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
115393 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
115394 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
115395 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
115396 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
115397 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
115398 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
115399 +construct_key_11329 construct_key 3 11329 NULL nohasharray
115400 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
115401 +next_segment_11330 next_segment 0-2-1 11330 NULL
115402 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
115403 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
115404 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
115405 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
115406 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
115407 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
115408 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
115409 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
115410 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
115411 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
115412 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
115413 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
115414 +str_to_user_11411 str_to_user 2 11411 NULL
115415 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
115416 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
115417 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
115418 +trace_options_read_11419 trace_options_read 3 11419 NULL
115419 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
115420 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
115421 +bttv_read_11432 bttv_read 3 11432 NULL
115422 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
115423 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
115424 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
115425 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
115426 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
115427 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
115428 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
115429 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
115430 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
115431 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
115432 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
115433 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
115434 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
115435 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
115436 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
115437 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
115438 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
115439 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
115440 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
115441 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
115442 +slab_ksize_11664 slab_ksize 0 11664 NULL
115443 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
115444 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
115445 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
115446 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
115447 +split_11691 split 2 11691 NULL
115448 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
115449 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
115450 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
115451 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
115452 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
115453 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
115454 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
115455 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
115456 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
115457 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
115458 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
115459 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
115460 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
115461 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
115462 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
115463 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
115464 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
115465 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
115466 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
115467 +ti_write_11916 ti_write 4 11916 NULL
115468 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
115469 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
115470 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
115471 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
115472 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
115473 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
115474 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
115475 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
115476 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
115477 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
115478 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
115479 +set_powered_12129 set_powered 4 12129 NULL
115480 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
115481 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
115482 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
115483 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
115484 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
115485 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
115486 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
115487 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
115488 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
115489 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
115490 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
115491 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
115492 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
115493 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
115494 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
115495 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
115496 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
115497 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
115498 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
115499 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
115500 +SYSC_vm86_12279 SYSC_vm86 2 12279 NULL
115501 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
115502 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
115503 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
115504 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
115505 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
115506 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
115507 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
115508 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
115509 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
115510 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
115511 +populate_dir_12391 populate_dir 0 12391 &write_file_dump_12391
115512 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
115513 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
115514 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
115515 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
115516 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
115517 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
115518 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
115519 +write_inode_now_12565 write_inode_now 0 12565 NULL
115520 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
115521 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
115522 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
115523 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
115524 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
115525 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
115526 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
115527 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
115528 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
115529 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
115530 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
115531 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
115532 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
115533 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
115534 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
115535 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
115536 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
115537 +ivtv_write_12721 ivtv_write 3 12721 NULL
115538 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
115539 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
115540 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
115541 +listxattr_12769 listxattr 3 12769 NULL
115542 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
115543 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
115544 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
115545 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
115546 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
115547 +spidev_sync_12842 spidev_sync 0 12842 NULL
115548 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
115549 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
115550 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
115551 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
115552 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
115553 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
115554 +bm_status_write_12964 bm_status_write 3 12964 NULL
115555 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
115556 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
115557 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
115558 +__btrfs_direct_write_13007 __btrfs_direct_write 4-0 13007 NULL
115559 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
115560 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
115561 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
115562 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
115563 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
115564 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
115565 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
115566 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
115567 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
115568 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
115569 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
115570 +blk_update_request_13146 blk_update_request 3 13146 NULL
115571 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
115572 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
115573 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
115574 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
115575 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
115576 +comedi_read_13199 comedi_read 3 13199 NULL
115577 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
115578 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
115579 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
115580 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
115581 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
115582 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
115583 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
115584 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
115585 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
115586 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
115587 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
115588 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
115589 +sd_major_13294 sd_major 0-1 13294 NULL
115590 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
115591 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
115592 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
115593 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
115594 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
115595 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
115596 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
115597 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
115598 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
115599 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
115600 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
115601 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
115602 +data_read_13494 data_read 3 13494 NULL
115603 +core_status_13515 core_status 4 13515 NULL
115604 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
115605 +bm_init_13529 bm_init 2 13529 NULL
115606 +request_any_context_irq_13530 request_any_context_irq 0 13530 NULL
115607 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
115608 +SyS_vm86_13557 SyS_vm86 2 13557 NULL
115609 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
115610 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
115611 +ubifs_get_idx_gc_leb_13566 ubifs_get_idx_gc_leb 0 13566 NULL
115612 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
115613 +cache_write_13589 cache_write 3 13589 NULL
115614 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
115615 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
115616 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
115617 +packet_snd_13634 packet_snd 3 13634 NULL
115618 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
115619 +cache_downcall_13666 cache_downcall 3 13666 NULL
115620 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
115621 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
115622 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
115623 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
115624 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
115625 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
115626 +random_read_13815 random_read 3 13815 NULL
115627 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
115628 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
115629 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
115630 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
115631 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
115632 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
115633 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
115634 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
115635 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
115636 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
115637 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
115638 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
115639 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
115640 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
115641 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
115642 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
115643 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
115644 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
115645 +qcam_read_13977 qcam_read 3 13977 NULL
115646 +dsp_read_13980 dsp_read 2 13980 NULL
115647 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
115648 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
115649 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
115650 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
115651 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
115652 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
115653 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
115654 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
115655 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
115656 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
115657 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
115658 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
115659 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
115660 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
115661 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
115662 +em_canid_change_14150 em_canid_change 3 14150 NULL
115663 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
115664 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
115665 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
115666 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
115667 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
115668 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
115669 +alloc_async_14208 alloc_async 1 14208 NULL
115670 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
115671 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
115672 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
115673 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
115674 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
115675 +rr_status_14293 rr_status 5 14293 NULL
115676 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
115677 +oo_objects_14319 oo_objects 0 14319 NULL
115678 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
115679 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
115680 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
115681 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
115682 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
115683 +lowpan_read_14369 lowpan_read 3 14369 NULL
115684 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
115685 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
115686 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
115687 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
115688 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
115689 +block_size_14443 block_size 0 14443 NULL
115690 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
115691 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
115692 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
115693 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
115694 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
115695 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
115696 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
115697 +split_state_14491 split_state 0 14491 NULL
115698 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
115699 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
115700 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
115701 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
115702 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
115703 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
115704 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
115705 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
115706 +dbJoin_14644 dbJoin 0 14644 NULL
115707 +profile_replace_14652 profile_replace 3 14652 NULL
115708 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
115709 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
115710 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
115711 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
115712 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
115713 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
115714 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
115715 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
115716 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
115717 +vfd_write_14717 vfd_write 3 14717 NULL
115718 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
115719 +raid1_resize_14740 raid1_resize 2 14740 NULL
115720 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
115721 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
115722 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
115723 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
115724 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
115725 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
115726 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
115727 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
115728 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
115729 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
115730 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
115731 +lcd_write_14857 lcd_write 3 14857 NULL
115732 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
115733 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
115734 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
115735 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
115736 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
115737 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
115738 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
115739 +queue_cnt_14951 queue_cnt 0 14951 NULL
115740 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
115741 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
115742 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
115743 +setkey_14987 setkey 3 14987 NULL nohasharray
115744 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
115745 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
115746 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
115747 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
115748 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
115749 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
115750 +ntfs_copy_from_user_15072 ntfs_copy_from_user 0-5-3 15072 NULL
115751 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
115752 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
115753 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
115754 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
115755 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
115756 +start_port_15124 start_port 0 15124 NULL
115757 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
115758 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
115759 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
115760 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
115761 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
115762 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
115763 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
115764 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
115765 +simple_strtol_15273 simple_strtol 0 15273 NULL
115766 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
115767 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
115768 +ioread16_15342 ioread16 0 15342 NULL
115769 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
115770 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
115771 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
115772 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
115773 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
115774 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
115775 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
115776 +get_modalias_15406 get_modalias 2 15406 NULL
115777 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
115778 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
115779 +rtw_cfg80211_rx_action_p2p_15432 rtw_cfg80211_rx_action_p2p 3 15432 NULL
115780 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
115781 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
115782 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
115783 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
115784 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
115785 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
115786 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
115787 +snd_pcm_channel_info_15572 snd_pcm_channel_info 0 15572 NULL
115788 +persistent_status_15574 persistent_status 4 15574 NULL
115789 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
115790 +vme_user_write_15587 vme_user_write 3 15587 NULL
115791 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
115792 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
115793 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
115794 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
115795 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
115796 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
115797 +fs_path_add_15648 fs_path_add 3 15648 NULL
115798 +__do_readpage_15652 __do_readpage 0 15652 NULL
115799 +xsd_read_15653 xsd_read 3 15653 NULL
115800 +unix_bind_15668 unix_bind 3 15668 NULL
115801 +dm_read_15674 dm_read 3 15674 NULL nohasharray
115802 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
115803 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
115804 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
115805 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
115806 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
115807 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
115808 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
115809 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
115810 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
115811 +table_size_15851 table_size 0-1-2 15851 NULL
115812 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
115813 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
115814 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
115815 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
115816 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
115817 +power_read_15939 power_read 3 15939 NULL
115818 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
115819 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
115820 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
115821 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
115822 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
115823 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
115824 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
115825 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
115826 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
115827 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
115828 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
115829 +fsm_init_16134 fsm_init 2 16134 NULL
115830 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
115831 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
115832 +mapping_level_16188 mapping_level 2-0 16188 NULL
115833 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
115834 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
115835 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
115836 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
115837 +create_table_16213 create_table 2 16213 NULL
115838 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
115839 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
115840 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
115841 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
115842 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
115843 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
115844 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
115845 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
115846 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
115847 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
115848 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
115849 +account_16283 account 0-4-2 16283 NULL nohasharray
115850 +mirror_status_16283 mirror_status 5 16283 &account_16283
115851 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
115852 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
115853 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
115854 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
115855 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
115856 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
115857 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
115858 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
115859 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
115860 +i8042_create_kbd_port_16379 i8042_create_kbd_port 0 16379 NULL
115861 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
115862 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
115863 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
115864 +cmdline_store_16442 cmdline_store 4 16442 NULL
115865 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
115866 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
115867 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
115868 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
115869 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
115870 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
115871 +raid10_resize_16537 raid10_resize 2 16537 NULL
115872 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
115873 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
115874 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
115875 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
115876 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
115877 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
115878 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
115879 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
115880 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
115881 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
115882 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
115883 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
115884 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
115885 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
115886 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
115887 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
115888 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
115889 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
115890 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
115891 +st_write_16874 st_write 3 16874 NULL
115892 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
115893 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
115894 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
115895 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
115896 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
115897 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
115898 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
115899 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
115900 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
115901 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
115902 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
115903 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
115904 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
115905 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
115906 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
115907 +entry_length_17093 entry_length 0 17093 NULL
115908 +write_mem_17114 write_mem 3 17114 NULL
115909 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
115910 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
115911 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
115912 +sep_read_17161 sep_read 3 17161 NULL
115913 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
115914 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
115915 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
115916 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
115917 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
115918 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
115919 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
115920 +sync_request_17208 sync_request 2 17208 NULL
115921 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
115922 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
115923 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
115924 +alloc_ep_17269 alloc_ep 1 17269 NULL
115925 +pg_read_17276 pg_read 3 17276 NULL
115926 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
115927 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
115928 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
115929 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
115930 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
115931 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
115932 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
115933 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
115934 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
115935 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
115936 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
115937 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
115938 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
115939 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
115940 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
115941 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
115942 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
115943 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
115944 +qp_free_res_17541 qp_free_res 5 17541 NULL
115945 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
115946 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
115947 +snd_pcm_action_lock_irq_17569 snd_pcm_action_lock_irq 0 17569 NULL
115948 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
115949 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
115950 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
115951 +osst_execute_17607 osst_execute 7-6 17607 NULL
115952 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
115953 +dma_map_page_17628 dma_map_page 0 17628 NULL
115954 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
115955 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
115956 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
115957 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
115958 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
115959 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
115960 +venus_rename_17707 venus_rename 4-5 17707 NULL
115961 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
115962 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
115963 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
115964 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
115965 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
115966 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
115967 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
115968 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
115969 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
115970 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
115971 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
115972 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
115973 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
115974 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
115975 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
115976 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
115977 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
115978 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
115979 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
115980 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
115981 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
115982 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
115983 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
115984 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
115985 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
115986 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
115987 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
115988 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
115989 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
115990 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
115991 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
115992 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
115993 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
115994 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
115995 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
115996 +fpregs_get_18066 fpregs_get 4 18066 NULL
115997 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
115998 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
115999 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
116000 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
116001 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
116002 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
116003 +svc_getnl_18120 svc_getnl 0 18120 NULL
116004 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
116005 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
116006 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
116007 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
116008 +snd_pcm_hw_refine_user_18204 snd_pcm_hw_refine_user 0 18204 NULL
116009 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
116010 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
116011 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
116012 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
116013 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
116014 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
116015 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
116016 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
116017 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
116018 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
116019 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
116020 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
116021 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
116022 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
116023 +um_idi_write_18293 um_idi_write 3 18293 NULL
116024 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
116025 +vga_r_18310 vga_r 0 18310 NULL
116026 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
116027 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
116028 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
116029 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
116030 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
116031 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
116032 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
116033 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
116034 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
116035 +ep_io_18367 ep_io 0 18367 NULL
116036 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
116037 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
116038 +ci_role_write_18388 ci_role_write 3 18388 NULL
116039 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
116040 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
116041 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
116042 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
116043 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
116044 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
116045 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
116046 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
116047 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
116048 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
116049 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
116050 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
116051 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
116052 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
116053 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
116054 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
116055 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
116056 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
116057 +debug_output_18575 debug_output 3 18575 NULL
116058 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
116059 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
116060 +from_buffer_18625 from_buffer 3 18625 NULL
116061 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
116062 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
116063 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
116064 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
116065 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
116066 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
116067 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
116068 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
116069 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
116070 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
116071 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
116072 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
116073 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
116074 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
116075 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
116076 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
116077 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
116078 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
116079 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
116080 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
116081 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
116082 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
116083 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
116084 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
116085 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
116086 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
116087 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
116088 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
116089 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
116090 +huge_page_size_19008 huge_page_size 0 19008 NULL
116091 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
116092 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
116093 +revalidate_19043 revalidate 2 19043 NULL
116094 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
116095 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL nohasharray
116096 +do_vm86_irq_handling_19056 do_vm86_irq_handling 2 19056 &osc_pinger_recov_seq_write_19056
116097 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
116098 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
116099 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
116100 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
116101 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
116102 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
116103 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
116104 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
116105 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
116106 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
116107 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
116108 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
116109 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
116110 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
116111 +snd_pcm_capture_rewind_19229 snd_pcm_capture_rewind 0-2 19229 NULL
116112 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
116113 +ucma_query_19260 ucma_query 4 19260 NULL
116114 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
116115 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
116116 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
116117 +qc_capture_19298 qc_capture 3 19298 NULL
116118 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
116119 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
116120 +debug_read_19322 debug_read 3 19322 NULL
116121 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL nohasharray
116122 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 &cfg80211_inform_bss_19332
116123 +closure_sub_19359 closure_sub 2 19359 NULL
116124 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
116125 +read_zero_19366 read_zero 3 19366 NULL
116126 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
116127 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
116128 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
116129 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
116130 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
116131 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
116132 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
116133 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
116134 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
116135 +sky2_read16_19475 sky2_read16 0 19475 NULL
116136 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
116137 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
116138 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
116139 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
116140 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
116141 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
116142 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
116143 +nfsd_read_19568 nfsd_read 5 19568 NULL
116144 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
116145 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
116146 +bm_status_read_19583 bm_status_read 3 19583 NULL
116147 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
116148 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
116149 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
116150 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
116151 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
116152 +read_reg_19723 read_reg 0 19723 NULL
116153 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
116154 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
116155 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
116156 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
116157 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
116158 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
116159 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
116160 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
116161 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
116162 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
116163 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
116164 +__nla_put_19857 __nla_put 3 19857 NULL
116165 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
116166 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
116167 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
116168 +mangle_name_19923 mangle_name 0 19923 NULL
116169 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
116170 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
116171 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
116172 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
116173 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
116174 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
116175 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
116176 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
116177 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
116178 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
116179 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
116180 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
116181 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
116182 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
116183 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
116184 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
116185 +target_message_20072 target_message 2 20072 NULL
116186 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
116187 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
116188 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
116189 +team_options_register_20091 team_options_register 3 20091 NULL
116190 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
116191 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
116192 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
116193 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
116194 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
116195 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
116196 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
116197 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
116198 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
116199 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
116200 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
116201 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
116202 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
116203 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
116204 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
116205 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
116206 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
116207 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
116208 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
116209 +snd_pcm_stop_20376 snd_pcm_stop 0 20376 NULL
116210 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
116211 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
116212 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
116213 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
116214 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
116215 +read_buf_20469 read_buf 2 20469 NULL
116216 +bio_trim_20472 bio_trim 2 20472 NULL
116217 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116218 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116219 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116220 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116221 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116222 +venus_create_20555 venus_create 4 20555 NULL
116223 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116224 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116225 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116226 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
116227 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116228 +lirc_write_20604 lirc_write 3 20604 NULL
116229 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116230 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116231 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116232 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116233 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116234 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116235 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116236 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116237 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116238 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116239 +cpumask_size_20683 cpumask_size 0 20683 NULL
116240 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116241 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116242 +__maestro_read_20700 __maestro_read 0 20700 NULL
116243 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116244 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116245 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116246 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116247 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116248 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116249 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116250 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116251 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116252 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
116253 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116254 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116255 +lowpan_write_20800 lowpan_write 3 20800 NULL
116256 +strndup_user_20819 strndup_user 2 20819 NULL
116257 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116258 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116259 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116260 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116261 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116262 +get_name_20855 get_name 4 20855 NULL
116263 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116264 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116265 +srq_free_res_20868 srq_free_res 5 20868 NULL
116266 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116267 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116268 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116269 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116270 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116271 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116272 +htable_bits_20933 htable_bits 0 20933 NULL
116273 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116274 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116275 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116276 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116277 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116278 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116279 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116280 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116281 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116282 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116283 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116284 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
116285 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116286 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116287 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116288 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116289 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116290 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116291 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116292 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116293 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116294 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116295 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116296 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
116297 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116298 +__generic_file_aio_write_21201 __generic_file_aio_write 0 21201 NULL
116299 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116300 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116301 +get_numpages_21227 get_numpages 0-2-1 21227 NULL
116302 +input_ff_create_21240 input_ff_create 2 21240 NULL
116303 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116304 +fru_length_21257 fru_length 0 21257 NULL
116305 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116306 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
116307 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116308 +add_res_range_21310 add_res_range 4 21310 NULL
116309 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116310 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116311 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116312 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116313 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116314 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116315 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116316 +insert_ptr_21386 insert_ptr 6 21386 NULL
116317 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116318 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
116319 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
116320 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
116321 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
116322 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
116323 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
116324 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
116325 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
116326 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
116327 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
116328 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
116329 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
116330 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
116331 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
116332 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
116333 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
116334 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
116335 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
116336 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
116337 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
116338 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
116339 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
116340 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
116341 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
116342 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
116343 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
116344 +update_time_21719 update_time 0 21719 NULL
116345 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
116346 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
116347 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
116348 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
116349 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
116350 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
116351 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
116352 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
116353 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
116354 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
116355 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
116356 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
116357 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
116358 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
116359 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
116360 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
116361 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
116362 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
116363 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
116364 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
116365 +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
116366 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
116367 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
116368 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
116369 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
116370 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
116371 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
116372 +mem_rw_22085 mem_rw 3 22085 NULL
116373 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
116374 +snd_pcm_xrun_22088 snd_pcm_xrun 0 22088 NULL
116375 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
116376 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
116377 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
116378 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
116379 +pci_request_region_22164 pci_request_region 0 22164 NULL
116380 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
116381 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
116382 +mem_write_22232 mem_write 3 22232 NULL
116383 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
116384 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
116385 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
116386 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
116387 +add_res_tree_22263 add_res_tree 7 22263 NULL
116388 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
116389 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 NULL nohasharray
116390 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 &pci_vpd_srdt_size_22300
116391 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
116392 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
116393 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
116394 +atomic_read_22342 atomic_read 0 22342 NULL
116395 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
116396 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
116397 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
116398 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
116399 +zoran_write_22404 zoran_write 3 22404 NULL
116400 +queue_reply_22416 queue_reply 3 22416 NULL
116401 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
116402 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
116403 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
116404 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
116405 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
116406 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
116407 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
116408 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2-0 22549 NULL
116409 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
116410 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
116411 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
116412 +snapshot_read_22601 snapshot_read 3 22601 NULL
116413 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
116414 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
116415 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
116416 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
116417 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
116418 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
116419 +fill_gap_22681 fill_gap 0 22681 NULL nohasharray
116420 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 &fill_gap_22681
116421 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
116422 +reg_umr_22686 reg_umr 5 22686 NULL
116423 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
116424 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
116425 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
116426 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
116427 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
116428 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
116429 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
116430 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
116431 +print_frame_22769 print_frame 0 22769 NULL
116432 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
116433 +__break_lease_22777 __break_lease 0 22777 NULL
116434 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
116435 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
116436 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
116437 +create_attr_set_22861 create_attr_set 1 22861 NULL
116438 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
116439 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
116440 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
116441 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
116442 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
116443 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
116444 +__set_xattr_22923 __set_xattr 0 22923 NULL
116445 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
116446 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
116447 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
116448 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
116449 +vme_get_size_22964 vme_get_size 0 22964 NULL
116450 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
116451 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
116452 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
116453 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
116454 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
116455 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
116456 +st_status_23032 st_status 5 23032 NULL
116457 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
116458 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
116459 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
116460 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
116461 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
116462 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
116463 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
116464 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
116465 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
116466 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
116467 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
116468 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
116469 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
116470 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
116471 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
116472 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
116473 +__clear_user_23118 __clear_user 0-2 23118 NULL
116474 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
116475 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
116476 +read_file_ani_23161 read_file_ani 3 23161 NULL
116477 +usblp_write_23178 usblp_write 3 23178 NULL
116478 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
116479 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
116480 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
116481 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
116482 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
116483 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
116484 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
116485 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
116486 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
116487 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
116488 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
116489 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
116490 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
116491 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
116492 +page_readlink_23346 page_readlink 3 23346 NULL
116493 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
116494 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
116495 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
116496 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
116497 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
116498 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
116499 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
116500 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
116501 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
116502 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
116503 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
116504 +event_filter_read_23494 event_filter_read 3 23494 NULL
116505 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
116506 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
116507 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
116508 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
116509 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
116510 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
116511 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
116512 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
116513 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
116514 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
116515 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
116516 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
116517 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
116518 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
116519 +sInW_23663 sInW 0 23663 NULL
116520 +SyS_connect_23669 SyS_connect 3 23669 NULL
116521 +cx18_read_23699 cx18_read 3 23699 NULL
116522 +at_get_23708 at_get 0 23708 NULL
116523 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
116524 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
116525 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
116526 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
116527 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
116528 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
116529 +map_write_23795 map_write 3 23795 NULL
116530 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
116531 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
116532 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
116533 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-3-4 23829 NULL
116534 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
116535 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
116536 +p54_init_common_23850 p54_init_common 1 23850 NULL
116537 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
116538 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
116539 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
116540 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
116541 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
116542 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
116543 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
116544 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
116545 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
116546 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
116547 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
116548 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
116549 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
116550 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
116551 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
116552 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
116553 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
116554 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
116555 +give_pages_24021 give_pages 3 24021 NULL
116556 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
116557 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
116558 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
116559 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
116560 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
116561 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
116562 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
116563 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
116564 +lov_brw_24122 lov_brw 4 24122 NULL
116565 +mpu401_read_24126 mpu401_read 3 24126 NULL
116566 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
116567 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
116568 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
116569 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
116570 +adu_read_24177 adu_read 3 24177 NULL
116571 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
116572 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
116573 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
116574 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
116575 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
116576 +mei_amthif_read_24224 mei_amthif_read 4 24224 NULL nohasharray
116577 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 &mei_amthif_read_24224
116578 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
116579 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
116580 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
116581 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
116582 +thin_status_24278 thin_status 5 24278 NULL
116583 +msg_size_24288 msg_size 0 24288 NULL
116584 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
116585 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
116586 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
116587 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
116588 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
116589 +prepare_pages_24349 prepare_pages 0 24349 NULL
116590 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
116591 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
116592 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
116593 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
116594 +igetword_24373 igetword 0 24373 NULL nohasharray
116595 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
116596 +max_io_len_24384 max_io_len 0-1 24384 NULL
116597 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
116598 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
116599 +getxattr_24398 getxattr 4 24398 NULL nohasharray
116600 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
116601 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
116602 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
116603 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
116604 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
116605 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
116606 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
116607 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
116608 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
116609 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 NULL nohasharray
116610 +smk_user_access_24440 smk_user_access 3 24440 &rtw_set_wps_assoc_resp_24440
116611 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
116612 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
116613 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
116614 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
116615 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
116616 +pd_video_read_24510 pd_video_read 3 24510 NULL
116617 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
116618 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
116619 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
116620 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
116621 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
116622 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
116623 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
116624 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
116625 +SyS_poll_24620 SyS_poll 2 24620 NULL
116626 +context_alloc_24645 context_alloc 3 24645 NULL
116627 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
116628 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
116629 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
116630 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
116631 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
116632 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
116633 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
116634 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
116635 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
116636 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
116637 +cache_read_24790 cache_read 3 24790 NULL
116638 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
116639 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
116640 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
116641 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
116642 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
116643 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
116644 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
116645 +queues_read_24877 queues_read 3 24877 NULL
116646 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
116647 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
116648 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
116649 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
116650 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
116651 +security_inode_rename_24971 security_inode_rename 0 24971 NULL
116652 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
116653 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
116654 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
116655 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
116656 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
116657 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
116658 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
116659 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
116660 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
116661 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
116662 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
116663 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
116664 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
116665 +_iwl_dbgfs_reduced_txp_write_25169 _iwl_dbgfs_reduced_txp_write 3 25169 NULL nohasharray
116666 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 &_iwl_dbgfs_reduced_txp_write_25169
116667 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
116668 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
116669 +stripe_status_25259 stripe_status 5 25259 NULL
116670 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
116671 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
116672 +vfs_writev_25278 vfs_writev 3 25278 NULL
116673 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
116674 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
116675 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
116676 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
116677 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
116678 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
116679 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
116680 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
116681 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
116682 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
116683 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
116684 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
116685 +sb_permission_25523 sb_permission 0 25523 NULL
116686 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
116687 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
116688 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
116689 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
116690 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
116691 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
116692 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
116693 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
116694 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
116695 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
116696 +__direct_map_25647 __direct_map 5-6 25647 NULL
116697 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
116698 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
116699 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
116700 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
116701 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
116702 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
116703 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
116704 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
116705 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
116706 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
116707 +sg_read_25799 sg_read 3 25799 NULL
116708 +system_enable_read_25815 system_enable_read 3 25815 NULL
116709 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
116710 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
116711 +parport_read_25855 parport_read 0 25855 NULL
116712 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
116713 +key_attr_size_25865 key_attr_size 0 25865 NULL
116714 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
116715 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
116716 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
116717 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
116718 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
116719 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
116720 +rcname_read_25919 rcname_read 3 25919 NULL
116721 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
116722 +key_flags_read_25931 key_flags_read 3 25931 NULL
116723 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
116724 +flush_25957 flush 2 25957 NULL
116725 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
116726 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
116727 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
116728 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
116729 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
116730 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
116731 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
116732 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
116733 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
116734 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
116735 +read_sb_page_26119 read_sb_page 5 26119 NULL
116736 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
116737 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
116738 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
116739 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
116740 +disk_devt_26180 disk_devt 0 26180 NULL
116741 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
116742 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
116743 +mce_write_26201 mce_write 3 26201 NULL
116744 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
116745 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
116746 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
116747 +simple_setattr_26234 simple_setattr 0 26234 NULL
116748 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
116749 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
116750 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
116751 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
116752 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
116753 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
116754 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
116755 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
116756 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
116757 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
116758 +ntty_write_26404 ntty_write 3 26404 NULL
116759 +firmware_store_26408 firmware_store 4 26408 NULL
116760 +pagemap_read_26441 pagemap_read 3 26441 NULL
116761 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 NULL nohasharray
116762 +tower_read_26461 tower_read 3 26461 &enc_pools_add_pages_26461
116763 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
116764 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
116765 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
116766 +read_vmcore_26501 read_vmcore 3 26501 NULL
116767 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
116768 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
116769 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
116770 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
116771 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
116772 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
116773 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
116774 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
116775 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
116776 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
116777 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
116778 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
116779 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
116780 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
116781 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
116782 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
116783 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
116784 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
116785 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
116786 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
116787 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
116788 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
116789 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
116790 +smk_write_load_26829 smk_write_load 3 26829 NULL
116791 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
116792 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
116793 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
116794 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
116795 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
116796 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
116797 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
116798 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
116799 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
116800 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
116801 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
116802 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
116803 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
116804 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
116805 +extract_entropy_user_26952 extract_entropy_user 3 26952 NULL nohasharray
116806 +do_trimming_26952 do_trimming 3 26952 &extract_entropy_user_26952
116807 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
116808 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
116809 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
116810 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
116811 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
116812 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
116813 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
116814 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
116815 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
116816 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
116817 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
116818 +pms_capture_27142 pms_capture 4 27142 NULL
116819 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
116820 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
116821 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
116822 +write_kmem_27225 write_kmem 3 27225 NULL
116823 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
116824 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
116825 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
116826 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
116827 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
116828 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
116829 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
116830 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
116831 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
116832 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
116833 +seq_read_27411 seq_read 3 27411 NULL
116834 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
116835 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
116836 +cypress_write_27423 cypress_write 4 27423 NULL
116837 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
116838 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
116839 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
116840 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
116841 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
116842 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
116843 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
116844 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
116845 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
116846 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
116847 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
116848 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
116849 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
116850 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
116851 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
116852 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
116853 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &nl80211_send_connect_result_27642
116854 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
116855 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
116856 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
116857 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
116858 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
116859 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
116860 +evm_write_key_27715 evm_write_key 3 27715 NULL
116861 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
116862 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
116863 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
116864 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
116865 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
116866 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
116867 +SyS_readv_27804 SyS_readv 3 27804 NULL
116868 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
116869 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
116870 +init_header_complete_27833 init_header_complete 0 27833 NULL
116871 +read_profile_27859 read_profile 3 27859 NULL
116872 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
116873 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
116874 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
116875 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
116876 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
116877 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
116878 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
116879 +security_path_chown_27966 security_path_chown 0 27966 NULL
116880 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
116881 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
116882 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
116883 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
116884 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
116885 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
116886 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
116887 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
116888 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
116889 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
116890 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
116891 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
116892 +pool_status_28055 pool_status 5 28055 NULL
116893 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
116894 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
116895 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
116896 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
116897 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
116898 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
116899 +video_read_28148 video_read 3 28148 NULL
116900 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
116901 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
116902 +vread_28173 vread 0-3 28173 NULL
116903 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
116904 +counter_free_res_28187 counter_free_res 5 28187 NULL
116905 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
116906 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
116907 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
116908 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
116909 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
116910 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
116911 +usemap_size_28281 usemap_size 0 28281 NULL
116912 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
116913 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
116914 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
116915 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
116916 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
116917 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
116918 +security_inode_link_28327 security_inode_link 0 28327 NULL
116919 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
116920 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
116921 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
116922 +snapshot_write_28351 snapshot_write 3 28351 NULL
116923 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
116924 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
116925 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
116926 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
116927 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
116928 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
116929 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
116930 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
116931 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
116932 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
116933 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
116934 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
116935 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
116936 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
116937 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
116938 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
116939 +aio_read_events_28545 aio_read_events 3 28545 &mptctl_getiocinfo_28545 nohasharray
116940 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &aio_read_events_28545
116941 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
116942 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
116943 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
116944 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
116945 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
116946 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
116947 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
116948 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
116949 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
116950 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
116951 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
116952 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
116953 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
116954 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
116955 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
116956 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
116957 +spi_execute_28736 spi_execute 5 28736 NULL
116958 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
116959 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
116960 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
116961 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
116962 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
116963 +sel_write_member_28800 sel_write_member 3 28800 NULL
116964 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
116965 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
116966 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
116967 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
116968 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
116969 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
116970 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
116971 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
116972 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
116973 +push_rx_28939 push_rx 3 28939 NULL
116974 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
116975 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
116976 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
116977 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
116978 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
116979 +bin_uuid_28999 bin_uuid 3 28999 NULL
116980 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
116981 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
116982 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
116983 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
116984 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
116985 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
116986 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
116987 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
116988 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
116989 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
116990 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
116991 +snprintf_29125 snprintf 0 29125 NULL
116992 +iov_shorten_29130 iov_shorten 0 29130 NULL
116993 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
116994 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
116995 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
116996 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
116997 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
116998 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
116999 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
117000 +recover_peb_29238 recover_peb 0 29238 NULL
117001 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
117002 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
117003 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
117004 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
117005 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
117006 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
117007 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
117008 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
117009 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
117010 +tun_put_user_29337 tun_put_user 5 29337 NULL
117011 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
117012 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
117013 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
117014 +mempool_create_29437 mempool_create 1 29437 NULL
117015 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
117016 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
117017 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
117018 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
117019 +do_register_entry_29478 do_register_entry 4 29478 NULL
117020 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
117021 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
117022 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
117023 +i2c_add_adapter_29507 i2c_add_adapter 0 29507 NULL
117024 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
117025 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
117026 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
117027 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
117028 +ftrace_write_29551 ftrace_write 3 29551 NULL
117029 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
117030 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
117031 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
117032 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
117033 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
117034 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
117035 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
117036 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
117037 +slots_per_page_29601 slots_per_page 0 29601 NULL
117038 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
117039 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
117040 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
117041 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
117042 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
117043 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
117044 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
117045 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
117046 +probes_write_29711 probes_write 3 29711 NULL
117047 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
117048 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
117049 +std_nic_write_29752 std_nic_write 3 29752 NULL
117050 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
117051 +dbAlloc_29794 dbAlloc 0 29794 NULL
117052 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
117053 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
117054 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
117055 +count_partial_29850 count_partial 0 29850 NULL
117056 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
117057 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
117058 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
117059 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
117060 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
117061 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
117062 +write_file_queue_29922 write_file_queue 3 29922 NULL
117063 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
117064 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
117065 +arch_setup_dmar_msi_29992 arch_setup_dmar_msi 0 29992 NULL
117066 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
117067 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
117068 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
117069 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
117070 +drp_wmove_30043 drp_wmove 4 30043 NULL
117071 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
117072 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
117073 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
117074 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
117075 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
117076 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
117077 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
117078 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
117079 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
117080 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
117081 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
117082 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
117083 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
117084 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
117085 +snd_pcm_playback_forward_30201 snd_pcm_playback_forward 0-2 30201 NULL
117086 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
117087 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
117088 +SyS_semop_30227 SyS_semop 3 30227 NULL
117089 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
117090 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
117091 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL nohasharray
117092 +try_break_deleg_30271 try_break_deleg 0 30271 &isr_pci_pm_read_30271
117093 +compat_readv_30273 compat_readv 3 30273 NULL
117094 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
117095 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
117096 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
117097 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
117098 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
117099 +i8254_read_30330 i8254_read 0 30330 NULL
117100 +resource_from_user_30341 resource_from_user 3 30341 NULL
117101 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
117102 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
117103 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
117104 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
117105 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
117106 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
117107 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
117108 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
117109 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
117110 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
117111 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
117112 +enable_write_30456 enable_write 3 30456 NULL
117113 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
117114 +urandom_read_30462 urandom_read 3 30462 NULL
117115 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
117116 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
117117 +adu_write_30487 adu_write 3 30487 NULL
117118 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
117119 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
117120 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
117121 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
117122 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
117123 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
117124 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 NULL
117125 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
117126 +set_le_30581 set_le 4 30581 NULL
117127 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
117128 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
117129 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
117130 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
117131 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
117132 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
117133 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
117134 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
117135 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
117136 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
117137 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
117138 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
117139 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
117140 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
117141 +snapshot_status_30744 snapshot_status 5 30744 NULL
117142 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
117143 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
117144 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
117145 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
117146 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
117147 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
117148 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
117149 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
117150 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
117151 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
117152 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
117153 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
117154 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
117155 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
117156 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
117157 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
117158 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
117159 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
117160 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
117161 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
117162 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
117163 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
117164 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
117165 +depth_read_31112 depth_read 3 31112 NULL
117166 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
117167 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
117168 +size_inside_page_31141 size_inside_page 0 31141 NULL
117169 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
117170 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
117171 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
117172 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
117173 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
117174 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
117175 +__read_reg_31216 __read_reg 0 31216 NULL
117176 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
117177 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
117178 +cyy_readb_31240 cyy_readb 0 31240 NULL
117179 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
117180 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
117181 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
117182 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
117183 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
117184 +command_file_write_31318 command_file_write 3 31318 NULL
117185 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
117186 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
117187 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
117188 +outlen_write_31358 outlen_write 3 31358 NULL
117189 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117190 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117191 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117192 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117193 +inb_31388 inb 0 31388 NULL
117194 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117195 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117196 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117197 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117198 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117199 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117200 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117201 +alg_setkey_31485 alg_setkey 3 31485 NULL
117202 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117203 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117204 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117205 +hidraw_write_31536 hidraw_write 3 31536 NULL
117206 +usbvision_read_31555 usbvision_read 3 31555 NULL
117207 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117208 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117209 +osst_write_31581 osst_write 3 31581 NULL
117210 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117211 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117212 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117213 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117214 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117215 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117216 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117217 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117218 +__lgread_31668 __lgread 4 31668 NULL
117219 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117220 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117221 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117222 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117223 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
117224 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
117225 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117226 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117227 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117228 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117229 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117230 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117231 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117232 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117233 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117234 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117235 +data_write_31805 data_write 3 31805 NULL
117236 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117237 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117238 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117239 +clone_bio_31854 clone_bio 4-3 31854 NULL
117240 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117241 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117242 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117243 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117244 +xattr_permission_31907 xattr_permission 0 31907 NULL
117245 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117246 +new_dir_31919 new_dir 3 31919 NULL
117247 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117248 +era_status_31934 era_status 5 31934 NULL
117249 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117250 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117251 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117252 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
117253 +vb2_write_31948 vb2_write 3 31948 NULL
117254 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117255 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117256 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117257 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117258 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117259 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117260 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117261 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117262 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117263 +calc_hmac_32010 calc_hmac 3 32010 NULL
117264 +aead_len_32021 aead_len 0 32021 NULL nohasharray
117265 +aer_init_32021 aer_init 0 32021 &aead_len_32021
117266 +stk_read_32038 stk_read 3 32038 NULL
117267 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117268 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117269 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117270 +bio_alloc_32095 bio_alloc 2 32095 NULL
117271 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117272 +disk_status_32120 disk_status 4 32120 NULL
117273 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117274 +venus_link_32165 venus_link 5 32165 NULL
117275 +do_writepages_32173 do_writepages 0 32173 NULL
117276 +del_ptr_32197 del_ptr 4 32197 NULL
117277 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117278 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117279 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117280 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117281 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117282 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117283 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117284 +SyS_select_32319 SyS_select 1 32319 NULL
117285 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117286 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117287 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117288 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117289 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117290 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
117291 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117292 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117293 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117294 +snd_pcm_sync_ptr_32461 snd_pcm_sync_ptr 0 32461 NULL
117295 +cache_status_32462 cache_status 5 32462 NULL
117296 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117297 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117298 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117299 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117300 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117301 +disconnect_32521 disconnect 4 32521 NULL
117302 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117303 +ilo_read_32531 ilo_read 3 32531 NULL
117304 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117305 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117306 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117307 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117308 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117309 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117310 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117311 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117312 +__pci_request_region_32618 __pci_request_region 0 32618 NULL
117313 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117314 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117315 +kvmalloc_32646 kvmalloc 1 32646 NULL
117316 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117317 +generic_readlink_32654 generic_readlink 3 32654 NULL
117318 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
117319 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
117320 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
117321 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
117322 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
117323 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
117324 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
117325 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
117326 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
117327 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
117328 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
117329 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
117330 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
117331 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
117332 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
117333 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
117334 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
117335 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
117336 +compat_filldir_32999 compat_filldir 3 32999 NULL
117337 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
117338 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
117339 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
117340 +snd_pcm_prepare_33036 snd_pcm_prepare 0 33036 NULL
117341 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
117342 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
117343 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
117344 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
117345 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
117346 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
117347 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
117348 +alloc_tio_33077 alloc_tio 3 33077 NULL
117349 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
117350 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
117351 +notify_change_33143 notify_change 0 33143 NULL
117352 +SyS_poll_33152 SyS_poll 2 33152 NULL
117353 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
117354 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
117355 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
117356 +pp_read_33210 pp_read 3 33210 NULL
117357 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
117358 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
117359 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
117360 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
117361 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
117362 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
117363 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
117364 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
117365 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
117366 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
117367 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
117368 +pvscsi_allocate_sg_33357 pvscsi_allocate_sg 0 33357 NULL
117369 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
117370 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
117371 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
117372 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
117373 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
117374 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
117375 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
117376 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
117377 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
117378 +message_stats_list_33440 message_stats_list 5 33440 NULL
117379 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
117380 +create_entry_33479 create_entry 2 33479 NULL
117381 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
117382 +res_counter_read_33499 res_counter_read 4 33499 NULL
117383 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
117384 +fb_read_33506 fb_read 3 33506 NULL
117385 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
117386 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
117387 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
117388 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
117389 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
117390 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
117391 +count_subheaders_33591 count_subheaders 0 33591 NULL
117392 +scsi_execute_33596 scsi_execute 5 33596 NULL
117393 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
117394 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
117395 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
117396 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
117397 +stride_page_count_33641 stride_page_count 2 33641 NULL
117398 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
117399 +inw_p_33668 inw_p 0 33668 NULL
117400 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
117401 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
117402 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
117403 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
117404 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
117405 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
117406 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
117407 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
117408 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
117409 +rtw_cbuf_alloc23a_33740 rtw_cbuf_alloc23a 1 33740 NULL
117410 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
117411 +hashtab_create_33769 hashtab_create 3 33769 NULL
117412 +i8042_create_aux_port_33777 i8042_create_aux_port 0 33777 NULL
117413 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
117414 +filter_write_33819 filter_write 3 33819 NULL
117415 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
117416 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
117417 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
117418 +snd_pcm_action_nonatomic_33844 snd_pcm_action_nonatomic 0 33844 NULL
117419 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
117420 +get_user_pages_33908 get_user_pages 0 33908 NULL
117421 +sg_nents_33909 sg_nents 0 33909 NULL
117422 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
117423 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
117424 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
117425 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
117426 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
117427 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
117428 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
117429 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
117430 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
117431 +ppp_write_34034 ppp_write 3 34034 NULL
117432 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
117433 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
117434 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
117435 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
117436 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
117437 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
117438 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
117439 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
117440 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
117441 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
117442 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
117443 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
117444 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
117445 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
117446 +device_private_init_34279 device_private_init 0 34279 NULL
117447 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
117448 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
117449 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
117450 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
117451 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
117452 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
117453 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
117454 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
117455 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
117456 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
117457 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
117458 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
117459 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
117460 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
117461 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
117462 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
117463 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
117464 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
117465 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
117466 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
117467 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
117468 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
117469 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
117470 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
117471 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
117472 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
117473 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
117474 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
117475 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
117476 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
117477 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
117478 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
117479 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
117480 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
117481 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
117482 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
117483 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
117484 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
117485 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
117486 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
117487 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
117488 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
117489 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
117490 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
117491 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
117492 +port_print_34704 port_print 3 34704 NULL
117493 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
117494 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
117495 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
117496 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
117497 +bootmode_store_34762 bootmode_store 4 34762 NULL
117498 +device_add_34766 device_add 0 34766 NULL
117499 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
117500 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
117501 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
117502 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
117503 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
117504 +file_page_index_34820 file_page_index 0-2 34820 NULL
117505 +bio_segments_34832 bio_segments 0 34832 NULL
117506 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
117507 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
117508 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
117509 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
117510 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
117511 +msg_print_text_34889 msg_print_text 0 34889 NULL
117512 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
117513 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
117514 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
117515 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
117516 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
117517 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
117518 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
117519 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
117520 +schedule_erase_34996 schedule_erase 0 34996 NULL
117521 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
117522 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
117523 +rtw_cfg80211_rx_p2p_action_public_35010 rtw_cfg80211_rx_p2p_action_public 3 35010 NULL
117524 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
117525 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
117526 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
117527 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
117528 +capi_write_35104 capi_write 3 35104 NULL nohasharray
117529 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
117530 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
117531 +message_stats_print_35158 message_stats_print 6 35158 NULL
117532 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
117533 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
117534 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
117535 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
117536 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
117537 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
117538 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
117539 +set_fd_set_35249 set_fd_set 1 35249 NULL
117540 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
117541 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
117542 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
117543 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
117544 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
117545 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
117546 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
117547 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
117548 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
117549 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
117550 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
117551 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
117552 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
117553 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
117554 +read_kmem_35372 read_kmem 3 35372 NULL
117555 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
117556 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
117557 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
117558 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
117559 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
117560 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
117561 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
117562 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
117563 +async_setkey_35521 async_setkey 3 35521 NULL
117564 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
117565 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
117566 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
117567 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
117568 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
117569 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
117570 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
117571 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
117572 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
117573 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
117574 +kernel_readv_35617 kernel_readv 3 35617 NULL
117575 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
117576 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
117577 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
117578 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
117579 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
117580 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
117581 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
117582 +md_super_write_35703 md_super_write 4 35703 NULL
117583 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
117584 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
117585 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
117586 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
117587 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
117588 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
117589 +fls64_35862 fls64 0 35862 NULL
117590 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
117591 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
117592 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
117593 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
117594 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
117595 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
117596 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
117597 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
117598 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
117599 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
117600 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
117601 +acl_alloc_35979 acl_alloc 1 35979 NULL
117602 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
117603 +kuc_alloc_35998 kuc_alloc 1 35998 NULL nohasharray
117604 +write_file_antenna_35998 write_file_antenna 3 35998 &kuc_alloc_35998
117605 +scsi_transfer_length_36011 scsi_transfer_length 0 36011 NULL
117606 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
117607 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
117608 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
117609 +account_shadowed_36048 account_shadowed 2 36048 NULL
117610 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
117611 +snd_pcm_playback_hw_avail_36061 snd_pcm_playback_hw_avail 0 36061 NULL
117612 +write_emulate_36065 write_emulate 2-4 36065 NULL
117613 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
117614 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
117615 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
117616 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
117617 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
117618 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
117619 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
117620 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
117621 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
117622 +twl_set_36154 twl_set 2 36154 NULL
117623 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
117624 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
117625 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
117626 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
117627 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
117628 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
117629 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
117630 +rtw_cfg80211_set_wpa_ie_36236 rtw_cfg80211_set_wpa_ie 3 36236 NULL
117631 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
117632 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
117633 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
117634 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
117635 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL nohasharray
117636 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 &cfs_hash_buckets_realloc_36276
117637 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
117638 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
117639 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
117640 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
117641 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
117642 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
117643 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
117644 +lc_create_36332 lc_create 4 36332 NULL
117645 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
117646 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
117647 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
117648 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
117649 +to_sector_36361 to_sector 0-1 36361 NULL
117650 +tunables_read_36385 tunables_read 3 36385 NULL
117651 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
117652 +sierra_write_36402 sierra_write 4 36402 NULL
117653 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
117654 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
117655 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
117656 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
117657 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
117658 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
117659 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
117660 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
117661 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
117662 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
117663 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
117664 +get_param_l_36518 get_param_l 0 36518 NULL
117665 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
117666 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
117667 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
117668 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
117669 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
117670 +__erst_read_36579 __erst_read 0 36579 NULL
117671 +put_cmsg_36589 put_cmsg 4 36589 NULL
117672 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
117673 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
117674 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
117675 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
117676 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
117677 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
117678 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
117679 +xillybus_read_36678 xillybus_read 3 36678 NULL
117680 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
117681 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
117682 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
117683 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
117684 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
117685 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
117686 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
117687 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
117688 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
117689 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
117690 +cm_write_36858 cm_write 3 36858 NULL
117691 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
117692 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
117693 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
117694 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
117695 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
117696 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
117697 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
117698 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
117699 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
117700 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
117701 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
117702 +setxattr_37006 setxattr 4 37006 NULL
117703 +command_file_read_37038 command_file_read 3 37038 NULL
117704 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
117705 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
117706 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
117707 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
117708 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
117709 +parse_command_37079 parse_command 2 37079 NULL
117710 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
117711 +tun_get_user_37094 tun_get_user 5 37094 NULL
117712 +has_wrprotected_page_37123 has_wrprotected_page 2-3 37123 NULL
117713 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
117714 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
117715 +msg_word_37164 msg_word 0 37164 NULL
117716 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
117717 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
117718 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
117719 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
117720 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 4-0 37212 &crypto_shash_descsize_37212
117721 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
117722 +__do_replace_37227 __do_replace 5 37227 NULL
117723 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
117724 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
117725 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
117726 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
117727 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
117728 +request_threaded_irq_37303 request_threaded_irq 0 37303 NULL
117729 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
117730 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
117731 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
117732 +tipc_send_37315 tipc_send 3 37315 NULL
117733 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
117734 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
117735 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
117736 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
117737 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
117738 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
117739 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
117740 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
117741 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
117742 +fru_alloc_37442 fru_alloc 1 37442 NULL
117743 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
117744 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
117745 +get_est_timing_37484 get_est_timing 0 37484 NULL
117746 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
117747 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
117748 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
117749 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
117750 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
117751 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
117752 +hdr_size_37536 hdr_size 0 37536 NULL
117753 +extent_map_end_37550 extent_map_end 0 37550 NULL
117754 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
117755 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
117756 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
117757 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
117758 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
117759 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
117760 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
117761 +may_delete_37656 may_delete 0 37656 NULL
117762 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
117763 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
117764 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
117765 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
117766 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
117767 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
117768 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
117769 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
117770 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
117771 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
117772 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
117773 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
117774 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
117775 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
117776 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
117777 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
117778 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
117779 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
117780 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
117781 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
117782 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
117783 +set_registers_37883 set_registers 4 37883 NULL
117784 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
117785 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
117786 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
117787 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
117788 +write_file_bool_37957 write_file_bool 3 37957 NULL
117789 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
117790 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
117791 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
117792 +vfs_readv_38011 vfs_readv 3 38011 NULL
117793 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
117794 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
117795 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
117796 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
117797 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
117798 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
117799 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
117800 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
117801 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 NULL nohasharray
117802 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 &wcn36xx_smd_rsp_process_38081
117803 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
117804 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
117805 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
117806 +ep0_read_38095 ep0_read 3 38095 NULL
117807 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
117808 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
117809 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
117810 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
117811 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
117812 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 4-3-0 38153 NULL
117813 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
117814 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
117815 +cdev_add_38176 cdev_add 2-3 38176 NULL
117816 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
117817 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
117818 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
117819 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
117820 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
117821 +snd_pcm_playback_rewind_38249 snd_pcm_playback_rewind 0-2 38249 NULL
117822 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
117823 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
117824 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
117825 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
117826 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
117827 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
117828 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
117829 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
117830 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
117831 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
117832 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
117833 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
117834 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
117835 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
117836 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
117837 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
117838 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
117839 +dev_names_read_38509 dev_names_read 3 38509 NULL
117840 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
117841 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
117842 +set_queue_count_38519 set_queue_count 0 38519 NULL
117843 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
117844 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
117845 +kuc_len_38557 kuc_len 0-1 38557 NULL
117846 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
117847 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
117848 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
117849 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
117850 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
117851 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
117852 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
117853 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
117854 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
117855 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
117856 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
117857 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
117858 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
117859 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
117860 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
117861 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
117862 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
117863 +udf_readpages_38761 udf_readpages 4 38761 NULL
117864 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
117865 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
117866 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
117867 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
117868 +err_decode_38804 err_decode 2 38804 NULL
117869 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
117870 +direct_entry_38836 direct_entry 3 38836 NULL
117871 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
117872 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
117873 +interfaces_38859 interfaces 2 38859 NULL
117874 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
117875 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
117876 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
117877 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
117878 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
117879 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
117880 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
117881 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
117882 +get_nodes_39012 get_nodes 3 39012 NULL
117883 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
117884 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
117885 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
117886 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
117887 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
117888 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
117889 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
117890 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
117891 +ea_foreach_39133 ea_foreach 0 39133 NULL
117892 +generic_permission_39150 generic_permission 0 39150 NULL
117893 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
117894 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
117895 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
117896 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
117897 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
117898 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
117899 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
117900 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
117901 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 0-2 39248 NULL
117902 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
117903 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
117904 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
117905 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
117906 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
117907 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
117908 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
117909 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
117910 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
117911 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
117912 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
117913 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
117914 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
117915 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
117916 +__send_to_port_39386 __send_to_port 3 39386 NULL
117917 +user_power_read_39414 user_power_read 3 39414 NULL
117918 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
117919 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
117920 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
117921 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
117922 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
117923 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
117924 +int_proc_write_39542 int_proc_write 3 39542 NULL
117925 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
117926 +pp_write_39554 pp_write 3 39554 NULL
117927 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
117928 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
117929 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
117930 +ext_depth_39607 ext_depth 0 39607 NULL
117931 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
117932 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
117933 +sdio_readb_39618 sdio_readb 0 39618 NULL
117934 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
117935 +set_dev_class_39645 set_dev_class 4 39645 NULL
117936 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
117937 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
117938 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
117939 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
117940 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
117941 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
117942 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
117943 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
117944 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
117945 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
117946 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
117947 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
117948 +pkt_add_39897 pkt_add 3 39897 NULL
117949 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
117950 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
117951 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
117952 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
117953 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
117954 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
117955 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
117956 +__spi_async_39932 __spi_async 0 39932 NULL
117957 +__get_order_39935 __get_order 0 39935 NULL
117958 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
117959 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
117960 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
117961 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
117962 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
117963 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
117964 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
117965 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
117966 +server_name2svname_39998 server_name2svname 4 39998 NULL
117967 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
117968 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
117969 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
117970 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
117971 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
117972 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
117973 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
117974 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
117975 +snd_pcm_sw_params_user_40095 snd_pcm_sw_params_user 0 40095 NULL
117976 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
117977 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
117978 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
117979 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
117980 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
117981 +pt_write_40159 pt_write 3 40159 NULL
117982 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
117983 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
117984 +allocate_probes_40204 allocate_probes 1 40204 NULL
117985 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
117986 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
117987 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
117988 +osst_read_40237 osst_read 3 40237 NULL
117989 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
117990 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
117991 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
117992 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
117993 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
117994 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
117995 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
117996 +SyS_bind_40303 SyS_bind 3 40303 NULL
117997 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
117998 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
117999 +mmio_read_40348 mmio_read 4 40348 NULL
118000 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
118001 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
118002 +get_chars_40373 get_chars 3 40373 NULL
118003 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
118004 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
118005 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
118006 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
118007 +SyS_writev_40467 SyS_writev 3 40467 NULL
118008 +SyS_select_40473 SyS_select 1 40473 NULL
118009 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
118010 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
118011 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
118012 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
118013 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
118014 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
118015 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
118016 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
118017 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
118018 +i2c_register_adapter_40660 i2c_register_adapter 0 40660 NULL
118019 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
118020 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
118021 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
118022 +fops_read_40672 fops_read 3 40672 NULL
118023 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
118024 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
118025 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
118026 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
118027 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
118028 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
118029 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
118030 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
118031 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
118032 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
118033 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
118034 +card_send_command_40757 card_send_command 3 40757 NULL
118035 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
118036 +pg_write_40766 pg_write 3 40766 NULL
118037 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
118038 +show_list_40775 show_list 3-0 40775 NULL
118039 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
118040 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
118041 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
118042 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
118043 +add_action_40811 add_action 4 40811 NULL
118044 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
118045 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
118046 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
118047 +read_file_queue_40895 read_file_queue 3 40895 NULL
118048 +waiters_read_40902 waiters_read 3 40902 NULL
118049 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
118050 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
118051 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
118052 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
118053 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
118054 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
118055 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
118056 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
118057 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
118058 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
118059 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
118060 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
118061 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
118062 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
118063 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
118064 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
118065 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
118066 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
118067 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
118068 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
118069 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
118070 +dma_attach_41094 dma_attach 5-6 41094 NULL
118071 +provide_user_output_41105 provide_user_output 3 41105 NULL
118072 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
118073 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
118074 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
118075 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
118076 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
118077 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
118078 +request_irq_41192 request_irq 0 41192 NULL
118079 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
118080 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
118081 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
118082 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
118083 +erst_read_41260 erst_read 0 41260 NULL
118084 +alloc_context_41283 alloc_context 1 41283 NULL
118085 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
118086 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
118087 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
118088 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
118089 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
118090 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
118091 +kmp_init_41373 kmp_init 2 41373 NULL
118092 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
118093 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
118094 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
118095 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
118096 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
118097 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
118098 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
118099 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
118100 +se_io_cb_41461 se_io_cb 3 41461 NULL
118101 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
118102 +snd_pcm_status_41472 snd_pcm_status 0 41472 NULL
118103 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
118104 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
118105 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
118106 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
118107 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
118108 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
118109 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
118110 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
118111 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
118112 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
118113 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
118114 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
118115 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
118116 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
118117 +vga_io_r_41609 vga_io_r 0 41609 NULL
118118 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
118119 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
118120 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
118121 +a2mp_send_41615 a2mp_send 4 41615 NULL
118122 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
118123 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
118124 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
118125 +get_std_timing_41654 get_std_timing 0 41654 NULL
118126 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
118127 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
118128 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
118129 +fillonedir_41746 fillonedir 3 41746 NULL
118130 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
118131 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
118132 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
118133 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
118134 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
118135 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
118136 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
118137 +pci_map_single_41869 pci_map_single 0 41869 NULL
118138 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
118139 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
118140 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
118141 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
118142 +read_gssp_41947 read_gssp 3 41947 NULL
118143 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
118144 +portnames_read_41958 portnames_read 3 41958 NULL
118145 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
118146 +dst_mtu_41969 dst_mtu 0 41969 NULL
118147 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
118148 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
118149 +pool_allocate_42012 pool_allocate 3 42012 NULL
118150 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
118151 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
118152 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
118153 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
118154 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
118155 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
118156 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
118157 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
118158 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
118159 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
118160 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
118161 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
118162 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
118163 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
118164 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
118165 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
118166 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
118167 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
118168 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
118169 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
118170 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118171 +find_last_bit_42260 find_last_bit 0 42260 NULL
118172 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118173 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118174 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118175 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
118176 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118177 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118178 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118179 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118180 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118181 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118182 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118183 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118184 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118185 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118186 +krng_get_random_42420 krng_get_random 3 42420 NULL
118187 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118188 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
118189 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118190 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118191 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118192 +kuc_free_42455 kuc_free 2 42455 NULL
118193 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118194 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118195 +bypass_write_42498 bypass_write 3 42498 NULL
118196 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
118197 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118198 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118199 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118200 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
118201 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118202 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118203 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118204 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118205 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118206 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118207 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118208 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118209 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118210 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118211 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118212 +vb2_read_42703 vb2_read 3 42703 NULL
118213 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118214 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118215 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118216 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118217 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118218 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118219 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118220 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118221 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118222 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118223 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118224 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118225 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118226 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118227 +set_arg_42824 set_arg 3 42824 NULL
118228 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118229 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118230 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118231 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118232 +hd_end_request_42904 hd_end_request 2 42904 NULL
118233 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118234 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118235 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118236 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118237 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2-0 42971 NULL
118238 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118239 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118240 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118241 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118242 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118243 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118244 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118245 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118246 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118247 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118248 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118249 +e1000_request_msix_43134 e1000_request_msix 0 43134 NULL
118250 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118251 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118252 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118253 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118254 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118255 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118256 +uio_write_43202 uio_write 3 43202 NULL
118257 +iso_callback_43208 iso_callback 3 43208 NULL
118258 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118259 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118260 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118261 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118262 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118263 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118264 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118265 +evtchn_write_43278 evtchn_write 3 43278 NULL
118266 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118267 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118268 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118269 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118270 +xenfb_write_43412 xenfb_write 3 43412 NULL
118271 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
118272 +msi_capability_init_43423 msi_capability_init 0 43423 &__alloc_bootmem_low_43423
118273 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118274 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118275 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118276 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
118277 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118278 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
118279 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118280 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118281 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118282 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118283 +read_events_43534 read_events 3 43534 NULL
118284 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118285 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118286 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118287 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118288 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118289 +proc_read_43614 proc_read 3 43614 NULL
118290 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118291 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118292 +random_write_43656 random_write 3 43656 NULL
118293 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118294 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118295 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118296 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118297 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118298 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118299 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118300 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118301 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118302 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118303 +generic_file_direct_write_43770 generic_file_direct_write 0 43770 NULL
118304 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118305 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
118306 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1-0 43806 NULL
118307 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118308 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118309 +read_flush_43851 read_flush 3 43851 NULL
118310 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118311 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
118312 +SendString_43928 SendString 3 43928 NULL
118313 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118314 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118315 +nla_reserve_43984 nla_reserve 3 43984 NULL
118316 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118317 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118318 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992 nohasharray
118319 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &bcm_recvmsg_43992
118320 +ulist_add_43994 ulist_add 0 43994 NULL
118321 +emit_flags_44006 emit_flags 4-3 44006 NULL
118322 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
118323 +fru_strlen_44046 fru_strlen 0 44046 NULL
118324 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
118325 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
118326 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
118327 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
118328 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
118329 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL nohasharray
118330 +file_remove_suid_44122 file_remove_suid 0 44122 &tracing_set_trace_read_44122
118331 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
118332 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
118333 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
118334 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
118335 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
118336 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
118337 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
118338 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
118339 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
118340 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
118341 +device_create_file_44285 device_create_file 0 44285 NULL
118342 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
118343 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
118344 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
118345 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
118346 +rs_init_44327 rs_init 1 44327 NULL
118347 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
118348 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
118349 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
118350 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
118351 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
118352 +strlcpy_44400 strlcpy 3 44400 NULL
118353 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
118354 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
118355 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
118356 +write_file_debug_44476 write_file_debug 3 44476 NULL
118357 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
118358 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
118359 +bio_advance_44496 bio_advance 2 44496 NULL
118360 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
118361 +ac_register_board_44504 ac_register_board 3 44504 NULL
118362 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
118363 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
118364 +spidev_write_44510 spidev_write 3 44510 NULL
118365 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
118366 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
118367 +comm_write_44537 comm_write 3 44537 NULL
118368 +snd_pcm_drop_44542 snd_pcm_drop 0 44542 NULL
118369 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
118370 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
118371 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
118372 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
118373 +mpi_resize_44674 mpi_resize 2 44674 NULL
118374 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
118375 +ts_read_44687 ts_read 3 44687 NULL
118376 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
118377 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
118378 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
118379 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
118380 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
118381 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
118382 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
118383 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
118384 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
118385 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
118386 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
118387 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
118388 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
118389 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
118390 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
118391 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
118392 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
118393 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
118394 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
118395 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
118396 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
118397 +sisusb_write_44834 sisusb_write 3 44834 NULL
118398 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
118399 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
118400 +copydesc_user_44855 copydesc_user 3 44855 NULL
118401 +set_advertising_44870 set_advertising 4 44870 NULL
118402 +init_rs_44873 init_rs 1 44873 NULL
118403 +skb_availroom_44883 skb_availroom 0 44883 NULL
118404 +do_tty_write_44896 do_tty_write 5 44896 NULL
118405 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
118406 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
118407 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
118408 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
118409 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
118410 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
118411 +sel_write_user_45060 sel_write_user 3 45060 NULL
118412 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
118413 +snd_card_new_45104 snd_card_new 5 45104 NULL
118414 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
118415 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
118416 +usbdev_read_45114 usbdev_read 3 45114 NULL
118417 +send_to_tty_45141 send_to_tty 3 45141 NULL
118418 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
118419 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
118420 +device_write_45156 device_write 3 45156 NULL nohasharray
118421 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
118422 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
118423 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
118424 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
118425 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
118426 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
118427 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
118428 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
118429 +event_enable_write_45238 event_enable_write 3 45238 NULL
118430 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
118431 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
118432 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
118433 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
118434 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
118435 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
118436 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
118437 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
118438 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
118439 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
118440 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
118441 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
118442 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
118443 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
118444 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
118445 +snd_pcm_hwsync_45479 snd_pcm_hwsync 0 45479 NULL
118446 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
118447 +copy_macs_45534 copy_macs 4 45534 NULL
118448 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
118449 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
118450 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
118451 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
118452 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
118453 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
118454 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
118455 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
118456 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
118457 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
118458 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
118459 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
118460 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
118461 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
118462 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
118463 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
118464 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
118465 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
118466 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
118467 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
118468 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
118469 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
118470 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
118471 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
118472 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
118473 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
118474 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
118475 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
118476 +insert_state_45848 insert_state 0 45848 NULL
118477 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
118478 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
118479 +isdn_write_45863 isdn_write 3 45863 NULL
118480 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
118481 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
118482 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
118483 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
118484 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
118485 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
118486 +alloc_mr_45935 alloc_mr 1 45935 NULL
118487 +copy_to_45969 copy_to 3 45969 NULL
118488 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
118489 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
118490 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
118491 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
118492 +get_free_entries_46030 get_free_entries 1 46030 NULL nohasharray
118493 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 &get_free_entries_46030
118494 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
118495 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
118496 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
118497 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
118498 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
118499 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
118500 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
118501 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
118502 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
118503 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
118504 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
118505 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
118506 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
118507 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
118508 +fq_resize_46195 fq_resize 2 46195 NULL
118509 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
118510 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
118511 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
118512 +dsp_write_46218 dsp_write 2 46218 NULL
118513 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
118514 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
118515 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
118516 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
118517 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
118518 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
118519 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
118520 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
118521 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
118522 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
118523 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
118524 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
118525 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
118526 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
118527 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
118528 +filldir64_46469 filldir64 3 46469 NULL
118529 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
118530 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
118531 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
118532 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 NULL nohasharray
118533 +kmsg_read_46514 kmsg_read 3 46514 &nouveau_drm_ioctl_46514
118534 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
118535 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
118536 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
118537 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
118538 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
118539 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
118540 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
118541 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
118542 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
118543 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
118544 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
118545 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
118546 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
118547 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
118548 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
118549 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
118550 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
118551 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
118552 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
118553 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
118554 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
118555 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
118556 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
118557 +spi_async_46857 spi_async 0 46857 NULL
118558 +vsnprintf_46863 vsnprintf 0 46863 NULL
118559 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
118560 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
118561 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
118562 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
118563 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
118564 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
118565 +wlcore_alloc_hw_46917 wlcore_alloc_hw 3-1 46917 NULL
118566 +fb_write_46924 fb_write 3 46924 NULL
118567 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
118568 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
118569 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
118570 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
118571 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
118572 +strlcat_46985 strlcat 3 46985 NULL
118573 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
118574 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
118575 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
118576 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
118577 +fs_path_len_47060 fs_path_len 0 47060 NULL
118578 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
118579 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
118580 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
118581 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
118582 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
118583 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
118584 +mousedev_read_47123 mousedev_read 3 47123 NULL
118585 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
118586 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
118587 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
118588 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
118589 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
118590 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
118591 +options_write_47243 options_write 3 47243 NULL
118592 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
118593 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
118594 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
118595 +vsnprintf_47291 vsnprintf 0 47291 NULL
118596 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
118597 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
118598 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
118599 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
118600 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
118601 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
118602 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
118603 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
118604 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
118605 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
118606 +nametbl_list_47391 nametbl_list 2 47391 NULL
118607 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
118608 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
118609 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
118610 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
118611 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
118612 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
118613 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
118614 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
118615 +newpart_47485 newpart 6-4 47485 NULL
118616 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
118617 +core_sys_select_47494 core_sys_select 1 47494 NULL
118618 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
118619 +unlink_simple_47506 unlink_simple 3 47506 NULL
118620 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
118621 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
118622 +snd_pcm_resume_47530 snd_pcm_resume 0 47530 NULL
118623 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
118624 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
118625 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
118626 +rtw_cfg80211_set_assoc_resp_wpsp2pie_47558 rtw_cfg80211_set_assoc_resp_wpsp2pie 3 47558 NULL
118627 +read_ldt_47570 read_ldt 2 47570 NULL
118628 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
118629 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
118630 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
118631 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
118632 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
118633 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
118634 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
118635 +get_size_47644 get_size 1-2 47644 NULL
118636 +snd_pcm_info_47699 snd_pcm_info 0 47699 NULL
118637 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
118638 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
118639 +save_microcode_47717 save_microcode 3 47717 NULL
118640 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
118641 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
118642 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
118643 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
118644 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
118645 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
118646 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
118647 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
118648 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
118649 +lov_packmd_47810 lov_packmd 0 47810 NULL
118650 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
118651 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
118652 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
118653 +vhci_read_47878 vhci_read 3 47878 NULL
118654 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
118655 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
118656 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
118657 +comedi_write_47926 comedi_write 3 47926 NULL
118658 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
118659 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
118660 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
118661 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
118662 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
118663 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
118664 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
118665 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
118666 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
118667 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
118668 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
118669 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
118670 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
118671 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
118672 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
118673 +disc_write_48070 disc_write 3 48070 NULL
118674 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
118675 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
118676 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
118677 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
118678 +set_discoverable_48141 set_discoverable 4 48141 NULL
118679 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
118680 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
118681 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
118682 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
118683 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
118684 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
118685 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
118686 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
118687 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
118688 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
118689 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
118690 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
118691 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
118692 +read_file_recv_48232 read_file_recv 3 48232 NULL
118693 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
118694 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
118695 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
118696 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
118697 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
118698 +trace_options_write_48275 trace_options_write 3 48275 NULL
118699 +send_set_info_48288 send_set_info 7 48288 NULL
118700 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
118701 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
118702 +hash_setkey_48310 hash_setkey 3 48310 NULL
118703 +skb_add_data_48363 skb_add_data 3 48363 NULL
118704 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
118705 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
118706 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
118707 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
118708 +snd_power_wait_48422 snd_power_wait 0 48422 NULL
118709 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
118710 +print_filtered_48442 print_filtered 2-0 48442 NULL
118711 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
118712 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
118713 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
118714 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
118715 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
118716 +send_control_msg_48498 send_control_msg 6 48498 NULL
118717 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
118718 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
118719 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
118720 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
118721 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
118722 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
118723 +llog_data_len_48607 llog_data_len 1 48607 NULL
118724 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
118725 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
118726 +mtd_read_48655 mtd_read 0 48655 NULL
118727 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
118728 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
118729 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
118730 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
118731 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
118732 +altera_drscan_48698 altera_drscan 2 48698 NULL
118733 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
118734 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
118735 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
118736 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
118737 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
118738 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
118739 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
118740 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
118741 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
118742 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
118743 +azx_get_position_48841 azx_get_position 0 48841 NULL
118744 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
118745 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
118746 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
118747 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
118748 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
118749 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
118750 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
118751 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
118752 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
118753 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
118754 +snd_pcm_update_hw_ptr_48925 snd_pcm_update_hw_ptr 0 48925 NULL
118755 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
118756 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
118757 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
118758 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
118759 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
118760 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
118761 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
118762 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
118763 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
118764 +transient_status_49027 transient_status 4 49027 NULL
118765 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
118766 +scsi_register_49094 scsi_register 2 49094 NULL
118767 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
118768 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
118769 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
118770 +pt_read_49136 pt_read 3 49136 NULL nohasharray
118771 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
118772 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
118773 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
118774 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
118775 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
118776 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
118777 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
118778 +print_queue_49191 print_queue 0-4 49191 NULL
118779 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
118780 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
118781 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
118782 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
118783 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
118784 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
118785 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
118786 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
118787 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
118788 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
118789 +uio_read_49300 uio_read 3 49300 NULL
118790 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
118791 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
118792 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
118793 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
118794 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
118795 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
118796 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
118797 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
118798 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
118799 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
118800 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
118801 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
118802 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
118803 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
118804 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
118805 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
118806 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
118807 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
118808 +smk_write_access_49561 smk_write_access 3 49561 NULL
118809 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
118810 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
118811 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
118812 +tap_write_49595 tap_write 3 49595 NULL
118813 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
118814 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
118815 +heap_init_49617 heap_init 2 49617 NULL
118816 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
118817 +port_fops_read_49626 port_fops_read 3 49626 NULL
118818 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
118819 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
118820 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
118821 +__setup_irq_49696 __setup_irq 0 49696 NULL
118822 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
118823 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
118824 +write_pool_49718 write_pool 3 49718 NULL
118825 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
118826 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
118827 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
118828 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
118829 +fuse_wr_pages_49753 fuse_wr_pages 0-2-1 49753 NULL
118830 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
118831 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
118832 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
118833 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
118834 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
118835 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
118836 +add_uuid_49831 add_uuid 4 49831 NULL
118837 +twl4030_write_49846 twl4030_write 2 49846 NULL
118838 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
118839 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
118840 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
118841 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
118842 +osc_brw_49896 osc_brw 4 49896 NULL
118843 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
118844 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
118845 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
118846 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
118847 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
118848 +isdn_read_50021 isdn_read 3 50021 NULL
118849 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
118850 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
118851 +ioread8_50049 ioread8 0 50049 NULL
118852 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
118853 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
118854 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
118855 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
118856 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
118857 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
118858 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
118859 +read_file_slot_50111 read_file_slot 3 50111 NULL
118860 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
118861 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
118862 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
118863 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
118864 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
118865 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
118866 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
118867 +odev_update_50169 odev_update 2 50169 NULL
118868 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
118869 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
118870 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
118871 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
118872 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
118873 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
118874 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
118875 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
118876 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
118877 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
118878 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
118879 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
118880 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
118881 +do_launder_page_50329 do_launder_page 0 50329 NULL
118882 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
118883 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
118884 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
118885 +tpm_read_50344 tpm_read 3 50344 NULL
118886 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
118887 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
118888 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
118889 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
118890 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
118891 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
118892 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
118893 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
118894 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
118895 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
118896 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
118897 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
118898 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
118899 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
118900 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
118901 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
118902 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
118903 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
118904 +fat_readpages_50582 fat_readpages 4 50582 NULL
118905 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
118906 +xillybus_write_50605 xillybus_write 3 50605 NULL
118907 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
118908 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
118909 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
118910 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
118911 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
118912 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
118913 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
118914 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
118915 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
118916 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
118917 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
118918 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
118919 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
118920 +ixgbe_acquire_msix_vectors_50789 ixgbe_acquire_msix_vectors 2 50789 NULL
118921 +tpm_write_50798 tpm_write 3 50798 NULL
118922 +tun_do_read_50800 tun_do_read 4 50800 NULL
118923 +write_flush_50803 write_flush 3 50803 NULL
118924 +dvb_play_50814 dvb_play 3 50814 NULL
118925 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
118926 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
118927 +SetArea_50835 SetArea 4 50835 NULL
118928 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
118929 +self_check_write_50856 self_check_write 0 50856 NULL
118930 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
118931 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
118932 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
118933 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
118934 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
118935 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
118936 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
118937 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
118938 +show_device_status_50947 show_device_status 0 50947 NULL
118939 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
118940 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
118941 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
118942 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
118943 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
118944 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
118945 +timeout_write_50991 timeout_write 3 50991 NULL
118946 +proc_write_51003 proc_write 3 51003 NULL
118947 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
118948 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
118949 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
118950 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
118951 +dump_midi_51040 dump_midi 3 51040 NULL
118952 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
118953 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
118954 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
118955 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
118956 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
118957 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
118958 +ti_recv_51110 ti_recv 3 51110 NULL
118959 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
118960 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
118961 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
118962 +snd_pcm_unlink_51210 snd_pcm_unlink 0 51210 NULL
118963 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
118964 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
118965 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
118966 +drm_property_create_51239 drm_property_create 4 51239 NULL
118967 +st_read_51251 st_read 3 51251 NULL
118968 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
118969 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
118970 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
118971 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
118972 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
118973 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
118974 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
118975 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
118976 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
118977 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
118978 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
118979 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
118980 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
118981 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
118982 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
118983 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
118984 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
118985 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
118986 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
118987 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
118988 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
118989 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
118990 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
118991 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
118992 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
118993 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
118994 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
118995 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
118996 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
118997 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
118998 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
118999 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
119000 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
119001 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
119002 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
119003 +sel_write_access_51704 sel_write_access 3 51704 NULL
119004 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
119005 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
119006 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
119007 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
119008 +cm4040_read_51732 cm4040_read 3 51732 NULL
119009 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
119010 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
119011 +if_write_51756 if_write 3 51756 NULL
119012 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
119013 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
119014 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
119015 +ioread32_51847 ioread32 0 51847 NULL nohasharray
119016 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
119017 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
119018 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
119019 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
119020 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
119021 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
119022 +user_read_51881 user_read 3 51881 NULL
119023 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
119024 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
119025 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
119026 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
119027 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
119028 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
119029 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
119030 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
119031 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
119032 +get_zone_51981 get_zone 0-1 51981 NULL
119033 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
119034 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
119035 +scsi_sysfs_add_host_52010 scsi_sysfs_add_host 0 52010 NULL
119036 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
119037 +rdmalt_52022 rdmalt 0 52022 NULL
119038 +override_release_52032 override_release 2 52032 NULL
119039 +end_port_52042 end_port 0 52042 NULL
119040 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
119041 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
119042 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
119043 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
119044 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
119045 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
119046 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
119047 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
119048 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
119049 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
119050 +retry_count_read_52129 retry_count_read 3 52129 NULL
119051 +snd_pcm_channel_info_user_52135 snd_pcm_channel_info_user 0 52135 NULL
119052 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
119053 +sub_alloc_52140 sub_alloc 0 52140 NULL
119054 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
119055 +htable_size_52148 htable_size 0-1 52148 NULL
119056 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
119057 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
119058 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
119059 +print_prefix_52176 print_prefix 0 52176 NULL
119060 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
119061 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
119062 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
119063 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
119064 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
119065 +shrink_slab_52261 shrink_slab 2 52261 NULL
119066 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
119067 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
119068 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
119069 +read_file_reset_52310 read_file_reset 3 52310 NULL
119070 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
119071 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
119072 +hwflags_read_52318 hwflags_read 3 52318 NULL
119073 +snd_pcm_hw_free_52327 snd_pcm_hw_free 0 52327 NULL
119074 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
119075 +hur_len_52339 hur_len 0 52339 NULL
119076 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
119077 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
119078 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
119079 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
119080 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
119081 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
119082 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
119083 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
119084 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
119085 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
119086 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
119087 +delay_status_52431 delay_status 5 52431 NULL
119088 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
119089 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
119090 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
119091 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
119092 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
119093 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
119094 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
119095 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
119096 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
119097 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
119098 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
119099 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
119100 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
119101 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
119102 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
119103 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
119104 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
119105 +snd_pcm_sw_params_52594 snd_pcm_sw_params 0 52594 NULL
119106 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
119107 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
119108 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
119109 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
119110 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
119111 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
119112 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
119113 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
119114 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
119115 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
119116 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
119117 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
119118 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
119119 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
119120 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
119121 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
119122 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
119123 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
119124 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
119125 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
119126 +twlreg_write_52880 twlreg_write 3 52880 NULL
119127 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
119128 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
119129 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
119130 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
119131 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
119132 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
119133 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
119134 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
119135 +num_node_state_52989 num_node_state 0 52989 NULL
119136 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
119137 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
119138 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119139 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119140 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119141 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119142 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119143 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119144 +vmci_check_host_caps_53087 vmci_check_host_caps 0 53087 NULL
119145 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119146 +verity_status_53120 verity_status 5 53120 NULL
119147 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119148 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL nohasharray
119149 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 &ps_poll_ps_poll_max_ap_turn_read_53140
119150 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119151 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119152 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119153 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119154 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119155 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
119156 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119157 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119158 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119159 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119160 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119161 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119162 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119163 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119164 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119165 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119166 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119167 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119168 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119169 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119170 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119171 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119172 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119173 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119174 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119175 +force_sc_support_write_53512 force_sc_support_write 3 53512 NULL nohasharray
119176 +check_acl_53512 check_acl 0 53512 &force_sc_support_write_53512
119177 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119178 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119179 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119180 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119181 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119182 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119183 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119184 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119185 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119186 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4-0 53682 NULL
119187 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119188 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119189 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119190 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119191 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119192 +wdm_write_53735 wdm_write 3 53735 NULL
119193 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL nohasharray
119194 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 &lpfc_idiag_queacc_read_qe_53755
119195 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119196 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119197 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119198 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119199 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119200 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119201 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119202 +setup_data_read_53822 setup_data_read 3 53822 NULL
119203 +pms_read_53873 pms_read 3 53873 NULL
119204 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119205 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119206 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119207 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
119208 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119209 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119210 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119211 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119212 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119213 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119214 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119215 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119216 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119217 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119218 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119219 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119220 +_malloc_54077 _malloc 1 54077 NULL
119221 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 NULL nohasharray
119222 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 &lustre_posix_acl_xattr_filter_54103
119223 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119224 +strn_len_54122 strn_len 0 54122 NULL
119225 +isku_receive_54130 isku_receive 4 54130 NULL
119226 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119227 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119228 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119229 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119230 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119231 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119232 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119233 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119234 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
119235 +reada_add_block_54247 reada_add_block 2 54247 NULL
119236 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119237 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119238 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119239 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119240 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119241 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119242 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119243 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119244 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119245 +sprintf_54306 sprintf 0 54306 NULL
119246 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119247 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119248 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119249 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119250 +readlink_copy_54366 readlink_copy 2 54366 NULL
119251 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119252 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119253 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119254 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119255 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
119256 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119257 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119258 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119259 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119260 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119261 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119262 +sst_byt_get_dsp_position_54513 sst_byt_get_dsp_position 0-3 54513 NULL
119263 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119264 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119265 +viacam_read_54526 viacam_read 3 54526 NULL
119266 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119267 +setsockopt_54539 setsockopt 5 54539 NULL
119268 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119269 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119270 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119271 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119272 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119273 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119274 +port_fops_write_54627 port_fops_write 3 54627 NULL
119275 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
119276 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119277 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119278 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119279 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119280 +bus_add_device_54665 bus_add_device 0 54665 NULL
119281 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119282 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119283 +evm_read_key_54674 evm_read_key 3 54674 NULL
119284 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119285 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119286 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119287 +kzalloc_54740 kzalloc 1 54740 NULL
119288 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119289 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119290 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
119291 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119292 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119293 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119294 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119295 +nfsd_write_54809 nfsd_write 6 54809 NULL
119296 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119297 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119298 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119299 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119300 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119301 +write_rio_54837 write_rio 3 54837 NULL
119302 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119303 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119304 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119305 +printer_read_54851 printer_read 3 54851 NULL
119306 +assign_irq_vector_54852 assign_irq_vector 0 54852 NULL
119307 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119308 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119309 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119310 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119311 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119312 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119313 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119314 +add_port_54941 add_port 2 54941 NULL
119315 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
119316 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
119317 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
119318 +c4_add_card_54968 c4_add_card 3 54968 NULL
119319 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
119320 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
119321 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
119322 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
119323 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
119324 +snd_pcm_capture_hw_avail_55086 snd_pcm_capture_hw_avail 0 55086 NULL
119325 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
119326 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
119327 +filldir_55137 filldir 3 55137 NULL
119328 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
119329 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
119330 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
119331 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
119332 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
119333 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
119334 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
119335 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
119336 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
119337 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
119338 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
119339 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
119340 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
119341 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
119342 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
119343 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
119344 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
119345 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
119346 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
119347 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
119348 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
119349 +vme_user_read_55338 vme_user_read 3 55338 NULL
119350 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
119351 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
119352 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
119353 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
119354 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
119355 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
119356 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
119357 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
119358 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
119359 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
119360 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
119361 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
119362 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
119363 +ea_get_55522 ea_get 3-0 55522 NULL
119364 +buffer_size_55534 buffer_size 0 55534 NULL
119365 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
119366 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
119367 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
119368 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
119369 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
119370 +add_partition_55588 add_partition 2 55588 NULL
119371 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
119372 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
119373 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
119374 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
119375 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
119376 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
119377 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
119378 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
119379 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
119380 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
119381 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
119382 +get_info_55681 get_info 3 55681 NULL
119383 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
119384 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
119385 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
119386 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
119387 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
119388 +set_local_name_55757 set_local_name 4 55757 NULL
119389 +strlen_55778 strlen 0 55778 NULL nohasharray
119390 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
119391 +set_spte_55783 set_spte 5-4 55783 NULL
119392 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
119393 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
119394 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
119395 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
119396 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
119397 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
119398 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
119399 +hsc_write_55875 hsc_write 3 55875 NULL
119400 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
119401 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
119402 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
119403 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
119404 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
119405 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
119406 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
119407 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
119408 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
119409 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
119410 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
119411 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
119412 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
119413 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
119414 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
119415 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
119416 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
119417 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
119418 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
119419 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
119420 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
119421 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
119422 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
119423 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
119424 +fd_copyin_56247 fd_copyin 3 56247 NULL
119425 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
119426 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
119427 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
119428 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
119429 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
119430 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
119431 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
119432 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
119433 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
119434 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
119435 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
119436 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
119437 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
119438 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
119439 +dev_read_56369 dev_read 3 56369 NULL
119440 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
119441 +snd_pcm_common_ioctl1_56382 snd_pcm_common_ioctl1 0 56382 NULL
119442 +write_gssp_56404 write_gssp 3 56404 NULL
119443 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
119444 +store_msg_56417 store_msg 3 56417 NULL
119445 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
119446 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
119447 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 NULL
119448 +fl_create_56435 fl_create 5 56435 NULL
119449 +gnttab_map_56439 gnttab_map 2 56439 NULL
119450 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
119451 +set_connectable_56458 set_connectable 4 56458 NULL
119452 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
119453 +putused_user_56467 putused_user 3 56467 NULL
119454 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
119455 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
119456 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
119457 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
119458 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
119459 +init_map_ip_56508 init_map_ip 5 56508 NULL
119460 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
119461 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
119462 +ip_options_get_56538 ip_options_get 4 56538 NULL
119463 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
119464 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
119465 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
119466 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
119467 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
119468 +event_filter_write_56609 event_filter_write 3 56609 NULL
119469 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
119470 +gather_array_56641 gather_array 3 56641 NULL
119471 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
119472 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
119473 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
119474 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
119475 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
119476 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
119477 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
119478 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
119479 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
119480 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
119481 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
119482 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
119483 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
119484 +do_syslog_56807 do_syslog 3 56807 NULL
119485 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
119486 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
119487 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
119488 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
119489 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
119490 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
119491 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
119492 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
119493 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
119494 +strcspn_56913 strcspn 0 56913 NULL
119495 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
119496 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
119497 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
119498 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
119499 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
119500 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
119501 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
119502 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
119503 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
119504 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
119505 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
119506 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
119507 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
119508 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
119509 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
119510 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
119511 +altera_get_note_57099 altera_get_note 6 57099 NULL
119512 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
119513 +snd_pcm_hw_params_old_user_57108 snd_pcm_hw_params_old_user 0 57108 NULL
119514 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
119515 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
119516 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
119517 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
119518 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
119519 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
119520 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
119521 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
119522 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
119523 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
119524 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
119525 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
119526 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
119527 +flush_space_57241 flush_space 0 57241 NULL
119528 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
119529 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
119530 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
119531 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
119532 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
119533 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
119534 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
119535 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
119536 +write_file_regval_57313 write_file_regval 3 57313 NULL
119537 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
119538 +usblp_read_57342 usblp_read 3 57342 NULL
119539 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
119540 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
119541 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
119542 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
119543 +read_file_blob_57406 read_file_blob 3 57406 NULL
119544 +enclosure_register_57412 enclosure_register 3 57412 NULL
119545 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
119546 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
119547 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
119548 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
119549 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
119550 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
119551 +skb_headlen_57501 skb_headlen 0 57501 NULL
119552 +copy_in_user_57502 copy_in_user 3 57502 NULL
119553 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
119554 +init_tag_map_57515 init_tag_map 3 57515 NULL
119555 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
119556 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
119557 +cmm_read_57520 cmm_read 3 57520 NULL
119558 +inode_permission_57531 inode_permission 0 57531 NULL
119559 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
119560 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
119561 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
119562 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
119563 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
119564 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
119565 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
119566 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
119567 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
119568 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
119569 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
119570 +mem_read_57631 mem_read 3 57631 NULL
119571 +pci_enable_msi_block_57632 pci_enable_msi_block 0 57632 NULL
119572 +msi_compose_msg_57637 msi_compose_msg 0 57637 NULL
119573 +r3964_write_57662 r3964_write 4 57662 NULL
119574 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
119575 +__lgwrite_57669 __lgwrite 4 57669 NULL
119576 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
119577 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
119578 +vm_find_vqs_57729 vm_find_vqs 0 57729 NULL
119579 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
119580 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
119581 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
119582 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
119583 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
119584 +ld2_57794 ld2 0 57794 NULL
119585 +ivtv_read_57796 ivtv_read 3 57796 NULL
119586 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
119587 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
119588 +copy_to_user_57835 copy_to_user 0-3 57835 NULL
119589 +flash_read_57843 flash_read 3 57843 NULL
119590 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
119591 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
119592 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
119593 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
119594 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
119595 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
119596 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
119597 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
119598 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
119599 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
119600 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
119601 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
119602 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
119603 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
119604 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
119605 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
119606 +mce_async_out_58056 mce_async_out 3 58056 NULL
119607 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
119608 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
119609 +cm4040_write_58079 cm4040_write 3 58079 NULL
119610 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
119611 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
119612 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
119613 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
119614 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
119615 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
119616 +read_file_debug_58256 read_file_debug 3 58256 NULL
119617 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
119618 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
119619 +profile_load_58267 profile_load 3 58267 NULL
119620 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
119621 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
119622 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
119623 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
119624 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
119625 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
119626 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
119627 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
119628 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
119629 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
119630 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 NULL
119631 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
119632 +capabilities_read_58457 capabilities_read 3 58457 NULL
119633 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
119634 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
119635 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
119636 +nv_rd08_58472 nv_rd08 0 58472 NULL
119637 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
119638 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
119639 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
119640 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3-0 58498 NULL
119641 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
119642 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
119643 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
119644 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
119645 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
119646 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
119647 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
119648 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
119649 +xip_file_read_58592 xip_file_read 3 58592 NULL
119650 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
119651 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
119652 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
119653 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
119654 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
119655 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
119656 +find_zero_58685 find_zero 0-1 58685 NULL
119657 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
119658 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
119659 +scsi_setup_command_freelist_58703 scsi_setup_command_freelist 0 58703 NULL
119660 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
119661 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
119662 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
119663 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
119664 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
119665 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
119666 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
119667 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
119668 +ep_read_58813 ep_read 3 58813 NULL
119669 +command_write_58841 command_write 3 58841 NULL
119670 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
119671 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
119672 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
119673 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
119674 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
119675 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
119676 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
119677 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
119678 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
119679 +init_list_set_59005 init_list_set 3 59005 NULL
119680 +ep_write_59008 ep_write 3 59008 NULL
119681 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
119682 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
119683 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
119684 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
119685 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
119686 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL nohasharray
119687 +i8042_enable_kbd_port_59049 i8042_enable_kbd_port 0 59049 &regmap_bulk_write_59049
119688 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
119689 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
119690 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
119691 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
119692 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
119693 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
119694 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
119695 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
119696 +ksize_59176 ksize 0 59176 NULL
119697 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
119698 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
119699 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
119700 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
119701 +dt3155_read_59226 dt3155_read 3 59226 NULL
119702 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
119703 +nla_len_59258 nla_len 0 59258 NULL
119704 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
119705 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
119706 +fd_copyout_59323 fd_copyout 3 59323 NULL
119707 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
119708 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
119709 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
119710 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
119711 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
119712 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
119713 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
119714 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
119715 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
119716 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
119717 +snd_pcm_tstamp_59431 snd_pcm_tstamp 0 59431 NULL
119718 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
119719 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
119720 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
119721 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
119722 +rtw_cfg80211_set_mgnt_wpsp2pie_59497 rtw_cfg80211_set_mgnt_wpsp2pie 3 59497 NULL
119723 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
119724 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
119725 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
119726 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL nohasharray
119727 +idr_alloc_59545 idr_alloc 0 59545 &msix_setup_entries_59545
119728 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
119729 +tunables_write_59563 tunables_write 3 59563 NULL
119730 +bio_split_59564 bio_split 2 59564 NULL
119731 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
119732 +memdup_user_59590 memdup_user 2 59590 NULL
119733 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
119734 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
119735 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
119736 +mtrr_write_59622 mtrr_write 3 59622 NULL
119737 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
119738 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
119739 +file_update_time_59647 file_update_time 0 59647 NULL
119740 +hidraw_read_59650 hidraw_read 3 59650 NULL
119741 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
119742 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
119743 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
119744 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
119745 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
119746 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
119747 +snd_pcm_info_user_59711 snd_pcm_info_user 0 59711 NULL
119748 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
119749 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
119750 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
119751 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
119752 +strnlen_59746 strnlen 0 59746 NULL
119753 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
119754 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
119755 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
119756 +venus_remove_59781 venus_remove 4 59781 NULL
119757 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
119758 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
119759 +ipw_write_59807 ipw_write 3 59807 NULL
119760 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
119761 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
119762 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
119763 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
119764 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
119765 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
119766 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
119767 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
119768 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
119769 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
119770 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
119771 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
119772 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
119773 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
119774 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
119775 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
119776 +copy_items_60009 copy_items 7 60009 NULL
119777 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
119778 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
119779 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
119780 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
119781 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
119782 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
119783 +vcs_size_60050 vcs_size 0 60050 NULL
119784 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
119785 +compat_writev_60063 compat_writev 3 60063 NULL
119786 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
119787 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
119788 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
119789 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
119790 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
119791 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
119792 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
119793 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
119794 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
119795 +init_state_60165 init_state 2 60165 NULL
119796 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
119797 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
119798 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
119799 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 NULL nohasharray
119800 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 &arch_setup_msi_irqs_60193
119801 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
119802 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
119803 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
119804 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
119805 +printer_write_60276 printer_write 3 60276 NULL
119806 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
119807 +getDataLength_60301 getDataLength 0 60301 NULL
119808 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
119809 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
119810 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
119811 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
119812 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
119813 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
119814 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
119815 +driver_names_read_60399 driver_names_read 3 60399 NULL
119816 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
119817 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
119818 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
119819 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
119820 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
119821 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
119822 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
119823 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
119824 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
119825 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
119826 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
119827 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
119828 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
119829 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
119830 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
119831 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
119832 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
119833 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
119834 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
119835 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
119836 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
119837 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
119838 +raid_status_60755 raid_status 5 60755 NULL
119839 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
119840 +opticon_write_60775 opticon_write 4 60775 NULL
119841 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
119842 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
119843 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
119844 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 3-4 60861 NULL
119845 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
119846 +generic_writepages_60871 generic_writepages 0 60871 NULL
119847 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
119848 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
119849 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
119850 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
119851 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
119852 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
119853 +pti_char_write_60960 pti_char_write 3 60960 NULL
119854 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
119855 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
119856 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
119857 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
119858 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
119859 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
119860 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
119861 +symtab_init_61050 symtab_init 2 61050 NULL
119862 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
119863 +snd_pcm_pause_61054 snd_pcm_pause 0 61054 NULL
119864 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
119865 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
119866 +snd_pcm_update_hw_ptr0_61084 snd_pcm_update_hw_ptr0 0 61084 NULL
119867 +get_derived_key_61100 get_derived_key 4 61100 NULL
119868 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
119869 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
119870 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
119871 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
119872 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
119873 +pair_device_61175 pair_device 4 61175 NULL nohasharray
119874 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
119875 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
119876 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
119877 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
119878 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
119879 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
119880 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
119881 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
119882 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
119883 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
119884 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
119885 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
119886 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
119887 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
119888 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
119889 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
119890 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
119891 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
119892 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
119893 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
119894 +system_enable_write_61396 system_enable_write 3 61396 NULL
119895 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
119896 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
119897 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
119898 +erst_errno_61526 erst_errno 0 61526 NULL
119899 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
119900 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
119901 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
119902 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
119903 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
119904 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
119905 +seq_open_private_61589 seq_open_private 3 61589 NULL
119906 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
119907 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
119908 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
119909 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
119910 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
119911 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
119912 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
119913 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
119914 +resize_stripes_61650 resize_stripes 2 61650 NULL
119915 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
119916 +insert_one_name_61668 insert_one_name 7 61668 NULL
119917 +snd_pcm_playback_avail_61671 snd_pcm_playback_avail 0 61671 NULL
119918 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
119919 +lock_loop_61681 lock_loop 1 61681 NULL
119920 +filter_read_61692 filter_read 3 61692 NULL
119921 +iov_length_61716 iov_length 0 61716 NULL
119922 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
119923 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
119924 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
119925 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
119926 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
119927 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
119928 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
119929 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
119930 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
119931 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
119932 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
119933 +get_fw_name_61874 get_fw_name 3 61874 NULL
119934 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
119935 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
119936 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
119937 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
119938 +kernfs_name_61910 kernfs_name 3 61910 NULL
119939 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
119940 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
119941 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
119942 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
119943 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
119944 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
119945 +fix_read_error_61965 fix_read_error 4 61965 NULL
119946 +cow_file_range_61979 cow_file_range 3 61979 NULL
119947 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
119948 +dequeue_event_62000 dequeue_event 3 62000 NULL
119949 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
119950 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
119951 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
119952 +SYSC_select_62024 SYSC_select 1 62024 NULL
119953 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
119954 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
119955 +do_pselect_62061 do_pselect 1 62061 NULL
119956 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
119957 +fat_setattr_62084 fat_setattr 0 62084 NULL
119958 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
119959 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
119960 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
119961 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
119962 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
119963 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
119964 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
119965 +ql_status_62135 ql_status 5 62135 NULL nohasharray
119966 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
119967 +video_usercopy_62151 video_usercopy 2 62151 NULL
119968 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
119969 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
119970 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
119971 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
119972 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
119973 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
119974 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
119975 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
119976 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
119977 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
119978 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
119979 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
119980 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
119981 +subseq_list_62332 subseq_list 3-0 62332 NULL
119982 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
119983 +flash_write_62354 flash_write 3 62354 NULL
119984 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
119985 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
119986 +altera_irscan_62396 altera_irscan 2 62396 NULL
119987 +set_ssp_62411 set_ssp 4 62411 NULL
119988 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
119989 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
119990 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
119991 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
119992 +debugfs_read_62535 debugfs_read 3 62535 NULL
119993 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
119994 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
119995 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
119996 +get_subdir_62581 get_subdir 3 62581 NULL
119997 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
119998 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
119999 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
120000 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
120001 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
120002 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
120003 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
120004 +rdm_62719 rdm 0 62719 NULL
120005 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
120006 +key_replays_read_62746 key_replays_read 3 62746 NULL
120007 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
120008 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
120009 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
120010 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
120011 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
120012 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
120013 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
120014 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
120015 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
120016 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
120017 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
120018 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
120019 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
120020 +aoechr_write_62883 aoechr_write 3 62883 NULL
120021 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
120022 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
120023 +getdqbuf_62908 getdqbuf 1 62908 NULL
120024 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
120025 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
120026 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
120027 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
120028 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
120029 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
120030 +unlink1_63059 unlink1 3 63059 NULL
120031 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
120032 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
120033 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
120034 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
120035 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
120036 +snd_pcm_status_user_63140 snd_pcm_status_user 0 63140 NULL
120037 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
120038 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
120039 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
120040 +vme_master_read_63221 vme_master_read 0 63221 NULL
120041 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
120042 +ptp_read_63251 ptp_read 4 63251 NULL
120043 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
120044 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
120045 +raid5_resize_63306 raid5_resize 2 63306 NULL
120046 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
120047 +proc_info_read_63344 proc_info_read 3 63344 NULL
120048 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
120049 +idmouse_read_63374 idmouse_read 3 63374 NULL
120050 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
120051 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
120052 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
120053 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
120054 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
120055 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
120056 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
120057 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
120058 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
120059 +read_kcore_63488 read_kcore 3 63488 NULL
120060 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
120061 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
120062 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
120063 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
120064 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
120065 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
120066 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
120067 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
120068 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
120069 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
120070 +write_debug_level_63613 write_debug_level 3 63613 NULL
120071 +__spi_validate_63618 __spi_validate 0 63618 NULL
120072 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
120073 +hid_report_len_63637 hid_report_len 0 63637 NULL
120074 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
120075 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
120076 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
120077 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
120078 +vbi_read_63673 vbi_read 3 63673 NULL
120079 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
120080 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
120081 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
120082 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
120083 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
120084 +snd_pcm_link_63772 snd_pcm_link 0 63772 NULL
120085 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
120086 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
120087 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
120088 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
120089 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
120090 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
120091 +sel_write_load_63830 sel_write_load 3 63830 NULL
120092 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
120093 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
120094 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
120095 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
120096 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
120097 +__team_options_register_63941 __team_options_register 3 63941 NULL
120098 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
120099 +set_bredr_63975 set_bredr 4 63975 NULL
120100 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
120101 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
120102 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
120103 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
120104 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
120105 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
120106 +get_u8_64076 get_u8 0 64076 NULL
120107 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
120108 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120109 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120110 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120111 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
120112 +to_bytes_64103 to_bytes 0-1 64103 NULL
120113 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120114 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120115 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120116 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120117 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120118 +init_bch_64130 init_bch 1-2 64130 NULL
120119 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120120 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120121 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
120122 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120123 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120124 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120125 +read_pulse_64227 read_pulse 0-3 64227 NULL
120126 +ea_len_64229 ea_len 0 64229 NULL
120127 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120128 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120129 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120130 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
120131 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120132 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120133 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120134 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120135 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120136 +ts_write_64336 ts_write 3 64336 NULL
120137 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120138 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
120139 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120140 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120141 +reg_create_64372 reg_create 5 64372 NULL nohasharray
120142 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
120143 +ilo_write_64378 ilo_write 3 64378 NULL
120144 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120145 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120146 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120147 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120148 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120149 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120150 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
120151 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120152 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120153 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120154 +__i2c_add_numbered_adapter_64445 __i2c_add_numbered_adapter 0 64445 NULL
120155 +single_open_size_64483 single_open_size 4 64483 NULL
120156 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
120157 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120158 +remove_uuid_64505 remove_uuid 4 64505 NULL
120159 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120160 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120161 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120162 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120163 +SyS_bind_64544 SyS_bind 3 64544 NULL
120164 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
120165 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120166 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
120167 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
120168 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120169 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120170 +do_erase_64574 do_erase 4 64574 NULL
120171 +fanotify_write_64623 fanotify_write 3 64623 NULL
120172 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
120173 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120174 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
120175 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
120176 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120177 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120178 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120179 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120180 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120181 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120182 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120183 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120184 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120185 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120186 +message_for_md_64777 message_for_md 5 64777 NULL
120187 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120188 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120189 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120190 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120191 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120192 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120193 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120194 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120195 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120196 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120197 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120198 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120199 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
120200 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
120201 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120202 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120203 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120204 +insert_dent_65034 insert_dent 7 65034 NULL
120205 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120206 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120207 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120208 +make_idx_node_65068 make_idx_node 0 65068 NULL
120209 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120210 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120211 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120212 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120213 +scsi_add_host_with_dma_65093 scsi_add_host_with_dma 0 65093 NULL
120214 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120215 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120216 +print_endpoint_stat_65232 print_endpoint_stat 0-3-4 65232 NULL
120217 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120218 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120219 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120220 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120221 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120222 +get_var_len_65304 get_var_len 0 65304 NULL
120223 +unpack_array_65318 unpack_array 0 65318 NULL
120224 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120225 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120226 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120227 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120228 +SyS_writev_65372 SyS_writev 3 65372 NULL
120229 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120230 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120231 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120232 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120233 +device_add_groups_65423 device_add_groups 0 65423 NULL
120234 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120235 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120236 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120237 +clear_user_65470 clear_user 2 65470 NULL
120238 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120239 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120240 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120241 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120242 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120243 new file mode 100644
120244 index 0000000..560cd7b
120245 --- /dev/null
120246 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120247 @@ -0,0 +1,92 @@
120248 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120249 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120250 +mappedread_2627 mappedread 2 2627 NULL
120251 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120252 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120253 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120254 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120255 +dmu_write_6048 dmu_write 4-3 6048 NULL
120256 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120257 +update_pages_6225 update_pages 2-3 6225 NULL
120258 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120259 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120260 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120261 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120262 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120263 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120264 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120265 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120266 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120267 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120268 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120269 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120270 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120271 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120272 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120273 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120274 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120275 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120276 +uiocopy_18680 uiocopy 2 18680 NULL
120277 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120278 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120279 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120280 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120281 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120282 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120283 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120284 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120285 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120286 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120287 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120288 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120289 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120290 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120291 +splat_write_30943 splat_write 3 30943 NULL
120292 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120293 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120294 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120295 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120296 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120297 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120298 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120299 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120300 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120301 +copyinstr_36980 copyinstr 3 36980 NULL
120302 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120303 +splat_read_38116 splat_read 3 38116 NULL
120304 +sa_setup_38756 sa_setup 4 38756 NULL
120305 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120306 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120307 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120308 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120309 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120310 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120311 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120312 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120313 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120314 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
120315 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
120316 +kcopy_write_43683 kcopy_write 3 43683 NULL
120317 +uiomove_44355 uiomove 2 44355 NULL
120318 +dmu_read_44418 dmu_read 4-3 44418 NULL
120319 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
120320 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
120321 +copyin_45945 copyin 3 45945 NULL
120322 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
120323 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
120324 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
120325 +spa_history_write_49650 spa_history_write 3 49650 NULL
120326 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
120327 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
120328 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
120329 +copyout_51409 copyout 3 51409 NULL
120330 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
120331 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
120332 +get_nvlist_56685 get_nvlist 2 56685 NULL
120333 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
120334 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
120335 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
120336 +zpios_write_61823 zpios_write 3 61823 NULL
120337 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
120338 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
120339 +zpios_read_64734 zpios_read 3 64734 NULL
120340 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120341 new file mode 100644
120342 index 0000000..e6fe17b
120343 --- /dev/null
120344 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120345 @@ -0,0 +1,259 @@
120346 +/*
120347 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120348 + * Licensed under the GPL v2, or (at your option) v3
120349 + *
120350 + * Homepage:
120351 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120352 + *
120353 + * Documentation:
120354 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120355 + *
120356 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120357 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120358 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120359 + *
120360 + * Usage:
120361 + * $ make
120362 + * $ make run
120363 + */
120364 +
120365 +#include "gcc-common.h"
120366 +#include "size_overflow.h"
120367 +
120368 +int plugin_is_GPL_compatible;
120369 +
120370 +tree report_size_overflow_decl;
120371 +
120372 +tree size_overflow_type_HI;
120373 +tree size_overflow_type_SI;
120374 +tree size_overflow_type_DI;
120375 +tree size_overflow_type_TI;
120376 +
120377 +static struct plugin_info size_overflow_plugin_info = {
120378 + .version = "20140517",
120379 + .help = "no-size-overflow\tturn off size overflow checking\n",
120380 +};
120381 +
120382 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120383 +{
120384 + unsigned int arg_count;
120385 + enum tree_code code = TREE_CODE(*node);
120386 +
120387 + switch (code) {
120388 + case FUNCTION_DECL:
120389 + arg_count = type_num_arguments(TREE_TYPE(*node));
120390 + break;
120391 + case FUNCTION_TYPE:
120392 + case METHOD_TYPE:
120393 + arg_count = type_num_arguments(*node);
120394 + break;
120395 + default:
120396 + *no_add_attrs = true;
120397 + error("%s: %qE attribute only applies to functions", __func__, name);
120398 + return NULL_TREE;
120399 + }
120400 +
120401 + for (; args; args = TREE_CHAIN(args)) {
120402 + tree position = TREE_VALUE(args);
120403 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120404 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120405 + *no_add_attrs = true;
120406 + }
120407 + }
120408 + return NULL_TREE;
120409 +}
120410 +
120411 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120412 +{
120413 + unsigned int arg_count;
120414 + enum tree_code code = TREE_CODE(*node);
120415 +
120416 + switch (code) {
120417 + case FUNCTION_DECL:
120418 + arg_count = type_num_arguments(TREE_TYPE(*node));
120419 + break;
120420 + case FUNCTION_TYPE:
120421 + case METHOD_TYPE:
120422 + arg_count = type_num_arguments(*node);
120423 + break;
120424 + case FIELD_DECL:
120425 + return NULL_TREE;
120426 + default:
120427 + *no_add_attrs = true;
120428 + error("%qE attribute only applies to functions", name);
120429 + return NULL_TREE;
120430 + }
120431 +
120432 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
120433 + return NULL_TREE;
120434 +
120435 + for (; args; args = TREE_CHAIN(args)) {
120436 + tree position = TREE_VALUE(args);
120437 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120438 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120439 + *no_add_attrs = true;
120440 + }
120441 + }
120442 + return NULL_TREE;
120443 +}
120444 +
120445 +static struct attribute_spec size_overflow_attr = {
120446 + .name = "size_overflow",
120447 + .min_length = 1,
120448 + .max_length = -1,
120449 + .decl_required = true,
120450 + .type_required = false,
120451 + .function_type_required = false,
120452 + .handler = handle_size_overflow_attribute,
120453 +#if BUILDING_GCC_VERSION >= 4007
120454 + .affects_type_identity = false
120455 +#endif
120456 +};
120457 +
120458 +static struct attribute_spec intentional_overflow_attr = {
120459 + .name = "intentional_overflow",
120460 + .min_length = 1,
120461 + .max_length = -1,
120462 + .decl_required = true,
120463 + .type_required = false,
120464 + .function_type_required = false,
120465 + .handler = handle_intentional_overflow_attribute,
120466 +#if BUILDING_GCC_VERSION >= 4007
120467 + .affects_type_identity = false
120468 +#endif
120469 +};
120470 +
120471 +static void register_attributes(void __unused *event_data, void __unused *data)
120472 +{
120473 + register_attribute(&size_overflow_attr);
120474 + register_attribute(&intentional_overflow_attr);
120475 +}
120476 +
120477 +static tree create_typedef(tree type, const char* ident)
120478 +{
120479 + tree new_type, decl;
120480 +
120481 + new_type = build_variant_type_copy(type);
120482 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
120483 + DECL_ORIGINAL_TYPE(decl) = type;
120484 + TYPE_NAME(new_type) = decl;
120485 + return new_type;
120486 +}
120487 +
120488 +// Create the noreturn report_size_overflow() function decl.
120489 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
120490 +{
120491 + tree const_char_ptr_type_node;
120492 + tree fntype;
120493 +
120494 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
120495 +
120496 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
120497 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
120498 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
120499 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
120500 +
120501 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
120502 + fntype = build_function_type_list(void_type_node,
120503 + const_char_ptr_type_node,
120504 + unsigned_type_node,
120505 + const_char_ptr_type_node,
120506 + const_char_ptr_type_node,
120507 + NULL_TREE);
120508 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
120509 +
120510 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
120511 + TREE_PUBLIC(report_size_overflow_decl) = 1;
120512 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
120513 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
120514 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
120515 +}
120516 +
120517 +
120518 +extern struct gimple_opt_pass pass_dce;
120519 +
120520 +static struct opt_pass *make_dce_pass(void)
120521 +{
120522 +#if BUILDING_GCC_VERSION >= 4009
120523 + return make_pass_dce(g);
120524 +#else
120525 + return &pass_dce.pass;
120526 +#endif
120527 +}
120528 +
120529 +
120530 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
120531 +{
120532 + int i;
120533 + const char * const plugin_name = plugin_info->base_name;
120534 + const int argc = plugin_info->argc;
120535 + const struct plugin_argument * const argv = plugin_info->argv;
120536 + bool enable = true;
120537 + struct register_pass_info insert_size_overflow_asm_pass_info;
120538 + struct register_pass_info __unused dump_before_pass_info;
120539 + struct register_pass_info __unused dump_after_pass_info;
120540 + struct register_pass_info insert_size_overflow_check_info;
120541 + struct register_pass_info dce_pass_info;
120542 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
120543 + {
120544 + .base = &report_size_overflow_decl,
120545 + .nelt = 1,
120546 + .stride = sizeof(report_size_overflow_decl),
120547 + .cb = &gt_ggc_mx_tree_node,
120548 + .pchw = &gt_pch_nx_tree_node
120549 + },
120550 + LAST_GGC_ROOT_TAB
120551 + };
120552 +
120553 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
120554 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
120555 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
120556 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120557 +
120558 + dump_before_pass_info.pass = make_dump_pass();
120559 + dump_before_pass_info.reference_pass_name = "increase_alignment";
120560 + dump_before_pass_info.ref_pass_instance_number = 1;
120561 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120562 +
120563 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
120564 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
120565 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
120566 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
120567 +
120568 + dump_after_pass_info.pass = make_dump_pass();
120569 + dump_after_pass_info.reference_pass_name = "increase_alignment";
120570 + dump_after_pass_info.ref_pass_instance_number = 1;
120571 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120572 +
120573 + dce_pass_info.pass = make_dce_pass();
120574 + dce_pass_info.reference_pass_name = "vrp";
120575 + dce_pass_info.ref_pass_instance_number = 1;
120576 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120577 +
120578 + if (!plugin_default_version_check(version, &gcc_version)) {
120579 + error(G_("incompatible gcc/plugin versions"));
120580 + return 1;
120581 + }
120582 +
120583 + for (i = 0; i < argc; ++i) {
120584 + if (!strcmp(argv[i].key, "no-size-overflow")) {
120585 + enable = false;
120586 + continue;
120587 + }
120588 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
120589 + }
120590 +
120591 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
120592 + if (enable) {
120593 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
120594 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
120595 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
120596 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
120597 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
120598 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
120599 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
120600 + }
120601 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
120602 +
120603 + return 0;
120604 +}
120605 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120606 new file mode 100644
120607 index 0000000..0888f6c
120608 --- /dev/null
120609 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120610 @@ -0,0 +1,364 @@
120611 +/*
120612 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120613 + * Licensed under the GPL v2, or (at your option) v3
120614 + *
120615 + * Homepage:
120616 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120617 + *
120618 + * Documentation:
120619 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120620 + *
120621 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120622 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120623 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120624 + *
120625 + * Usage:
120626 + * $ make
120627 + * $ make run
120628 + */
120629 +
120630 +#include "gcc-common.h"
120631 +#include "size_overflow.h"
120632 +
120633 +#include "size_overflow_hash.h"
120634 +#include "size_overflow_hash_aux.h"
120635 +
120636 +#define CODES_LIMIT 32
120637 +
120638 +static unsigned char get_tree_code(const_tree type)
120639 +{
120640 + switch (TREE_CODE(type)) {
120641 + case ARRAY_TYPE:
120642 + return 0;
120643 + case BOOLEAN_TYPE:
120644 + return 1;
120645 + case ENUMERAL_TYPE:
120646 + return 2;
120647 + case FUNCTION_TYPE:
120648 + return 3;
120649 + case INTEGER_TYPE:
120650 + return 4;
120651 + case POINTER_TYPE:
120652 + return 5;
120653 + case RECORD_TYPE:
120654 + return 6;
120655 + case UNION_TYPE:
120656 + return 7;
120657 + case VOID_TYPE:
120658 + return 8;
120659 + case REAL_TYPE:
120660 + return 9;
120661 + case VECTOR_TYPE:
120662 + return 10;
120663 + case REFERENCE_TYPE:
120664 + return 11;
120665 + case OFFSET_TYPE:
120666 + return 12;
120667 + case COMPLEX_TYPE:
120668 + return 13;
120669 + default:
120670 + debug_tree((tree)type);
120671 + gcc_unreachable();
120672 + }
120673 +}
120674 +
120675 +struct function_hash {
120676 + size_t tree_codes_len;
120677 + unsigned char tree_codes[CODES_LIMIT];
120678 + const_tree fndecl;
120679 + unsigned int hash;
120680 +};
120681 +
120682 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
120683 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
120684 +{
120685 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
120686 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
120687 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
120688 +
120689 + unsigned int m = 0x57559429;
120690 + unsigned int n = 0x5052acdb;
120691 + const unsigned int *key4 = (const unsigned int *)key;
120692 + unsigned int h = len;
120693 + unsigned int k = len + seed + n;
120694 + unsigned long long p;
120695 +
120696 + while (len >= 8) {
120697 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
120698 + len -= 8;
120699 + }
120700 + if (len >= 4) {
120701 + cwmixb(key4[0]) key4 += 1;
120702 + len -= 4;
120703 + }
120704 + if (len)
120705 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
120706 + cwmixb(h ^ (k + n));
120707 + return k ^ h;
120708 +
120709 +#undef cwfold
120710 +#undef cwmixa
120711 +#undef cwmixb
120712 +}
120713 +
120714 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
120715 +{
120716 + unsigned int fn, codes, seed = 0;
120717 +
120718 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
120719 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
120720 +
120721 + fn_hash_data->hash = fn ^ codes;
120722 +}
120723 +
120724 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
120725 +{
120726 + gcc_assert(type != NULL_TREE);
120727 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
120728 +
120729 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
120730 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
120731 + fn_hash_data->tree_codes_len++;
120732 + type = TREE_TYPE(type);
120733 + }
120734 +}
120735 +
120736 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
120737 +{
120738 + const_tree result;
120739 +
120740 + gcc_assert(node != NULL_TREE);
120741 +
120742 + if (DECL_P(node)) {
120743 + result = DECL_RESULT(node);
120744 + if (result != NULL_TREE)
120745 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
120746 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120747 + }
120748 +
120749 + gcc_assert(TYPE_P(node));
120750 +
120751 + if (TREE_CODE(node) == FUNCTION_TYPE)
120752 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120753 +
120754 + return set_node_codes(node, fn_hash_data);
120755 +}
120756 +
120757 +static void set_function_codes(struct function_hash *fn_hash_data)
120758 +{
120759 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
120760 + enum tree_code code = TREE_CODE(type);
120761 +
120762 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
120763 +
120764 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
120765 +
120766 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
120767 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
120768 +}
120769 +
120770 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
120771 +{
120772 + while (entry) {
120773 + if (!strcmp(entry->name, func_name))
120774 + return entry;
120775 + entry = entry->next;
120776 + }
120777 + return NULL;
120778 +}
120779 +
120780 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
120781 +{
120782 + const struct size_overflow_hash *entry;
120783 + struct function_hash fn_hash_data;
120784 + const char *func_name;
120785 +
120786 + // skip builtins __builtin_constant_p
120787 + if (DECL_BUILT_IN(fndecl))
120788 + return NULL;
120789 +
120790 + fn_hash_data.fndecl = fndecl;
120791 + fn_hash_data.tree_codes_len = 0;
120792 +
120793 + set_function_codes(&fn_hash_data);
120794 + gcc_assert(fn_hash_data.tree_codes_len != 0);
120795 +
120796 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
120797 + set_hash(func_name, &fn_hash_data);
120798 +
120799 + entry = size_overflow_hash[fn_hash_data.hash];
120800 + entry = get_proper_hash_chain(entry, func_name);
120801 + if (entry)
120802 + return entry;
120803 + entry = size_overflow_hash_aux[fn_hash_data.hash];
120804 + return get_proper_hash_chain(entry, func_name);
120805 +}
120806 +
120807 +static void print_missing_msg(const_tree func, unsigned int argnum)
120808 +{
120809 + location_t loc;
120810 + const char *curfunc;
120811 + struct function_hash fn_hash_data;
120812 +
120813 + fn_hash_data.fndecl = DECL_ORIGIN(func);
120814 + fn_hash_data.tree_codes_len = 0;
120815 +
120816 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
120817 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
120818 +
120819 + set_function_codes(&fn_hash_data);
120820 + set_hash(curfunc, &fn_hash_data);
120821 +
120822 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
120823 +}
120824 +
120825 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
120826 +{
120827 + tree var;
120828 + unsigned int argnum = 1;
120829 +
120830 + if (TREE_CODE(arg) == SSA_NAME)
120831 + arg = SSA_NAME_VAR(arg);
120832 +
120833 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
120834 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
120835 + continue;
120836 + if (!skip_types(var))
120837 + return argnum;
120838 + }
120839 +
120840 + return CANNOT_FIND_ARG;
120841 +}
120842 +
120843 +static const char *get_asm_string(const_gimple stmt)
120844 +{
120845 + if (!stmt)
120846 + return NULL;
120847 + if (gimple_code(stmt) != GIMPLE_ASM)
120848 + return NULL;
120849 +
120850 + return gimple_asm_string(stmt);
120851 +}
120852 +
120853 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
120854 +{
120855 + const char *str;
120856 +
120857 + str = get_asm_string(stmt);
120858 + if (!str)
120859 + return false;
120860 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
120861 +}
120862 +
120863 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
120864 +{
120865 + const char *str;
120866 +
120867 + str = get_asm_string(stmt);
120868 + if (!str)
120869 + return false;
120870 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
120871 +}
120872 +
120873 +bool is_size_overflow_asm(const_gimple stmt)
120874 +{
120875 + const char *str;
120876 +
120877 + str = get_asm_string(stmt);
120878 + if (!str)
120879 + return false;
120880 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
120881 +}
120882 +
120883 +bool is_a_return_check(const_tree node)
120884 +{
120885 + if (TREE_CODE(node) == FUNCTION_DECL)
120886 + return true;
120887 +
120888 + gcc_assert(TREE_CODE(node) == PARM_DECL);
120889 + return false;
120890 +}
120891 +
120892 +// Get the argnum of a function decl, if node is a return then the argnum is 0
120893 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
120894 +{
120895 + if (is_a_return_check(node))
120896 + return 0;
120897 + else
120898 + return find_arg_number_tree(node, orig_fndecl);
120899 +}
120900 +
120901 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
120902 +{
120903 + const struct size_overflow_hash *hash;
120904 + unsigned int new_argnum;
120905 + tree arg;
120906 + const_tree origarg;
120907 +
120908 + if (argnum == 0)
120909 + return argnum;
120910 +
120911 + hash = get_function_hash(fndecl);
120912 + if (hash && hash->param & (1U << argnum))
120913 + return argnum;
120914 +
120915 + if (DECL_EXTERNAL(fndecl))
120916 + return argnum;
120917 +
120918 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
120919 + argnum--;
120920 + while (origarg && argnum) {
120921 + origarg = TREE_CHAIN(origarg);
120922 + argnum--;
120923 + }
120924 + gcc_assert(argnum == 0);
120925 + gcc_assert(origarg != NULL_TREE);
120926 +
120927 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
120928 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
120929 + return new_argnum;
120930 +
120931 + return CANNOT_FIND_ARG;
120932 +}
120933 +
120934 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
120935 +{
120936 + const struct size_overflow_hash *hash;
120937 +
120938 + hash = get_function_hash(fndecl);
120939 + if (hash && (hash->param & (1U << num)))
120940 + return true;
120941 + return false;
120942 +}
120943 +
120944 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
120945 + * If the function is missing everywhere then print the missing message into stderr.
120946 + */
120947 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
120948 +{
120949 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
120950 +#if BUILDING_GCC_VERSION >= 4008
120951 + case BUILT_IN_BSWAP16:
120952 +#endif
120953 + case BUILT_IN_BSWAP32:
120954 + case BUILT_IN_BSWAP64:
120955 + case BUILT_IN_EXPECT:
120956 + case BUILT_IN_MEMCMP:
120957 + return false;
120958 + default:
120959 + break;
120960 + }
120961 +
120962 + // skip test.c
120963 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
120964 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
120965 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
120966 + }
120967 +
120968 + if (is_in_hash_table(orig_fndecl, num))
120969 + return false;
120970 +
120971 + print_missing_msg(orig_fndecl, num);
120972 + return true;
120973 +}
120974 +
120975 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
120976 new file mode 100644
120977 index 0000000..dd94983
120978 --- /dev/null
120979 +++ b/tools/gcc/stackleak_plugin.c
120980 @@ -0,0 +1,376 @@
120981 +/*
120982 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
120983 + * Licensed under the GPL v2
120984 + *
120985 + * Note: the choice of the license means that the compilation process is
120986 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
120987 + * but for the kernel it doesn't matter since it doesn't link against
120988 + * any of the gcc libraries
120989 + *
120990 + * gcc plugin to help implement various PaX features
120991 + *
120992 + * - track lowest stack pointer
120993 + *
120994 + * TODO:
120995 + * - initialize all local variables
120996 + *
120997 + * BUGS:
120998 + * - none known
120999 + */
121000 +
121001 +#include "gcc-common.h"
121002 +
121003 +int plugin_is_GPL_compatible;
121004 +
121005 +static int track_frame_size = -1;
121006 +static const char track_function[] = "pax_track_stack";
121007 +static const char check_function[] = "pax_check_alloca";
121008 +static tree track_function_decl, check_function_decl;
121009 +static bool init_locals;
121010 +
121011 +static struct plugin_info stackleak_plugin_info = {
121012 + .version = "201402131920",
121013 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
121014 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
121015 +};
121016 +
121017 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
121018 +{
121019 + gimple check_alloca;
121020 + tree alloca_size;
121021 +
121022 + // insert call to void pax_check_alloca(unsigned long size)
121023 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
121024 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
121025 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
121026 +}
121027 +
121028 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
121029 +{
121030 + gimple track_stack;
121031 +
121032 + // insert call to void pax_track_stack(void)
121033 + track_stack = gimple_build_call(track_function_decl, 0);
121034 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
121035 +}
121036 +
121037 +static bool is_alloca(gimple stmt)
121038 +{
121039 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
121040 + return true;
121041 +
121042 +#if BUILDING_GCC_VERSION >= 4007
121043 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
121044 + return true;
121045 +#endif
121046 +
121047 + return false;
121048 +}
121049 +
121050 +static unsigned int execute_stackleak_tree_instrument(void)
121051 +{
121052 + basic_block bb, entry_bb;
121053 + bool prologue_instrumented = false, is_leaf = true;
121054 +
121055 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
121056 +
121057 + // 1. loop through BBs and GIMPLE statements
121058 + FOR_EACH_BB_FN(bb, cfun) {
121059 + gimple_stmt_iterator gsi;
121060 +
121061 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121062 + gimple stmt;
121063 +
121064 + stmt = gsi_stmt(gsi);
121065 +
121066 + if (is_gimple_call(stmt))
121067 + is_leaf = false;
121068 +
121069 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
121070 + if (!is_alloca(stmt))
121071 + continue;
121072 +
121073 + // 2. insert stack overflow check before each __builtin_alloca call
121074 + stackleak_check_alloca(&gsi);
121075 +
121076 + // 3. insert track call after each __builtin_alloca call
121077 + stackleak_add_instrumentation(&gsi);
121078 + if (bb == entry_bb)
121079 + prologue_instrumented = true;
121080 + }
121081 + }
121082 +
121083 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
121084 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
121085 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
121086 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
121087 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
121088 + return 0;
121089 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
121090 + return 0;
121091 +
121092 + // 4. insert track call at the beginning
121093 + if (!prologue_instrumented) {
121094 + gimple_stmt_iterator gsi;
121095 +
121096 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121097 + if (dom_info_available_p(CDI_DOMINATORS))
121098 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121099 + gsi = gsi_start_bb(bb);
121100 + stackleak_add_instrumentation(&gsi);
121101 + }
121102 +
121103 + return 0;
121104 +}
121105 +
121106 +static unsigned int execute_stackleak_final(void)
121107 +{
121108 + rtx insn, next;
121109 +
121110 + if (cfun->calls_alloca)
121111 + return 0;
121112 +
121113 + // keep calls only if function frame is big enough
121114 + if (get_frame_size() >= track_frame_size)
121115 + return 0;
121116 +
121117 + // 1. find pax_track_stack calls
121118 + for (insn = get_insns(); insn; insn = next) {
121119 + // 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))
121120 + rtx body;
121121 +
121122 + next = NEXT_INSN(insn);
121123 + if (!CALL_P(insn))
121124 + continue;
121125 + body = PATTERN(insn);
121126 + if (GET_CODE(body) != CALL)
121127 + continue;
121128 + body = XEXP(body, 0);
121129 + if (GET_CODE(body) != MEM)
121130 + continue;
121131 + body = XEXP(body, 0);
121132 + if (GET_CODE(body) != SYMBOL_REF)
121133 + continue;
121134 +// if (strcmp(XSTR(body, 0), track_function))
121135 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121136 + continue;
121137 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121138 + // 2. delete call
121139 + delete_insn_and_edges(insn);
121140 +#if BUILDING_GCC_VERSION >= 4007
121141 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121142 + insn = next;
121143 + next = NEXT_INSN(insn);
121144 + delete_insn_and_edges(insn);
121145 + }
121146 +#endif
121147 + }
121148 +
121149 +// print_simple_rtl(stderr, get_insns());
121150 +// print_rtl(stderr, get_insns());
121151 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121152 +
121153 + return 0;
121154 +}
121155 +
121156 +static bool gate_stackleak_track_stack(void)
121157 +{
121158 + return track_frame_size >= 0;
121159 +}
121160 +
121161 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121162 +{
121163 + tree fntype;
121164 +
121165 + // void pax_track_stack(void)
121166 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121167 + track_function_decl = build_fn_decl(track_function, fntype);
121168 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121169 + TREE_PUBLIC(track_function_decl) = 1;
121170 + DECL_EXTERNAL(track_function_decl) = 1;
121171 + DECL_ARTIFICIAL(track_function_decl) = 1;
121172 +
121173 + // void pax_check_alloca(unsigned long)
121174 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121175 + check_function_decl = build_fn_decl(check_function, fntype);
121176 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121177 + TREE_PUBLIC(check_function_decl) = 1;
121178 + DECL_EXTERNAL(check_function_decl) = 1;
121179 + DECL_ARTIFICIAL(check_function_decl) = 1;
121180 +}
121181 +
121182 +#if BUILDING_GCC_VERSION >= 4009
121183 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121184 +#else
121185 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121186 + .pass = {
121187 +#endif
121188 + .type = GIMPLE_PASS,
121189 + .name = "stackleak_tree_instrument",
121190 +#if BUILDING_GCC_VERSION >= 4008
121191 + .optinfo_flags = OPTGROUP_NONE,
121192 +#endif
121193 +#if BUILDING_GCC_VERSION >= 4009
121194 + .has_gate = true,
121195 + .has_execute = true,
121196 +#else
121197 + .gate = gate_stackleak_track_stack,
121198 + .execute = execute_stackleak_tree_instrument,
121199 + .sub = NULL,
121200 + .next = NULL,
121201 + .static_pass_number = 0,
121202 +#endif
121203 + .tv_id = TV_NONE,
121204 + .properties_required = PROP_gimple_leh | PROP_cfg,
121205 + .properties_provided = 0,
121206 + .properties_destroyed = 0,
121207 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121208 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121209 +#if BUILDING_GCC_VERSION < 4009
121210 + }
121211 +#endif
121212 +};
121213 +
121214 +#if BUILDING_GCC_VERSION >= 4009
121215 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121216 +#else
121217 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121218 + .pass = {
121219 +#endif
121220 + .type = RTL_PASS,
121221 + .name = "stackleak_final",
121222 +#if BUILDING_GCC_VERSION >= 4008
121223 + .optinfo_flags = OPTGROUP_NONE,
121224 +#endif
121225 +#if BUILDING_GCC_VERSION >= 4009
121226 + .has_gate = true,
121227 + .has_execute = true,
121228 +#else
121229 + .gate = gate_stackleak_track_stack,
121230 + .execute = execute_stackleak_final,
121231 + .sub = NULL,
121232 + .next = NULL,
121233 + .static_pass_number = 0,
121234 +#endif
121235 + .tv_id = TV_NONE,
121236 + .properties_required = 0,
121237 + .properties_provided = 0,
121238 + .properties_destroyed = 0,
121239 + .todo_flags_start = 0,
121240 + .todo_flags_finish = TODO_dump_func
121241 +#if BUILDING_GCC_VERSION < 4009
121242 + }
121243 +#endif
121244 +};
121245 +
121246 +#if BUILDING_GCC_VERSION >= 4009
121247 +namespace {
121248 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121249 +public:
121250 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121251 + bool gate() { return gate_stackleak_track_stack(); }
121252 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121253 +};
121254 +
121255 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121256 +public:
121257 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121258 + bool gate() { return gate_stackleak_track_stack(); }
121259 + unsigned int execute() { return execute_stackleak_final(); }
121260 +};
121261 +}
121262 +
121263 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121264 +{
121265 + return new stackleak_tree_instrument_pass();
121266 +}
121267 +
121268 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121269 +{
121270 + return new stackleak_final_rtl_opt_pass();
121271 +}
121272 +#else
121273 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121274 +{
121275 + return &stackleak_tree_instrument_pass.pass;
121276 +}
121277 +
121278 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121279 +{
121280 + return &stackleak_final_rtl_opt_pass.pass;
121281 +}
121282 +#endif
121283 +
121284 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121285 +{
121286 + const char * const plugin_name = plugin_info->base_name;
121287 + const int argc = plugin_info->argc;
121288 + const struct plugin_argument * const argv = plugin_info->argv;
121289 + int i;
121290 + struct register_pass_info stackleak_tree_instrument_pass_info;
121291 + struct register_pass_info stackleak_final_pass_info;
121292 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121293 + {
121294 + .base = &track_function_decl,
121295 + .nelt = 1,
121296 + .stride = sizeof(track_function_decl),
121297 + .cb = &gt_ggc_mx_tree_node,
121298 + .pchw = &gt_pch_nx_tree_node
121299 + },
121300 + {
121301 + .base = &check_function_decl,
121302 + .nelt = 1,
121303 + .stride = sizeof(check_function_decl),
121304 + .cb = &gt_ggc_mx_tree_node,
121305 + .pchw = &gt_pch_nx_tree_node
121306 + },
121307 + LAST_GGC_ROOT_TAB
121308 + };
121309 +
121310 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
121311 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
121312 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
121313 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
121314 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121315 +
121316 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
121317 + stackleak_final_pass_info.reference_pass_name = "final";
121318 + stackleak_final_pass_info.ref_pass_instance_number = 1;
121319 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121320 +
121321 + if (!plugin_default_version_check(version, &gcc_version)) {
121322 + error(G_("incompatible gcc/plugin versions"));
121323 + return 1;
121324 + }
121325 +
121326 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
121327 +
121328 + for (i = 0; i < argc; ++i) {
121329 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
121330 + if (!argv[i].value) {
121331 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121332 + continue;
121333 + }
121334 + track_frame_size = atoi(argv[i].value);
121335 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
121336 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121337 + continue;
121338 + }
121339 + if (!strcmp(argv[i].key, "initialize-locals")) {
121340 + if (argv[i].value) {
121341 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121342 + continue;
121343 + }
121344 + init_locals = true;
121345 + continue;
121346 + }
121347 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121348 + }
121349 +
121350 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
121351 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
121352 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
121353 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
121354 +
121355 + return 0;
121356 +}
121357 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
121358 new file mode 100644
121359 index 0000000..4ee2231
121360 --- /dev/null
121361 +++ b/tools/gcc/structleak_plugin.c
121362 @@ -0,0 +1,274 @@
121363 +/*
121364 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
121365 + * Licensed under the GPL v2
121366 + *
121367 + * Note: the choice of the license means that the compilation process is
121368 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121369 + * but for the kernel it doesn't matter since it doesn't link against
121370 + * any of the gcc libraries
121371 + *
121372 + * gcc plugin to forcibly initialize certain local variables that could
121373 + * otherwise leak kernel stack to userland if they aren't properly initialized
121374 + * by later code
121375 + *
121376 + * Homepage: http://pax.grsecurity.net/
121377 + *
121378 + * Usage:
121379 + * $ # for 4.5/4.6/C based 4.7
121380 + * $ 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
121381 + * $ # for C++ based 4.7/4.8+
121382 + * $ 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
121383 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
121384 + *
121385 + * TODO: eliminate redundant initializers
121386 + * increase type coverage
121387 + */
121388 +
121389 +#include "gcc-common.h"
121390 +
121391 +// unused C type flag in all versions 4.5-4.9
121392 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
121393 +
121394 +int plugin_is_GPL_compatible;
121395 +
121396 +static struct plugin_info structleak_plugin_info = {
121397 + .version = "201401260140",
121398 + .help = "disable\tdo not activate plugin\n",
121399 +};
121400 +
121401 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
121402 +{
121403 + *no_add_attrs = true;
121404 +
121405 + // check for types? for now accept everything linux has to offer
121406 + if (TREE_CODE(*node) != FIELD_DECL)
121407 + return NULL_TREE;
121408 +
121409 + *no_add_attrs = false;
121410 + return NULL_TREE;
121411 +}
121412 +
121413 +static struct attribute_spec user_attr = {
121414 + .name = "user",
121415 + .min_length = 0,
121416 + .max_length = 0,
121417 + .decl_required = false,
121418 + .type_required = false,
121419 + .function_type_required = false,
121420 + .handler = handle_user_attribute,
121421 +#if BUILDING_GCC_VERSION >= 4007
121422 + .affects_type_identity = true
121423 +#endif
121424 +};
121425 +
121426 +static void register_attributes(void *event_data, void *data)
121427 +{
121428 + register_attribute(&user_attr);
121429 +// register_attribute(&force_attr);
121430 +}
121431 +
121432 +static tree get_field_type(tree field)
121433 +{
121434 + return strip_array_types(TREE_TYPE(field));
121435 +}
121436 +
121437 +static bool is_userspace_type(tree type)
121438 +{
121439 + tree field;
121440 +
121441 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
121442 + tree fieldtype = get_field_type(field);
121443 + enum tree_code code = TREE_CODE(fieldtype);
121444 +
121445 + if (code == RECORD_TYPE || code == UNION_TYPE)
121446 + if (is_userspace_type(fieldtype))
121447 + return true;
121448 +
121449 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
121450 + return true;
121451 + }
121452 + return false;
121453 +}
121454 +
121455 +static void finish_type(void *event_data, void *data)
121456 +{
121457 + tree type = (tree)event_data;
121458 +
121459 + if (TYPE_USERSPACE(type))
121460 + return;
121461 +
121462 + if (is_userspace_type(type))
121463 + TYPE_USERSPACE(type) = 1;
121464 +}
121465 +
121466 +static void initialize(tree var)
121467 +{
121468 + basic_block bb;
121469 + gimple_stmt_iterator gsi;
121470 + tree initializer;
121471 + gimple init_stmt;
121472 +
121473 + // this is the original entry bb before the forced split
121474 + // TODO: check further BBs in case more splits occured before us
121475 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
121476 +
121477 + // first check if the variable is already initialized, warn otherwise
121478 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121479 + gimple stmt = gsi_stmt(gsi);
121480 + tree rhs1;
121481 +
121482 + // we're looking for an assignment of a single rhs...
121483 + if (!gimple_assign_single_p(stmt))
121484 + continue;
121485 + rhs1 = gimple_assign_rhs1(stmt);
121486 +#if BUILDING_GCC_VERSION >= 4007
121487 + // ... of a non-clobbering expression...
121488 + if (TREE_CLOBBER_P(rhs1))
121489 + continue;
121490 +#endif
121491 + // ... to our variable...
121492 + if (gimple_get_lhs(stmt) != var)
121493 + continue;
121494 + // if it's an initializer then we're good
121495 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
121496 + return;
121497 + }
121498 +
121499 + // these aren't the 0days you're looking for
121500 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
121501 +
121502 + // build the initializer expression
121503 + initializer = build_constructor(TREE_TYPE(var), NULL);
121504 +
121505 + // build the initializer stmt
121506 + init_stmt = gimple_build_assign(var, initializer);
121507 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
121508 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
121509 + update_stmt(init_stmt);
121510 +}
121511 +
121512 +static unsigned int handle_function(void)
121513 +{
121514 + basic_block bb;
121515 + unsigned int ret = 0;
121516 + tree var;
121517 + unsigned int i;
121518 +
121519 + // split the first bb where we can put the forced initializers
121520 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121521 + if (dom_info_available_p(CDI_DOMINATORS))
121522 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121523 +
121524 + // enumarate all local variables and forcibly initialize our targets
121525 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
121526 + tree type = TREE_TYPE(var);
121527 +
121528 + gcc_assert(DECL_P(var));
121529 + if (!auto_var_in_fn_p(var, current_function_decl))
121530 + continue;
121531 +
121532 + // only care about structure types
121533 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
121534 + continue;
121535 +
121536 + // if the type is of interest, examine the variable
121537 + if (TYPE_USERSPACE(type))
121538 + initialize(var);
121539 + }
121540 +
121541 + return ret;
121542 +}
121543 +
121544 +#if BUILDING_GCC_VERSION >= 4009
121545 +static const struct pass_data structleak_pass_data = {
121546 +#else
121547 +static struct gimple_opt_pass structleak_pass = {
121548 + .pass = {
121549 +#endif
121550 + .type = GIMPLE_PASS,
121551 + .name = "structleak",
121552 +#if BUILDING_GCC_VERSION >= 4008
121553 + .optinfo_flags = OPTGROUP_NONE,
121554 +#endif
121555 +#if BUILDING_GCC_VERSION >= 4009
121556 + .has_gate = false,
121557 + .has_execute = true,
121558 +#else
121559 + .gate = NULL,
121560 + .execute = handle_function,
121561 + .sub = NULL,
121562 + .next = NULL,
121563 + .static_pass_number = 0,
121564 +#endif
121565 + .tv_id = TV_NONE,
121566 + .properties_required = PROP_cfg,
121567 + .properties_provided = 0,
121568 + .properties_destroyed = 0,
121569 + .todo_flags_start = 0,
121570 + .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
121571 +#if BUILDING_GCC_VERSION < 4009
121572 + }
121573 +#endif
121574 +};
121575 +
121576 +#if BUILDING_GCC_VERSION >= 4009
121577 +namespace {
121578 +class structleak_pass : public gimple_opt_pass {
121579 +public:
121580 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
121581 + unsigned int execute() { return handle_function(); }
121582 +};
121583 +}
121584 +
121585 +static opt_pass *make_structleak_pass(void)
121586 +{
121587 + return new structleak_pass();
121588 +}
121589 +#else
121590 +static struct opt_pass *make_structleak_pass(void)
121591 +{
121592 + return &structleak_pass.pass;
121593 +}
121594 +#endif
121595 +
121596 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121597 +{
121598 + int i;
121599 + const char * const plugin_name = plugin_info->base_name;
121600 + const int argc = plugin_info->argc;
121601 + const struct plugin_argument * const argv = plugin_info->argv;
121602 + bool enable = true;
121603 + struct register_pass_info structleak_pass_info;
121604 +
121605 + structleak_pass_info.pass = make_structleak_pass();
121606 + structleak_pass_info.reference_pass_name = "ssa";
121607 + structleak_pass_info.ref_pass_instance_number = 1;
121608 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121609 +
121610 + if (!plugin_default_version_check(version, &gcc_version)) {
121611 + error(G_("incompatible gcc/plugin versions"));
121612 + return 1;
121613 + }
121614 +
121615 + if (strcmp(lang_hooks.name, "GNU C")) {
121616 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
121617 + enable = false;
121618 + }
121619 +
121620 + for (i = 0; i < argc; ++i) {
121621 + if (!strcmp(argv[i].key, "disable")) {
121622 + enable = false;
121623 + continue;
121624 + }
121625 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121626 + }
121627 +
121628 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
121629 + if (enable) {
121630 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
121631 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
121632 + }
121633 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
121634 +
121635 + return 0;
121636 +}
121637 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
121638 index fbc6665..5e9ce79 100644
121639 --- a/tools/include/linux/compiler.h
121640 +++ b/tools/include/linux/compiler.h
121641 @@ -35,4 +35,12 @@
121642 # define unlikely(x) __builtin_expect(!!(x), 0)
121643 #endif
121644
121645 +#ifndef __size_overflow
121646 +# define __size_overflow(...)
121647 +#endif
121648 +
121649 +#ifndef __intentional_overflow
121650 +# define __intentional_overflow(...)
121651 +#endif
121652 +
121653 #endif /* _TOOLS_LINUX_COMPILER_H */
121654 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
121655 index ce00f7e..0aca5e4 100644
121656 --- a/tools/lib/api/Makefile
121657 +++ b/tools/lib/api/Makefile
121658 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
121659
121660 LIBFILE = libapikfs.a
121661
121662 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121663 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121664 EXTLIBS = -lelf -lpthread -lrt -lm
121665 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
121666 ALL_LDFLAGS = $(LDFLAGS)
121667 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
121668 index 6789d788..4afd019e 100644
121669 --- a/tools/perf/util/include/asm/alternative-asm.h
121670 +++ b/tools/perf/util/include/asm/alternative-asm.h
121671 @@ -5,4 +5,7 @@
121672
121673 #define altinstruction_entry #
121674
121675 + .macro pax_force_retaddr rip=0, reload=0
121676 + .endm
121677 +
121678 #endif
121679 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
121680 index 0a578fe..b81f62d 100644
121681 --- a/tools/virtio/linux/uaccess.h
121682 +++ b/tools/virtio/linux/uaccess.h
121683 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
121684 ({ \
121685 typeof(ptr) __pu_ptr = (ptr); \
121686 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
121687 - ACCESS_ONCE(*(__pu_ptr)) = x; \
121688 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
121689 0; \
121690 })
121691
121692 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
121693 index 56baae8..2c889c2 100644
121694 --- a/virt/kvm/kvm_main.c
121695 +++ b/virt/kvm/kvm_main.c
121696 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
121697
121698 static cpumask_var_t cpus_hardware_enabled;
121699 static int kvm_usage_count = 0;
121700 -static atomic_t hardware_enable_failed;
121701 +static atomic_unchecked_t hardware_enable_failed;
121702
121703 struct kmem_cache *kvm_vcpu_cache;
121704 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
121705
121706 -static __read_mostly struct preempt_ops kvm_preempt_ops;
121707 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
121708 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
121709 +static struct preempt_ops kvm_preempt_ops = {
121710 + .sched_in = kvm_sched_in,
121711 + .sched_out = kvm_sched_out,
121712 +};
121713
121714 struct dentry *kvm_debugfs_dir;
121715
121716 @@ -755,7 +760,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
121717 /* We can read the guest memory with __xxx_user() later on. */
121718 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
121719 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
121720 - !access_ok(VERIFY_WRITE,
121721 + !access_ok_noprefault(VERIFY_WRITE,
121722 (void __user *)(unsigned long)mem->userspace_addr,
121723 mem->memory_size)))
121724 goto out;
121725 @@ -1612,9 +1617,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
121726
121727 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
121728 {
121729 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
121730 + int r;
121731 + unsigned long addr;
121732
121733 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
121734 + addr = gfn_to_hva(kvm, gfn);
121735 + if (kvm_is_error_hva(addr))
121736 + return -EFAULT;
121737 + r = __clear_user((void __user *)addr + offset, len);
121738 + if (r)
121739 + return -EFAULT;
121740 + mark_page_dirty(kvm, gfn);
121741 + return 0;
121742 }
121743 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
121744
121745 @@ -1864,7 +1877,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
121746 return 0;
121747 }
121748
121749 -static struct file_operations kvm_vcpu_fops = {
121750 +static file_operations_no_const kvm_vcpu_fops __read_only = {
121751 .release = kvm_vcpu_release,
121752 .unlocked_ioctl = kvm_vcpu_ioctl,
121753 #ifdef CONFIG_COMPAT
121754 @@ -2534,7 +2547,7 @@ out:
121755 }
121756 #endif
121757
121758 -static struct file_operations kvm_vm_fops = {
121759 +static file_operations_no_const kvm_vm_fops __read_only = {
121760 .release = kvm_vm_release,
121761 .unlocked_ioctl = kvm_vm_ioctl,
121762 #ifdef CONFIG_COMPAT
121763 @@ -2634,7 +2647,7 @@ out:
121764 return r;
121765 }
121766
121767 -static struct file_operations kvm_chardev_ops = {
121768 +static file_operations_no_const kvm_chardev_ops __read_only = {
121769 .unlocked_ioctl = kvm_dev_ioctl,
121770 .compat_ioctl = kvm_dev_ioctl,
121771 .llseek = noop_llseek,
121772 @@ -2660,7 +2673,7 @@ static void hardware_enable_nolock(void *junk)
121773
121774 if (r) {
121775 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
121776 - atomic_inc(&hardware_enable_failed);
121777 + atomic_inc_unchecked(&hardware_enable_failed);
121778 printk(KERN_INFO "kvm: enabling virtualization on "
121779 "CPU%d failed\n", cpu);
121780 }
121781 @@ -2716,10 +2729,10 @@ static int hardware_enable_all(void)
121782
121783 kvm_usage_count++;
121784 if (kvm_usage_count == 1) {
121785 - atomic_set(&hardware_enable_failed, 0);
121786 + atomic_set_unchecked(&hardware_enable_failed, 0);
121787 on_each_cpu(hardware_enable_nolock, NULL, 1);
121788
121789 - if (atomic_read(&hardware_enable_failed)) {
121790 + if (atomic_read_unchecked(&hardware_enable_failed)) {
121791 hardware_disable_all_nolock();
121792 r = -EBUSY;
121793 }
121794 @@ -3123,7 +3136,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
121795 kvm_arch_vcpu_put(vcpu);
121796 }
121797
121798 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121799 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121800 struct module *module)
121801 {
121802 int r;
121803 @@ -3170,7 +3183,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121804 if (!vcpu_align)
121805 vcpu_align = __alignof__(struct kvm_vcpu);
121806 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
121807 - 0, NULL);
121808 + SLAB_USERCOPY, NULL);
121809 if (!kvm_vcpu_cache) {
121810 r = -ENOMEM;
121811 goto out_free_3;
121812 @@ -3180,9 +3193,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121813 if (r)
121814 goto out_free;
121815
121816 + pax_open_kernel();
121817 kvm_chardev_ops.owner = module;
121818 kvm_vm_fops.owner = module;
121819 kvm_vcpu_fops.owner = module;
121820 + pax_close_kernel();
121821
121822 r = misc_register(&kvm_dev);
121823 if (r) {
121824 @@ -3192,9 +3207,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121825
121826 register_syscore_ops(&kvm_syscore_ops);
121827
121828 - kvm_preempt_ops.sched_in = kvm_sched_in;
121829 - kvm_preempt_ops.sched_out = kvm_sched_out;
121830 -
121831 r = kvm_init_debug();
121832 if (r) {
121833 printk(KERN_ERR "kvm: create debugfs files failed\n");